@Test public void test() throws ApiSenderException { PrimaryStorageInventory local = deployer.primaryStorages.get("local"); VmInstanceInventory vm1 = deployer.vms.get("TestVm"); VmInstanceInventory vm2 = deployer.vms.get("TestVm1"); DiskOfferingInventory dof = deployer.diskOfferings.get("TestDiskOffering1"); VolumeInventory data = api.createDataVolume("data", dof.getUuid()); data = api.attachVolumeToVm(vm1.getUuid(), data.getUuid()); data = api.detachVolumeFromVm(data.getUuid()); List<VmInstanceInventory> vms = api.getDataVolumeCandidateVmForAttaching(data.getUuid()); Assert.assertEquals(1, vms.size()); api.localStorageMigrateVolume(data.getUuid(), vm2.getHostUuid(), null); vms = api.getDataVolumeCandidateVmForAttaching(data.getUuid()); Assert.assertEquals(1, vms.size()); Assert.assertEquals(vm2.getUuid(), vms.get(0).getUuid()); List<VolumeInventory> vols = api.getVmAttachableVolume(vm2.getUuid()); Assert.assertEquals(1, vols.size()); Assert.assertEquals(data.getUuid(), vols.get(0).getUuid()); vols = api.getVmAttachableVolume(vm1.getUuid()); Assert.assertEquals(0, vols.size()); api.localStorageMigrateVolume(data.getUuid(), vm1.getHostUuid(), null); vols = api.getVmAttachableVolume(vm1.getUuid()); Assert.assertEquals(1, vols.size()); Assert.assertEquals(data.getUuid(), vols.get(0).getUuid()); vols = api.getVmAttachableVolume(vm2.getUuid()); Assert.assertEquals(0, vols.size()); }
@Test public void test() throws ApiSenderException { VmInstanceInventory vm = deployer.vms.get("TestVm"); api.stopVmInstance(vm.getUuid()); PrimaryStorageInventory local = deployer.primaryStorages.get("local"); VolumeSnapshotInventory sp = api.createSnapshot(vm.getRootVolumeUuid()); Assert.assertFalse(kconfig.snapshotCmds.isEmpty()); LocalStorageResourceRefVO ref = dbf.findByUuid(sp.getUuid(), LocalStorageResourceRefVO.class); Assert.assertNotNull(ref); Assert.assertEquals(vm.getHostUuid(), ref.getHostUuid()); sp = api.createSnapshot(vm.getRootVolumeUuid()); ref = dbf.findByUuid(sp.getUuid(), LocalStorageResourceRefVO.class); Assert.assertNotNull(ref); Assert.assertEquals(vm.getHostUuid(), ref.getHostUuid()); sp = api.createSnapshot(vm.getRootVolumeUuid()); ref = dbf.findByUuid(sp.getUuid(), LocalStorageResourceRefVO.class); Assert.assertNotNull(ref); Assert.assertEquals(vm.getHostUuid(), ref.getHostUuid()); PrimaryStorageVO localvo = dbf.findByUuid(local.getUuid(), PrimaryStorageVO.class); long avail = localvo.getCapacity().getAvailableCapacity(); ImageInventory img = api.createTemplateFromSnapshot(sp.getUuid()); Assert.assertTrue(img.getSize() != 0); localvo = dbf.findByUuid(local.getUuid(), PrimaryStorageVO.class); Assert.assertEquals(avail, localvo.getCapacity().getAvailableCapacity()); }
@Test public void test() throws ApiSenderException, InterruptedException { VmInstanceInventory vm1 = deployer.vms.get("TestVm1"); VmInstanceInventory vm2 = deployer.vms.get("TestVm2"); api.setVmHaLevel(vm1.getUuid(), VmHaLevel.NeverStop, null); api.setVmHaLevel(vm2.getUuid(), VmHaLevel.OnHostFailure, null); api.maintainHost(vm1.getHostUuid()); HostInventory host2 = deployer.hosts.get("host2"); VmInstanceVO vmvo1 = dbf.findByUuid(vm1.getUuid(), VmInstanceVO.class); VmInstanceVO vmvo2 = dbf.findByUuid(vm2.getUuid(), VmInstanceVO.class); Assert.assertEquals(VmInstanceState.Running, vmvo1.getState()); Assert.assertEquals(host2.getUuid(), vmvo1.getHostUuid()); Assert.assertEquals(VmInstanceState.Stopped, vmvo2.getState()); }
@Test public void test() throws ApiSenderException { L3NetworkInventory l3 = deployer.l3Networks.get("l3Network1"); InstanceOfferingInventory instanceOffering = deployer.instanceOfferings.get("instanceOffering512M512HZ"); ImageInventory imageInventory = deployer.images.get("image1"); ZoneInventory zone1 = deployer.zones.get("zone1"); VmCreator creator = new VmCreator(); creator.addL3Network(l3.getUuid()); creator.imageUuid = imageInventory.getUuid(); creator.instanceOfferingUuid = instanceOffering.getUuid(); creator.zoneUuid = zone1.getUuid(); VmInstanceInventory vm = creator.create(); HostCapacityVO cvo = dbf.findByUuid(vm.getHostUuid(), HostCapacityVO.class); Assert.assertEquals(instanceOffering.getCpuNum(), cvo.getUsedCpu()); Assert.assertEquals(instanceOffering.getMemorySize(), cvo.getUsedMemory()); Assert.assertEquals(zone1.getUuid(), vm.getZoneUuid()); }