package org.zstack.test.kvm; 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.host.HostInventory; import org.zstack.header.host.HostStateEvent; import org.zstack.header.identity.SessionInventory; import org.zstack.header.storage.primary.PrimaryStorageInventory; import org.zstack.simulator.storage.primary.nfs.NfsPrimaryStorageSimulatorConfig; 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.test.storage.backup.sftp.TestSftpBackupStorageDeleteImage2; import org.zstack.utils.Utils; import org.zstack.utils.logging.CLogger; import java.util.concurrent.TimeUnit; /** * 1. have two hosts in cluster * 2. put host1 into maintenance mode * 3. attach primary storage to cluster * 4. enable host1 * <p> * confirm after host gets out of maintenance mode, primary storage mounts on it */ public class TestKvmMaintenanceModeAttachPrimaryStorage { CLogger logger = Utils.getLogger(TestSftpBackupStorageDeleteImage2.class); Deployer deployer; Api api; ComponentLoader loader; CloudBus bus; DatabaseFacade dbf; SessionInventory session; NfsPrimaryStorageSimulatorConfig config; @Before public void setUp() throws Exception { DBUtil.reDeployDB(); WebBeanConstructor con = new WebBeanConstructor(); deployer = new Deployer("deployerXml/kvm/TestKvmMaintenanceClusterAttachResource.xml", con); deployer.addSpringConfig("KVMRelated.xml"); deployer.build(); api = deployer.getApi(); loader = deployer.getComponentLoader(); bus = loader.getComponent(CloudBus.class); dbf = loader.getComponent(DatabaseFacade.class); config = loader.getComponent(NfsPrimaryStorageSimulatorConfig.class); session = api.loginAsAdmin(); } @Test public void test() throws ApiSenderException, InterruptedException { HostInventory host1 = deployer.hosts.get("host1"); api.maintainHost(host1.getUuid()); PrimaryStorageInventory nfs = deployer.primaryStorages.get("nfs"); api.attachPrimaryStorage(host1.getClusterUuid(), nfs.getUuid()); Assert.assertEquals(1, config.mountCmds.size()); config.mountCmds.clear(); api.changeHostState(host1.getUuid(), HostStateEvent.enable); // wait for host reconnect TimeUnit.SECONDS.sleep(5); Assert.assertEquals(1, config.remountCmds.size()); } }