cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gir...@apache.org
Subject git commit: updated refs/heads/master to b5a9375
Date Wed, 09 Apr 2014 09:44:47 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master ade4d44de -> b5a93751e


CLOUDSTACK-6147: Adding automation tests for Dynamic Compute
 Offering


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/b5a93751
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/b5a93751
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/b5a93751

Branch: refs/heads/master
Commit: b5a93751e24564d660ed36efd5f0f1774896162f
Parents: ade4d44
Author: Ashutosh K <ashutosh@clogeny.com>
Authored: Wed Apr 9 15:13:35 2014 +0530
Committer: Girish Shilamkar <girish@clogeny.com>
Committed: Wed Apr 9 15:13:35 2014 +0530

----------------------------------------------------------------------
 .../component/test_dynamic_compute_offering.py  | 1057 +++++++++++++++++-
 tools/marvin/marvin/config/config.cfg           |    6 +-
 2 files changed, 1060 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b5a93751/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 75cf0d6..cb21caf 100644
--- a/test/integration/component/test_dynamic_compute_offering.py
+++ b/test/integration/component/test_dynamic_compute_offering.py
@@ -25,10 +25,14 @@
 """
 from marvin.cloudstackTestCase import cloudstackTestCase
 from marvin.integration.lib.utils import (cleanup_resources,
-                                          validateList)
+                                          validateList,
+                                          random_gen)
 from marvin.integration.lib.base import (ServiceOffering,
                                          VirtualMachine,
-                                         Account)
+                                         Account,
+                                         Resources,
+                                         AffinityGroup,
+                                         Host)
 from marvin.integration.lib.common import (get_domain,
                                            get_zone,
                                            get_template,
@@ -37,6 +41,7 @@ from marvin.integration.lib.common import (get_domain,
 from nose.plugins.attrib import attr
 from marvin.codes import PASS, ADMIN_ACCOUNT, USER_ACCOUNT
 from ddt import ddt, data
+import time
 
 @ddt
 class TestDynamicServiceOffering(cloudstackTestCase):
@@ -407,3 +412,1051 @@ class TestDynamicServiceOffering(cloudstackTestCase):
                  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()
+        cls.api_client = cloudstackTestClient.getApiClient()
+
+        # Fill services from the external config file
+        cls.services = cloudstackTestClient.getConfigParser().parsedDict
+
+        # Get Zone, Domain and templates
+        cls.domain = get_domain(cls.api_client, cls.services)
+        cls.zone = get_zone(cls.api_client, cls.services)
+        cls.mode = str(cls.zone.networktype).lower()
+        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._cleanup = []
+        return
+
+    @classmethod
+    def tearDownClass(cls):
+        try:
+            # Cleanup resources used
+            cleanup_resources(cls.api_client, cls._cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def setUp(self):
+        self.apiclient = self.testClient.getApiClient()
+        self.dbclient = self.testClient.getDbConnection()
+        self.cleanup_co = []
+        self.cleanup = []
+        return
+
+    def tearDown(self):
+        try:
+            # Clean up compute offerings
+            cleanup_resources(self.apiclient, self.cleanup)
+
+            # Clean up compute offerings
+            cleanup_resources(self.apiclient, self.cleanup_co)
+
+            self.cleanup_co[:] = []
+            self.cleanup[:] = []
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def stopVM(self, vm):
+        """Stop VM and verify that it is indeed in stopped state"""
+        try:
+            vm.stop(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to stop VM: %s" % e)
+
+        retriesCount = 10
+        while True:
+            vmlist = VirtualMachine.list(self.apiclient, id=vm.id)
+            if str(vmlist[0].state).lower() == "stopped":
+                break
+            elif retriesCount == 0:
+                self.fail("Failed to stop VM even after 10 minutes")
+            else:
+                retriesCount -= 1
+                time.sleep(60)
+                continue
+        # End while
+        return
+
+    @data(ADMIN_ACCOUNT, USER_ACCOUNT)
+    @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"""
+
+        # Steps:
+        # 1. Create Account (admin/user) and its api client
+        # 2. Make two static service offerings
+        # 3. Deploy VM with one static offering
+        # 4. Stop the VM
+        # 5. Scale VM with 2nd static service offering
+
+        # Validations:
+        # 1. Scaling operation should be successful
+
+        isadmin=True
+        if value == USER_ACCOUNT:
+            isadmin=False
+
+        # Create Account
+        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id,
admin=isadmin)
+        apiclient = self.testClient.createUserApiClient(
+                                    UserName=self.account.name,
+                                    DomainName=self.account.domain)
+        self.cleanup.append(self.account)
+
+        # Create static service offerings (Second offering should have
+        # 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"])
+
+        self.services["service_offering"]["cpunumber"] = "4"
+
+        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
+        try:
+            virtualMachine = VirtualMachine.create(apiclient,self.services["virtual_machine"],
+                serviceofferingid=serviceOffering_static_1.id,
+                accountid=self.account.name,domainid=self.account.domainid)
+        except Exception as e:
+            self.fail("vm creation failed: %s" % e)
+
+        # Stop VM and verify it is in stopped state
+        self.stopVM(virtualMachine)
+
+        # Scale VM to new static service offering
+        try:
+            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"])
+    def test_change_so_stopped_vm_static_to_dynamic(self, value):
+        """Test scale stopped VM from static offering to dynamic offering"""
+
+        # Steps:
+        # 1. Create Account (admin/user) and its api client
+        # 2. Make static and dynamic service offerings
+        # 3. Deploy VM with static offering
+        # 4. Stop the VM
+        # 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
+
+        # Validations:
+        # 1. Scale operation in step 5 should be successful
+        # 2. Scale operation in step 7 should fail
+
+        isadmin=True
+        if value == USER_ACCOUNT:
+            isadmin=False
+
+        # Create Account and api client
+        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id,
admin=isadmin)
+        apiclient = self.testClient.createUserApiClient(
+                                    UserName=self.account.name,
+                                    DomainName=self.account.domain)
+        self.cleanup.append(self.account)
+
+        # Create static and dynamic service offerings
+        self.services["service_offering"]["cpunumber"] = "2"
+        self.services["service_offering"]["cpuspeed"] = "256"
+        self.services["service_offering"]["memory"] = "128"
+
+        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"])
+
+        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"],
+                serviceofferingid=serviceOffering_static.id,
+                accountid=self.account.name,domainid=self.account.domainid)
+        except Exception as e:
+            self.fail("vm creation failed: %s" % e)
+
+        # Stop VM and verify it is in stopped state
+        self.stopVM(virtualMachine_1)
+
+        # Scale VM to dynamic service offering proving all custom values
+        try:
+            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)
+
+        # Deploy VM with static service offering
+        try:
+            virtualMachine_2 = VirtualMachine.create(apiclient,self.services["virtual_machine"],
+                serviceofferingid=serviceOffering_static.id,
+                accountid=self.account.name,domainid=self.account.domainid)
+        except Exception as e:
+            self.fail("vm creation failed: %s" % e)
+
+        # Stop VM and verify it is in stopped state
+        self.stopVM(virtualMachine_2)
+
+        # Scale VM to dynamic service offering proving only custom cpu number
+        try:
+            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)
+
+        return
+
+    @data(ADMIN_ACCOUNT, USER_ACCOUNT)
+    @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"""
+
+        # Steps:
+        # 1. Create Account (admin/user) and its api client
+        # 2. Make static and dynamic service offerings
+        # 3. Deploy VM with dynamic service offering
+        # 4. Stop the VM
+        # 5. Scale VM with static service offering
+
+        # Validations:
+        # 1. Scale operation in step 5 should be successful
+
+        isadmin=True
+        if value == USER_ACCOUNT:
+            isadmin=False
+
+        # Create account and api client
+        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id,
admin=isadmin)
+        apiclient = self.testClient.createUserApiClient(
+                                    UserName=self.account.name,
+                                    DomainName=self.account.domain)
+        self.cleanup.append(self.account)
+
+        # Create dynamic and static 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"])
+
+        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"])
+
+        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"],
+                serviceofferingid=serviceOffering_dynamic.id,
+                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)
+
+        # Stop VM and verify that it is in stopped state
+        self.stopVM(virtualMachine)
+
+        # Scale VM to static service offering
+        try:
+            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"])
+    def test_change_so_stopped_vm_dynamic_to_dynamic(self, value):
+        """Test scale stopped VM from dynamic offering to dynamic offering"""
+
+        # Steps:
+        # 1. Create Account (admin/user) and its api client
+        # 2. Make 2 dynamic service offerings
+        # 3. Deploy VM with dynamic service offering
+        # 4. Stop the VM
+        # 5. Scale VM with same dynamic service offering
+        # 6. Scale VM with other dynamic service offering
+        # 7. Scale VM with same/other dynamic offering but providing custom
+        #    value for only cpu number
+
+        # Validations:
+        # 1. Scale operation in step 5 should be successful
+        # 2. Scale operation in step 6 should be successful
+        # 3. Scale operation in step 7 should fail
+
+        isadmin=True
+        if value == USER_ACCOUNT:
+            isadmin=False
+
+        # Create Account
+        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id,
admin=isadmin)
+        apiclient = self.testClient.createUserApiClient(
+                                    UserName=self.account.name,
+                                    DomainName=self.account.domain)
+        self.cleanup.append(self.account)
+
+        # Create dynamic service offerings
+        self.services["service_offering"]["cpunumber"] = ""
+        self.services["service_offering"]["cpuspeed"] = ""
+        self.services["service_offering"]["memory"] = ""
+
+        serviceOffering_dynamic_1 = 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"],
+                serviceofferingid=serviceOffering_dynamic_1.id,
+                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)
+
+        # Stop VM and verify that it is in stopped state
+        self.stopVM(virtualMachine)
+
+        # Scale VM with same dynamic service offering
+        try:
+            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=256)
+        except Exception as e:
+            self.fail("Failure while changing service offering: %s" % e)
+
+        # Scale VM with dynamic service 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")
+        except Exception as e:
+            self.debug("Failure while changing service offering: %s" % e)
+
+        return
+
+    @data(ADMIN_ACCOUNT, USER_ACCOUNT)
+    @attr(tags=["basic","advanced"])
+    def test_change_so_running_vm_static_to_static(self, value):
+        """Test scale running VM from static offering to static offering"""
+
+        # Steps:
+        # 1. Create Account (admin/user) and its api client
+        # 2. Make two static service offerings
+        # 3. Deploy VM with one static offering
+        # 4. Scale VM with 2nd static service offering
+
+        # Validations:
+        # 1. Scaling operation should be successful
+
+        isadmin=True
+        if value == USER_ACCOUNT:
+            isadmin=False
+
+        # Create Account and api client
+        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id,
admin=isadmin)
+        apiclient = self.testClient.createUserApiClient(
+                                    UserName=self.account.name,
+                                    DomainName=self.account.domain)
+        self.cleanup.append(self.account)
+
+        # Create static service offerings
+        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"])
+
+        self.services["service_offering"]["cpunumber"] = "4"
+
+        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"],
+                serviceofferingid=serviceOffering_static_1.id,
+                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)
+        except Exception as e:
+            self.fail("Failure while changing service offering: %s" % e)
+        return
+
+    @data(ADMIN_ACCOUNT, USER_ACCOUNT)
+    @attr(tags=["basic","advanced"])
+    def test_change_so_running_vm_static_to_dynamic(self, value):
+        """Test scale running VM from static offering to dynamic offering"""
+
+        # Steps:
+        # 1. Create Account (admin/user) and its api client
+        # 2. Make static and dynamic service offerings
+        # 3. Deploy VM with static offering
+        # 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
+
+        # Validations:
+        # 1. Scale operation in step 4 should be successful
+        # 2. Scale operation in step 6 should fail
+
+        isadmin=True
+        if value == USER_ACCOUNT:
+            isadmin=False
+
+        # Crate account and api client
+        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id,
admin=isadmin)
+        apiclient = self.testClient.createUserApiClient(
+                                    UserName=self.account.name,
+                                    DomainName=self.account.domain)
+        self.cleanup.append(self.account)
+
+        # Create static and dynamic service offerings
+        self.services["service_offering"]["cpunumber"] = "2"
+        self.services["service_offering"]["cpuspeed"] = "256"
+        self.services["service_offering"]["memory"] = "128"
+
+        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"])
+
+        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"],
+                serviceofferingid=serviceOffering_static.id,
+                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)
+        except Exception as e:
+            self.fail("Failure while changing service offering: %s" % e)
+
+        try:
+            virtualMachine_2 = VirtualMachine.create(apiclient,self.services["virtual_machine"],
+                serviceofferingid=serviceOffering_static.id,
+                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")
+        except Exception as e:
+            self.debug("Failure while changing service offering as expected: %s" % e)
+
+        return
+
+    @data(ADMIN_ACCOUNT, USER_ACCOUNT)
+    @attr(tags=["basic","advanced"])
+    def test_change_so_running_vm_dynamic_to_static(self, value):
+        """Test scale running VM from dynamic offering to static offering"""
+
+        # Steps:
+        # 1. Create Account (admin/user) and its api client
+        # 2. Make static and dynamic service offerings
+        # 3. Deploy VM with dynamic service offering
+        # 4. Scale VM with static service offering
+
+        # Validations:
+        # 1. Scale operation in step 4 should be successful
+
+        isadmin=True
+        if value == USER_ACCOUNT:
+            isadmin=False
+
+        # Create account and api client
+        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id,
admin=isadmin)
+        apiclient = self.testClient.createUserApiClient(
+                                    UserName=self.account.name,
+                                    DomainName=self.account.domain)
+        self.cleanup.append(self.account)
+
+        # Create dynamic and static service offerings
+        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"])
+
+        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"])
+
+        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"],
+                serviceofferingid=serviceOffering_dynamic.id,
+                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)
+        except Exception as e:
+            self.fail("Failure while changing service offering: %s" % e)
+
+        return
+
+    @data(ADMIN_ACCOUNT, USER_ACCOUNT)
+    @attr(tags=["basic","advanced"])
+    def test_change_so_running_vm_dynamic_to_dynamic(self, value):
+        """Test scale running VM from dynamic offering to dynamic offering"""
+
+        # Steps:
+        # 1. Create Account (admin/user) and its api client
+        # 2. Make 2 dynamic service offerings
+        # 3. Deploy VM with dynamic service offering
+        # 4. Scale VM with same dynamic service offering
+        # 5. Scale VM with other dynamic service offering
+        # 6. Scale VM with same/other dynamic offering but providing custom
+        #    value for only cpu number
+
+        # Validations:
+        # 1. Scale operation in step 4 should be successful
+        # 2. Scale operation in step 5 should be successful
+        # 3. Scale operation in step 6 should fail
+
+        isadmin=True
+        if value == USER_ACCOUNT:
+            isadmin=False
+
+        # Create account and api client
+        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id,
admin=isadmin)
+        apiclient = self.testClient.createUserApiClient(
+                                    UserName=self.account.name,
+                                    DomainName=self.account.domain)
+        self.cleanup.append(self.account)
+
+        # Create dynamic service offerings
+        self.services["service_offering"]["cpunumber"] = ""
+        self.services["service_offering"]["cpuspeed"] = ""
+        self.services["service_offering"]["memory"] = ""
+
+        serviceOffering_dynamic_1 = 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"],
+                serviceofferingid=serviceOffering_dynamic_1.id,
+                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)
+        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)
+        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
+        try:
+            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
+    """
+
+    @classmethod
+    def setUpClass(cls):
+        cloudstackTestClient = super(TestAccountLimits,cls).getClsTestClient()
+        cls.api_client = cloudstackTestClient.getApiClient()
+
+        # Fill services from the external config file
+        cls.services = cloudstackTestClient.getConfigParser().parsedDict
+
+        # Get Zone, Domain and templates
+        cls.domain = get_domain(cls.api_client, cls.services)
+        cls.zone = get_zone(cls.api_client, cls.services)
+        cls.mode = str(cls.zone.networktype).lower()
+        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._cleanup = []
+        return
+
+    @classmethod
+    def tearDownClass(cls):
+        try:
+            # Cleanup resources used
+            cleanup_resources(cls.api_client, cls._cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def setUp(self):
+        self.apiclient = self.testClient.getApiClient()
+        self.dbclient = self.testClient.getDbConnection()
+        self.cleanup_co = []
+        self.cleanup = []
+        return
+
+    def tearDown(self):
+        try:
+            # Clean up compute offerings
+            cleanup_resources(self.apiclient, self.cleanup)
+
+            # Clean up compute offerings
+            cleanup_resources(self.apiclient, self.cleanup_co)
+
+            self.cleanup_co[:] = []
+            self.cleanup[:] = []
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    @data(ADMIN_ACCOUNT, USER_ACCOUNT)
+    @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"""
+
+        # Steps:
+        # 1. Create Account (admin/user)
+        # 2. Update max cpu limit of account to 2
+        # 3. Create dynamic service offering
+        # 4. Deploy VM with dynamic service offering and cpu number 3
+
+        # Validations:
+        # 1. VM creation should fail
+
+        isadmin=True
+        if value == USER_ACCOUNT:
+            isadmin=False
+
+        # Create account and api client
+        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id,
admin=isadmin)
+        self.cleanup.append(self.account)
+
+        Resources.updateLimit(self.apiclient,
+                              resourcetype=8,
+                              max=2,
+                              account=self.account.name,
+                              domainid=self.account.domainid)
+
+        # Create dynamic service offerings
+        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"])
+
+        self.cleanup_co.append(serviceOffering_dynamic)
+
+        # Deploy VM with dynamic service offering
+        try:
+            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)
+            self.fail("vm creation should have failed, it succeeded")
+        except Exception as e:
+            self.debug("vm creation failed as expected with error: %s" % e)
+
+        return
+
+    @data(ADMIN_ACCOUNT, USER_ACCOUNT)
+    @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"""
+
+        # Steps:
+        # 1. Create Account (admin/user)
+        # 2. Update max cpu limit of account to 2
+        # 3. Create dynamic service offering
+        # 4. Deploy VM with dynamic service offering and cpu number 2
+        # 5. Try to Scale VM with dynamic service offering and cpu number 3
+
+        # Validations:
+        # 1. VM creation should succeed
+        # 2. VM scaling operation should fail
+
+        isadmin=True
+        if value == USER_ACCOUNT:
+            isadmin=False
+
+        # Create account and api client
+        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id,
admin=isadmin)
+        self.cleanup.append(self.account)
+
+        Resources.updateLimit(self.apiclient,
+                              resourcetype=8,
+                              max=2,
+                              account=self.account.name,
+                              domainid=self.account.domainid)
+
+        # Create dynamic service offerings
+        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"])
+
+        self.cleanup_co.append(serviceOffering_dynamic)
+
+        # Deploy VM with dynamic service offering
+        try:
+            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)
+        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)
+            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)
+
+        return
+
+    @data(ADMIN_ACCOUNT, USER_ACCOUNT)
+    @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"""
+
+        # Steps:
+        # 1. Create Account (admin/user)
+        # 2. Update max memory limit of account to 256
+        # 3. Create dynamic service offering
+        # 4. Deploy VM with dynamic service offering and memory 512
+
+        # Validations:
+        # 1. VM creation should fail
+
+        isadmin=True
+        if value == USER_ACCOUNT:
+            isadmin=False
+
+        # Create account and api client
+        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id,
admin=isadmin)
+        self.cleanup.append(self.account)
+
+        Resources.updateLimit(self.apiclient,
+                              resourcetype=9,
+                              max=256,
+                              account=self.account.name,
+                              domainid=self.account.domainid)
+
+        # Create dynamic service offerings
+        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"])
+
+        self.cleanup_co.append(serviceOffering_dynamic)
+
+        # Deploy VM with dynamic service offering
+        try:
+            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)
+            self.fail("vm creation should have failed, it succeeded")
+        except Exception as e:
+            self.debug("vm creation failed as expected with error: %s" % e)
+
+        return
+
+    @data(ADMIN_ACCOUNT, USER_ACCOUNT)
+    @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"""
+
+        # Steps:
+        # 1. Create Account (admin/user)
+        # 2. Update max memory limit of account to 256
+        # 3. Create dynamic service offering
+        # 4. Deploy VM with dynamic service offering and memory 256
+        # 5. Try to Scale VM with dynamic service offering and memory 512
+
+        # Validations:
+        # 1. VM creation should succeed
+        # 2. VM scaling operation should fail
+
+        isadmin=True
+        if value == USER_ACCOUNT:
+            isadmin=False
+
+        # Create account and api client
+        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id,
admin=isadmin)
+        self.cleanup.append(self.account)
+
+        Resources.updateLimit(self.apiclient,
+                              resourcetype=9,
+                              max=256,
+                              account=self.account.name,
+                              domainid=self.account.domainid)
+
+        # Create dynamic service offerings
+        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"])
+
+        self.cleanup_co.append(serviceOffering_dynamic)
+
+        # Deploy VM with dynamic service offering
+        try:
+            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)
+        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)
+            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)
+
+        return
+
+@ddt
+class TestAffinityGroup(cloudstackTestCase):
+    """Test affinity group working with VMs created with dynamic offering
+    """
+
+    @classmethod
+    def setUpClass(cls):
+        cloudstackTestClient = super(TestAffinityGroup,cls).getClsTestClient()
+        cls.api_client = cloudstackTestClient.getApiClient()
+
+        # Fill services from the external config file
+        cls.services = cloudstackTestClient.getConfigParser().parsedDict
+
+        # Get Zone, Domain and templates
+        cls.domain = get_domain(cls.api_client, cls.services)
+        cls.zone = get_zone(cls.api_client, cls.services)
+        cls.mode = str(cls.zone.networktype).lower()
+        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._cleanup = []
+        return
+
+    @classmethod
+    def tearDownClass(cls):
+        try:
+            # Cleanup resources used
+            cleanup_resources(cls.api_client, cls._cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def setUp(self):
+        self.apiclient = self.testClient.getApiClient()
+        self.dbclient = self.testClient.getDbConnection()
+        self.cleanup_co = []
+        self.cleanup = []
+        return
+
+    def tearDown(self):
+        try:
+            # Clean up compute offerings
+            cleanup_resources(self.apiclient, self.cleanup)
+
+            # Clean up compute offerings
+            cleanup_resources(self.apiclient, self.cleanup_co)
+
+            self.cleanup_co[:] = []
+            self.cleanup[:] = []
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    @data(ADMIN_ACCOUNT, USER_ACCOUNT)
+    @attr(tags=["basic","advanced"])
+    def test_deploy_VM_with_affinity_group(self, value):
+        """Test deploy VMs with affinity group and dynamic compute offering"""
+
+        # Steps:
+        # 1. Create Account (admin/user)
+        # 2. Update max cpu limit of account to 2
+        # 3. Create dynamic service offering
+        # 4. Deploy VM with dynamic service offering and cpu number 3
+
+        # Validations:
+        # 1. VM creation should fail
+
+        isadmin=True
+        if value == USER_ACCOUNT:
+            isadmin=False
+
+        # Create account and api client
+        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id,
admin=isadmin)
+        self.cleanup.append(self.account)
+
+        # Create dynamic service offerings
+        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"])
+
+        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)
+
+        # Deploy VM with dynamic service offering
+        try:
+            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])
+        except Exception as e:
+            self.fail("vm creation failed with error: %s" % e)
+
+        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])
+            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])
+                self.fail("vm creation should have failed, it succeded")
+            except Exception as e:
+                self.debug("vm creation failed as expected with error: %s" % e)
+
+        return

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b5a93751/tools/marvin/marvin/config/config.cfg
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/config/config.cfg b/tools/marvin/marvin/config/config.cfg
index 4a5fd75..017c00d 100644
--- a/tools/marvin/marvin/config/config.cfg
+++ b/tools/marvin/marvin/config/config.cfg
@@ -423,5 +423,9 @@
                                     "securitygroupenabled": "true"
                                 },
                          "securitygroupenabled": "true"
-                       }
+                       },
+        "host_anti_affinity": {
+                               "name": "",
+                               "type": "host anti-affinity"
+                              }
 }


Mime
View raw message