Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5FD21173A6 for ; Fri, 20 Feb 2015 14:41:09 +0000 (UTC) Received: (qmail 89761 invoked by uid 500); 20 Feb 2015 14:34:29 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 89717 invoked by uid 500); 20 Feb 2015 14:34:29 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 89516 invoked by uid 99); 20 Feb 2015 14:34:29 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Feb 2015 14:34:29 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5D377E05D1; Fri, 20 Feb 2015 14:34:29 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: talluri@apache.org To: commits@cloudstack.apache.org Date: Fri, 20 Feb 2015 14:34:30 -0000 Message-Id: In-Reply-To: <74fe20bbf7a748ef8724842cc1931d27@git.apache.org> References: <74fe20bbf7a748ef8724842cc1931d27@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/4] git commit: updated refs/heads/master to 53bae00 CLOUDSTACK-8264: Code improvement - test_stopped_vm.py Signed-off-by: SrikanteswaraRao Talluri Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/ba08229f Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/ba08229f Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/ba08229f Branch: refs/heads/master Commit: ba08229ff9a8246eddfc9e373dd4efdf35268013 Parents: db9a4f3 Author: Gaurav Aradhye Authored: Wed Feb 18 23:35:00 2015 -0800 Committer: SrikanteswaraRao Talluri Committed: Fri Feb 20 19:59:37 2015 +0530 ---------------------------------------------------------------------- test/integration/component/test_stopped_vm.py | 1515 ++++++++++---------- tools/marvin/marvin/config/test_data.py | 23 +- 2 files changed, 818 insertions(+), 720 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/ba08229f/test/integration/component/test_stopped_vm.py ---------------------------------------------------------------------- diff --git a/test/integration/component/test_stopped_vm.py b/test/integration/component/test_stopped_vm.py index 1cefc07..92822c3 100644 --- a/test/integration/component/test_stopped_vm.py +++ b/test/integration/component/test_stopped_vm.py @@ -17,10 +17,9 @@ """ P1 for stopped Virtual Maschine life cycle """ -#Import Local Modules +# Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase -#from marvin.cloudstackAPI import * from marvin.lib.utils import cleanup_resources from marvin.lib.base import (Account, VirtualMachine, @@ -41,80 +40,6 @@ from marvin.lib.common import (get_zone, from marvin.codes import PASS -class Services: - """Test Stopped VM Life Cycle Services - """ - - def __init__(self): - self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended in create account to - # ensure unique username generated each time - "password": "password", - }, - "virtual_machine": - { - "displayname": "testserver", - "username": "root", # VM creds for SSH - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "service_offering": - { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, # in MHz - "memory": 128, # In MBs - }, - "disk_offering": { - "displaytext": "Tiny volume", - "name": "Tiny volume", - "disksize": 1 - }, - "volume": { - "diskname": "DataDisk", - "url": 'http://download.cloud.com/releases/2.0.0/UbuntuServer-10-04-64bit.vhd.bz2', - "format": 'VHD' - }, - "iso": # ISO settings for Attach/Detach ISO tests - { - "displaytext": "Test ISO", - "name": "testISO", - "url": "http://people.apache.org/~tsp/dummy.iso", - # Source URL where ISO is located - "ostype": 'CentOS 5.3 (64-bit)', - "mode": 'HTTP_DOWNLOAD', # Downloading existing ISO - }, - "template": { - "url": "", - "hypervisor": '', - "format": '', - "isfeatured": True, - "ispublic": True, - "isextractable": True, - "displaytext": "Cent OS Template", - "name": "Cent OS Template", - "ostype": 'CentOS 5.3 (64-bit)', - "templatefilter": 'self', - "passwordenabled": True, - }, - "sleep": 60, - "timeout": 10, - #Migrate VM to hostid - "ostype": 'CentOS 5.3 (64-bit)', - # CentOS 5.3 (64-bit) - } - - class TestDeployVM(cloudstackTestCase): @classmethod @@ -123,31 +48,31 @@ class TestDeployVM(cloudstackTestCase): cls.testClient = super(TestDeployVM, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() - cls.services = Services().services + 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.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.testdata["ostype"] + ) # Create service offerings, disk offerings etc cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.testdata["service_offering"] + ) cls.disk_offering = DiskOffering.create( - cls.api_client, - cls.services["disk_offering"] - ) + cls.api_client, + cls.testdata["disk_offering"] + ) # Cleanup cls._cleanup = [ - cls.service_offering, - cls.disk_offering, - ] + cls.service_offering, + cls.disk_offering, + ] return @classmethod @@ -161,15 +86,14 @@ class TestDeployVM(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() - self.services = Services().services - self.services["virtual_machine"]["zoneid"] = self.zone.id - self.services["iso"]["zoneid"] = self.zone.id - self.services["virtual_machine"]["template"] = self.template.id + self.testdata["virtual_machine"]["zoneid"] = self.zone.id + self.testdata["iso"]["zoneid"] = self.zone.id + self.testdata["virtual_machine"]["template"] = self.template.id self.account = Account.create( - self.apiclient, - self.services["account"], - domainid=self.domain.id - ) + self.apiclient, + self.testdata["account"], + domainid=self.domain.id + ) self.cleanup = [self.account] return @@ -193,22 +117,31 @@ class TestDeployVM(cloudstackTestCase): # should be "Running". self.debug("Deploying instance in the account: %s" % - self.account.name) + self.account.name) self.virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - diskofferingid=self.disk_offering.id, - mode=self.zone.networktype - ) - - response = self.virtual_machine.getState(self.apiclient, VirtualMachine.RUNNING) + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + diskofferingid=self.disk_offering.id, + mode=self.zone.networktype + ) + + response = self.virtual_machine.getState( + self.apiclient, + VirtualMachine.RUNNING) self.assertEqual(response[0], PASS, response[1]) return - @attr(tags=["advanced", "eip", "advancedns", "basic", "sg"], required_hardware="false") + @attr( + tags=[ + "advanced", + "eip", + "advancedns", + "basic", + "sg"], + required_hardware="false") def test_02_deploy_vm_startvm_true(self): """Test Deploy Virtual Machine with startVM=true parameter """ @@ -220,23 +153,32 @@ class TestDeployVM(cloudstackTestCase): # should be "Running". self.debug("Deploying instance in the account: %s" % - self.account.name) + self.account.name) self.virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - startvm=True, - diskofferingid=self.disk_offering.id, - mode=self.zone.networktype - ) - - response = self.virtual_machine.getState(self.apiclient, VirtualMachine.RUNNING) + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=True, + diskofferingid=self.disk_offering.id, + mode=self.zone.networktype + ) + + response = self.virtual_machine.getState( + self.apiclient, + VirtualMachine.RUNNING) self.assertEqual(response[0], PASS, response[1]) return - @attr(tags=["advanced", "eip", "advancedns", "basic", "sg"], required_hardware="false") + @attr( + tags=[ + "advanced", + "eip", + "advancedns", + "basic", + "sg"], + required_hardware="false") def test_03_deploy_vm_startvm_false(self): """Test Deploy Virtual Machine with startVM=false parameter """ @@ -250,35 +192,44 @@ class TestDeployVM(cloudstackTestCase): # return empty response self.debug("Deploying instance in the account: %s" % - self.account.name) + self.account.name) self.virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - startvm=False, - diskofferingid=self.disk_offering.id, - ) - - response = self.virtual_machine.getState(self.apiclient, VirtualMachine.STOPPED) + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False, + diskofferingid=self.disk_offering.id, + ) + + response = self.virtual_machine.getState( + self.apiclient, + VirtualMachine.STOPPED) self.assertEqual(response[0], PASS, response[1]) routers = Router.list( - self.apiclient, - account=self.account.name, - domainid=self.account.domainid, - listall=True - ) + self.apiclient, + account=self.account.name, + domainid=self.account.domainid, + listall=True + ) self.assertEqual( - routers, - None, - "List routers should return empty response" - ) + routers, + None, + "List routers should return empty response" + ) self.debug("Destroying instance: %s" % self.virtual_machine.name) self.virtual_machine.delete(self.apiclient, expunge=True) return - @attr(tags=["advanced", "eip", "advancedns", "basic", "sg"], required_hardware="false") + @attr( + tags=[ + "advanced", + "eip", + "advancedns", + "basic", + "sg"], + required_hardware="false") def test_04_deploy_startvm_false_attach_volume(self): """Test Deploy Virtual Machine with startVM=false and attach volume """ @@ -290,39 +241,48 @@ class TestDeployVM(cloudstackTestCase): # 3. Attach volume should be successful self.debug("Deploying instance in the account: %s" % - self.account.name) + self.account.name) self.virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - startvm=False, - diskofferingid=self.disk_offering.id, - ) - - response = self.virtual_machine.getState(self.apiclient, VirtualMachine.STOPPED) + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False, + diskofferingid=self.disk_offering.id, + ) + + response = self.virtual_machine.getState( + self.apiclient, + VirtualMachine.STOPPED) self.assertEqual(response[0], PASS, response[1]) self.debug("Creating a volume in account: %s" % - self.account.name) + self.account.name) volume = Volume.create( - self.apiclient, - self.services["volume"], - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid, - diskofferingid=self.disk_offering.id - ) + self.apiclient, + self.testdata["volume"], + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid, + diskofferingid=self.disk_offering.id + ) self.debug("Created volume in account: %s" % self.account.name) self.debug("Attaching volume to instance: %s" % - self.virtual_machine.name) + self.virtual_machine.name) try: self.virtual_machine.attach_volume(self.apiclient, volume) except Exception as e: self.fail("Attach volume failed with Exception: %s" % e) return - @attr(tags=["advanced", "eip", "advancedns", "basic", "sg"], required_hardware="false") + @attr( + tags=[ + "advanced", + "eip", + "advancedns", + "basic", + "sg"], + required_hardware="false") def test_05_deploy_startvm_false_change_so(self): """Test Deploy Virtual Machine with startVM=false and change service offering """ @@ -334,31 +294,33 @@ class TestDeployVM(cloudstackTestCase): # 4. Change service offering self.debug("Deploying instance in the account: %s" % - self.account.name) + self.account.name) self.virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - startvm=False, - ) - - response = self.virtual_machine.getState(self.apiclient, VirtualMachine.STOPPED) + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False, + ) + + response = self.virtual_machine.getState( + self.apiclient, + VirtualMachine.STOPPED) self.assertEqual(response[0], PASS, response[1]) medium_service_off = ServiceOffering.create( - self.apiclient, - self.services["service_offering"] - ) + self.apiclient, + self.testdata["service_offering"] + ) self.cleanup.append(medium_service_off) self.debug("Changing service offering for instance: %s" % - self.virtual_machine.name) + self.virtual_machine.name) try: self.virtual_machine.change_service_offering( - self.apiclient, - medium_service_off.id - ) + self.apiclient, + medium_service_off.id + ) except Exception as e: self.fail("Change service offering failed: %s" % e) @@ -366,14 +328,26 @@ class TestDeployVM(cloudstackTestCase): self.virtual_machine.start(self.apiclient) self.debug("Instance: %s started" % self.virtual_machine.name) - listedvm = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id) + listedvm = VirtualMachine.list( + self.apiclient, + id=self.virtual_machine.id) self.assert_(isinstance(listedvm, list)) self.assert_(len(listedvm) > 0) - self.assertEqual(listedvm[0].serviceofferingid, medium_service_off.id, msg="VM did not change service offering") + self.assertEqual( + listedvm[0].serviceofferingid, + medium_service_off.id, + msg="VM did not change service offering") return - @attr(tags=["advanced", "eip", "advancedns", "basic", "sg"], required_hardware="false") + @attr( + tags=[ + "advanced", + "eip", + "advancedns", + "basic", + "sg"], + required_hardware="false") def test_06_deploy_startvm_attach_detach(self): """Test Deploy Virtual Machine with startVM=false and attach detach volumes @@ -387,32 +361,34 @@ class TestDeployVM(cloudstackTestCase): # 4. Detach volume from instance. Detach should be successful self.debug("Deploying instance in the account: %s" % - self.account.name) + self.account.name) self.virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - startvm=False, - diskofferingid=self.disk_offering.id, - ) - - response = self.virtual_machine.getState(self.apiclient, VirtualMachine.STOPPED) + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False, + diskofferingid=self.disk_offering.id, + ) + + response = self.virtual_machine.getState( + self.apiclient, + VirtualMachine.STOPPED) self.assertEqual(response[0], PASS, response[1]) self.debug("Creating a volume in account: %s" % - self.account.name) + self.account.name) volume = Volume.create( - self.apiclient, - self.services["volume"], - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid, - diskofferingid=self.disk_offering.id - ) + self.apiclient, + self.testdata["volume"], + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid, + diskofferingid=self.disk_offering.id + ) self.debug("Created volume in account: %s" % self.account.name) self.debug("Attaching volume to instance: %s" % - self.virtual_machine.name) + self.virtual_machine.name) try: self.virtual_machine.attach_volume(self.apiclient, volume) except Exception as e: @@ -423,20 +399,27 @@ class TestDeployVM(cloudstackTestCase): self.debug("Datadisk %s detached!" % volume.name) volumes = Volume.list( - self.apiclient, - virtualmachineid=self.virtual_machine.id, - type='DATADISK', - id=volume.id, - listall=True - ) + self.apiclient, + virtualmachineid=self.virtual_machine.id, + type='DATADISK', + id=volume.id, + listall=True + ) self.assertEqual( - volumes, - None, - "List Volumes should not list any volume for instance" - ) + volumes, + None, + "List Volumes should not list any volume for instance" + ) return - @attr(tags=["advanced", "eip", "advancedns", "basic", "sg"], required_hardware="false") + @attr( + tags=[ + "advanced", + "eip", + "advancedns", + "basic", + "sg"], + required_hardware="false") def test_07_deploy_startvm_attach_iso(self): """Test Deploy Virtual Machine with startVM=false and attach ISO """ @@ -448,64 +431,73 @@ class TestDeployVM(cloudstackTestCase): # 3. Attach ISO to the instance. Attach ISO should be successful self.debug("Deploying instance in the account: %s" % - self.account.name) + self.account.name) self.virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - startvm=False, - diskofferingid=self.disk_offering.id, - ) - - response = self.virtual_machine.getState(self.apiclient, VirtualMachine.STOPPED) + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False, + diskofferingid=self.disk_offering.id, + ) + + response = self.virtual_machine.getState( + self.apiclient, + VirtualMachine.STOPPED) self.assertEqual(response[0], PASS, response[1]) self.debug("Registering a ISO in account: %s" % - self.account.name) + self.account.name) iso = Iso.create( - self.apiclient, - self.services["iso"], - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + self.testdata["iso"], + account=self.account.name, + domainid=self.account.domainid + ) self.debug("Successfully created ISO with ID: %s" % iso.id) try: iso.download(self.apiclient) - + except Exception as e: - self.fail("Exception while downloading ISO %s: %s"\ + self.fail("Exception while downloading ISO %s: %s" % (iso.id, e)) self.debug("Attach ISO with ID: %s to VM ID: %s" % ( - iso.id, - self.virtual_machine.id - )) + iso.id, + self.virtual_machine.id + )) try: self.virtual_machine.attach_iso(self.apiclient, iso) except Exception as e: self.fail("Attach ISO failed!") vms = VirtualMachine.list( - self.apiclient, - id=self.virtual_machine.id, - listall=True - ) + self.apiclient, + id=self.virtual_machine.id, + listall=True + ) self.assertEqual( - isinstance(vms, list), - True, - "List vms should return a valid list" - ) + isinstance(vms, list), + True, + "List vms should return a valid list" + ) vm = vms[0] self.assertEqual( - vm.isoid, - iso.id, - "The ISO status should be reflected in list Vm call" - ) + vm.isoid, + iso.id, + "The ISO status should be reflected in list Vm call" + ) return - @attr(tags=["advanced", "eip", "advancedns", "basic", "sg"], required_hardware="false") + @attr( + tags=[ + "advanced", + "eip", + "advancedns", + "basic", + "sg"], + required_hardware="false") def test_08_deploy_attached_volume(self): """Test Deploy Virtual Machine with startVM=false and attach volume already attached to different machine """ @@ -518,47 +510,49 @@ class TestDeployVM(cloudstackTestCase): # 4. Attach the volume to first virtual machine. self.debug("Deploying instance in the account: %s" % - self.account.name) + self.account.name) self.virtual_machine_1 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - startvm=False, - ) - - response = self.virtual_machine_1.getState(self.apiclient, VirtualMachine.STOPPED) + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False, + ) + + response = self.virtual_machine_1.getState( + self.apiclient, + VirtualMachine.STOPPED) self.assertEqual(response[0], PASS, response[1]) self.debug("Deploying instance in the account: %s" % - self.account.name) + self.account.name) self.virtual_machine_2 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - diskofferingid=self.disk_offering.id - ) + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + diskofferingid=self.disk_offering.id + ) self.debug("Deployed instance in account: %s" % - self.account.name) + self.account.name) list_vm_response = VirtualMachine.list( - self.apiclient, - id=self.virtual_machine_2.id - ) + self.apiclient, + id=self.virtual_machine_2.id + ) self.debug( - "Verify listVirtualMachines response for virtual machine: %s" \ - % self.virtual_machine_2.id - ) + "Verify listVirtualMachines response for virtual machine: %s" + % self.virtual_machine_2.id + ) self.assertEqual( - isinstance(list_vm_response, list), - True, - "Check list response returns a valid list" - ) + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) vm_response = list_vm_response[0] self.assertEqual( @@ -569,19 +563,19 @@ class TestDeployVM(cloudstackTestCase): self.debug( "Fetching DATADISK details for instance: %s" % - self.virtual_machine_2.name) + self.virtual_machine_2.name) volumes = Volume.list( - self.apiclient, - type='DATADISK', - account=self.account.name, - domainid=self.account.domainid, - virtualmachineid=self.virtual_machine_2.id - ) + self.apiclient, + type='DATADISK', + account=self.account.name, + domainid=self.account.domainid, + virtualmachineid=self.virtual_machine_2.id + ) self.assertEqual( - isinstance(volumes, list), - True, - "List volumes should return a valid list" - ) + isinstance(volumes, list), + True, + "List volumes should return a valid list" + ) volume = volumes[0] self.debug("Detaching the disk: %s" % volume.name) @@ -593,27 +587,34 @@ class TestDeployVM(cloudstackTestCase): self.fail("Detach volume failed!") self.debug("Attaching volume to instance: %s" % - self.virtual_machine_1.name) + self.virtual_machine_1.name) try: self.virtual_machine_1.attach_volume(self.apiclient, volume) except Exception as e: self.fail("Attach volume failed with %s!" % e) volumes = Volume.list( - self.apiclient, - virtualmachineid=self.virtual_machine_1.id, - type='DATADISK', - id=volume.id, - listall=True - ) + self.apiclient, + virtualmachineid=self.virtual_machine_1.id, + type='DATADISK', + id=volume.id, + listall=True + ) self.assertNotEqual( - volumes, - None, - "List Volumes should not list any volume for instance" - ) + volumes, + None, + "List Volumes should not list any volume for instance" + ) return - @attr(tags=["advanced", "eip", "advancedns", "basic", "sg"], required_hardware="false") + @attr( + tags=[ + "advanced", + "eip", + "advancedns", + "basic", + "sg"], + required_hardware="false") def test_09_stop_vm_migrate_vol(self): """Test Stopped Virtual Machine's ROOT volume migration """ @@ -628,78 +629,83 @@ class TestDeployVM(cloudstackTestCase): # 6.Migrate voluem to another available primary storage self.hypervisor = self.testClient.getHypervisorInfo() if self.hypervisor.lower() in ['lxc']: - self.skipTest("vm migrate is not supported in %s" % self.hypervisor) + self.skipTest( + "vm migrate is not supported in %s" % + self.hypervisor) clusters = Cluster.list( - self.apiclient, - zoneid = self.zone.id - ) + self.apiclient, + zoneid=self.zone.id + ) self.assertEqual( - isinstance(clusters, list), - True, - "Check list response returns a valid list" - ) + isinstance(clusters, list), + True, + "Check list response returns a valid list" + ) i = 0 - for cluster in clusters : + for cluster in clusters: storage_pools = StoragePool.list( - self.apiclient, - clusterid = cluster.id - ) - if len(storage_pools) > 1 : + self.apiclient, + clusterid=cluster.id + ) + if len(storage_pools) > 1: self.cluster_id = cluster.id i += 1 break - if i == 0 : - self.skipTest("No cluster with more than one primary storage pool to perform migrate volume test") + if i == 0: + self.skipTest( + "No cluster with more than one primary storage pool to perform migrate volume test") hosts = Host.list( - self.apiclient, - clusterid = self.cluster_id - ) + self.apiclient, + clusterid=self.cluster_id + ) self.assertEqual( - isinstance(hosts, list), - True, - "Check list response returns a valid list" - ) + isinstance(hosts, list), + True, + "Check list response returns a valid list" + ) host = hosts[0] self.debug("Deploying instance on host: %s" % host.id) self.debug("Deploying instance in the account: %s" % - self.account.name) + self.account.name) self.virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - diskofferingid=self.disk_offering.id, - hostid=host.id, - mode=self.zone.networktype - ) - - response = self.virtual_machine.getState(self.apiclient, VirtualMachine.RUNNING) + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + diskofferingid=self.disk_offering.id, + hostid=host.id, + mode=self.zone.networktype + ) + + response = self.virtual_machine.getState( + self.apiclient, + VirtualMachine.RUNNING) self.assertEqual(response[0], PASS, response[1]) try: self.virtual_machine.stop(self.apiclient) except Exception as e: self.fail("failed to stop instance: %s" % e) volumes = Volume.list( - self.apiclient, - virtualmachineid=self.virtual_machine.id, - type='ROOT', - listall=True - ) + self.apiclient, + virtualmachineid=self.virtual_machine.id, + type='ROOT', + listall=True + ) self.assertEqual( - isinstance(volumes, list), - True, - "Check volume list response returns a valid list" - ) + isinstance(volumes, list), + True, + "Check volume list response returns a valid list" + ) vol_response = volumes[0] - #get the storage name in which volume is stored + # get the storage name in which volume is stored storage_name = vol_response.storage storage_pools = StoragePool.list( - self.apiclient, - clusterid = self.cluster_id - ) - #Get storage pool to migrate volume + self.apiclient, + clusterid=self.cluster_id + ) + # Get storage pool to migrate volume for spool in storage_pools: if spool.name == storage_name: continue @@ -709,23 +715,24 @@ class TestDeployVM(cloudstackTestCase): break self.debug("Migrating volume to storage pool: %s" % self.storage_name) Volume.migrate( - self.apiclient, - storageid = self.storage_id, - volumeid = vol_response.id - ) + self.apiclient, + storageid=self.storage_id, + volumeid=vol_response.id + ) volume = Volume.list( - self.apiclient, - virtualmachineid=self.virtual_machine.id, - type='ROOT', - listall=True - ) + self.apiclient, + virtualmachineid=self.virtual_machine.id, + type='ROOT', + listall=True + ) self.assertEqual( - volume[0].storage, - self.storage_name, - "Check volume migration response") - + volume[0].storage, + self.storage_name, + "Check volume migration response") + return + class TestDeployHaEnabledVM(cloudstackTestCase): @classmethod @@ -734,32 +741,32 @@ class TestDeployHaEnabledVM(cloudstackTestCase): cls.testClient = super(TestDeployHaEnabledVM, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() - cls.services = Services().services + 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.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.testdata["ostype"] + ) # Create service, disk offerings etc cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"], - offerha=True - ) + cls.api_client, + cls.testdata["service_offering"], + offerha=True + ) cls.disk_offering = DiskOffering.create( - cls.api_client, - cls.services["disk_offering"] - ) + cls.api_client, + cls.testdata["disk_offering"] + ) # Cleanup cls._cleanup = [ - cls.service_offering, - cls.disk_offering, - ] + cls.service_offering, + cls.disk_offering, + ] return @classmethod @@ -774,15 +781,14 @@ class TestDeployHaEnabledVM(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.hypervisor = self.testClient.getHypervisorInfo() - self.services = Services().services - self.services["virtual_machine"]["zoneid"] = self.zone.id - self.services["virtual_machine"]["template"] = self.template.id - self.services["iso"]["zoneid"] = self.zone.id + self.testdata["virtual_machine"]["zoneid"] = self.zone.id + self.testdata["virtual_machine"]["template"] = self.template.id + self.testdata["iso"]["zoneid"] = self.zone.id self.account = Account.create( - self.apiclient, - self.services["account"], - domainid=self.domain.id - ) + self.apiclient, + self.testdata["account"], + domainid=self.domain.id + ) self.cleanup = [self.account] return @@ -794,7 +800,14 @@ class TestDeployHaEnabledVM(cloudstackTestCase): except Exception as e: self.debug("Warning! Exception in tearDown: %s" % e) - @attr(tags=["advanced", "eip", "advancedns", "basic", "sg"], required_hardware="false") + @attr( + tags=[ + "advanced", + "eip", + "advancedns", + "basic", + "sg"], + required_hardware="false") def test_01_deploy_ha_vm_startvm_false(self): """Test Deploy HA enabled Virtual Machine with startvm=false """ @@ -805,22 +818,31 @@ class TestDeployHaEnabledVM(cloudstackTestCase): # should be "Created". self.debug("Deploying instance in the account: %s" % - self.account.name) + self.account.name) self.virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - diskofferingid=self.disk_offering.id, - startvm=False - ) - - response = self.virtual_machine.getState(self.apiclient, VirtualMachine.STOPPED) + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + diskofferingid=self.disk_offering.id, + startvm=False + ) + + response = self.virtual_machine.getState( + self.apiclient, + VirtualMachine.STOPPED) self.assertEqual(response[0], PASS, response[1]) return - @attr(tags=["advanced", "eip", "advancedns", "basic", "sg"], required_hardware="false") + @attr( + tags=[ + "advanced", + "eip", + "advancedns", + "basic", + "sg"], + required_hardware="true") def test_02_deploy_ha_vm_from_iso(self): """Test Deploy HA enabled Virtual Machine from ISO """ @@ -831,42 +853,62 @@ class TestDeployHaEnabledVM(cloudstackTestCase): # 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()) + self.skipTest( + "vm deploy from ISO feature is not supported on %s" % + self.hypervisor.lower()) + + if not self.testdata["configurableData"][ + "bootableIso"][self.hypervisor.lower()]["url"]: + self.skipTest( + "Bootable Iso URL not present in test data for %s" % + self.hypervisor) + + self.testdata["configurableData"]["bootableIso"]["url"] = self.testdata[ + "configurableData"]["bootableIso"][self.hypervisor.lower()]["url"] self.iso = Iso.create( - self.apiclient, - self.services["iso"], - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + self.testdata["configurableData"]["bootableIso"], + account=self.account.name, + domainid=self.account.domainid + ) try: # Download the ISO self.iso.download(self.apiclient) - + except Exception as e: - raise Exception("Exception while downloading ISO %s: %s"\ - % (self.iso.id, e)) + 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.account.name) self.virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - templateid=self.iso.id, - serviceofferingid=self.service_offering.id, - diskofferingid=self.disk_offering.id, - startvm=True, - hypervisor=self.hypervisor - ) - - response = self.virtual_machine.getState(self.apiclient, VirtualMachine.RUNNING) + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + templateid=self.iso.id, + serviceofferingid=self.service_offering.id, + diskofferingid=self.disk_offering.id, + startvm=True, + hypervisor=self.hypervisor + ) + + response = self.virtual_machine.getState( + self.apiclient, + VirtualMachine.RUNNING) self.assertEqual(response[0], PASS, response[1]) return - @attr(tags=["advanced", "eip", "advancedns", "basic", "sg"], required_hardware="false") + @attr( + tags=[ + "advanced", + "eip", + "advancedns", + "basic", + "sg"], + required_hardware="false") def test_03_deploy_ha_vm_iso_startvm_false(self): """Test Deploy HA enabled Virtual Machine from ISO with startvm=false """ @@ -877,21 +919,25 @@ class TestDeployHaEnabledVM(cloudstackTestCase): # should be "Stopped". 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()) + self.skipTest( + "vm deploy from ISO feature is not supported on %s" % + self.hypervisor.lower()) self.debug("Deploying instance in the account: %s" % - self.account.name) + self.account.name) self.virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - diskofferingid=self.disk_offering.id, - startvm=False - ) - - response = self.virtual_machine.getState(self.apiclient, VirtualMachine.STOPPED) + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + diskofferingid=self.disk_offering.id, + startvm=False + ) + + response = self.virtual_machine.getState( + self.apiclient, + VirtualMachine.STOPPED) self.assertEqual(response[0], PASS, response[1]) return @@ -901,34 +947,36 @@ class TestRouterStateAfterDeploy(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.testClient = super(TestRouterStateAfterDeploy, cls).getClsTestClient() + cls.testClient = super( + TestRouterStateAfterDeploy, + cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() - cls.services = Services().services + 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.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.testdata["ostype"] + ) # Create service offerings, disk offerings etc cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.testdata["service_offering"] + ) cls.disk_offering = DiskOffering.create( - cls.api_client, - cls.services["disk_offering"] - ) + cls.api_client, + cls.testdata["disk_offering"] + ) # Cleanup cls._cleanup = [ - cls.service_offering, - cls.disk_offering, - ] + cls.service_offering, + cls.disk_offering, + ] return @classmethod @@ -942,15 +990,14 @@ class TestRouterStateAfterDeploy(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() - self.services = Services().services - self.services["virtual_machine"]["zoneid"] = self.zone.id - self.services["virtual_machine"]["template"] = self.template.id - self.services["iso"]["zoneid"] = self.zone.id + self.testdata["virtual_machine"]["zoneid"] = self.zone.id + self.testdata["virtual_machine"]["template"] = self.template.id + self.testdata["iso"]["zoneid"] = self.zone.id self.account = Account.create( - self.apiclient, - self.services["account"], - domainid=self.domain.id - ) + self.apiclient, + self.testdata["account"], + domainid=self.domain.id + ) self.cleanup = [self.account] return @@ -974,79 +1021,82 @@ class TestRouterStateAfterDeploy(cloudstackTestCase): # should be "Running". self.debug("Deploying instance in the account: %s" % - self.account.name) + self.account.name) self.virtual_machine_1 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - diskofferingid=self.disk_offering.id, - startvm=False - ) - - response = self.virtual_machine_1.getState(self.apiclient, VirtualMachine.STOPPED) + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + diskofferingid=self.disk_offering.id, + startvm=False + ) + + response = self.virtual_machine_1.getState( + self.apiclient, + VirtualMachine.STOPPED) self.assertEqual(response[0], PASS, response[1]) self.debug("Checking the router state after VM deployment") routers = Router.list( - self.apiclient, - account=self.account.name, - domainid=self.account.domainid, - listall=True - ) + self.apiclient, + account=self.account.name, + domainid=self.account.domainid, + listall=True + ) self.assertEqual( - routers, - None, - "List routers should return empty response" - ) + routers, + None, + "List routers should return empty response" + ) self.debug( "Deploying another instance (startvm=true) in the account: %s" % - self.account.name) + self.account.name) self.virtual_machine_2 = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - diskofferingid=self.disk_offering.id, - startvm=True - ) - - response = self.virtual_machine_2.getState(self.apiclient, VirtualMachine.RUNNING) + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + diskofferingid=self.disk_offering.id, + startvm=True + ) + + response = self.virtual_machine_2.getState( + self.apiclient, + VirtualMachine.RUNNING) self.assertEqual(response[0], PASS, response[1]) self.debug("Checking the router state after VM deployment") routers = Router.list( - self.apiclient, - account=self.account.name, - domainid=self.account.domainid, - listall=True - ) + self.apiclient, + account=self.account.name, + domainid=self.account.domainid, + listall=True + ) self.assertEqual( - isinstance(routers, list), - True, - "List routers should not return empty response" - ) + isinstance(routers, list), + True, + "List routers should not return empty response" + ) for router in routers: self.debug("Router state: %s" % router.state) self.assertEqual( router.state, "Running", - "Router should be in running state when instance is running in the account" - ) + "Router should be in running state when instance is running in the account") self.debug("Destroying the running VM:%s" % - self.virtual_machine_2.name) + self.virtual_machine_2.name) self.virtual_machine_2.delete(self.apiclient, expunge=True) routers = Router.list( - self.apiclient, - account=self.account.name, - domainid=self.account.domainid, - listall=True - ) + self.apiclient, + account=self.account.name, + domainid=self.account.domainid, + listall=True + ) self.assertNotEqual( - routers, - None, - "Router should get deleted after expunge delay+wait" - ) + routers, + None, + "Router should get deleted after expunge delay+wait" + ) return @@ -1058,31 +1108,31 @@ class TestDeployVMBasicZone(cloudstackTestCase): cls.testClient = super(TestDeployVMBasicZone, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() - cls.services = Services().services + 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.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.api_client, + cls.zone.id, + cls.testdata["ostype"] + ) # Create service offerings, disk offerings etc cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.testdata["service_offering"] + ) cls.disk_offering = DiskOffering.create( - cls.api_client, - cls.services["disk_offering"] - ) + cls.api_client, + cls.testdata["disk_offering"] + ) # Cleanup cls._cleanup = [ - cls.service_offering, - cls.disk_offering, - ] + cls.service_offering, + cls.disk_offering, + ] return @classmethod @@ -1096,15 +1146,14 @@ class TestDeployVMBasicZone(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() - self.services = Services().services - self.services["virtual_machine"]["zoneid"] = self.zone.id - self.services["iso"]["zoneid"] = self.zone.id - self.services["virtual_machine"]["template"] = self.template.id + self.testdata["virtual_machine"]["zoneid"] = self.zone.id + self.testdata["iso"]["zoneid"] = self.zone.id + self.testdata["virtual_machine"]["template"] = self.template.id self.account = Account.create( - self.apiclient, - self.services["account"], - domainid=self.domain.id - ) + self.apiclient, + self.testdata["account"], + domainid=self.domain.id + ) self.cleanup = [self.account] return @@ -1122,29 +1171,31 @@ class TestDeployVMFromTemplate(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.testClient = super(TestDeployVMFromTemplate, cls).getClsTestClient() + cls.testClient = super( + TestDeployVMFromTemplate, + cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() - cls.services = Services().services + 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()) # Create service, disk offerings etc cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"], - offerha=True - ) + cls.api_client, + cls.testdata["service_offering"], + offerha=True + ) cls.disk_offering = DiskOffering.create( - cls.api_client, - cls.services["disk_offering"] - ) + cls.api_client, + cls.testdata["disk_offering"] + ) # Cleanup cls._cleanup = [ - cls.service_offering, - cls.disk_offering, - ] + cls.service_offering, + cls.disk_offering, + ] return @classmethod @@ -1158,33 +1209,32 @@ class TestDeployVMFromTemplate(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.hypervisor = self.testClient.getHypervisorInfo() self.dbclient = self.testClient.getDbConnection() - self.services = Services().services - self.services["virtual_machine"]["zoneid"] = self.zone.id + self.testdata["virtual_machine"]["zoneid"] = self.zone.id self.account = Account.create( - self.apiclient, - self.services["account"], - domainid=self.domain.id - ) + self.apiclient, + self.testdata["account"], + domainid=self.domain.id + ) builtin_info = get_builtin_template_info(self.apiclient, self.zone.id) - self.services["template"]["url"] = builtin_info[0] - self.services["template"]["hypervisor"] = builtin_info[1] - self.services["template"]["format"] = builtin_info[2] + self.testdata["privatetemplate"]["url"] = builtin_info[0] + self.testdata["privatetemplate"]["hypervisor"] = builtin_info[1] + self.testdata["privatetemplate"]["format"] = builtin_info[2] # Register new template self.template = Template.register( - self.apiclient, - self.services["template"], - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid, - hypervisor=self.hypervisor - ) + self.apiclient, + self.testdata["privatetemplate"], + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid, + hypervisor=self.hypervisor + ) self.debug( - "Registered a template of format: %s with ID: %s" % ( - self.services["template"]["format"], - self.template.id - )) + "Registered a template of format: %s with ID: %s" % ( + self.testdata["privatetemplate"]["format"], + self.template.id + )) try: self.template.download(self.apiclient) except Exception as e: @@ -1201,7 +1251,14 @@ class TestDeployVMFromTemplate(cloudstackTestCase): except Exception as e: self.debug("Warning! Exception in tearDown: %s" % e) - @attr(tags=["advanced", "eip", "advancedns", "basic", "sg"], required_hardware="true") + @attr( + tags=[ + "advanced", + "eip", + "advancedns", + "basic", + "sg"], + required_hardware="true") def test_deploy_vm_password_enabled(self): """Test Deploy Virtual Machine with startVM=false & enabledpassword in template @@ -1214,24 +1271,28 @@ class TestDeployVMFromTemplate(cloudstackTestCase): # and running state self.debug("Deploying instance in the account: %s" % - self.account.name) + self.account.name) self.virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - templateid=self.template.id, - startvm=False, - ) - - response = self.virtual_machine.getState(self.apiclient, VirtualMachine.STOPPED) + self.apiclient, + self.testdata["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + templateid=self.template.id, + startvm=False, + ) + + response = self.virtual_machine.getState( + self.apiclient, + VirtualMachine.STOPPED) self.assertEqual(response[0], PASS, response[1]) self.debug("Starting the instance: %s" % self.virtual_machine.name) self.virtual_machine.start(self.apiclient) self.debug("Started the instance: %s" % self.virtual_machine.name) - response = self.virtual_machine.getState(self.apiclient, VirtualMachine.RUNNING) + response = self.virtual_machine.getState( + self.apiclient, + VirtualMachine.RUNNING) self.assertEqual(response[0], PASS, response[1]) return @@ -1243,39 +1304,39 @@ class TestVMAccountLimit(cloudstackTestCase): cls.testClient = super(TestVMAccountLimit, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() - cls.services = Services().services + 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.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) - cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.api_client, + cls.zone.id, + cls.testdata["ostype"] + ) + cls.testdata["virtual_machine"]["zoneid"] = cls.zone.id # Create Account, VMs etc cls.account = Account.create( - cls.api_client, - cls.services["account"], - domainid=cls.domain.id - ) + cls.api_client, + cls.testdata["account"], + domainid=cls.domain.id + ) cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.testdata["service_offering"] + ) cls._cleanup = [ - cls.service_offering, - cls.account - ] + cls.service_offering, + cls.account + ] return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -1289,13 +1350,20 @@ class TestVMAccountLimit(cloudstackTestCase): def tearDown(self): try: - #Clean up, terminate the created instance, volumes and snapshots + # Clean up, terminate the created instance, volumes and snapshots cleanup_resources(self.apiclient, self.cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags=["advanced", "eip", "advancedns", "basic", "sg"], required_hardware="false") + @attr( + tags=[ + "advanced", + "eip", + "advancedns", + "basic", + "sg"], + required_hardware="false") def test_vm_per_account(self): """Test VM limit per account """ @@ -1307,47 +1375,47 @@ class TestVMAccountLimit(cloudstackTestCase): self.debug( "Updating instance resource limit for account: %s" % - self.account.name) + self.account.name) # Set usage_vm=1 for Account 1 update_resource_limit( - self.apiclient, - 0, # Instance - account=self.account.name, - domainid=self.account.domainid, - max=1 - ) + self.apiclient, + 0, # Instance + account=self.account.name, + domainid=self.account.domainid, + max=1 + ) self.debug( "Deploying VM instance in account: %s" % - self.account.name) + self.account.name) virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - templateid=self.template.id, - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - startvm=False - ) + self.apiclient, + self.testdata["virtual_machine"], + templateid=self.template.id, + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False + ) # Verify VM state self.assertEqual( - virtual_machine.state, - 'Stopped', - "Check VM state is Running or not" - ) + virtual_machine.state, + 'Stopped', + "Check VM state is Running or not" + ) # Exception should be raised for second instance (account_1) with self.assertRaises(Exception): VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - templateid=self.template.id, - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - startvm=False - ) + self.apiclient, + self.testdata["virtual_machine"], + templateid=self.template.id, + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False + ) return @@ -1358,39 +1426,39 @@ class TestUploadAttachVolume(cloudstackTestCase): cls.testClient = super(TestUploadAttachVolume, cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() - cls.services = Services().services + 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.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) - cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.api_client, + cls.zone.id, + cls.testdata["ostype"] + ) + cls.testdata["virtual_machine"]["zoneid"] = cls.zone.id # Create Account, VMs etc cls.account = Account.create( - cls.api_client, - cls.services["account"], - domainid=cls.domain.id - ) + cls.api_client, + cls.testdata["account"], + domainid=cls.domain.id + ) cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.testdata["service_offering"] + ) cls._cleanup = [ - cls.service_offering, - cls.account - ] + cls.service_offering, + cls.account + ] return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -1404,13 +1472,20 @@ class TestUploadAttachVolume(cloudstackTestCase): def tearDown(self): try: - #Clean up, terminate the created instance, volumes and snapshots + # Clean up, terminate the created instance, volumes and snapshots cleanup_resources(self.apiclient, self.cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags=["advanced", "eip", "advancedns", "basic", "sg"], required_hardware="false") + @attr( + tags=[ + "advanced", + "eip", + "advancedns", + "basic", + "sg"], + required_hardware="false") def test_upload_attach_volume(self): """Test Upload volume and attach to VM in stopped state """ @@ -1421,16 +1496,16 @@ class TestUploadAttachVolume(cloudstackTestCase): # 3. Attach the volume to the deployed VM in step 2 self.debug( - "Uploading the volume: %s" % - self.services["volume"]["diskname"]) + "Uploading the volume: %s" % + self.testdata["configurableData"]["upload_volume"]["diskname"]) try: volume = Volume.upload( - self.apiclient, - self.services["volume"], - zoneid=self.zone.id, - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + self.testdata["configurableData"]["upload_volume"], + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid + ) self.debug("Uploading the volume: %s" % volume.name) volume.wait_for_upload(self.apiclient) self.debug("Volume: %s uploaded successfully") @@ -1439,23 +1514,23 @@ class TestUploadAttachVolume(cloudstackTestCase): self.debug( "Deploying VM instance in account: %s" % - self.account.name) + self.account.name) virtual_machine = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - templateid=self.template.id, - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - startvm=False - ) + self.apiclient, + self.testdata["virtual_machine"], + templateid=self.template.id, + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + startvm=False + ) # Verify VM state self.assertEqual( - virtual_machine.state, - 'Stopped', - "Check VM state is Running or not" - ) + virtual_machine.state, + 'Stopped', + "Check VM state is Running or not" + ) virtual_machine.attach_volume(self.apiclient, volume) return @@ -1464,35 +1539,37 @@ class TestDeployOnSpecificHost(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.testClient = super(TestDeployOnSpecificHost, cls).getClsTestClient() + cls.testClient = super( + TestDeployOnSpecificHost, + cls).getClsTestClient() cls.api_client = cls.testClient.getApiClient() - cls.services = Services().services + 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.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) - cls.services["virtual_machine"]["zoneid"] = cls.zone.id - cls.services["virtual_machine"]["template"] = cls.template.id + cls.api_client, + cls.zone.id, + cls.testdata["ostype"] + ) + cls.testdata["virtual_machine"]["zoneid"] = cls.zone.id + cls.testdata["virtual_machine"]["template"] = cls.template.id cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] - ) + cls.api_client, + cls.testdata["service_offering"] + ) cls._cleanup = [ - cls.service_offering, - ] + cls.service_offering, + ] return @classmethod def tearDownClass(cls): try: - #Cleanup resources used + # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -1502,11 +1579,11 @@ class TestDeployOnSpecificHost(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.account = Account.create( - self.apiclient, - self.services["account"], - admin=True, - domainid=self.domain.id - ) + self.apiclient, + self.testdata["account"], + admin=True, + domainid=self.domain.id + ) self.cleanup = [] return @@ -1535,60 +1612,60 @@ class TestDeployOnSpecificHost(cloudstackTestCase): # 3. VM should be on the host that it was deployed on hosts = Host.list( - self.apiclient, - zoneid=self.zone.id, - type='Routing', - state='Up', - listall=True - ) + self.apiclient, + zoneid=self.zone.id, + type='Routing', + state='Up', + listall=True + ) self.assertEqual( - isinstance(hosts, list), - True, - "CS should have atleast one host Up and Running" - ) + isinstance(hosts, list), + True, + "CS should have atleast one host Up and Running" + ) host = hosts[0] self.debug("Deploting VM on host: %s" % host.name) try: vm = VirtualMachine.create( - self.apiclient, - self.services["virtual_machine"], - templateid=self.template.id, - accountid=self.account.name, - domainid=self.account.domainid, - serviceofferingid=self.service_offering.id, - hostid=host.id - ) + self.apiclient, + self.testdata["virtual_machine"], + templateid=self.template.id, + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + hostid=host.id + ) self.debug("Deploy VM succeeded") except Exception as e: self.fail("Deploy VM failed with exception: %s" % e) self.debug("Cheking the state of deployed VM") vms = VirtualMachine.list( - self.apiclient, - id=vm.id, - listall=True, - account=self.account.name, - domainid=self.account.domainid - ) + self.apiclient, + id=vm.id, + listall=True, + account=self.account.name, + domainid=self.account.domainid + ) self.assertEqual( - isinstance(vms, list), - True, - "List Vm should return a valid response" - ) + isinstance(vms, list), + True, + "List Vm should return a valid response" + ) vm_response = vms[0] self.assertEqual( - vm_response.state, - "Running", - "VM should be in running state after deployment" - ) + vm_response.state, + "Running", + "VM should be in running state after deployment" + ) self.assertEqual( - vm_response.hostid, - host.id, - "Host id where VM is deployed should match" - ) + vm_response.hostid, + host.id, + "Host id where VM is deployed should match" + ) return