package org.zstack.test.virtualrouter; import junit.framework.Assert; import org.junit.Before; import org.junit.Test; import org.zstack.appliancevm.ApplianceVmGlobalProperty; import org.zstack.core.cloudbus.CloudBus; import org.zstack.core.componentloader.ComponentLoader; import org.zstack.core.db.DatabaseFacade; import org.zstack.header.configuration.InstanceOfferingInventory; import org.zstack.header.identity.SessionInventory; import org.zstack.header.image.ImageInventory; import org.zstack.header.network.l3.L3NetworkInventory; import org.zstack.header.volume.VolumeVO; import org.zstack.simulator.appliancevm.ApplianceVmSimulatorConfig; import org.zstack.simulator.kvm.KVMSimulatorConfig; import org.zstack.simulator.virtualrouter.VirtualRouterSimulatorConfig; import org.zstack.test.*; import org.zstack.test.deployer.Deployer; import org.zstack.utils.Utils; import org.zstack.utils.logging.CLogger; public class TestCreateVirtualRouterFailure { CLogger logger = Utils.getLogger(TestCreateVirtualRouterFailure.class); Deployer deployer; Api api; ComponentLoader loader; CloudBus bus; DatabaseFacade dbf; SessionInventory session; VirtualRouterSimulatorConfig vconfig; KVMSimulatorConfig kconfig; ApplianceVmSimulatorConfig aconfig; @Before public void setUp() throws Exception { DBUtil.reDeployDB(); WebBeanConstructor con = new WebBeanConstructor(); deployer = new Deployer("deployerXml/virtualRouter/startVirtualRouter.xml", con); deployer.addSpringConfig("VirtualRouter.xml"); deployer.addSpringConfig("VirtualRouterSimulator.xml"); deployer.addSpringConfig("KVMRelated.xml"); deployer.build(); api = deployer.getApi(); loader = deployer.getComponentLoader(); vconfig = loader.getComponent(VirtualRouterSimulatorConfig.class); kconfig = loader.getComponent(KVMSimulatorConfig.class); aconfig = loader.getComponent(ApplianceVmSimulatorConfig.class); bus = loader.getComponent(CloudBus.class); dbf = loader.getComponent(DatabaseFacade.class); session = api.loginAsAdmin(); } @Test public void test() throws ApiSenderException { ApplianceVmGlobalProperty.NO_ROLLBACK_ON_POST_FAILURE = false; ImageInventory iminv = deployer.images.get("TestImage"); InstanceOfferingInventory ioinv = deployer.instanceOfferings.get("TestInstanceOffering"); L3NetworkInventory l3inv = deployer.l3Networks.get("TestL3Network2"); boolean success = false; aconfig.prepareBootstrapInfoSuccess = false; VmCreator creator = new VmCreator(api); creator.imageUuid = iminv.getUuid(); creator.instanceOfferingUuid = ioinv.getUuid(); creator.addL3Network(l3inv.getUuid()); creator.name = "TestVm"; try { creator.create(); } catch (ApiSenderException e) { long count = dbf.count(VolumeVO.class); Assert.assertEquals(0, count); success = true; } Assert.assertTrue(success); } }