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 D96CC109F9 for ; Tue, 23 Dec 2014 09:33:58 +0000 (UTC) Received: (qmail 9104 invoked by uid 500); 23 Dec 2014 09:33:55 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 9075 invoked by uid 500); 23 Dec 2014 09:33:55 -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 9066 invoked by uid 99); 23 Dec 2014 09:33:55 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Dec 2014 09:33:55 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5C704A34C1E; Tue, 23 Dec 2014 09:33:55 +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 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: git commit: updated refs/heads/master to bce67bc Date: Tue, 23 Dec 2014 09:33:55 +0000 (UTC) Repository: cloudstack Updated Branches: refs/heads/master fc2c1a09a -> bce67bc28 CLOUDSTACK-8099: Fixed missing import in test_dynamic_compute_offering.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/bce67bc2 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/bce67bc2 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/bce67bc2 Branch: refs/heads/master Commit: bce67bc282e12db15a2630af30a0bf9ea5d46c29 Parents: fc2c1a0 Author: Ashutosh K Authored: Mon Dec 22 15:40:39 2014 +0530 Committer: SrikanteswaraRao Talluri Committed: Tue Dec 23 15:03:30 2014 +0530 ---------------------------------------------------------------------- .../component/test_dynamic_compute_offering.py | 944 ++++++++++++------- 1 file changed, 620 insertions(+), 324 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/bce67bc2/test/integration/component/test_dynamic_compute_offering.py ---------------------------------------------------------------------- diff --git a/test/integration/component/test_dynamic_compute_offering.py b/test/integration/component/test_dynamic_compute_offering.py index 1e47579..5215f84 100644 --- a/test/integration/component/test_dynamic_compute_offering.py +++ b/test/integration/component/test_dynamic_compute_offering.py @@ -17,13 +17,15 @@ """ Tests for Dynamic Compute Offering Feature - Test Plan: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Dynamic+ComputeOffering + Test Plan: https://cwiki.apache.org/confluence/display/CLOUDSTACK + /Dynamic+ComputeOffering Issue Link: https://issues.apache.org/jira/browse/CLOUDSTACK-6147 - Feature Specifications: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Dynamic+Compute+Offering+FS + Feature Specifications: https://cwiki.apache.org/confluence/display/ + CLOUDSTACK/Dynamic+Compute+Offering+FS """ -from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.cloudstackTestCase import cloudstackTestCase, unittest from marvin.lib.utils import (cleanup_resources, validateList, random_gen, @@ -43,8 +45,10 @@ from nose.plugins.attrib import attr from marvin.codes import PASS, ADMIN_ACCOUNT, USER_ACCOUNT, FAILED from ddt import ddt, data + @ddt class TestDynamicServiceOffering(cloudstackTestCase): + """Test Dynamic Service Offerings """ @@ -65,7 +69,8 @@ class TestDynamicServiceOffering(cloudstackTestCase): cls.services["ostype"] ) if cls.template == FAILED: - assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + assert False, "get_template() failed to return template\ + with description %s" % cls.services["ostype"] cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id cls._cleanup = [] @@ -101,14 +106,14 @@ class TestDynamicServiceOffering(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) return - @attr(tags=["basic","advanced"]) + @attr(tags=["basic", "advanced"]) def test_create_normal_compute_offering(self): """ Create normal compute offering with non zero values for cpu, cpu number and memory""" # Steps: - # 1. Create normal compute offering with non zero values for cpu number, - # cpu speed, memory + # 1. Create normal compute offering with non zero values + # for cpu number, cpu speed, memory # Validations: # 1. Compute offering should be created @@ -117,16 +122,20 @@ class TestDynamicServiceOffering(cloudstackTestCase): self.services["service_offering"]["cpuspeed"] = 256 self.services["service_offering"]["memory"] = 128 - serviceOffering = ServiceOffering.create(self.api_client, - self.services["service_offering"] - ) - self.assertEqual(verifyComputeOfferingCreation(self.apiclient, serviceOffering.id), - PASS, "Compute Offering verification failed") + serviceOffering = ServiceOffering.create( + self.api_client, + self.services["service_offering"]) + self.assertEqual( + verifyComputeOfferingCreation( + self.apiclient, + serviceOffering.id), + PASS, + "Compute Offering verification failed") self.cleanup_co.append(serviceOffering) return - @attr(tags=["basic","advanced"]) + @attr(tags=["basic", "advanced"]) def test_create_dynamic_compute_offering(self): """ Create dynamic compute offering with cpunumber, cpuspeed and memory not specified""" @@ -142,16 +151,20 @@ class TestDynamicServiceOffering(cloudstackTestCase): self.services["service_offering"]["cpuspeed"] = "" self.services["service_offering"]["memory"] = "" - serviceOffering = ServiceOffering.create(self.api_client, - self.services["service_offering"] - ) - self.assertEqual(verifyComputeOfferingCreation(self.apiclient, serviceOffering.id), - PASS, "Compute Offering verification failed") + serviceOffering = ServiceOffering.create( + self.api_client, + self.services["service_offering"]) + self.assertEqual( + verifyComputeOfferingCreation( + self.apiclient, + serviceOffering.id), + PASS, + "Compute Offering verification failed") self.cleanup_co.append(serviceOffering) return - @attr(tags=["basic","advanced"]) + @attr(tags=["basic", "advanced"]) def test_create_dynamic_compute_offering_no_cpunumber(self): """ Create dynamic compute offering with only cpunumber unspecified""" @@ -163,16 +176,17 @@ class TestDynamicServiceOffering(cloudstackTestCase): self.services["service_offering"]["memory"] = 128 try: - serviceOffering = ServiceOffering.create(self.api_client, - self.services["service_offering"] - ) + serviceOffering = ServiceOffering.create( + self.api_client, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering) - self.fail("Compute Offering creation succeded, it should have failed") + self.fail( + "Compute Offering creation succeded, it should have failed") except Exception: self.debug("Compute Offering Creation failed as expected") return - @attr(tags=["basic","advanced"]) + @attr(tags=["basic", "advanced"]) def test_create_dynamic_compute_offering_no_cpuspeed(self): """ Create dynamic compute offering with only cpuspeed unspecified""" @@ -184,16 +198,17 @@ class TestDynamicServiceOffering(cloudstackTestCase): self.services["service_offering"]["memory"] = 128 try: - serviceOffering = ServiceOffering.create(self.api_client, - self.services["service_offering"] - ) + serviceOffering = ServiceOffering.create( + self.api_client, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering) - self.fail("Compute Offering creation succeded, it should have failed") + self.fail( + "Compute Offering creation succeded, it should have failed") except Exception: self.debug("Compute Offering Creation failed as expected") return - @attr(tags=["basic","advanced"]) + @attr(tags=["basic", "advanced"]) def test_create_dynamic_compute_offering_no_memory(self): """ Create dynamic compute offering with only memory unspecified""" @@ -205,17 +220,18 @@ class TestDynamicServiceOffering(cloudstackTestCase): self.services["service_offering"]["memory"] = "" try: - serviceOffering = ServiceOffering.create(self.api_client, - self.services["service_offering"] - ) + serviceOffering = ServiceOffering.create( + self.api_client, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering) - self.fail("Compute Offering creation succeded, it should have failed") + self.fail( + "Compute Offering creation succeded, it should have failed") except Exception: self.debug("Compute Offering Creation failed as expected") return @data(ADMIN_ACCOUNT, USER_ACCOUNT) - @attr(tags=["basic","advanced"]) + @attr(tags=["basic", "advanced"]) def test_deploy_virtual_machines_static_offering(self, value): """Test deploy VM with static offering""" @@ -223,22 +239,26 @@ class TestDynamicServiceOffering(cloudstackTestCase): # 1. Create admin/user account and create its user api client # 2. Create a static compute offering # 3. Deploy a VM with account api client and static service offering - # 4. Repeat step 3 but also pass custom values for cpu number, cpu speed and memory - # while deploying VM + # 4. Repeat step 3 but also pass custom values for cpu number, + # cpu speed and memory while deploying VM # Validations: # 1. Step 3 should succeed # 2. Step 4 should fail - isadmin=True + isadmin = True if value == USER_ACCOUNT: - isadmin=False + isadmin = False # Create Account - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id, + admin=isadmin) apiclient = self.testClient.getUserApiClient( - UserName=self.account.name, - DomainName=self.account.domain) + UserName=self.account.name, + DomainName=self.account.domain) self.cleanup.append(self.account) # Create service offering @@ -246,34 +266,41 @@ class TestDynamicServiceOffering(cloudstackTestCase): self.services["service_offering"]["cpuspeed"] = 256 self.services["service_offering"]["memory"] = 128 - serviceOffering = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering) # Deploy VM with static service offering try: - VirtualMachine.create(apiclient,self.services["virtual_machine"], - serviceofferingid=serviceOffering.id, - accountid=self.account.name,domainid=self.account.domainid) + VirtualMachine.create( + apiclient, + self.services["virtual_machine"], + serviceofferingid=serviceOffering.id, + accountid=self.account.name, + domainid=self.account.domainid) except Exception as e: self.fail("vm creation failed: %s" % e) # Deploy VM with static service offering, also with custom values try: - VirtualMachine.create(apiclient,self.services["virtual_machine"], + VirtualMachine.create( + apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering.id, customcpunumber=4, customcpuspeed=512, custommemory=256, - accountid=self.account.name,domainid=self.account.domainid) + accountid=self.account.name, + domainid=self.account.domainid) self.fail("VM creation should have failed, it succeeded") except Exception as e: self.debug("vm creation failed as expected: %s" % e) return @data(ADMIN_ACCOUNT, USER_ACCOUNT) - @attr(tags=["basic","advanced"]) + @attr(tags=["basic", "advanced"]) def test_deploy_virtual_machines_dynamic_offering(self, value): """Test deploy VM with dynamic compute offering""" @@ -281,26 +308,31 @@ class TestDynamicServiceOffering(cloudstackTestCase): # 1. Create admin/user account and create its user api client # 2. Create a dynamic service offering # 3. Deploy a VM with account api client and dynamic service offering - # without providing custom values for cpu number, cpu speed and memory - # 4. Deploy a VM with account api client and dynamic service offering providing - # custom values for cpu number, cpu speed and memory - # 5. Deploy a VM with account api client and dynamic service offering providing - # custom values only for cpu number + # without providing custom values for cpu number, cpu speed and + # memory + # 4. Deploy a VM with account api client and dynamic service offering + # providing custom values for cpu number, cpu speed and memory + # 5. Deploy a VM with account api client and dynamic service offering + # providing custom values only for cpu number # Validations: # 1. Step 3 should fail # 2. Step 4 should succeed # 3. Step 5 should fail - isadmin=True + isadmin = True if value == USER_ACCOUNT: - isadmin=False + isadmin = False # Create Account and its api client - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id, + admin=isadmin) apiclient = self.testClient.getUserApiClient( - UserName=self.account.name, - DomainName=self.account.domain) + UserName=self.account.name, + DomainName=self.account.domain) self.cleanup.append(self.account) # Create dynamic service offering @@ -308,17 +340,22 @@ class TestDynamicServiceOffering(cloudstackTestCase): self.services["service_offering"]["cpuspeed"] = "" self.services["service_offering"]["memory"] = "" - serviceOffering = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering) - # Deploy VM with dynamic compute offering without providing custom values for + # Deploy VM with dynamic compute offering without providing + # custom values for # cpu number, cpu speed and memory try: - VirtualMachine.create(apiclient,self.services["virtual_machine"], - serviceofferingid=serviceOffering.id, - accountid=self.account.name,domainid=self.account.domainid) + VirtualMachine.create( + apiclient, + self.services["virtual_machine"], + serviceofferingid=serviceOffering.id, + accountid=self.account.name, + domainid=self.account.domainid) self.fail("VM creation succeded, it should have failed") except Exception as e: self.debug("vm creation failed as expected with error: %s" % e) @@ -326,29 +363,35 @@ class TestDynamicServiceOffering(cloudstackTestCase): # Deploy VM with dynamic compute offering providing custom values for # cpu number, cpu speed and memory try: - VirtualMachine.create(apiclient,self.services["virtual_machine"], + VirtualMachine.create( + apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering.id, customcpunumber=2, customcpuspeed=256, custommemory=128, - accountid=self.account.name,domainid=self.account.domainid) + accountid=self.account.name, + domainid=self.account.domainid) except Exception as e: self.fail("vm creation failed: %s" % e) - # Deploy VM with dynamic compute offering providing custom values for only - # cpu number + # Deploy VM with dynamic compute offering providing custom values + # for only cpu number try: - VirtualMachine.create(apiclient,self.services["virtual_machine"], + VirtualMachine.create( + apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering.id, customcpunumber=2, - accountid=self.account.name,domainid=self.account.domainid) + accountid=self.account.name, + domainid=self.account.domainid) self.fail("VM deployment should have failed, it succeded") except Exception as e: self.debug("vm creation failed as expected: %s" % e) return @data(ADMIN_ACCOUNT, USER_ACCOUNT) - @attr(tags=["basic","advanced"]) + @attr(tags=["basic", "advanced"]) def test_check_vm_stats(self, value): """Deploy VM with dynamic service offering and check VM stats""" @@ -359,15 +402,19 @@ class TestDynamicServiceOffering(cloudstackTestCase): # providing custom values for cpu number, cpu speed and memory # 4. List the VM and verify the dynamic parameters are same as passed - isadmin=True + isadmin = True if value == USER_ACCOUNT: - isadmin=False + isadmin = False # Create Account and api client - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id, + admin=isadmin) apiclient = self.testClient.getUserApiClient( - UserName=self.account.name, - DomainName=self.account.domain) + UserName=self.account.name, + DomainName=self.account.domain) self.cleanup.append(self.account) # Create dynamic compute offering @@ -375,8 +422,9 @@ class TestDynamicServiceOffering(cloudstackTestCase): self.services["service_offering"]["cpuspeed"] = "" self.services["service_offering"]["memory"] = "" - serviceOffering = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering) @@ -387,41 +435,51 @@ class TestDynamicServiceOffering(cloudstackTestCase): # Deploy VM with dynamic service offering and the custom values try: - virtualMachine = VirtualMachine.create(apiclient,self.services["virtual_machine"], + virtualMachine = VirtualMachine.create( + apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering.id, customcpunumber=customcpunumber, customcpuspeed=customcpuspeed, custommemory=custommemory, - accountid=self.account.name,domainid=self.account.domainid) + accountid=self.account.name, + domainid=self.account.domainid) except Exception as e: self.fail("vm creation failed: %s" % e) vmlist = VirtualMachine.list(self.apiclient, id=virtualMachine.id) - self.assertEqual(validateList(vmlist)[0], PASS, "vm list validation failed") + self.assertEqual( + validateList(vmlist)[0], + PASS, + "vm list validation failed") vm = vmlist[0] # Verify the custom values self.assertEqual(str(vm.cpunumber), str(customcpunumber), "vm cpu number %s\ - not matching with provided custom cpu number %s" % \ - (vm.cpunumber, customcpunumber)) + not matching with provided custom cpu number %s" % + (vm.cpunumber, customcpunumber)) self.assertEqual(str(vm.cpuspeed), str(customcpuspeed), "vm cpu speed %s\ - not matching with provided custom cpu speed %s" % \ - (vm.cpuspeed, customcpuspeed)) + not matching with provided custom cpu speed %s" % + (vm.cpuspeed, customcpuspeed)) self.assertEqual(str(vm.memory), str(custommemory), "vm memory %s\ - not matching with provided custom memory %s" % \ - (vm.memory, custommemory)) + not matching with provided custom memory %s" % + (vm.memory, custommemory)) return + @ddt class TestScaleVmDynamicServiceOffering(cloudstackTestCase): + """Test scaling VMs with dynamic Service Offerings """ @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestScaleVmDynamicServiceOffering,cls).getClsTestClient() + cloudstackTestClient = super( + TestScaleVmDynamicServiceOffering, + cls).getClsTestClient() cls.api_client = cloudstackTestClient.getApiClient() cls.hypervisor = cloudstackTestClient.getHypervisorInfo() @@ -430,29 +488,35 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): # Get Zone, Domain and templates cls.domain = get_domain(cls.api_client) - cls.zone = get_zone(cls.api_client, cloudstackTestClient.getZoneForTests()) + cls.zone = get_zone( + cls.api_client, + cloudstackTestClient.getZoneForTests()) cls.mode = str(cls.zone.networktype).lower() cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + 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._cleanup = [] - cls.serviceOffering_static_1 = ServiceOffering.create(cls.api_client, - cls.services["service_offering"]) + cls.serviceOffering_static_1 = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"]) cls._cleanup.append(cls.serviceOffering_static_1) if cls.hypervisor.lower() == "vmware": - virtual_machine = VirtualMachine.create(cls.api_client,cls.services["virtual_machine"], - serviceofferingid=cls.serviceOffering_static_1.id, mode=cls.zone.networktype) + virtual_machine = VirtualMachine.create( + cls.api_client, + cls.services["virtual_machine"], + serviceofferingid=cls.serviceOffering_static_1.id, + mode=cls.zone.networktype) cls._cleanup.append(virtual_machine) sshClient = virtual_machine.get_ssh_client() result = str( sshClient.execute("service vmware-tools status")).lower() - if not "running" in result: + if "running" not in result: cls.tearDownClass() raise unittest.SkipTest("Skipping scale VM operation because\ VMware tools are not installed on the VM") @@ -489,7 +553,7 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): return @data(ADMIN_ACCOUNT, USER_ACCOUNT) - @attr(tags=["basic","advanced"]) + @attr(tags=["basic", "advanced"]) def test_change_so_stopped_vm_static_to_static(self, value): """Test scale stopped VM from static offering to static offering""" @@ -503,51 +567,63 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): # Validations: # 1. Scaling operation should be successful - isadmin=True + isadmin = True if value == USER_ACCOUNT: - isadmin=False + isadmin = False try: # Create Account - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id, + admin=isadmin) self.cleanup.append(self.account) apiclient = self.testClient.getUserApiClient( - UserName=self.account.name, - DomainName=self.account.domain) + UserName=self.account.name, + DomainName=self.account.domain) # Create static service offerings (Second offering should have - # one of the custom values greater than 1st one, scaling down is not allowed + # one of the custom values greater than 1st one, scaling down is + # not allowed self.services["service_offering"]["cpunumber"] = "2" self.services["service_offering"]["cpuspeed"] = "256" self.services["service_offering"]["memory"] = "128" - serviceOffering_static_1 = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_static_1 = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.services["service_offering"]["cpunumber"] = "4" - serviceOffering_static_2 = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_static_2 = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering_static_1) self.cleanup_co.append(serviceOffering_static_2) # Deploy VM - virtualMachine = VirtualMachine.create(apiclient,self.services["virtual_machine"], + virtualMachine = VirtualMachine.create( + apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering_static_1.id, - accountid=self.account.name,domainid=self.account.domainid) + accountid=self.account.name, + domainid=self.account.domainid) # Stop VM virtualMachine.stop(apiclient) # Scale VM to new static service offering - virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_static_2.id) + virtualMachine.scale( + apiclient, + serviceOfferingId=serviceOffering_static_2.id) except Exception as e: self.fail("Exception occured: %s" % e) return @data(ADMIN_ACCOUNT, USER_ACCOUNT) - @attr(tags=["basic","advanced"]) + @attr(tags=["basic", "advanced"]) def test_change_so_stopped_vm_static_to_dynamic(self, value): """Test scale stopped VM from static offering to dynamic offering""" @@ -559,22 +635,27 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): # 5. Scale VM with dynamic service offering providing all required # custom values # 6. Deploy another VM with static offring and stop the VM - # 7. Scale VM with dynamic service offering providing only custom cpu number + # 7. Scale VM with dynamic service offering providing only custom cpu + # number # Validations: # 1. Scale operation in step 5 should be successful # 2. Scale operation in step 7 should fail - isadmin=True + isadmin = True if value == USER_ACCOUNT: - isadmin=False + isadmin = False try: # Create Account and api client - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id, + admin=isadmin) apiclient = self.testClient.getUserApiClient( - UserName=self.account.name, - DomainName=self.account.domain) + UserName=self.account.name, + DomainName=self.account.domain) self.cleanup.append(self.account) # Create static and dynamic service offerings @@ -582,50 +663,64 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): self.services["service_offering"]["cpuspeed"] = "256" self.services["service_offering"]["memory"] = "128" - serviceOffering_static = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) - + serviceOffering_static = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.services["service_offering"]["cpunumber"] = "" self.services["service_offering"]["cpuspeed"] = "" self.services["service_offering"]["memory"] = "" - serviceOffering_dynamic = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_dynamic = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering_static) self.cleanup_co.append(serviceOffering_dynamic) # Deploy VM with static service offering - virtualMachine_1 = VirtualMachine.create(apiclient,self.services["virtual_machine"], + virtualMachine_1 = VirtualMachine.create( + apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering_static.id, - accountid=self.account.name,domainid=self.account.domainid) + accountid=self.account.name, + domainid=self.account.domainid) # Stop VM virtualMachine_1.stop(apiclient) # Scale VM to dynamic service offering proving all custom values - virtualMachine_1.scale(apiclient, serviceOfferingId=serviceOffering_dynamic.id, - customcpunumber=4, customcpuspeed=256, custommemory=128) + virtualMachine_1.scale( + apiclient, + serviceOfferingId=serviceOffering_dynamic.id, + customcpunumber=4, + customcpuspeed=256, + custommemory=128) # Deploy VM with static service offering - virtualMachine_2 = VirtualMachine.create(apiclient,self.services["virtual_machine"], + virtualMachine_2 = VirtualMachine.create( + apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering_static.id, - accountid=self.account.name,domainid=self.account.domainid) + accountid=self.account.name, + domainid=self.account.domainid) # Stop VM virtualMachine_2.stop(apiclient) except Exception as e: self.fail("Exception occuered: %s" % e) - # Scale VM to dynamic service offering proving only custom cpu number + # Scale VM to dynamic service offering proving only custom cpu + # number with self.assertRaises(Exception): - virtualMachine_2.scale(apiclient, serviceOfferingId=serviceOffering_dynamic.id, - customcpunumber=4) + virtualMachine_2.scale( + apiclient, + serviceOfferingId=serviceOffering_dynamic.id, + customcpunumber=4) return @data(ADMIN_ACCOUNT, USER_ACCOUNT) - @attr(tags=["basic","advanced"]) + @attr(tags=["basic", "advanced"]) def test_change_so_stopped_vm_dynamic_to_static(self, value): """Test scale stopped VM from dynamic offering to static offering""" @@ -639,16 +734,20 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): # Validations: # 1. Scale operation in step 5 should be successful - isadmin=True + isadmin = True if value == USER_ACCOUNT: - isadmin=False + isadmin = False try: # Create account and api client - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id, + admin=isadmin) apiclient = self.testClient.getUserApiClient( - UserName=self.account.name, - DomainName=self.account.domain) + UserName=self.account.name, + DomainName=self.account.domain) self.cleanup.append(self.account) # Create dynamic and static service offering @@ -656,36 +755,45 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): self.services["service_offering"]["cpuspeed"] = "" self.services["service_offering"]["memory"] = "" - serviceOffering_dynamic = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_dynamic = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.services["service_offering"]["cpunumber"] = "4" self.services["service_offering"]["cpuspeed"] = "256" self.services["service_offering"]["memory"] = "128" - serviceOffering_static = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_static = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering_static) self.cleanup_co.append(serviceOffering_dynamic) # Deploy VM with dynamic service offering - virtualMachine = VirtualMachine.create(apiclient,self.services["virtual_machine"], + virtualMachine = VirtualMachine.create( + apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering_dynamic.id, - accountid=self.account.name,domainid=self.account.domainid, - customcpunumber=2, customcpuspeed=256, custommemory=128) + accountid=self.account.name, + domainid=self.account.domainid, + customcpunumber=2, + customcpuspeed=256, + custommemory=128) # Stop VM and verify that it is in stopped state virtualMachine.stop(apiclient) # Scale VM to static service offering - virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_static.id) + virtualMachine.scale( + apiclient, + serviceOfferingId=serviceOffering_static.id) except Exception as e: self.fail("Exception occured: %s" % e) return @data(ADMIN_ACCOUNT, USER_ACCOUNT) - @attr(tags=["basic","advanced"]) + @attr(tags=["basic", "advanced"]) def test_change_so_stopped_vm_dynamic_to_dynamic(self, value): """Test scale stopped VM from dynamic offering to dynamic offering""" @@ -704,16 +812,20 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): # 2. Scale operation in step 6 should be successful # 3. Scale operation in step 7 should fail - isadmin=True + isadmin = True if value == USER_ACCOUNT: - isadmin=False + isadmin = False try: # Create Account - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id, + admin=isadmin) apiclient = self.testClient.getUserApiClient( - UserName=self.account.name, - DomainName=self.account.domain) + UserName=self.account.name, + DomainName=self.account.domain) self.cleanup.append(self.account) # Create dynamic service offerings @@ -721,43 +833,60 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): self.services["service_offering"]["cpuspeed"] = "" self.services["service_offering"]["memory"] = "" - serviceOffering_dynamic_1 = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_dynamic_1 = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) - serviceOffering_dynamic_2 = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_dynamic_2 = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering_dynamic_1) self.cleanup_co.append(serviceOffering_dynamic_2) # Deploy VM with dynamic service offering - virtualMachine = VirtualMachine.create(apiclient,self.services["virtual_machine"], + virtualMachine = VirtualMachine.create( + apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering_dynamic_1.id, - accountid=self.account.name,domainid=self.account.domainid, - customcpunumber=2, customcpuspeed=256, custommemory=128) + accountid=self.account.name, + domainid=self.account.domainid, + customcpunumber=2, + customcpuspeed=256, + custommemory=128) # Stop VM virtualMachine.stop(apiclient) # Scale VM with same dynamic service offering - virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_dynamic_1.id, - customcpunumber=4, customcpuspeed=512, custommemory=256) + virtualMachine.scale( + apiclient, + serviceOfferingId=serviceOffering_dynamic_1.id, + customcpunumber=4, + customcpuspeed=512, + custommemory=256) # Scale VM with other dynamic service offering - virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_dynamic_2.id, - customcpunumber=4, customcpuspeed=512, custommemory=256) + virtualMachine.scale( + apiclient, + serviceOfferingId=serviceOffering_dynamic_2.id, + customcpunumber=4, + customcpuspeed=512, + custommemory=256) except Exception as e: self.fail("Exception occured: %s" % e) # Scale VM with dynamic service offering proving custom value # only for cpu number with self.assertRaises(Exception): - virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_dynamic_1.id, - customcpunumber=4) + virtualMachine.scale( + apiclient, + serviceOfferingId=serviceOffering_dynamic_1.id, + customcpunumber=4) return @data(ADMIN_ACCOUNT, USER_ACCOUNT) - @attr(tags=["basic","advanced"],required_hardware="true") + @attr(tags=["basic", "advanced"],required_hardware="true") def test_change_so_running_vm_static_to_static(self, value): """Test scale running VM from static offering to static offering""" @@ -772,17 +901,22 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): hypervisor = get_hypervisor_type(self.apiclient) if hypervisor.lower() == "kvm": - self.skipTest("Scaling VM in running state is not supported on KVM") + self.skipTest( + "Scaling VM in running state is not supported on KVM") - isadmin=True + isadmin = True if value == USER_ACCOUNT: - isadmin=False + isadmin = False # Create Account and api client - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id, + admin=isadmin) apiclient = self.testClient.getUserApiClient( - UserName=self.account.name, - DomainName=self.account.domain) + UserName=self.account.name, + DomainName=self.account.domain) self.cleanup.append(self.account) # Create static service offerings @@ -790,34 +924,41 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): self.services["service_offering"]["cpuspeed"] = "256" self.services["service_offering"]["memory"] = "128" - serviceOffering_static_1 = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_static_1 = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.services["service_offering"]["cpunumber"] = "4" - serviceOffering_static_2 = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_static_2 = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering_static_1) self.cleanup_co.append(serviceOffering_static_2) # Deploy VM with static service offering try: - virtualMachine = VirtualMachine.create(apiclient,self.services["virtual_machine"], + virtualMachine = VirtualMachine.create( + apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering_static_1.id, - accountid=self.account.name,domainid=self.account.domainid) + accountid=self.account.name, + domainid=self.account.domainid) except Exception as e: self.fail("vm creation failed: %s" % e) # Scale VM to other static service offering try: - virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_static_2.id) + virtualMachine.scale( + apiclient, + serviceOfferingId=serviceOffering_static_2.id) except Exception as e: self.fail("Failure while changing service offering: %s" % e) return @data(ADMIN_ACCOUNT, USER_ACCOUNT) - @attr(tags=["basic","advanced"],required_hardware="true") + @attr(tags=["basic", "advanced"],required_hardware="true") def test_change_so_running_vm_static_to_dynamic(self, value): """Test scale running VM from static offering to dynamic offering""" @@ -828,7 +969,8 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): # 4. Scale VM with dynamic service offering providing all required # custom values # 5. Deploy another VM with static offring - # 6. Scale VM with dynamic service offering providing only custom cpu number + # 6. Scale VM with dynamic service offering providing only custom cpu + # number # Validations: # 1. Scale operation in step 4 should be successful @@ -836,17 +978,22 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): hypervisor = get_hypervisor_type(self.apiclient) if hypervisor.lower() == "kvm": - self.skipTest("Scaling VM in running state is not supported on KVM") + self.skipTest( + "Scaling VM in running state is not supported on KVM") - isadmin=True + isadmin = True if value == USER_ACCOUNT: - isadmin=False + isadmin = False # Crate account and api client - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id, + admin=isadmin) apiclient = self.testClient.getUserApiClient( - UserName=self.account.name, - DomainName=self.account.domain) + UserName=self.account.name, + DomainName=self.account.domain) self.cleanup.append(self.account) # Create static and dynamic service offerings @@ -854,53 +1001,70 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): self.services["service_offering"]["cpuspeed"] = "256" self.services["service_offering"]["memory"] = "128" - serviceOffering_static = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) - + serviceOffering_static = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.services["service_offering"]["cpunumber"] = "" self.services["service_offering"]["cpuspeed"] = "" self.services["service_offering"]["memory"] = "" - serviceOffering_dynamic = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_dynamic = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering_static) self.cleanup_co.append(serviceOffering_dynamic) # Deploy VM with static service offering try: - virtualMachine_1 = VirtualMachine.create(apiclient,self.services["virtual_machine"], + virtualMachine_1 = VirtualMachine.create( + apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering_static.id, - accountid=self.account.name,domainid=self.account.domainid) + accountid=self.account.name, + domainid=self.account.domainid) except Exception as e: self.fail("vm creation failed: %s" % e) # Scale VM to dynamic service offering try: - virtualMachine_1.scale(apiclient, serviceOfferingId=serviceOffering_dynamic.id, - customcpunumber=4, customcpuspeed=256, custommemory=128) + virtualMachine_1.scale( + apiclient, + serviceOfferingId=serviceOffering_dynamic.id, + customcpunumber=4, + customcpuspeed=256, + custommemory=128) except Exception as e: self.fail("Failure while changing service offering: %s" % e) try: - virtualMachine_2 = VirtualMachine.create(apiclient,self.services["virtual_machine"], + virtualMachine_2 = VirtualMachine.create( + apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering_static.id, - accountid=self.account.name,domainid=self.account.domainid) + accountid=self.account.name, + domainid=self.account.domainid) except Exception as e: self.fail("vm creation failed: %s" % e) try: - virtualMachine_2.scale(apiclient, serviceOfferingId=serviceOffering_dynamic.id, - customcpunumber=4) - self.fail("Changing service offering with incomplete data should have failed, it succeded") + virtualMachine_2.scale( + apiclient, + serviceOfferingId=serviceOffering_dynamic.id, + customcpunumber=4) + self.fail( + "Changing service offering with incomplete data should\ + have failed, it succeded") except Exception as e: - self.debug("Failure while changing service offering as expected: %s" % e) + self.debug( + "Failure while changing service offering as expected: %s" % + e) return @data(ADMIN_ACCOUNT, USER_ACCOUNT) - @attr(tags=["basic","advanced"],required_hardware="true") + @attr(tags=["basic", "advanced"],required_hardware="true") def test_change_so_running_vm_dynamic_to_static(self, value): """Test scale running VM from dynamic offering to static offering""" @@ -914,17 +1078,22 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): # 1. Scale operation in step 4 should be successful hypervisor = get_hypervisor_type(self.apiclient) if hypervisor.lower() == "kvm": - self.skipTest("Scaling VM in running state is not supported on KVM") + self.skipTest( + "Scaling VM in running state is not supported on KVM") - isadmin=True + isadmin = True if value == USER_ACCOUNT: - isadmin=False + isadmin = False # Create account and api client - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id, + admin=isadmin) apiclient = self.testClient.getUserApiClient( - UserName=self.account.name, - DomainName=self.account.domain) + UserName=self.account.name, + DomainName=self.account.domain) self.cleanup.append(self.account) # Create dynamic and static service offerings @@ -932,38 +1101,47 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): self.services["service_offering"]["cpuspeed"] = "" self.services["service_offering"]["memory"] = "" - serviceOffering_dynamic = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_dynamic = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.services["service_offering"]["cpunumber"] = "4" self.services["service_offering"]["cpuspeed"] = "256" self.services["service_offering"]["memory"] = "128" - serviceOffering_static = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_static = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering_static) self.cleanup_co.append(serviceOffering_dynamic) # deploy VM with dynamic service offering try: - virtualMachine = VirtualMachine.create(apiclient,self.services["virtual_machine"], + virtualMachine = VirtualMachine.create( + apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering_dynamic.id, - accountid=self.account.name,domainid=self.account.domainid, - customcpunumber=2, customcpuspeed=256, custommemory=128) + accountid=self.account.name, + domainid=self.account.domainid, + customcpunumber=2, + customcpuspeed=256, + custommemory=128) except Exception as e: self.fail("vm creation failed: %s" % e) # Scale VM to static service offering try: - virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_static.id) + virtualMachine.scale( + apiclient, + serviceOfferingId=serviceOffering_static.id) except Exception as e: self.fail("Failure while changing service offering: %s" % e) return @data(ADMIN_ACCOUNT, USER_ACCOUNT) - @attr(tags=["basic","advanced"],required_hardware="true") + @attr(tags=["basic", "advanced"],required_hardware="true") def test_change_so_running_vm_dynamic_to_dynamic(self, value): """Test scale running VM from dynamic offering to dynamic offering""" @@ -983,17 +1161,22 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): hypervisor = get_hypervisor_type(self.apiclient) if hypervisor.lower() == "kvm": - self.skipTest("Scaling VM in running state is not supported on KVM") + self.skipTest( + "Scaling VM in running state is not supported on KVM") - isadmin=True + isadmin = True if value == USER_ACCOUNT: - isadmin=False + isadmin = False # Create account and api client - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id, + admin=isadmin) apiclient = self.testClient.getUserApiClient( - UserName=self.account.name, - DomainName=self.account.domain) + UserName=self.account.name, + DomainName=self.account.domain) self.cleanup.append(self.account) # Create dynamic service offerings @@ -1001,56 +1184,78 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase): self.services["service_offering"]["cpuspeed"] = "" self.services["service_offering"]["memory"] = "" - serviceOffering_dynamic_1 = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_dynamic_1 = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) - serviceOffering_dynamic_2 = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_dynamic_2 = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering_dynamic_1) self.cleanup_co.append(serviceOffering_dynamic_2) # Deploy VM with dynamic service offering try: - virtualMachine = VirtualMachine.create(apiclient,self.services["virtual_machine"], + virtualMachine = VirtualMachine.create( + apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering_dynamic_1.id, - accountid=self.account.name,domainid=self.account.domainid, - customcpunumber=2, customcpuspeed=256, custommemory=128) + accountid=self.account.name, + domainid=self.account.domainid, + customcpunumber=2, + customcpuspeed=256, + custommemory=128) except Exception as e: self.fail("vm creation failed: %s" % e) # Scale VM with same dynamic offering try: - virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_dynamic_1.id, - customcpunumber=4, customcpuspeed=512, custommemory=256) + virtualMachine.scale( + apiclient, + serviceOfferingId=serviceOffering_dynamic_1.id, + customcpunumber=4, + customcpuspeed=512, + custommemory=256) except Exception as e: self.fail("Failure while changing service offering: %s" % e) # Scale VM with other dynamic service offering try: - virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_dynamic_2.id, - customcpunumber=4, customcpuspeed=512, custommemory=512) + virtualMachine.scale( + apiclient, + serviceOfferingId=serviceOffering_dynamic_2.id, + customcpunumber=4, + customcpuspeed=512, + custommemory=512) except Exception as e: self.fail("Failure while changing service offering: %s" % e) - # Scale VM with dynamic offering proving custom value only for cpu number + # Scale VM with dynamic offering proving custom value only for cpu + # number try: - virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_dynamic_1.id, - customcpunumber=4) - self.fail("Changing service offering should have failed, it succeded") + virtualMachine.scale( + apiclient, + serviceOfferingId=serviceOffering_dynamic_1.id, + customcpunumber=4) + self.fail( + "Changing service offering should have failed, it succeded") except Exception as e: self.debug("Failure while changing service offering: %s" % e) return + @ddt class TestAccountLimits(cloudstackTestCase): - """Test max limit of account (cpunumber and memory) with dynamic compute offering + + """Test max limit of account (cpunumber and memory) with dynamic + compute offering """ @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestAccountLimits,cls).getClsTestClient() + cloudstackTestClient = super(TestAccountLimits, cls).getClsTestClient() cls.api_client = cloudstackTestClient.getApiClient() # Fill services from the external config file @@ -1058,13 +1263,15 @@ class TestAccountLimits(cloudstackTestCase): # Get Zone, Domain and templates cls.domain = get_domain(cls.api_client) - cls.zone = get_zone(cls.api_client, cloudstackTestClient.getZoneForTests()) + cls.zone = get_zone( + cls.api_client, + cloudstackTestClient.getZoneForTests()) cls.mode = str(cls.zone.networktype).lower() cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + 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._cleanup = [] @@ -1101,9 +1308,10 @@ class TestAccountLimits(cloudstackTestCase): return @data(ADMIN_ACCOUNT, USER_ACCOUNT) - @attr(tags=["basic","advanced"]) + @attr(tags=["basic", "advanced"]) def test_max_account_cpus_deploy_VM(self, value): - """Test cpu limits of account while deploying VM with dynamic compute offering""" + """Test cpu limits of account while deploying VM with dynamic + compute offering""" # Steps: # 1. Create Account (admin/user) @@ -1114,12 +1322,16 @@ class TestAccountLimits(cloudstackTestCase): # Validations: # 1. VM creation should fail - isadmin=True + isadmin = True if value == USER_ACCOUNT: - isadmin=False + isadmin = False # Create account and api client - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id, + admin=isadmin) self.cleanup.append(self.account) Resources.updateLimit(self.apiclient, @@ -1133,17 +1345,23 @@ class TestAccountLimits(cloudstackTestCase): self.services["service_offering"]["cpuspeed"] = "" self.services["service_offering"]["memory"] = "" - serviceOffering_dynamic = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_dynamic = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering_dynamic) # Deploy VM with dynamic service offering try: - VirtualMachine.create(self.apiclient,self.services["virtual_machine"], + VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering_dynamic.id, - accountid=self.account.name,domainid=self.account.domainid, - customcpunumber=3, customcpuspeed=256, custommemory=128) + accountid=self.account.name, + domainid=self.account.domainid, + customcpunumber=3, + customcpuspeed=256, + custommemory=128) self.fail("vm creation should have failed, it succeeded") except Exception as e: self.debug("vm creation failed as expected with error: %s" % e) @@ -1151,9 +1369,10 @@ class TestAccountLimits(cloudstackTestCase): return @data(ADMIN_ACCOUNT, USER_ACCOUNT) - @attr(tags=["basic","advanced"]) + @attr(tags=["basic", "advanced"]) def test_max_account_cpus_scale_VM(self, value): - """Test cpu limits of account while scaling VM with dynamic compute offering""" + """Test cpu limits of account while scaling VM with dynamic + compute offering""" # Steps: # 1. Create Account (admin/user) @@ -1166,12 +1385,16 @@ class TestAccountLimits(cloudstackTestCase): # 1. VM creation should succeed # 2. VM scaling operation should fail - isadmin=True + isadmin = True if value == USER_ACCOUNT: - isadmin=False + isadmin = False # Create account and api client - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id, + admin=isadmin) self.cleanup.append(self.account) Resources.updateLimit(self.apiclient, @@ -1185,35 +1408,48 @@ class TestAccountLimits(cloudstackTestCase): self.services["service_offering"]["cpuspeed"] = "" self.services["service_offering"]["memory"] = "" - serviceOffering_dynamic = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_dynamic = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering_dynamic) # Deploy VM with dynamic service offering try: - virtualMachine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], + virtualMachine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering_dynamic.id, - accountid=self.account.name,domainid=self.account.domainid, - customcpunumber=2, customcpuspeed=256, custommemory=128) + accountid=self.account.name, + domainid=self.account.domainid, + customcpunumber=2, + customcpuspeed=256, + custommemory=128) except Exception as e: self.fail("vm creation failed: %s" % e) # Scale VM with same dynamic offering try: - virtualMachine.scale(self.apiclient, serviceOfferingId=serviceOffering_dynamic.id, - customcpunumber=4, customcpuspeed=512, custommemory=256) + virtualMachine.scale( + self.apiclient, + serviceOfferingId=serviceOffering_dynamic.id, + customcpunumber=4, + customcpuspeed=512, + custommemory=256) self.fail("Scaling virtual machine with cpu number more than \ allowed limit (of account) succeded, should have failed") except Exception as e: - self.debug("Failure while changing service offering as expected: %s" % e) + self.debug( + "Failure while changing service offering as expected: %s" % + e) return @data(ADMIN_ACCOUNT, USER_ACCOUNT) - @attr(tags=["basic","advanced"]) + @attr(tags=["basic", "advanced"]) def test_max_account_memory_deploy_VM(self, value): - """Test memory limits of account while deploying VM with dynamic compute offering""" + """Test memory limits of account while deploying VM with dynamic + compute offering""" # Steps: # 1. Create Account (admin/user) @@ -1224,12 +1460,16 @@ class TestAccountLimits(cloudstackTestCase): # Validations: # 1. VM creation should fail - isadmin=True + isadmin = True if value == USER_ACCOUNT: - isadmin=False + isadmin = False # Create account and api client - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id, + admin=isadmin) self.cleanup.append(self.account) Resources.updateLimit(self.apiclient, @@ -1243,17 +1483,23 @@ class TestAccountLimits(cloudstackTestCase): self.services["service_offering"]["cpuspeed"] = "" self.services["service_offering"]["memory"] = "" - serviceOffering_dynamic = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_dynamic = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering_dynamic) # Deploy VM with dynamic service offering try: - VirtualMachine.create(self.apiclient,self.services["virtual_machine"], + VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering_dynamic.id, - accountid=self.account.name,domainid=self.account.domainid, - customcpunumber=3, customcpuspeed=256, custommemory=512) + accountid=self.account.name, + domainid=self.account.domainid, + customcpunumber=3, + customcpuspeed=256, + custommemory=512) self.fail("vm creation should have failed, it succeeded") except Exception as e: self.debug("vm creation failed as expected with error: %s" % e) @@ -1261,9 +1507,10 @@ class TestAccountLimits(cloudstackTestCase): return @data(ADMIN_ACCOUNT, USER_ACCOUNT) - @attr(tags=["basic","advanced"]) + @attr(tags=["basic", "advanced"]) def test_max_account_memory_scale_VM(self, value): - """Test memory limits of account while scaling VM with dynamic compute offering""" + """Test memory limits of account while scaling VM with + dynamic compute offering""" # Steps: # 1. Create Account (admin/user) @@ -1276,12 +1523,16 @@ class TestAccountLimits(cloudstackTestCase): # 1. VM creation should succeed # 2. VM scaling operation should fail - isadmin=True + isadmin = True if value == USER_ACCOUNT: - isadmin=False + isadmin = False # Create account and api client - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id, + admin=isadmin) self.cleanup.append(self.account) Resources.updateLimit(self.apiclient, @@ -1295,39 +1546,53 @@ class TestAccountLimits(cloudstackTestCase): self.services["service_offering"]["cpuspeed"] = "" self.services["service_offering"]["memory"] = "" - serviceOffering_dynamic = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_dynamic = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering_dynamic) # Deploy VM with dynamic service offering try: - virtualMachine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], + virtualMachine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering_dynamic.id, - accountid=self.account.name,domainid=self.account.domainid, - customcpunumber=2, customcpuspeed=256, custommemory=256) + accountid=self.account.name, + domainid=self.account.domainid, + customcpunumber=2, + customcpuspeed=256, + custommemory=256) except Exception as e: self.fail("vm creation failed: %s" % e) # Scale VM with same dynamic offering try: - virtualMachine.scale(self.apiclient, serviceOfferingId=serviceOffering_dynamic.id, - customcpunumber=4, customcpuspeed=512, custommemory=512) + virtualMachine.scale( + self.apiclient, + serviceOfferingId=serviceOffering_dynamic.id, + customcpunumber=4, + customcpuspeed=512, + custommemory=512) self.fail("Scaling virtual machine with cpu number more than \ allowed limit (of account) succeded, should have failed") except Exception as e: - self.debug("Failure while changing service offering as expected: %s" % e) + self.debug( + "Failure while changing service offering as expected: %s" % + e) return + @ddt class TestAffinityGroup(cloudstackTestCase): + """Test affinity group working with VMs created with dynamic offering """ @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestAffinityGroup,cls).getClsTestClient() + cloudstackTestClient = super(TestAffinityGroup, cls).getClsTestClient() cls.api_client = cloudstackTestClient.getApiClient() # Fill services from the external config file @@ -1335,13 +1600,15 @@ class TestAffinityGroup(cloudstackTestCase): # Get Zone, Domain and templates cls.domain = get_domain(cls.api_client) - cls.zone = get_zone(cls.api_client, cloudstackTestClient.getZoneForTests()) + cls.zone = get_zone( + cls.api_client, + cloudstackTestClient.getZoneForTests()) cls.mode = str(cls.zone.networktype).lower() cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + 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._cleanup = [] @@ -1378,7 +1645,7 @@ class TestAffinityGroup(cloudstackTestCase): return @data(ADMIN_ACCOUNT, USER_ACCOUNT) - @attr(tags=["basic","advanced"], BugId="7180", required_hardware="true") + @attr(tags=["basic", "advanced"], BugId="7180", required_hardware="true") def test_deploy_VM_with_affinity_group(self, value): """Test deploy VMs with affinity group and dynamic compute offering""" @@ -1391,12 +1658,16 @@ class TestAffinityGroup(cloudstackTestCase): # Validations: # 1. VM creation should fail - isadmin=True + isadmin = True if value == USER_ACCOUNT: - isadmin=False + isadmin = False # Create account and api client - self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) + self.account = Account.create( + self.apiclient, + self.services["account"], + domainid=self.domain.id, + admin=isadmin) self.cleanup.append(self.account) # Create dynamic service offerings @@ -1404,43 +1675,68 @@ class TestAffinityGroup(cloudstackTestCase): self.services["service_offering"]["cpuspeed"] = "" self.services["service_offering"]["memory"] = "" - serviceOffering_dynamic = ServiceOffering.create(self.apiclient, - self.services["service_offering"]) + serviceOffering_dynamic = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]) self.cleanup_co.append(serviceOffering_dynamic) - self.services["host_anti_affinity"]["name"] = "aff_grp_" + random_gen(size=6) - affinityGroup = AffinityGroup.create(self.apiclient, self.services["host_anti_affinity"], - self.account.name, self.domain.id) + self.services["host_anti_affinity"][ + "name"] = "aff_grp_" + random_gen(size=6) + affinityGroup = AffinityGroup.create( + self.apiclient, + self.services["host_anti_affinity"], + self.account.name, + self.domain.id) # Deploy VM with dynamic service offering try: - virtualMachine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], + virtualMachine = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], serviceofferingid=serviceOffering_dynamic.id, - accountid=self.account.name,domainid=self.account.domainid, - customcpunumber=2, customcpuspeed=256, custommemory=128, - affinitygroupnames=[affinityGroup.name]) + accountid=self.account.name, + domainid=self.account.domainid, + customcpunumber=2, + customcpuspeed=256, + custommemory=128, + affinitygroupnames=[ + affinityGroup.name]) except Exception as e: self.fail("vm creation failed with error: %s" % e) - otherHostsInCluster = Host.list(self.apiclient, virtualmachineid=virtualMachine.id) + otherHostsInCluster = Host.list( + self.apiclient, + virtualmachineid=virtualMachine.id) if validateList(otherHostsInCluster)[0] == PASS: try: - VirtualMachine.create(self.apiclient,self.services["virtual_machine"], - serviceofferingid=serviceOffering_dynamic.id, - accountid=self.account.name,domainid=self.account.domainid, - customcpunumber=2, customcpuspeed=256, custommemory=128, - affinitygroupnames=[affinityGroup.name]) + VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + serviceofferingid=serviceOffering_dynamic.id, + accountid=self.account.name, + domainid=self.account.domainid, + customcpunumber=2, + customcpuspeed=256, + custommemory=128, + affinitygroupnames=[ + affinityGroup.name]) except Exception as e: self.fail("vm creation failed with error: %s" % e) else: try: - VirtualMachine.create(self.apiclient,self.services["virtual_machine"], - serviceofferingid=serviceOffering_dynamic.id, - accountid=self.account.name,domainid=self.account.domainid, - customcpunumber=2, customcpuspeed=256, custommemory=128, - affinitygroupnames=[affinityGroup.name]) + VirtualMachine.create( + self.apiclient, + self.services["virtual_machine"], + serviceofferingid=serviceOffering_dynamic.id, + accountid=self.account.name, + domainid=self.account.domainid, + customcpunumber=2, + customcpuspeed=256, + custommemory=128, + affinitygroupnames=[ + affinityGroup.name]) self.fail("vm creation should have failed, it succeded") except Exception as e: self.debug("vm creation failed as expected with error: %s" % e)