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));
}
}
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);
}
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);
}
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();
}
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);
}
Aggregations