package org.zstack.test.storage.volume; 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.configuration.DiskOfferingInventory; import org.zstack.header.configuration.DiskOfferingVO; import org.zstack.header.storage.primary.PrimaryStorageInventory; import org.zstack.header.vm.VmInstanceInventory; import org.zstack.header.volume.VolumeInventory; import org.zstack.storage.primary.PrimaryStorageSystemTags; import org.zstack.test.Api; import org.zstack.test.ApiSenderException; import org.zstack.test.DBUtil; import org.zstack.test.deployer.Deployer; import static org.zstack.utils.CollectionDSL.e; import static org.zstack.utils.CollectionDSL.map; /** * 1. create system tag of primary storage uuid on disk offering * 2. use that disk offering to create 3 data disks * 3. attach all data disks * <p> * confirm all data disks are created on specified primary storage */ public class TestCreateDataVolume2 { Deployer deployer; Api api; ComponentLoader loader; CloudBus bus; DatabaseFacade dbf; @Before public void setUp() throws Exception { DBUtil.reDeployDB(); deployer = new Deployer("deployerXml/volume/TestCreateDataVolume.xml"); deployer.build(); api = deployer.getApi(); loader = deployer.getComponentLoader(); bus = loader.getComponent(CloudBus.class); dbf = loader.getComponent(DatabaseFacade.class); } @Test public void test() throws ApiSenderException, InterruptedException { VmInstanceInventory vm = deployer.vms.get("TestVm"); DiskOfferingInventory dinv = deployer.diskOfferings.get("TestDataDiskOffering"); PrimaryStorageInventory ps1 = deployer.primaryStorages.get("TestPrimaryStorage1"); String itag = PrimaryStorageSystemTags.PRIMARY_STORAGE_ALLOCATOR_UUID_TAG.instantiateTag(map(e("uuid", ps1.getUuid()))); api.createSystemTag(dinv.getUuid(), itag, DiskOfferingVO.class); VolumeInventory vol = api.createDataVolume("data", dinv.getUuid()); vol = api.attachVolumeToVm(vm.getUuid(), vol.getUuid()); Assert.assertEquals(vol.getPrimaryStorageUuid(), ps1.getUuid()); vol = api.createDataVolume("data", dinv.getUuid()); vol = api.attachVolumeToVm(vm.getUuid(), vol.getUuid()); Assert.assertEquals(vol.getPrimaryStorageUuid(), ps1.getUuid()); vol = api.createDataVolume("data", dinv.getUuid()); vol = api.attachVolumeToVm(vm.getUuid(), vol.getUuid()); Assert.assertEquals(vol.getPrimaryStorageUuid(), ps1.getUuid()); } }