@Test public void test() throws ApiSenderException { EipInventory eip = deployer.eips.get("eip"); VmInstanceInventory vm = deployer.vms.get("TestVm"); VmNicInventory nic = vm.getVmNics().get(0); IpRangeInventory ipr = deployer.ipRanges.get("GuestIpRange"); String newIp = null; long s = NetworkUtils.ipv4StringToLong(ipr.getStartIp()); long e = NetworkUtils.ipv4StringToLong(ipr.getEndIp()); for (long l = s; s < e; s++) { String ip = NetworkUtils.longToIpv4String(l); if (!ip.equals(nic.getIp())) { newIp = ip; break; } } Assert.assertNotNull(newIp); api.stopVmInstance(vm.getUuid()); api.setStaticIp(vm.getUuid(), nic.getL3NetworkUuid(), newIp); EipVO eipvo = dbf.findByUuid(eip.getUuid(), EipVO.class); Assert.assertEquals(newIp, eipvo.getGuestIp()); }
@Test public void test() throws ApiSenderException, InterruptedException { ImageInventory img = deployer.images.get("TestImage"); VmInstanceInventory vm = deployer.vms.get("TestVm"); api.deleteImage(img.getUuid()); api.stopVmInstance(vm.getUuid()); api.startVmInstance(vm.getUuid()); api.rebootVmInstance(vm.getUuid()); api.destroyVmInstance(vm.getUuid()); }
@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()); }
@Override @Transactional( readOnly = true, noRollbackForClassName = {"org.zstack.header.errorcode.OperationFailureException"}) public void preVmMigration(VmInstanceInventory vm) { List<String> volUuids = CollectionUtils.transformToList( vm.getAllVolumes(), new Function<String, VolumeInventory>() { @Override public String call(VolumeInventory arg) { return arg.getUuid(); } }); String sql = "select count(ps) from PrimaryStorageVO ps, VolumeVO vol where ps.uuid = vol.primaryStorageUuid and" + " vol.uuid in (:volUuids) and ps.type = :ptype"; TypedQuery<Long> q = dbf.getEntityManager().createQuery(sql, Long.class); q.setParameter("volUuids", volUuids); q.setParameter("ptype", LocalStorageConstants.LOCAL_STORAGE_TYPE); q.setMaxResults(1); Long count = q.getSingleResult(); if (count > 0) { throw new OperationFailureException( errf.stringToOperationError( String.format( "unable to live migrate with local storage. The vm[uuid:%s] has volumes on local storage," + "to protect your data, please stop the vm and do the volume migration", vm.getUuid()))); } }
@Override @Transactional(readOnly = true) public void preRecoverVm(VmInstanceInventory vm) { String rootVolUuid = vm.getRootVolumeUuid(); String sql = "select ps.uuid from PrimaryStorageVO ps, VolumeVO vol where ps.uuid = vol.primaryStorageUuid" + " and vol.uuid = :uuid and ps.type = :pstype"; TypedQuery<String> q = dbf.getEntityManager().createQuery(sql, String.class); q.setParameter("uuid", rootVolUuid); q.setParameter("pstype", LocalStorageConstants.LOCAL_STORAGE_TYPE); String psuuid = dbf.find(q); if (psuuid == null) { return; } sql = "select count(ref) from LocalStorageResourceRefVO ref where ref.resourceUuid = :uuid and ref.resourceType = :rtype"; TypedQuery<Long> rq = dbf.getEntityManager().createQuery(sql, Long.class); rq.setParameter("uuid", rootVolUuid); rq.setParameter("rtype", VolumeVO.class.getSimpleName()); long count = rq.getSingleResult(); if (count == 0) { throw new OperationFailureException( errf.stringToOperationError( String.format( "unable to recover the vm[uuid:%s, name:%s]. The vm's root volume is on the local" + " storage[uuid:%s]; however, the host on which the root volume is has been deleted", vm.getUuid(), vm.getName(), psuuid))); } }
@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()); }
@Override protected FlowChain getStartVmWorkFlowChain(VmInstanceInventory inv) { FlowChain chain = super.getStartVmWorkFlowChain(inv); chain.setName(String.format("start-appliancevm-%s", inv.getUuid())); chain.insert( new Flow() { String __name__ = "change-appliancevm-status-to-connecting"; ApplianceVmStatus originStatus = getSelf().getStatus(); @Override public void run(FlowTrigger trigger, Map data) { getSelf().setStatus(ApplianceVmStatus.Connecting); self = dbf.updateAndRefresh(self); trigger.next(); } @Override public void rollback(FlowTrigger trigger, Map data) { self = dbf.reload(self); getSelf().setStatus(originStatus); self = dbf.updateAndRefresh(self); trigger.rollback(); } }); prepareLifeCycleInfo(chain); prepareFirewallInfo(chain); addBootstrapFlows(chain, HypervisorType.valueOf(inv.getHypervisorType())); List<Flow> subStartFlows = getPostStartFlows(); if (subStartFlows != null) { for (Flow f : subStartFlows) { chain.then(f); } } chain.then( new NoRollbackFlow() { String __name__ = "change-appliancevm-status-to-connected"; @Override public void run(FlowTrigger trigger, Map data) { getSelf().setStatus(ApplianceVmStatus.Connected); self = dbf.updateAndRefresh(self); trigger.next(); } }); boolean noRollbackOnFailure = ApplianceVmGlobalProperty.NO_ROLLBACK_ON_POST_FAILURE; chain.noRollback(noRollbackOnFailure); return chain; }
@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 { final L3NetworkInventory l3 = deployer.l3Networks.get("TestL3Network4"); VmInstanceInventory vm = deployer.vms.get("TestVm"); vm = api.attachNic(vm.getUuid(), l3.getUuid()); Assert.assertEquals(4, vm.getVmNics().size()); VmNicInventory nic = vm.getVmNics().get(0); vm = api.detachNic(nic.getUuid()); Assert.assertEquals(3, vm.getVmNics().size()); Assert.assertFalse(config.detachNicCommands.isEmpty()); String l3Uuid = nic.getL3NetworkUuid(); nic = vm.findNic(l3Uuid); Assert.assertNull(nic); api.stopVmInstance(vm.getUuid()); vm = api.startVmInstance(vm.getUuid()); Assert.assertEquals(3, vm.getVmNics().size()); nic = vm.findNic(l3Uuid); Assert.assertNull(nic); }
@Test public void test() throws ApiSenderException { VmInstanceInventory vm = deployer.vms.get("TestVm"); ClusterInventory cluster1 = deployer.clusters.get("Cluster1"); HostInventory host1 = deployer.hosts.get("host1"); ClusterInventory cluster2 = deployer.clusters.get("Cluster2"); HostInventory host2 = deployer.hosts.get("host2"); boolean s = false; try { // vm is running, failure api.getVmStartingCandidateHosts(vm.getUuid(), null); } catch (ApiSenderException e) { s = true; } Assert.assertTrue(s); api.stopVmInstance(vm.getUuid()); APIGetVmStartingCandidateClustersHostsReply reply = api.getVmStartingCandidateHosts(vm.getUuid(), null); Assert.assertEquals(2, reply.getClusterInventories().size()); Assert.assertEquals(2, reply.getHostInventories().size()); }
@Override protected FlowChain getMigrateVmWorkFlowChain(VmInstanceInventory inv) { FlowChain chain = super.getMigrateVmWorkFlowChain(inv); chain.setName(String.format("migrate-appliancevm-%s", inv.getUuid())); prepareLifeCycleInfo(chain); prepareFirewallInfo(chain); List<Flow> subMigrateFlows = getPostMigrateFlows(); if (subMigrateFlows != null) { for (Flow f : subMigrateFlows) { chain.then(f); } } boolean noRollbackOnFailure = ApplianceVmGlobalProperty.NO_ROLLBACK_ON_POST_FAILURE; chain.noRollback(noRollbackOnFailure); return chain; }
@Test public void test() throws ApiSenderException { VmInstanceInventory vm = deployer.vms.get("TestVm"); api.stopVmInstance(vm.getUuid()); String rootVolumeUuid = vm.getRootVolumeUuid(); VolumeVO vol = dbf.findByUuid(rootVolumeUuid, VolumeVO.class); BackupStorageInventory sftp = deployer.backupStorages.get("sftp"); ImageInventory image = api.createTemplateFromRootVolume("testImage", rootVolumeUuid, (List) null); Assert.assertEquals(sftp.getUuid(), image.getBackupStorageRefs().get(0).getBackupStorageUuid()); Assert.assertEquals(ImageStatus.Ready.toString(), image.getStatus()); Assert.assertEquals(vol.getSize(), image.getSize()); Assert.assertEquals(String.format("volume://%s", vol.getUuid()), image.getUrl()); ImageVO ivo = dbf.findByUuid(image.getUuid(), ImageVO.class); Assert.assertNotNull(ivo); }
@Test public void test() throws ApiSenderException, InterruptedException { VmInstanceInventory vm = deployer.vms.get("TestVm"); final L3NetworkInventory l31 = deployer.l3Networks.get("TestL3Network1"); final L3NetworkInventory l32 = deployer.l3Networks.get("TestL3Network2"); VmNicInventory nic1 = CollectionUtils.find( vm.getVmNics(), new Function<VmNicInventory, VmNicInventory>() { @Override public VmNicInventory call(VmNicInventory arg) { return arg.getL3NetworkUuid().equals(l31.getUuid()) ? arg : null; } }); VmNicInventory nic2 = CollectionUtils.find( vm.getVmNics(), new Function<VmNicInventory, VmNicInventory>() { @Override public VmNicInventory call(VmNicInventory arg) { return arg.getL3NetworkUuid().equals(l32.getUuid()) ? arg : null; } }); VmInstanceInventory update = new VmInstanceInventory(); update.setUuid(vm.getUuid()); update.setDefaultL3NetworkUuid(l32.getUuid()); api.updateVm(update); TimeUnit.SECONDS.sleep(2); Assert.assertEquals(1, fconfig.resetDefaultGatewayCmds.size()); ResetDefaultGatewayCmd cmd = fconfig.resetDefaultGatewayCmds.get(0); Assert.assertEquals(nic1.getMac(), cmd.macOfGatewayToRemove); Assert.assertEquals(nic1.getGateway(), cmd.gatewayToRemove); Assert.assertEquals( new BridgeNameFinder().findByL3Uuid(l31.getUuid()), cmd.bridgeNameOfGatewayToRemove); Assert.assertEquals(nic2.getMac(), cmd.macOfGatewayToAdd); Assert.assertEquals(nic2.getGateway(), cmd.gatewayToAdd); Assert.assertEquals( new BridgeNameFinder().findByL3Uuid(l32.getUuid()), cmd.bridgeNameOfGatewayToAdd); }
@Test public void test() throws ApiSenderException { VmInstanceInventory vm = deployer.vms.get("TestVm"); ImageInventory iso = deployer.images.get("TestIso"); PrimaryStorageInventory ps = deployer.primaryStorages.get("ceph-pri"); restf.installBeforeAsyncJsonPostInterceptor( new BeforeAsyncJsonPostInterceptor() { @Override public void beforeAsyncJsonPost(String url, Object body, TimeUnit unit, long timeout) { if (body instanceof AttachIsoCmd) { AttachIsoCmd cmd = (AttachIsoCmd) body; isoto = (KvmCephIsoTO) cmd.iso; } } @Override public void beforeAsyncJsonPost(String url, String body, TimeUnit unit, long timeout) {} }); api.attachIso(vm.getUuid(), iso.getUuid(), null); Assert.assertNotNull(isoto); Assert.assertFalse(isoto.getMonInfo().isEmpty()); CephPrimaryStorageVO ceph = dbf.findByUuid(ps.getUuid(), CephPrimaryStorageVO.class); Assert.assertEquals(ceph.getMons().size(), isoto.getMonInfo().size()); for (final CephPrimaryStorageMonVO mon : ceph.getMons()) { MonInfo info = CollectionUtils.find( isoto.getMonInfo(), new Function<MonInfo, MonInfo>() { @Override public MonInfo call(MonInfo arg) { return arg.getHostname().equals(mon.getHostname()) ? arg : null; } }); Assert.assertNotNull(info); } }
@Override public void preAttachVolume(VmInstanceInventory vm, final VolumeInventory volume) { SimpleQuery<LocalStorageResourceRefVO> q = dbf.createQuery(LocalStorageResourceRefVO.class); q.add( LocalStorageResourceRefVO_.resourceUuid, Op.IN, list(vm.getRootVolumeUuid(), volume.getUuid())); q.groupBy(LocalStorageResourceRefVO_.hostUuid); long count = q.count(); if (count < 2) { return; } q = dbf.createQuery(LocalStorageResourceRefVO.class); q.select(LocalStorageResourceRefVO_.hostUuid); q.add(LocalStorageResourceRefVO_.resourceUuid, Op.EQ, vm.getRootVolumeUuid()); String rootHost = q.findValue(); q = dbf.createQuery(LocalStorageResourceRefVO.class); q.select(LocalStorageResourceRefVO_.hostUuid); q.add(LocalStorageResourceRefVO_.resourceUuid, Op.EQ, volume.getUuid()); String dataHost = q.findValue(); if (!rootHost.equals(dataHost)) { throw new OperationFailureException( errf.stringToOperationError( String.format( "cannot attach the data volume[uuid:%s] to the vm[uuid:%s]. Both vm's root volume and the data volume are" + " on local primary storage, but they are on different hosts. The root volume[uuid:%s] is on the host[uuid:%s] but the data volume[uuid: %s]" + " is on the host[uuid: %s]", volume.getUuid(), vm.getUuid(), vm.getRootVolumeUuid(), rootHost, volume.getUuid(), dataHost))); } }
@Test public void test() throws ApiSenderException, InterruptedException { VmInstanceInventory vm = deployer.vms.get("TestVm"); VolumeInventory root = CollectionUtils.find( vm.getAllVolumes(), new Function<VolumeInventory, VolumeInventory>() { @Override public VolumeInventory call(VolumeInventory arg) { return VolumeType.Root.toString().equals(arg.getType()) ? arg : null; } }); assert root != null; VolumeSnapshotInventory sp = api.createSnapshot(root.getUuid()); IscsiBtrfsSnapshotValidator validator = new IscsiBtrfsSnapshotValidator(); validator.validate(sp); Assert.assertEquals(1, iconfig.createSubVolumeCmds.size()); api.destroyVmInstance(vm.getUuid()); api.deleteSnapshot(sp.getUuid()); VolumeSnapshotVO spvo = dbf.findByUuid(sp.getUuid(), VolumeSnapshotVO.class); Assert.assertNull(spvo); }
@Test public void test() throws ApiSenderException, InterruptedException { HostInventory host2 = deployer.hosts.get("host2"); HostInventory host1 = deployer.hosts.get("host1"); VmInstanceInventory vm = deployer.vms.get("TestVm"); PrimaryStorageInventory local = deployer.primaryStorages.get("local"); List<VolumeVO> vols = dbf.listAll(VolumeVO.class); List<VolumeVO> volumesOnLocal = new ArrayList<VolumeVO>(); ImageCacheVO cacheVO = dbf.listAll(ImageCacheVO.class).get(0); long imageSize = cacheVO.getSize(); long usedVolumeSize = 0; for (VolumeVO vol : vols) { if (vol.getPrimaryStorageUuid().equals(local.getUuid())) { volumesOnLocal.add(vol); usedVolumeSize += ratioMgr.calculateByRatio(vol.getPrimaryStorageUuid(), vol.getSize()); } } config.createEmptyVolumeCmds.clear(); config.deleteBitsCmds.clear(); vm = api.migrateVmInstance(vm.getUuid(), host2.getUuid()); TimeUnit.SECONDS.sleep(5); LocalStorageHostRefVO ref1 = dbf.findByUuid(host1.getUuid(), LocalStorageHostRefVO.class); Assert.assertEquals(ref1.getTotalCapacity() - imageSize, ref1.getAvailableCapacity()); LocalStorageHostRefVO ref2 = dbf.findByUuid(host2.getUuid(), LocalStorageHostRefVO.class); Assert.assertEquals( ref2.getTotalCapacity() - imageSize - usedVolumeSize, ref2.getAvailableCapacity()); Assert.assertEquals(volumesOnLocal.size(), config.createEmptyVolumeCmds.size()); for (final VolumeVO vol : volumesOnLocal) { // volumes are created on dst host CreateEmptyVolumeCmd cmd = CollectionUtils.find( config.createEmptyVolumeCmds, new Function<CreateEmptyVolumeCmd, CreateEmptyVolumeCmd>() { @Override public CreateEmptyVolumeCmd call(CreateEmptyVolumeCmd arg) { return arg.getVolumeUuid().equals(vol.getUuid()) ? arg : null; } }); Assert.assertNotNull(cmd); Assert.assertEquals(vol.getInstallPath(), cmd.getInstallUrl()); LocalStorageResourceRefVO r = dbf.findByUuid(vol.getUuid(), LocalStorageResourceRefVO.class); Assert.assertEquals(host2.getUuid(), r.getHostUuid()); // volumes are deleted on src host DeleteBitsCmd dcmd = CollectionUtils.find( config.deleteBitsCmds, new Function<DeleteBitsCmd, DeleteBitsCmd>() { @Override public DeleteBitsCmd call(DeleteBitsCmd arg) { return arg.getPath().equals(vol.getInstallPath()) ? arg : null; } }); Assert.assertNotNull( String.format( "no delete command for volume[uuid:%s, path:%s]", vol.getUuid(), vol.getInstallPath()), dcmd); } Assert.assertFalse(kconfig.migrateVmCmds.isEmpty()); MigrateVmCmd mcmd = kconfig.migrateVmCmds.get(0); Assert.assertEquals(host2.getManagementIp(), mcmd.getDestHostIp()); Assert.assertEquals(vm.getUuid(), mcmd.getVmUuid()); Assert.assertEquals( StorageMigrationPolicy.IncCopy.toString(), mcmd.getStorageMigrationPolicy()); }
@Test public void test() throws ApiSenderException, InterruptedException { final L3NetworkInventory l3 = deployer.l3Networks.get("TestL3Network4"); VmInstanceInventory vm = deployer.vms.get("TestVm"); APIGetIpAddressCapacityReply ipcap = api.getIpAddressCapacityByAll(); long avail1 = ipcap.getAvailableCapacity(); int num = 50; final CountDownLatch latch = new CountDownLatch(num); final String vmUuid = vm.getUuid(); class Ret { int count; } final Ret ret = new Ret(); for (int i = 0; i < num; i++) { new Runnable() { @Override @AsyncThread public void run() { try { VmInstanceInventory v = api.attachNic(vmUuid, l3.getUuid()); ret.count += 1; } catch (Exception e) { logger.warn(e.getMessage(), e); } finally { latch.countDown(); } } }.run(); } latch.await(120, TimeUnit.SECONDS); VmInstanceVO vmvo = dbf.findByUuid(vmUuid, VmInstanceVO.class); final CountDownLatch latch1 = new CountDownLatch(vmvo.getVmNics().size()); for (final VmNicVO nic : vmvo.getVmNics()) { new Runnable() { @Override @AsyncThread public void run() { try { api.detachNic(nic.getUuid()); } catch (Exception e) { logger.warn(e.getMessage(), e); } finally { latch1.countDown(); } } }.run(); } latch1.await(120, TimeUnit.SECONDS); TimeUnit.SECONDS.sleep(5); ipcap = api.getIpAddressCapacityByAll(); long avail2 = ipcap.getAvailableCapacity(); Assert.assertEquals(avail1, avail2 - 3); }
@Test public void test() throws ApiSenderException { StartVmCmd scmd = config.startVmCmd; Assert.assertTrue(scmd.getBootDev().contains(BootDev.cdrom.toString())); VmInstanceInventory vm = deployer.vms.get("TestVm"); List<String> order = api.getVmBootOrder(vm.getUuid(), null); Assert.assertEquals(1, order.size()); Assert.assertEquals(VmBootDevice.HardDisk.toString(), order.get(0)); vm = api.setVmBootOrder( vm.getUuid(), list(VmBootDevice.CdRom.toString(), VmBootDevice.HardDisk.toString()), null); Assert.assertTrue(VmSystemTags.BOOT_ORDER.hasTag(vm.getUuid())); vm = api.rebootVmInstance(vm.getUuid()); scmd = config.startVmCmd; Assert.assertTrue(scmd.getBootDev().contains(BootDev.cdrom.toString())); Assert.assertTrue(scmd.getBootDev().contains(BootDev.hd.toString())); order = api.getVmBootOrder(vm.getUuid(), null); Assert.assertEquals(2, order.size()); Assert.assertTrue(order.contains(VmBootDevice.CdRom.toString())); Assert.assertTrue(order.contains(VmBootDevice.HardDisk.toString())); api.stopVmInstance(vm.getUuid()); api.startVmInstance(vm.getUuid()); scmd = config.startVmCmd; Assert.assertTrue(scmd.getBootDev().contains(BootDev.cdrom.toString())); Assert.assertTrue(scmd.getBootDev().contains(BootDev.hd.toString())); config.rebootVmCmds.clear(); vm = api.setVmBootOrder(vm.getUuid(), null, null); Assert.assertFalse(VmSystemTags.BOOT_ORDER.hasTag(vm.getUuid())); order = api.getVmBootOrder(vm.getUuid(), null); Assert.assertEquals(1, order.size()); Assert.assertEquals(VmBootDevice.HardDisk.toString(), order.get(0)); api.rebootVmInstance(vm.getUuid()); scmd = config.startVmCmd; Assert.assertTrue(scmd.getBootDev().contains(BootDev.hd.toString())); api.stopVmInstance(vm.getUuid()); api.startVmInstance(vm.getUuid()); scmd = config.startVmCmd; Assert.assertTrue(scmd.getBootDev().contains(BootDev.hd.toString())); }
private void handleDeletion(final CascadeAction action, final Completion completion) { int op = toDeletionOpCode(action); if (op == OP_NOPE) { completion.success(); return; } if (op == OP_REMOVE_INSTANCE_OFFERING) { if (VmGlobalConfig.UPDATE_INSTANCE_OFFERING_TO_NULL_WHEN_DELETING.value(Boolean.class)) { new Runnable() { @Override @Transactional public void run() { List<InstanceOfferingInventory> offerings = action.getParentIssuerContext(); List<String> offeringUuids = CollectionUtils.transformToList( offerings, new Function<String, InstanceOfferingInventory>() { @Override public String call(InstanceOfferingInventory arg) { return arg.getUuid(); } }); String sql = "update VmInstanceVO vm set vm.instanceOfferingUuid = null where vm.instanceOfferingUuid in (:offeringUuids)"; Query q = dbf.getEntityManager().createQuery(sql); q.setParameter("offeringUuids", offeringUuids); q.executeUpdate(); } }.run(); } completion.success(); return; } final List<VmInstanceInventory> vminvs = vmFromDeleteAction(action); if (vminvs == null) { completion.success(); return; } if (op == OP_STOP) { List<StopVmInstanceMsg> msgs = new ArrayList<StopVmInstanceMsg>(); for (VmInstanceInventory inv : vminvs) { StopVmInstanceMsg msg = new StopVmInstanceMsg(); msg.setVmInstanceUuid(inv.getUuid()); bus.makeTargetServiceIdByResourceUuid(msg, VmInstanceConstant.SERVICE_ID, inv.getUuid()); msgs.add(msg); } bus.send( msgs, 20, new CloudBusListCallBack(completion) { @Override public void run(List<MessageReply> replies) { if (!action.isActionCode(CascadeConstant.DELETION_FORCE_DELETE_CODE)) { for (MessageReply r : replies) { if (!r.isSuccess()) { completion.fail(r.getError()); return; } } } completion.success(); } }); } else if (op == OP_DELETION) { List<VmInstanceDeletionMsg> msgs = new ArrayList<VmInstanceDeletionMsg>(); for (VmInstanceInventory inv : vminvs) { VmInstanceDeletionMsg msg = new VmInstanceDeletionMsg(); msg.setForceDelete(action.isActionCode(CascadeConstant.DELETION_FORCE_DELETE_CODE)); msg.setVmInstanceUuid(inv.getUuid()); bus.makeTargetServiceIdByResourceUuid(msg, VmInstanceConstant.SERVICE_ID, inv.getUuid()); msgs.add(msg); } bus.send( msgs, 20, new CloudBusListCallBack(completion) { @Override public void run(List<MessageReply> replies) { if (!action.isActionCode(CascadeConstant.DELETION_FORCE_DELETE_CODE)) { for (MessageReply r : replies) { if (!r.isSuccess()) { completion.fail(r.getError()); return; } } } completion.success(); } }); } else if (op == OP_DETACH_NIC) { List<DetachNicFromVmMsg> msgs = new ArrayList<DetachNicFromVmMsg>(); List<L3NetworkInventory> l3s = action.getParentIssuerContext(); for (VmInstanceInventory vm : vminvs) { for (L3NetworkInventory l3 : l3s) { DetachNicFromVmMsg msg = new DetachNicFromVmMsg(); msg.setVmInstanceUuid(vm.getUuid()); msg.setVmNicUuid(vm.findNic(l3.getUuid()).getUuid()); bus.makeTargetServiceIdByResourceUuid(msg, VmInstanceConstant.SERVICE_ID, vm.getUuid()); msgs.add(msg); } } bus.send( msgs, new CloudBusListCallBack(completion) { @Override public void run(List<MessageReply> replies) { if (!action.isActionCode(CascadeConstant.DELETION_FORCE_DELETE_CODE)) { for (MessageReply r : replies) { if (!r.isSuccess()) { completion.fail(r.getError()); return; } } } completion.success(); } }); } }