diff --git a/test/integration/smoke/test_deploy_vm_iso.py b/test/integration/smoke/test_deploy_vm_iso.py index 33d4261c9d56..d8e746c8201f 100644 --- a/test/integration/smoke/test_deploy_vm_iso.py +++ b/test/integration/smoke/test_deploy_vm_iso.py @@ -20,7 +20,6 @@ # Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.lib.utils import cleanup_resources from marvin.lib.base import (Account, VirtualMachine, ServiceOffering, @@ -38,28 +37,28 @@ class TestDeployVMFromISO(cloudstackTestCase): def setUpClass(cls): cls.testClient = super(TestDeployVMFromISO, cls).getClsTestClient() - cls.api_client = cls.testClient.getApiClient() + cls.apiclient = cls.testClient.getApiClient() cls.testdata = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client) - cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) cls.hypervisor = cls.testClient.getHypervisorInfo() cls.template = get_test_template( - cls.api_client, + cls.apiclient, cls.zone.id, cls.hypervisor ) # Create service, disk offerings etc cls.service_offering = ServiceOffering.create( - cls.api_client, + cls.apiclient, cls.testdata["service_offering"] ) cls.disk_offering = DiskOffering.create( - cls.api_client, + cls.apiclient, cls.testdata["disk_offering"] ) @@ -69,13 +68,6 @@ def setUpClass(cls): ] return - @classmethod - def tearDownClass(cls): - try: - cleanup_resources(cls.api_client, cls._cleanup) - except Exception as e: - raise Exception("Warning: Exception during cleanup : %s" % e) - def setUp(self): self.apiclient = self.testClient.getApiClient() @@ -92,35 +84,24 @@ def setUp(self): self.cleanup = [self.account] return - def tearDown(self): - try: - self.debug("Cleaning up the resources") - cleanup_resources(self.apiclient, self.cleanup) - self.debug("Cleanup complete!") - except Exception as e: - self.debug("Warning! Exception in tearDown: %s" % e) - @attr( tags=[ "advanced", "eip", "advancedns", "basic", - "sg"], - required_hardware="true") + "sg" + ], + required_hardware="true" + ) def test_deploy_vm_from_iso(self): """Test Deploy Virtual Machine from ISO """ # Validate the following: - # 1. deploy VM using ISO - # 2. listVM command should return the deployed VM. State of this VM - # should be "Running". - self.hypervisor = self.testClient.getHypervisorInfo() - if self.hypervisor.lower() in ['lxc']: - self.skipTest( - "vm deploy from ISO feature is not supported on %s" % - self.hypervisor.lower()) + # 1. Create an ISO + # 2. Deploy a VM from the ISO + # 3. VM should be in 'Running' state self.iso = Iso.create( self.apiclient, @@ -129,6 +110,20 @@ def test_deploy_vm_from_iso(self): domainid=self.account.domainid, zoneid=self.zone.id ) + self.cleanup.append(self.iso) + + self.debug("ISO created with ID: %s" % self.iso.id) + + list_iso_response = Iso.list( + self.apiclient, + id=self.iso.id + ) + self.assertEqual( + isinstance(list_iso_response, list), + True, + "Check list response returns a valid list" + ) + try: # Download the ISO self.iso.download(self.apiclient) @@ -136,9 +131,8 @@ def test_deploy_vm_from_iso(self): raise Exception("Exception while downloading ISO %s: %s" % (self.iso.id, e)) - self.debug("Registered ISO: %s" % self.iso.name) - self.debug("Deploying instance in the account: %s" % - self.account.name) + self.debug(f"Registered ISO: {self.iso.name}") + self.debug(f"Deploying instance in the account: {self.account.name}") self.virtual_machine = VirtualMachine.create( self.apiclient, self.testdata["virtual_machine"], @@ -149,9 +143,35 @@ def test_deploy_vm_from_iso(self): diskofferingid=self.disk_offering.id, hypervisor=self.hypervisor ) + self.cleanup.append(self.virtual_machine) + + self.debug("VM created with ID: %s" % self.virtual_machine.id) + + list_vm_response = VirtualMachine.list( + self.apiclient, + id=self.virtual_machine.id + ) - response = self.virtual_machine.getState( + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + vm_response = list_vm_response[0] + vm_state = self.virtual_machine.getState( self.apiclient, - VirtualMachine.RUNNING) - self.assertEqual(response[0], PASS, response[1]) + VirtualMachine.RUNNING + ) + + self.assertEqual( + vm_state, + VirtualMachine.RUNNING, + "Check virtual machine is in running state" + ) + + self.assertEqual( + vm_response.isoid, + self.iso.id, + "Check virtual machine is booted from the ISO" + ) return