Search in sources :

Example 1 with LibvirtComputingResource

use of com.cloud.hypervisor.kvm.resource.LibvirtComputingResource in project cloudstack by apache.

the class LibvirtMigrateCommandWrapperTest method testMigrationUri.

@Test
public void testMigrationUri() {
    final String ip = "10.1.1.1";
    LibvirtComputingResource lcr = new LibvirtComputingResource();
    if (lcr.isHostSecured()) {
        assertEquals(libvirtMigrateCmdWrapper.createMigrationURI(ip, lcr), String.format("qemu+tls://%s/system", ip));
    } else {
        assertEquals(libvirtMigrateCmdWrapper.createMigrationURI(ip, lcr), String.format("qemu+tcp://%s/system", ip));
    }
}
Also used : LibvirtComputingResource(com.cloud.hypervisor.kvm.resource.LibvirtComputingResource) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with LibvirtComputingResource

use of com.cloud.hypervisor.kvm.resource.LibvirtComputingResource in project cloudstack by apache.

the class LibvirtMigrateCommandWrapperTest method deleteOrDisconnectDisksOnSourcePoolTest.

@Test
public void deleteOrDisconnectDisksOnSourcePoolTest() {
    LibvirtMigrateCommandWrapper spyLibvirtMigrateCmdWrapper = PowerMockito.spy(libvirtMigrateCmdWrapper);
    Mockito.doNothing().when(spyLibvirtMigrateCmdWrapper).deleteLocalVolume("volPath");
    List<MigrateDiskInfo> migrateDiskInfoList = new ArrayList<>();
    MigrateDiskInfo migrateDiskInfo0 = createMigrateDiskInfo(true);
    MigrateDiskInfo migrateDiskInfo2 = createMigrateDiskInfo(false);
    List<DiskDef> disks = new ArrayList<>();
    DiskDef diskDef0 = new DiskDef();
    DiskDef diskDef1 = new DiskDef();
    DiskDef diskDef2 = new DiskDef();
    diskDef0.setDiskPath("volPath");
    disks.add(diskDef0);
    disks.add(diskDef1);
    disks.add(diskDef2);
    LibvirtComputingResource libvirtComputingResource = Mockito.spy(new LibvirtComputingResource());
    Mockito.doReturn(true).when(libvirtComputingResource).cleanupDisk(diskDef1);
    Mockito.doReturn(migrateDiskInfo0).when(spyLibvirtMigrateCmdWrapper).searchDiskDefOnMigrateDiskInfoList(migrateDiskInfoList, diskDef0);
    Mockito.doReturn(null).when(spyLibvirtMigrateCmdWrapper).searchDiskDefOnMigrateDiskInfoList(migrateDiskInfoList, diskDef1);
    Mockito.doReturn(migrateDiskInfo2).when(spyLibvirtMigrateCmdWrapper).searchDiskDefOnMigrateDiskInfoList(migrateDiskInfoList, diskDef2);
    spyLibvirtMigrateCmdWrapper.deleteOrDisconnectDisksOnSourcePool(libvirtComputingResource, migrateDiskInfoList, disks);
    InOrder inOrder = Mockito.inOrder(spyLibvirtMigrateCmdWrapper, libvirtComputingResource);
    inOrderVerifyDeleteOrDisconnect(inOrder, spyLibvirtMigrateCmdWrapper, libvirtComputingResource, migrateDiskInfoList, diskDef0, 1, 0);
    inOrderVerifyDeleteOrDisconnect(inOrder, spyLibvirtMigrateCmdWrapper, libvirtComputingResource, migrateDiskInfoList, diskDef1, 0, 1);
    inOrderVerifyDeleteOrDisconnect(inOrder, spyLibvirtMigrateCmdWrapper, libvirtComputingResource, migrateDiskInfoList, diskDef2, 0, 1);
}
Also used : DiskDef(com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef) InOrder(org.mockito.InOrder) ArrayList(java.util.ArrayList) LibvirtComputingResource(com.cloud.hypervisor.kvm.resource.LibvirtComputingResource) MigrateDiskInfo(com.cloud.agent.api.MigrateCommand.MigrateDiskInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with LibvirtComputingResource

use of com.cloud.hypervisor.kvm.resource.LibvirtComputingResource in project cloudstack by apache.

the class LibvirtReplugNicCommandWrapperTest method setUp.

@Before
public void setUp() throws Exception {
    Scanner scanner = new Scanner(memInfo);
    PowerMockito.whenNew(Scanner.class).withAnyArguments().thenReturn(scanner);
    // Use a spy because we only want to override getVifDriverClass
    LibvirtComputingResource resReal = new LibvirtComputingResource();
    res = spy(resReal);
    Connect conn = mock(Connect.class);
    LibvirtUtilitiesHelper helper = mock(LibvirtUtilitiesHelper.class);
    when(_domain.getXMLDesc(0)).thenReturn(fullfile).thenReturn(part_1 + part_3);
    when(conn.domainLookupByName(anyString())).thenReturn(_domain);
    when(helper.getConnectionByVmName(anyString())).thenReturn(conn);
    PowerMockito.mockStatic(Script.class);
    BDDMockito.given(Script.findScript(anyString(), anyString())).willReturn("dummypath/tofile.sh");
    Map<String, String> pifs = new HashMap<>();
    pifs.put(GUEST_BR, "eth0");
    Map<String, Object> params = new HashMap<>();
    params.put("libvirt.computing.resource", res);
    params.put("libvirt.host.pifs", pifs);
    BridgeVifDriver bridgeVifDriver = spy(new BridgeVifDriver());
    OvsVifDriver ovsVifDriver = spy(new OvsVifDriver());
    doNothing().when(bridgeVifDriver).getPifs();
    doNothing().when(ovsVifDriver).getPifs();
    doReturn(helper).when(res).getLibvirtUtilitiesHelper();
    doReturn(bridgeVifDriver).when(res).getVifDriver(eq(Networks.TrafficType.Guest), anyString());
    doReturn(ovsVifDriver).when(res).getVifDriver(Networks.TrafficType.Guest, GUEST_BR);
    doReturn(bridgeVifDriver).when(res).getVifDriver(not(eq(Networks.TrafficType.Guest)));
    doReturn(Arrays.asList(bridgeVifDriver, ovsVifDriver)).when(res).getAllVifDrivers();
    bridgeVifDriver.configure(params);
    ovsVifDriver.configure(params);
}
Also used : Scanner(java.util.Scanner) HashMap(java.util.HashMap) Connect(org.libvirt.Connect) LibvirtComputingResource(com.cloud.hypervisor.kvm.resource.LibvirtComputingResource) BridgeVifDriver(com.cloud.hypervisor.kvm.resource.BridgeVifDriver) Matchers.anyString(org.mockito.Matchers.anyString) OvsVifDriver(com.cloud.hypervisor.kvm.resource.OvsVifDriver) Before(org.junit.Before)

Example 4 with LibvirtComputingResource

use of com.cloud.hypervisor.kvm.resource.LibvirtComputingResource in project cloudstack by apache.

the class LibvirtNetworkElementCommandWrapperTest method setUp.

@Before
public void setUp() throws Exception {
    Scanner scanner = new Scanner(memInfo);
    PowerMockito.whenNew(Scanner.class).withAnyArguments().thenReturn(scanner);
    // Use a spy because we only want to override getVifDriverClass
    LibvirtComputingResource resReal = new LibvirtComputingResource() {

        {
            _linkLocalBridgeName = "cloud0";
            _guestBridgeName = "guestbr";
            _publicBridgeName = "publicbr";
            _privBridgeName = "mgmtbr";
        }
    };
    res = spy(resReal);
    Connect conn = mock(Connect.class);
    LibvirtUtilitiesHelper helper = mock(LibvirtUtilitiesHelper.class);
    when(_domain.getXMLDesc(0)).thenReturn(fullfile);
    when(conn.domainLookupByName(nullable(String.class))).thenReturn(_domain);
    when(helper.getConnectionByVmName(nullable(String.class))).thenReturn(conn);
    doReturn(helper).when(res).getLibvirtUtilitiesHelper();
}
Also used : Scanner(java.util.Scanner) Connect(org.libvirt.Connect) LibvirtComputingResource(com.cloud.hypervisor.kvm.resource.LibvirtComputingResource) Before(org.junit.Before)

Example 5 with LibvirtComputingResource

use of com.cloud.hypervisor.kvm.resource.LibvirtComputingResource in project cloudstack by apache.

the class DirectAgentManagerSimpleImpl method loadResource.

protected void loadResource(Long hostId) {
    HostVO host = hostDao.findById(hostId);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("guid", host.getGuid());
    params.put("ipaddress", host.getPrivateIpAddress());
    params.put("username", "root");
    params.put("password", "password");
    params.put("zone", String.valueOf(host.getDataCenterId()));
    params.put("pod", String.valueOf(host.getPodId()));
    ServerResource resource = null;
    if (host.getHypervisorType() == HypervisorType.XenServer) {
        resource = new XcpOssResource();
        try {
            resource.configure(host.getName(), params);
        } catch (ConfigurationException e) {
            logger.debug("Failed to load resource:" + e.toString());
        }
    } else if (host.getHypervisorType() == HypervisorType.KVM) {
        resource = new LibvirtComputingResource();
        try {
            params.put("public.network.device", "cloudbr0");
            params.put("private.network.device", "cloudbr0");
            resource.configure(host.getName(), params);
        } catch (ConfigurationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else if (host.getHypervisorType() == HypervisorType.VMware) {
        ClusterVO cluster = clusterDao.findById(host.getClusterId());
        String url = clusterDetailsDao.findDetail(cluster.getId(), "url").getValue();
        URI uri;
        try {
            uri = new URI(url);
            String userName = clusterDetailsDao.findDetail(cluster.getId(), "username").getValue();
            String password = clusterDetailsDao.findDetail(cluster.getId(), "password").getValue();
            VmwareServerDiscoverer discover = new VmwareServerDiscoverer();
            Map<? extends ServerResource, Map<String, String>> resources = discover.find(host.getDataCenterId(), host.getPodId(), host.getClusterId(), uri, userName, password, null);
            for (Map.Entry<? extends ServerResource, Map<String, String>> entry : resources.entrySet()) {
                resource = entry.getKey();
            }
            if (resource == null) {
                throw new CloudRuntimeException("can't find resource");
            }
        } catch (DiscoveryException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    hostResourcesMap.put(hostId, resource);
    HostEnvironment env = new HostEnvironment();
    SetupCommand cmd = new SetupCommand(env);
    cmd.setNeedSetup(true);
    resource.executeRequest(cmd);
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) HashMap(java.util.HashMap) ServerResource(com.cloud.resource.ServerResource) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) VmwareServerDiscoverer(com.cloud.hypervisor.vmware.VmwareServerDiscoverer) HostEnvironment(com.cloud.host.HostEnvironment) SetupCommand(com.cloud.agent.api.SetupCommand) HostVO(com.cloud.host.HostVO) XcpOssResource(com.cloud.hypervisor.xenserver.resource.XcpOssResource) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) LibvirtComputingResource(com.cloud.hypervisor.kvm.resource.LibvirtComputingResource) HashMap(java.util.HashMap) Map(java.util.Map) DiscoveryException(com.cloud.exception.DiscoveryException)

Aggregations

LibvirtComputingResource (com.cloud.hypervisor.kvm.resource.LibvirtComputingResource)5 HashMap (java.util.HashMap)2 Scanner (java.util.Scanner)2 Before (org.junit.Before)2 Test (org.junit.Test)2 Connect (org.libvirt.Connect)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 MigrateDiskInfo (com.cloud.agent.api.MigrateCommand.MigrateDiskInfo)1 SetupCommand (com.cloud.agent.api.SetupCommand)1 ClusterVO (com.cloud.dc.ClusterVO)1 DiscoveryException (com.cloud.exception.DiscoveryException)1 HostEnvironment (com.cloud.host.HostEnvironment)1 HostVO (com.cloud.host.HostVO)1 BridgeVifDriver (com.cloud.hypervisor.kvm.resource.BridgeVifDriver)1 DiskDef (com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef)1 OvsVifDriver (com.cloud.hypervisor.kvm.resource.OvsVifDriver)1 VmwareServerDiscoverer (com.cloud.hypervisor.vmware.VmwareServerDiscoverer)1 XcpOssResource (com.cloud.hypervisor.xenserver.resource.XcpOssResource)1 ServerResource (com.cloud.resource.ServerResource)1 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)1