package org.zstack.test.compute.vm; import junit.framework.Assert; import org.junit.Before; import org.junit.Test; import org.zstack.core.cloudbus.CloudBus; import org.zstack.core.componentloader.ComponentLoader; import org.zstack.core.db.DatabaseFacade; import org.zstack.header.identity.SessionInventory; import org.zstack.header.image.ImageConstant; import org.zstack.header.image.ImageVO; import org.zstack.header.vm.*; import org.zstack.storage.primary.local.*; import org.zstack.test.Api; import org.zstack.test.ApiSenderException; import org.zstack.test.DBUtil; import org.zstack.test.WebBeanConstructor; import org.zstack.test.deployer.Deployer; import org.zstack.utils.data.SizeUnit; import java.util.Map; public class TestGetVmCapabilities { Deployer deployer; Api api; ComponentLoader loader; CloudBus bus; DatabaseFacade dbf; SessionInventory session; LocalStorageSimulatorConfig config; long totalSize = SizeUnit.GIGABYTE.toByte(100); @Before public void setUp() throws Exception { DBUtil.reDeployDB(); WebBeanConstructor con = new WebBeanConstructor(); deployer = new Deployer("deployerXml/vm/TestGetVmCapabilities.xml", con); deployer.addSpringConfig("KVMRelated.xml"); deployer.addSpringConfig("localStorageSimulator.xml"); deployer.addSpringConfig("localStorage.xml"); deployer.load(); loader = deployer.getComponentLoader(); bus = loader.getComponent(CloudBus.class); dbf = loader.getComponent(DatabaseFacade.class); config = loader.getComponent(LocalStorageSimulatorConfig.class); LocalStorageSimulatorConfig.Capacity c = new LocalStorageSimulatorConfig.Capacity(); c.total = totalSize; c.avail = totalSize; config.capacityMap.put("host1", c); config.capacityMap.put("host4", c); deployer.build(); api = deployer.getApi(); session = api.loginAsAdmin(); } @Test public void test() throws ApiSenderException { VmInstanceInventory vm = deployer.vms.get("TestVm"); Map<String, Object> cap = api.getVmCapabilities(vm.getUuid(), null); Assert.assertFalse((Boolean) cap.get(VmInstanceConstant.Capability.LiveMigration.toString())); Assert.assertTrue((Boolean) cap.get(VmInstanceConstant.Capability.VolumeMigration.toString())); Assert.assertTrue((Boolean) cap.get(VmInstanceConstant.Capability.Reimage.toString())); } }