cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tall...@apache.org
Subject [3/6] CLOUDSTACK-4934: Renamed Limit Resources tests so that they have unique name.
Date Fri, 08 Nov 2013 05:05:05 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/8f76c49a/test/integration/component/test_cpu_limits.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_cpu_limits.py b/test/integration/component/test_cpu_limits.py
index 814e4b0..d721a45 100644
--- a/test/integration/component/test_cpu_limits.py
+++ b/test/integration/component/test_cpu_limits.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # Licensed to the Apache Software Foundation (ASF) under one
 # or more contributor license agreements.  See the NOTICE file
 # distributed with this work for additional information
@@ -9,13 +8,14 @@
 #
 #   http://www.apache.org/licenses/LICENSE-2.0
 #
-# Unless required byswa applicable law or agreed to in writing,
+# Unless required by applicable law or agreed to in writing,
 # software distributed under the License is distributed on an
 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-""" P1 tests for resource limits
+
+""" Tests for cpu resource limits
 """
 # Import Local Modules
 from nose.plugins.attrib import attr
@@ -24,14 +24,15 @@ from marvin.integration.lib.base import (
                                         Account,
                                         ServiceOffering,
                                         VirtualMachine,
-                                        Network,
-                                        Resources,
-                                        Host
+                                        Domain,
+                                        Resources
                                         )
 from marvin.integration.lib.common import (get_domain,
                                         get_zone,
                                         get_template,
                                         cleanup_resources,
+                                        find_suitable_host,
+                                        get_resource_type
                                         )
 
 
@@ -53,7 +54,7 @@ class Services:
                          "service_offering": {
                                 "name": "Tiny Instance",
                                 "displaytext": "Tiny Instance",
-                                "cpunumber": 2,
+                                "cpunumber": 4,
                                 "cpuspeed": 100,    # in MHz
                                 "memory": 128,    # In MBs
                         },
@@ -86,8 +87,6 @@ class Services:
                         # Networking mode: Advanced, Basic
                     }
 
-
-@unittest.skip("Skipping - Work in progress")
 class TestCPULimits(cloudstackTestCase):
 
     @classmethod
@@ -98,6 +97,7 @@ class TestCPULimits(cloudstackTestCase):
         # Get Zone, Domain and templates
         cls.domain = get_domain(cls.api_client, cls.services)
         cls.zone = get_zone(cls.api_client, cls.services)
+        cls.services["mode"] = cls.zone.networktype
 
         cls.template = get_template(
                             cls.api_client,
@@ -107,7 +107,12 @@ class TestCPULimits(cloudstackTestCase):
 
         cls.services["virtual_machine"]["zoneid"] = cls.zone.id
 
-        cls._cleanup = []
+        cls.service_offering = ServiceOffering.create(
+                                            cls.api_client,
+                                            cls.services["service_offering"]
+                                            )
+
+        cls._cleanup = [cls.service_offering, ]
         return
 
     @classmethod
@@ -127,6 +132,11 @@ class TestCPULimits(cloudstackTestCase):
                             self.services["account"],
                             admin=True
                             )
+
+        self.debug("Creating an instance with service offering: %s" %
+                                                    self.service_offering.name)
+        self.vm = self.createInstance(service_off=self.service_offering)
+
         self.cleanup = [self.account, ]
         return
 
@@ -134,174 +144,182 @@ class TestCPULimits(cloudstackTestCase):
         try:
             # Clean up, terminate the created instance, volumes and snapshots
             cleanup_resources(self.apiclient, self.cleanup)
-            pass
         except Exception as e:
             raise Exception("Warning: Exception during cleanup : %s" % e)
         return
 
-    def create_Instance(self, service_off, networks=None):
-        """Creates an instance in account"""
+    def createInstance(self, service_off, networks=None, api_client=None):
+        """Creates an instance in account
+        """
+        if api_client is None:
+            api_client = self.apiclient
+
         self.debug("Deploying an instance in account: %s" %
-                                                self.account.account.name)
+                       self.account.name)
         try:
             vm = VirtualMachine.create(
-                                self.apiclient,
-                                self.services["virtual_machine"],
-                                templateid=self.template.id,
-                                accountid=self.account.account.name,
-                                domainid=self.account.account.domainid,
-                                networkids=networks,
-                                serviceofferingid=service_off.id)
-            vms = VirtualMachine.list(self.apiclient, id=vm.id, listall=True)
+                    api_client,
+                    self.services["virtual_machine"],
+                    templateid=self.template.id,
+                    accountid=self.account.name,
+                    domainid=self.account.domainid,
+                    networkids=networks,
+                    serviceofferingid=service_off.id)
+            vms = VirtualMachine.list(api_client, id=vm.id, listall=True)
             self.assertIsInstance(vms,
-                                  list,
-                                  "List VMs should return a valid response")
+                    list,
+                    "List VMs should return a valid response")
             self.assertEqual(vms[0].state, "Running",
-                             "Vm state should be running after deployment")
+                    "Vm state should be running after deployment")
             return vm
         except Exception as e:
             self.fail("Failed to deploy an instance: %s" % e)
 
-    def get_Network(self, account):
-        """Returns a network for account"""
+    @attr(tags=["advanced", "advancedns","simulator"])
+    def test_01_multiplecore_start_stop_instance(self):
+        """Test Deploy VM with multiple core CPU & verify the usage"""
 
-        networks = Network.list(
-                                self.apiclient,
-                                account=account.account.name,
-                                domainid=account.account.domainid,
-                                listall=True
-                                )
-        self.assertIsInstance(networks,
+        # Validate the following
+        # 1. Deploy VM with multiple core CPU & verify the usage
+        # 2. Stop VM & verify the update resource count of Root Admin Account
+        # 3. Start VM & verify the update resource count of Root Admin Account
+        # 4. Resource count should list properly.
+
+        account_list = Account.list(self.apiclient, id=self.account.id)
+        self.assertIsInstance(account_list,
                               list,
-                              "List networks should return a valid response")
-        return networks[0]
-
-    def get_Resource_Type(self, resource_id):
-        """Returns resource type"""
-
-        lookup = {1: "VM", 2: "Public IP", 3: "Volume", 4: "Snapshot",
-                     5: "Template", 6: "Projects", 7: "Network", 8: "VPC",
-                     9: "CPUs", 10: "RAM",
-                     11: "Primary (shared) storage (Volumes)",
-                     12: "Secondary storage (Snapshots, Templates & ISOs)",
-                     13: "Network bandwidth rate (in bps)",
-                     14: "Number of times a OS template can be deployed"}
-        return lookup[resource_id]
-
-    def check_Resource_Count(self, account, rtype, delete=False):
-        """Validates the resource count
-            9     - CPUs
-            10    - RAM
-            11    - Primary (shared) storage (Volumes)
-            12    - Secondary storage (Snapshots, Templates & ISOs)
-            13    - Network bandwidth rate (in bps)
-            14    - Number of times a OS template can be deployed"""
-
-        self.debug("Updating the CPU resource count for account: %s" %
-                                                    account.account.name)
-        responses = Resources.updateCount(self.apiclient,
-                              domainid=account.account.domainid,
-                              account=account.account.name,
-                              resourcetype=rtype
+                              "List Accounts should return a valid response"
                               )
-        self.assertIsInstance(responses, list,
-                        "Update resource count should return valid response")
-        response = responses[0]
-        self.debug(response.resourcecount)
-        if delete:
-            self.assertEqual(response.resourcecount,
-                         0,
-                         "Resource count for %s should be 0" %
-                                        self.get_Resource_Type(rtype))
-        else:
-            self.assertNotEqual(response.resourcecount,
-                         0,
-                         "Resource count for %s should not be 0" %
-                                        self.get_Resource_Type(rtype))
-        return
+        resource_count = account_list[0].cputotal
+
+        expected_resource_count = int(self.services["service_offering"]["cpunumber"])
+
+        self.assertEqual(resource_count, expected_resource_count,
+                         "Resource count should match with the expected resource count")
+
+        self.debug("Stopping instance: %s" % self.vm.name)
+        try:
+            self.vm.stop(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to stop instance: %s" % e)
+
+        account_list = Account.list(self.apiclient, id=self.account.id)
+        self.assertIsInstance(account_list,
+                              list,
+                              "List Accounts should return a valid response"
+                              )
+        resource_count_after_stop = account_list[0].cputotal
 
-    def find_Suitable_Host(self, vm):
-        """Returns a suitable host for VM migration"""
+        self.assertEqual(resource_count, resource_count_after_stop,
+                         "Resource count should be same after stopping the instance")
 
+        self.debug("Starting instance: %s" % self.vm.name)
         try:
-            hosts = Host.list(self.apiclient,
-                              virtualmachineid=vm.id,
-                              listall=True)
-            self.assertIsInstance(hosts, list, "Failed to find suitable host")
-            return hosts[0]
+            self.vm.start(self.apiclient)
         except Exception as e:
-            self.fail("Failed to find suitable host vm migration: %s" % e)
+            self.fail("Failed to start instance: %s" % e)
+
+        account_list = Account.list(self.apiclient, id=self.account.id)
+        self.assertIsInstance(account_list,
+                              list,
+                              "List Accounts should return a valid response"
+                              )
+        resource_count_after_start = account_list[0].cputotal
+
+        self.assertEqual(resource_count, resource_count_after_start,
+                         "Resource count should be same after stopping the instance")
         return
 
-    @attr(tags=["advanced", "advancedns"])
-    def test_01_deploy_vm_with_5_cpus(self):
-        """Test Deploy VM with 5 core CPU & verify the usage"""
+    @attr(tags=["advanced", "advancedns","simulator"])
+    def test_02_multiplecore_migrate_instance(self):
+        """Test Deploy VM with multiple core CPU & verify the usage"""
 
         # Validate the following
-        # 1. Deploy VM with 5 core CPU & verify the usage
-        # 2. Stop VM & verify the update resource limit of Root Admin Account
-        # 3. Start VM & verify the update resource limit of Root Admin Account
-        # 4. Migrate VM & verify update resource limit of Root Admin Account
-        # 5. Destroy VM & verify update resource limit of Root Admin Account
-
-        self.debug("Creating service offering with 5 CPU cores")
-        self.service_offering = ServiceOffering.create(
-                                            self.apiclient,
-                                            self.services["service_offering"]
-                                            )
-        # Adding to cleanup list after execution
-        self.cleanup.append(self.service_offering)
+        # 1. Deploy VM with multiple core CPU & verify the usage
+        # 2. Migrate VM & verify updated resource count of Root Admin Account
+        # 3. Resource count should list properly.
 
-        self.debug("Creating an instance with service offering: %s" %
-                                                    self.service_offering.name)
-        vm = self.create_Instance(service_off=self.service_offering)
+        account_list = Account.list(self.apiclient, id=self.account.id)
+        self.assertIsInstance(account_list,
+                              list,
+                              "List Accounts should return a valid response"
+                              )
+        resource_count = account_list[0].cputotal
 
-        self.check_Resource_Count(account=self.account, rtype=9)
-        self.debug("Stopping instance: %s" % vm.name)
-        try:
-            vm.stop(self.apiclient)
-        except Exception as e:
-            self.fail("Failed to stop instance: %s" % e)
-        self.check_Resource_Count(account=self.account, rtype=9)
+        expected_resource_count = int(self.services["service_offering"]["cpunumber"])
 
-        self.debug("Starting instance: %s" % vm.name)
-        try:
-            vm.start(self.apiclient)
-        except Exception as e:
-            self.fail("Failed to start instance: %s" % e)
-        self.check_Resource_Count(account=self.account, rtype=9)
+        self.assertEqual(resource_count, expected_resource_count,
+                         "Resource count should match with the expected resource count")
 
-        host = self.find_Suitable_Host(vm)
-        self.debug("Migrating instance: %s to host: %s" % (vm.name, host.name))
+        host = find_suitable_host(self.apiclient, self.vm)
+        self.debug("Migrating instance: %s to host: %s" % (self.vm.name, host.name))
         try:
-            vm.migrate(self.apiclient, host.id)
+            self.vm.migrate(self.apiclient, host.id)
         except Exception as e:
             self.fail("Failed to migrate instance: %s" % e)
-        self.check_Resource_Count(account=self.account, rtype=9)
 
-        self.debug("Destroying instance: %s" % vm.name)
+        account_list = Account.list(self.apiclient, id=self.account.id)
+        self.assertIsInstance(account_list,
+                              list,
+                              "List Accounts should return a valid response"
+                              )
+        resource_count_after_migrate = account_list[0].cputotal
+
+        self.assertEqual(resource_count, resource_count_after_migrate,
+                         "Resource count should be same after migrating the instance")
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    def test_03_multiplecore_delete_instance(self):
+        """Test Deploy VM with multiple core CPU & verify the usage"""
+
+        # Validate the following
+        # 1. Deploy VM with multiple core CPU & verify the usage
+        # 2. Destroy VM & verify update resource count of Root Admin Account
+        # 3. Resource count should list properly.
+
+        account_list = Account.list(self.apiclient, id=self.account.id)
+        self.assertIsInstance(account_list,
+                              list,
+                              "List Accounts should return a valid response"
+                              )
+        resource_count = account_list[0].cputotal
+
+        expected_resource_count = int(self.services["service_offering"]["cpunumber"])
+
+        self.assertEqual(resource_count, expected_resource_count,
+                         "Resource count should match with the expected resource count")
+
+        self.debug("Destroying instance: %s" % self.vm.name)
         try:
-            vm.delete(self.apiclient)
+            self.vm.delete(self.apiclient)
         except Exception as e:
             self.fail("Failed to delete instance: %s" % e)
-        self.check_Resource_Count(account=self.account, rtype=9, delete=True)
+
+        account_list = Account.list(self.apiclient, id=self.account.id)
+        self.assertIsInstance(account_list,
+                              list,
+                              "List Accounts should return a valid response"
+                              )
+        resource_count = account_list[0].cputotal
+        self.assertEqual(resource_count, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=8))#CPU
         return
 
-    @attr(tags=["advanced", "advancedns"])
-    def test_02_deploy_multiple_vm_with_5_cpus(self):
-        """Test Deploy multiple VM with 5 core CPU & verify the usage"""
+    @attr(tags=["advanced", "advancedns","simulator"])
+    def test_04_deploy_multiple_vm_with_multiple_cpus(self):
+        """Test Deploy multiple VM with 4 core CPU & verify the usage"""
 
         # Validate the following
-        # 1. Create compute offering with 5 core CPU
+        # 1. Create compute offering with 4 core CPU
         # 2. Deploy multiple VMs with this service offering
-        # 3. Update Resource count for the root admin CPU usage
+        # 3. List Resource count for the root admin CPU usage
         # 4. CPU usage should list properly
-        # 5. Destroy one VM among multiple VM's and verify the resource limit
+        # 5. Destroy one VM among multiple VM's and verify the resource count
         # 6. Migrate VM from & verify resource updates
-        # 7. List resources of Root Admin for CPU
+        # 7. List resource count for Root Admin
         # 8. Failed to deploy VM and verify the resource usage
 
-        self.debug("Creating service offering with 5 CPU cores")
+        self.debug("Creating service offering with 4 CPU cores")
         self.service_offering = ServiceOffering.create(
                                             self.apiclient,
                                             self.services["service_offering"]
@@ -311,50 +329,47 @@ class TestCPULimits(cloudstackTestCase):
 
         self.debug("Creating an instance with service offering: %s" %
                                                     self.service_offering.name)
-        vm_1 = self.create_Instance(service_off=self.service_offering)
-        vm_2 = self.create_Instance(service_off=self.service_offering)
-        self.create_Instance(service_off=self.service_offering)
-        self.create_Instance(service_off=self.service_offering)
+        vm_1 = self.createInstance(service_off=self.service_offering)
+        vm_2 = self.createInstance(service_off=self.service_offering)
+        self.createInstance(service_off=self.service_offering)
 
-        self.check_Resource_Count(account=self.account, rtype=9)
-        self.debug("Destroying instance: %s" % vm_1.name)
-        try:
-            vm_1.delete(self.apiclient)
-        except Exception as e:
-            self.fail("Failed to delete instance: %s" % e)
-        self.check_Resource_Count(account=self.account, rtype=9)
+        account_list = Account.list(self.apiclient, id=self.account.id)
+        self.assertIsInstance(account_list,
+                              list,
+                              "List Accounts should return a valid response"
+                              )
+        resource_count = account_list[0].cputotal
 
-        host = self.find_Suitable_Host(vm_2)
-        self.debug("Migrating instance: %s to host: %s" % (vm_2.name,
-                                                           host.name))
-        try:
-            vm_2.migrate(self.apiclient, host.id)
-        except Exception as e:
-            self.fail("Failed to migrate instance: %s" % e)
-        self.check_Resource_Count(account=self.account, rtype=9)
+        expected_resource_count = int(self.services["service_offering"]["cpunumber"]) * 4 #Total 4 Vms
+        self.assertTrue(resource_count == expected_resource_count,
+                         "Resource count does not match the expected vavlue")
         return
 
-
-class TestDomainCPULimits(cloudstackTestCase):
+class TestDomainCPULimitsConfiguration(cloudstackTestCase):
 
     @classmethod
     def setUpClass(cls):
-        cls.api_client = super(TestDomainCPULimits,
+        cls.api_client = super(TestDomainCPULimitsConfiguration,
                                cls).getClsTestClient().getApiClient()
         cls.services = Services().services
         # Get Zone, Domain and templates
         cls.domain = get_domain(cls.api_client, cls.services)
         cls.zone = get_zone(cls.api_client, cls.services)
-
+        cls.services["mode"] = cls.zone.networktype
         cls.template = get_template(
                             cls.api_client,
                             cls.zone.id,
                             cls.services["ostype"]
                             )
 
+        cls.service_offering = ServiceOffering.create(
+                                            cls.api_client,
+                                            cls.services["service_offering"]
+                                            )
+
         cls.services["virtual_machine"]["zoneid"] = cls.zone.id
 
-        cls._cleanup = []
+        cls._cleanup = [cls.service_offering, ]
         return
 
     @classmethod
@@ -376,456 +391,270 @@ class TestDomainCPULimits(cloudstackTestCase):
         try:
             # Clean up, terminate the created instance, volumes and snapshots
             cleanup_resources(self.apiclient, self.cleanup)
-            pass
         except Exception as e:
             raise Exception("Warning: Exception during cleanup : %s" % e)
         return
 
-    def create_Instance(self, service_off, networks=None):
-        """Creates an instance in account"""
+    def createInstance(self, service_off, networks=None, api_client=None):
+        """Creates an instance in account
+        """
+        if api_client is None:
+            api_client = self.apiclient
+
         self.debug("Deploying an instance in account: %s" %
-                                                self.account.account.name)
+                       self.account.name)
         try:
             vm = VirtualMachine.create(
-                                self.apiclient,
-                                self.services["virtual_machine"],
-                                templateid=self.template.id,
-                                accountid=self.account.account.name,
-                                domainid=self.account.account.domainid,
-                                networkids=networks,
-                                serviceofferingid=service_off.id)
-            vms = VirtualMachine.list(self.apiclient, id=vm.id, listall=True)
+                    api_client,
+                    self.services["virtual_machine"],
+                    templateid=self.template.id,
+                    accountid=self.account.name,
+                    domainid=self.account.domainid,
+                    networkids=networks,
+                    serviceofferingid=service_off.id)
+            vms = VirtualMachine.list(api_client, id=vm.id, listall=True)
             self.assertIsInstance(vms,
-                                  list,
-                                  "List VMs should return a valid response")
+                    list,
+                    "List VMs should return a valid response")
             self.assertEqual(vms[0].state, "Running",
-                             "Vm state should be running after deployment")
+                    "Vm state should be running after deployment")
             return vm
         except Exception as e:
             self.fail("Failed to deploy an instance: %s" % e)
 
-    def get_Network(self, account):
-        """Returns a network for account"""
+    def setupAccounts(self):
 
-        networks = Network.list(
-                                self.apiclient,
-                                account=account.account.name,
-                                domainid=account.account.domainid,
-                                listall=True
-                                )
-        self.assertIsInstance(networks,
-                              list,
-                              "List networks should return a valid response")
-        return networks[0]
-
-    def get_Resource_Type(self, resource_id):
-        """Returns resource type"""
-
-        lookup = {1: "VM", 2: "Public IP", 3: "Volume", 4: "Snapshot",
-                     5: "Template", 6: "Projects", 7: "Network", 8: "VPC",
-                     9: "CPUs", 10: "RAM",
-                     11: "Primary (shared) storage (Volumes)",
-                     12: "Secondary storage (Snapshots, Templates & ISOs)",
-                     13: "Network bandwidth rate (in bps)",
-                     14: "Number of times a OS template can be deployed"}
-        return lookup[resource_id]
-
-    def check_Resource_Count(self, account, rtype, delete=False):
-        """Validates the resource count
-            9     - CPUs
-            10    - RAM
-            11    - Primary (shared) storage (Volumes)
-            12    - Secondary storage (Snapshots, Templates & ISOs)
-            13    - Network bandwidth rate (in bps)
-            14    - Number of times a OS template can be deployed"""
-
-        self.debug("Updating the CPU resource count for account: %s" %
-                                                    account.account.name)
-        responses = Resources.updateCount(self.apiclient,
-                              domainid=account.account.domainid,
-                              account=account.account.name,
-                              resourcetype=rtype
-                              )
-        self.assertIsInstance(responses, list,
-                        "Update resource count should return valid response")
-        response = responses[0]
-        self.debug(response.resourcecount)
-        if delete:
-            self.assertEqual(response.resourcecount,
-                         0,
-                         "Resource count for %s should be 0" %
-                                        self.get_Resource_Type(rtype))
-        else:
-            self.assertNotEqual(response.resourcecount,
-                         0,
-                         "Resource count for %s should not be 0" %
-                                        self.get_Resource_Type(rtype))
-        return
-
-    def find_Suitable_Host(self, vm):
-        """Returns a suitable host for VM migration"""
-
-        try:
-            hosts = Host.list(self.apiclient,
-                              virtualmachineid=vm.id,
-                              listall=True)
-            self.assertIsInstance(hosts, list, "Failed to find suitable host")
-            return hosts[0]
-        except Exception as e:
-            self.fail("Failed to find suitable host vm migration: %s" % e)
-        return
-
-    def setup_Accounts(self):
-
-        self.debug("Creating a domain under: %s" % self.domain.name)
-        self.parent_domain = Domain.create(self.apiclient,
-                                        services=self.services["domain"],
-                                        parentdomainid=self.domain.id)
-        self.parentd_admin = Account.create(
-                            self.apiclient,
-                            self.services["account"],
-                            admin=True,
-                            domainid=self.domain.id
-                            )
-        # Cleanup the resources created at end of test
-        self.cleanup.append(self.parentd_admin)
-        self.cleanup.append(self.parent_domain)
-
-        self.debug("Updating the CPU resource count for domain: %s" %
-                                                            self.domain.name)
-        Resources.updateLimit(self.apiclient,
-                              resourcetype=9,
-                              max=1280,
-                              account=self.parentd_admin.account.name,
-                              domainid=self.parentd_admin.account.domainid)
         self.debug("Creating a sub-domain under: %s" % self.domain.name)
-        self.sub_domain = Domain.create(self.apiclient,
-                                        services=self.services["domain"],
-                                        parentdomainid=self.domain.id)
-        self.childd_admin = Account.create(
-                                        self.apiclient,
-                                        self.services["account"],
-                                        admin=True,
-                                        domainid=self.sub_domain.id
-                                        )
+        self.child_domain_1 = Domain.create(
+            self.apiclient,
+            services=self.services["domain"],
+            parentdomainid=self.domain.id
+        )
+        self.child_do_admin_1 = Account.create(
+            self.apiclient,
+            self.services["account"],
+            admin=True,
+            domainid=self.child_domain_1.id
+        )
         # Cleanup the resources created at end of test
-        self.cleanup.append(self.childd_admin)
-        self.cleanup.append(self.sub_domain)
+        self.cleanup.append(self.child_do_admin_1)
+        self.cleanup.append(self.child_domain_1)
+
+        self.child_domain_2 = Domain.create(
+            self.apiclient,
+            services=self.services["domain"],
+            parentdomainid=self.domain.id
+        )
+
+        self.child_do_admin_2 = Account.create(
+            self.apiclient,
+            self.services["account"],
+            admin=True,
+            domainid=self.child_domain_2.id
+        )
+
+        # Cleanup the resources created at end of test
+        self.cleanup.append(self.child_do_admin_2)
+        self.cleanup.append(self.child_domain_2)
+
         return
 
-    @attr(tags=["advanced", "advancedns"])
-    @attr(configuration='max.account.cpus')
-    def test_01_deploy_vm_with_5_cpus(self):
-        """Test Deploy VM with 5 core CPU & verify the usage"""
+    @attr(tags=["advanced", "advancedns","simulator"])
+    def test_01_stop_start_instance(self):
+        """Test Deploy VM with 4 core CPU & verify the usage"""
 
         # Validate the following
-        # 1. Create compute offering with 5 core CPU & Deploy VM as root admin
-        # 2. Update Resource count for the root admin CPU usage
-
-        self.debug("Creating service offering with 5 CPU cores")
-        self.service_offering = ServiceOffering.create(
-                                            self.apiclient,
-                                            self.services["service_offering"]
-                                            )
-        # Adding to cleanup list after execution
-        self.cleanup.append(self.service_offering)
+        # 1. Create compute offering with 4 core CPU & Deploy VM
+        # 2. List Resource count CPU usage
+        # 3. Stop and Start instance, check resource count.
+        # 4. Resource count should list properly.
 
         self.debug("Setting up account and domain hierarchy")
-        self.setup_Accounts()
-        users = {self.parent_domain: self.parentd_admin,
-                 self.sub_domain: self.childd_admin
+        self.setupAccounts()
+        users = {self.child_domain_1: self.child_do_admin_1,
+                 self.child_domain_2: self.child_do_admin_2
                  }
         for domain, admin in users.items():
             self.account = admin
             self.domain = domain
-            self.debug("Creating an instance with service offering: %s" %
-                                                    self.service_offering.name)
-            vm = self.create_Instance(service_off=self.service_offering)
 
-            self.check_Resource_Count(account=self.account, rtype=9)
-            self.debug("Stopping instance: %s" % vm.name)
-            try:
-                vm.stop(self.apiclient)
-            except Exception as e:
-                self.fail("Failed to stop instance: %s" % e)
-            self.check_Resource_Count(account=self.account, rtype=9)
+        api_client = self.testClient.createUserApiClient(
+            UserName=self.account.name,
+            DomainName=self.account.domain)
 
-            self.debug("Starting instance: %s" % vm.name)
-            try:
-                vm.start(self.apiclient)
-            except Exception as e:
-                self.fail("Failed to start instance: %s" % e)
-            self.check_Resource_Count(account=self.account, rtype=9)
+        self.debug("Creating an instance with service offering: %s" %
+                   self.service_offering.name)
+        vm = self.createInstance(service_off=self.service_offering, api_client=api_client)
 
-            host = self.find_Suitable_Host(vm)
-            self.debug("Migrating instance: %s to host: %s" %
-                                                        (vm.name, host.name))
-            try:
-                vm.migrate(self.apiclient, host.id)
-            except Exception as e:
-                self.fail("Failed to migrate instance: %s" % e)
-            self.check_Resource_Count(account=self.account, rtype=9)
+        account_list = Account.list(self.apiclient, id=self.account.id)
+        self.assertIsInstance(account_list,
+            list,
+            "List Accounts should return a valid response"
+        )
+        resource_count = account_list[0].cputotal
 
-            self.debug("Destroying instance: %s" % vm.name)
-            try:
-                vm.delete(self.apiclient)
-            except Exception as e:
-                self.fail("Failed to delete instance: %s" % e)
-            self.check_Resource_Count(account=self.account, rtype=9,
-                                      delete=True)
+        expected_resource_count = int(self.services["service_offering"]["cpunumber"])
+
+        self.assertEqual(resource_count, expected_resource_count,
+            "Initial resource count should match with the expected resource count")
+
+        self.debug("Stopping instance: %s" % vm.name)
+        try:
+            vm.stop(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to stop instance: %s" % e)
+
+        account_list = Account.list(self.apiclient, id=self.account.id)
+        self.assertIsInstance(account_list,
+            list,
+            "List Accounts should return a valid response"
+        )
+        resource_count_after_stop = account_list[0].cputotal
+
+        self.assertEqual(resource_count, resource_count_after_stop,
+            "Resource count should be same after stopping the instance")
+
+        self.debug("Starting instance: %s" % vm.name)
+        try:
+            vm.start(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to start instance: %s" % e)
+
+        account_list = Account.list(self.apiclient, id=self.account.id)
+        self.assertIsInstance(account_list,
+            list,
+            "List Accounts should return a valid response"
+        )
+        resource_count_after_start = account_list[0].cputotal
+
+        self.assertEqual(resource_count_after_stop, resource_count_after_start,
+            "Resource count should be same after starting the instance")
         return
 
-    @attr(tags=["advanced", "advancedns"])
-    @attr(configuration='max.account.cpus')
-    def test_02_deploy_multiple_vm_with_5_cpus(self):
-        """Test Deploy multiple VM with 5 core CPU & verify the usage"""
+    @attr(tags=["advanced", "advancedns","simulator"])
+    def test_02_migrate_instance(self):
+        """Test Deploy VM with 4 core CPU & verify the usage"""
 
         # Validate the following
-        # 1. Create compute offering with 5 core CPU
-        # 2. Deploy multiple VMs with this service offering
-        # 3. Update Resource count for the root admin CPU usage
-        # 4. CPU usage should list properly
-
-        self.debug("Creating service offering with 5 CPU cores")
-        self.service_offering = ServiceOffering.create(
-                                            self.apiclient,
-                                            self.services["service_offering"]
-                                            )
-        # Adding to cleanup list after execution
-        self.cleanup.append(self.service_offering)
+        # 1. Create compute offering with 4 core CPU & Deploy VM
+        # 2. List Resource count
+        # 3. Migrate instance to another host
+        # 4. Resource count should list properly.
 
         self.debug("Setting up account and domain hierarchy")
-        self.setup_Accounts()
-        users = {self.parent_domain: self.parentd_admin,
-                 self.sub_domain: self.childd_admin
+        self.setupAccounts()
+        users = {self.child_domain_1: self.child_do_admin_1,
+                 self.child_domain_2: self.child_do_admin_2
                  }
         for domain, admin in users.items():
             self.account = admin
             self.domain = domain
-            self.debug("Creating an instance with service offering: %s" %
-                                                    self.service_offering.name)
-            vm_1 = self.create_Instance(service_off=self.service_offering)
-            vm_2 = self.create_Instance(service_off=self.service_offering)
-            vm_3 = self.create_Instance(service_off=self.service_offering)
-            vm_4 = self.create_Instance(service_off=self.service_offering)
-
-            self.debug("Deploying instance - CPU capacity is fully utilized")
-#            with self.assertRaises(Exception):
-#                self.create_Instance(service_off=self.service_offering)
 
-            self.check_Resource_Count(account=self.account, rtype=9)
-            self.debug("Destroying instance: %s" % vm_1.name)
-            try:
-                vm_1.delete(self.apiclient)
-            except Exception as e:
-                self.fail("Failed to delete instance: %s" % e)
-            self.check_Resource_Count(account=self.account, rtype=9)
+        api_client = self.testClient.createUserApiClient(
+            UserName=self.account.name,
+            DomainName=self.account.domain)
 
-            host = self.find_Suitable_Host(vm_2)
-            self.debug("Migrating instance: %s to host: %s" % (vm_2.name,
-                                                               host.name))
-            try:
-                vm_2.migrate(self.apiclient, host.id)
-            except Exception as e:
-                self.fail("Failed to migrate instance: %s" % e)
-            self.check_Resource_Count(account=self.account, rtype=9)
-        return
+        self.debug("Creating an instance with service offering: %s" %
+                   self.service_offering.name)
+        vm = self.createInstance(service_off=self.service_offering, api_client=api_client)
 
+        account_list = Account.list(self.apiclient, id=self.account.id)
+        self.assertIsInstance(account_list,
+            list,
+            "List Accounts should return a valid response"
+        )
+        resource_count = account_list[0].cputotal
 
-class TestCPULimitsUpdateResources(cloudstackTestCase):
+        expected_resource_count = int(self.services["service_offering"]["cpunumber"])
 
-    @classmethod
-    def setUpClass(cls):
-        cls.api_client = super(TestCPULimitsUpdateResources,
-                               cls).getClsTestClient().getApiClient()
-        cls.services = Services().services
-        # Get Zone, Domain and templates
-        cls.domain = get_domain(cls.api_client, cls.services)
-        cls.zone = get_zone(cls.api_client, cls.services)
+        self.assertEqual(resource_count, expected_resource_count,
+            "Initial resource count should with the expected resource count")
 
-        cls.template = get_template(
-                            cls.api_client,
-                            cls.zone.id,
-                            cls.services["ostype"]
-                            )
+        host = find_suitable_host(self.apiclient, vm)
+        self.debug("Migrating instance: %s to host: %s" %
+                   (vm.name, host.name))
+        try:
+            vm.migrate(self.apiclient, host.id)
+        except Exception as e:
+            self.fail("Failed to migrate instance: %s" % e)
 
-        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+        account_list = Account.list(self.apiclient, id=self.account.id)
+        self.assertIsInstance(account_list,
+            list,
+            "List Accounts should return a valid response"
+        )
+        resource_count_after_migrate = account_list[0].cputotal
 
-        cls._cleanup = []
+        self.assertEqual(resource_count, resource_count_after_migrate,
+            "Resource count should be same after starting the instance")
         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
+    @attr(tags=["advanced", "advancedns","simulator"])
+    def test_03_delete_instance(self):
+        """Test Deploy VM with 4 core CPU & verify the usage"""
 
-    def setUp(self):
-        self.apiclient = self.testClient.getApiClient()
-        self.dbclient = self.testClient.getDbConnection()
-        self.cleanup = []
-        return
+        # Validate the following
+        # 1. Create compute offering with 4 core CPU & Deploy VM
+        # 2. List Resource count for the CPU usage
+        # 3. Delete instance
+        # 4. Resource count should list as 0
 
-    def tearDown(self):
-        try:
-            # Clean up, terminate the created instance, volumes and snapshots
-            cleanup_resources(self.apiclient, self.cleanup)
-            pass
-        except Exception as e:
-            raise Exception("Warning: Exception during cleanup : %s" % e)
-        return
+        self.debug("Setting up account and domain hierarchy")
+        self.setupAccounts()
+        users = {self.child_domain_1: self.child_do_admin_1,
+                 self.child_domain_2: self.child_do_admin_2
+                 }
+        for domain, admin in users.items():
+            self.account = admin
+            self.domain = domain
 
-    def create_Instance(self, service_off, networks=None):
-        """Creates an instance in account"""
-        self.debug("Deploying an instance in account: %s" %
-                                                self.account.account.name)
-        try:
-            vm = VirtualMachine.create(
-                                self.apiclient,
-                                self.services["virtual_machine"],
-                                templateid=self.template.id,
-                                accountid=self.account.account.name,
-                                domainid=self.account.account.domainid,
-                                networkids=networks,
-                                serviceofferingid=service_off.id)
-            vms = VirtualMachine.list(self.apiclient, id=vm.id, listall=True)
-            self.assertIsInstance(vms,
-                                  list,
-                                  "List VMs should return a valid response")
-            self.assertEqual(vms[0].state, "Running",
-                             "Vm state should be running after deployment")
-            return vm
-        except Exception as e:
-            self.fail("Failed to deploy an instance: %s" % e)
+        api_client = self.testClient.createUserApiClient(
+            UserName=self.account.name,
+            DomainName=self.account.domain)
 
-    def get_Network(self, account):
-        """Returns a network for account"""
+        self.debug("Creating an instance with service offering: %s" %
+                   self.service_offering.name)
+        vm = self.createInstance(service_off=self.service_offering, api_client=api_client)
 
-        networks = Network.list(
-                                self.apiclient,
-                                account=account.account.name,
-                                domainid=account.account.domainid,
-                                listall=True
-                                )
-        self.assertIsInstance(networks,
-                              list,
-                              "List networks should return a valid response")
-        return networks[0]
-
-    def get_Resource_Type(self, resource_id):
-        """Returns resource type"""
-
-        lookup = {1: "VM", 2: "Public IP", 3: "Volume", 4: "Snapshot",
-                     5: "Template", 6: "Projects", 7: "Network", 8: "VPC",
-                     9: "CPUs", 10: "RAM",
-                     11: "Primary (shared) storage (Volumes)",
-                     12: "Secondary storage (Snapshots, Templates & ISOs)",
-                     13: "Network bandwidth rate (in bps)",
-                     14: "Number of times a OS template can be deployed"}
-        return lookup[resource_id]
-
-    def check_Resource_Count(self, account, rtype, delete=False):
-        """Validates the resource count
-            9     - CPUs
-            10    - RAM
-            11    - Primary (shared) storage (Volumes)
-            12    - Secondary storage (Snapshots, Templates & ISOs)
-            13    - Network bandwidth rate (in bps)
-            14    - Number of times a OS template can be deployed"""
-
-        self.debug("Updating the CPU resource count for account: %s" %
-                                                    account.account.name)
-        responses = Resources.updateCount(self.apiclient,
-                              domainid=account.account.domainid,
-                              account=account.account.name,
-                              resourcetype=rtype
-                              )
-        self.assertIsInstance(responses, list,
-                        "Update resource count should return valid response")
-        response = responses[0]
-        self.debug(response.resourcecount)
-        if delete:
-            self.assertEqual(response.resourcecount,
-                         0,
-                         "Resource count for %s should be 0" %
-                                        self.get_Resource_Type(rtype))
-        else:
-            self.assertNotEqual(response.resourcecount,
-                         0,
-                         "Resource count for %s should not be 0" %
-                                        self.get_Resource_Type(rtype))
-        return
+        account_list = Account.list(self.apiclient, id=self.account.id)
+        self.assertIsInstance(account_list,
+            list,
+            "List Accounts should return a valid response"
+        )
+        resource_count = account_list[0].cputotal
+
+        expected_resource_count = int(self.services["service_offering"]["cpunumber"])
 
-    def find_Suitable_Host(self, vm):
-        """Returns a suitable host for VM migration"""
+        self.assertEqual(resource_count, expected_resource_count,
+            "Initial resource count should match with the expected resource count")
 
+        self.debug("Destroying instance: %s" % vm.name)
         try:
-            hosts = Host.list(self.apiclient,
-                              virtualmachineid=vm.id,
-                              listall=True)
-            self.assertIsInstance(hosts, list, "Failed to find suitable host")
-            return hosts[0]
+            vm.delete(self.apiclient)
         except Exception as e:
-            self.fail("Failed to find suitable host vm migration: %s" % e)
-        return
-
-    def setup_Accounts(self):
-
-        self.debug("Creating a domain under: %s" % self.domain.name)
-        self.parent_domain = Domain.create(self.apiclient,
-                                        services=self.services["domain"],
-                                        parentdomainid=self.domain.id)
-        self.parentd_admin = Account.create(
-                            self.apiclient,
-                            self.services["account"],
-                            admin=True,
-                            domainid=self.domain.id
-                            )
-        # Cleanup the resources created at end of test
-        self.cleanup.append(self.parentd_admin)
-        self.cleanup.append(self.parent_domain)
-        self.debug("Updating the CPU resource count for domain: %s" %
-                                                            self.domain.name)
-        Resources.updateLimit(self.apiclient,
-                              resourcetype=9,
-                              max=1280,
-                              account=self.parentd_admin.account.name,
-                              domainid=self.parentd_admin.account.domainid)
-        self.debug("Creating a sub-domain under: %s" % self.domain.name)
-        self.sub_domain = Domain.create(self.apiclient,
-                                        services=self.services["domain"],
-                                        parentdomainid=self.domain.id)
-        self.childd_admin = Account.create(
-                                        self.apiclient,
-                                        self.services["account"],
-                                        admin=True,
-                                        domainid=self.sub_domain.id
-                                        )
+            self.fail("Failed to delete instance: %s" % e)
 
-        # Cleanup the resources created at end of test
-        self.cleanup.append(self.sub_domain)
-        self.cleanup.append(self.childd_admin)
-        self.debug("Updating the CPU resource count for domain: %s" %
-                                                        self.sub_domain.name)
-        Resources.updateLimit(self.apiclient,
-                              resourcetype=9,
-                              max=1280,
-                              account=self.childd_admin.account.name,
-                              domainid=self.childd_admin.account.domainid)
+        account_list = Account.list(self.apiclient, id=self.account.id)
+        self.assertIsInstance(account_list,
+            list,
+            "List Accounts should return a valid response"
+        )
+        resource_count = account_list[0].cputotal
+        self.assertEqual(resource_count, 0, "Resource count for %s should be 0" % get_resource_type(resource_id=8))#CPU
         return
 
-    @attr(tags=["advanced", "advancedns"])
-    def test_01_deploy_vm_with_5_cpus(self):
-        """Test Deploy VM with 5 core CPU & verify the usage"""
-
+    @attr(tags=["advanced", "advancedns","simulator"])
+    @attr(configuration='max.account.cpus')
+    def test_04_deploy_multiple_vm_with_multiple_cpus(self):
+        """Test Deploy multiple VM with 4 core CPU & verify the usage"""
+        #keep the configuration value - max.account.cpus number = 16
         # Validate the following
-        # 1. Create compute offering with 5 core CPU & Deploy VM as root admin
-        # 2. Update Resource count for the root admin CPU usage
+        # 1. Create compute offering with 4 core CPU
+        # 2. Deploy multiple VMs with this service offering
+        # 3. List Resource count for the root admin CPU usage
+        # 4. CPU usage should list properly
 
-        self.debug("Creating service offering with 5 CPU cores")
+        self.debug("Creating service offering with 4 CPU cores")
         self.service_offering = ServiceOffering.create(
                                             self.apiclient,
                                             self.services["service_offering"]
@@ -834,963 +663,83 @@ class TestCPULimitsUpdateResources(cloudstackTestCase):
         self.cleanup.append(self.service_offering)
 
         self.debug("Setting up account and domain hierarchy")
-        self.setup_Accounts()
-        users = {self.parent_domain: self.parentd_admin,
-                 self.sub_domain: self.childd_admin
+        self.setupAccounts()
+        users = {self.child_domain_1: self.child_do_admin_1,
+                 self.child_domain_2: self.child_do_admin_2
                  }
         for domain, admin in users.items():
             self.account = admin
             self.domain = domain
+
+            cpu_account_gc = Resources.list(self.apiclient,
+                                resourcetype = 8, #CPU
+                                account = self.account.name,
+                                domainid = self.domain.id
+                                )
+
+            if cpu_account_gc[0].max != 16:
+                self.skipTest("This test case requires configuration value max.account.cpus to be 16")
+
+            api_client = self.testClient.createUserApiClient(
+                UserName=self.account.name,
+                DomainName=self.account.domain)
+
             self.debug("Creating an instance with service offering: %s" %
-                                                    self.service_offering.name)
-            vm = self.create_Instance(service_off=self.service_offering)
+                       self.service_offering.name)
+            vm_1 = self.createInstance(service_off=self.service_offering, api_client=api_client)
+            vm_2 = self.createInstance(service_off=self.service_offering, api_client=api_client)
+            self.createInstance(service_off=self.service_offering, api_client=api_client)
+            self.createInstance(service_off=self.service_offering, api_client=api_client)
 
-            self.check_Resource_Count(account=self.account, rtype=9)
-            self.debug("Stopping instance: %s" % vm.name)
-            try:
-                vm.stop(self.apiclient)
-            except Exception as e:
-                self.fail("Failed to stop instance: %s" % e)
-            self.check_Resource_Count(account=self.account, rtype=9)
+            self.debug("Deploying instance - CPU capacity is fully utilized")
+            with self.assertRaises(Exception):
+                self.createInstance(service_off=self.service_offering, api_client=api_client)
 
-            self.debug("Starting instance: %s" % vm.name)
-            try:
-                vm.start(self.apiclient)
-            except Exception as e:
-                self.fail("Failed to start instance: %s" % e)
-            self.check_Resource_Count(account=self.account, rtype=9)
+            account_list = Account.list(self.apiclient, id=self.account.id)
+            self.assertIsInstance(account_list,
+                list,
+                "List Accounts should return a valid response"
+            )
+            resource_count = account_list[0].cputotal
 
-            host = self.find_Suitable_Host(vm)
-            self.debug("Migrating instance: %s to host: %s" %
-                                                        (vm.name, host.name))
-            try:
-                vm.migrate(self.apiclient, host.id)
-            except Exception as e:
-                self.fail("Failed to migrate instance: %s" % e)
-            self.check_Resource_Count(account=self.account, rtype=9)
+            expected_resource_count = int(self.services["service_offering"]["cpunumber"]) * 4 #Total 4 vms
+
+            self.assertEqual(resource_count, expected_resource_count,
+                "Initial resource count should with the expected resource count")
 
-            self.debug("Destroying instance: %s" % vm.name)
+            self.debug("Destroying instance: %s" % vm_1.name)
             try:
-                vm.delete(self.apiclient)
+                vm_1.delete(self.apiclient)
             except Exception as e:
                 self.fail("Failed to delete instance: %s" % e)
-            self.check_Resource_Count(account=self.account, rtype=9,
-                                      delete=True)
-        return
 
-    @attr(tags=["advanced", "advancedns"])
-    def test_02_deploy_multiple_vm_with_5_cpus(self):
-        """Test Deploy multiple VM with 5 core CPU & verify the usage"""
+            account_list = Account.list(self.apiclient, id=self.account.id)
+            self.assertIsInstance(account_list,
+                list,
+                "List Accounts should return a valid response"
+            )
+            resource_count_after_delete = account_list[0].cputotal
 
-        # Validate the following
-        # 1. Create compute offering with 5 core CPU
-        # 2. Deploy multiple VMs with this service offering
-        # 3. Update Resource count for the root admin CPU usage
-        # 4. CPU usage should list properly
+            expected_resource_count -= int(self.services["service_offering"]["cpunumber"])
 
-        self.debug("Creating service offering with 5 CPU cores")
-        self.service_offering = ServiceOffering.create(
-                                            self.apiclient,
-                                            self.services["service_offering"]
-                                            )
-        # Adding to cleanup list after execution
-        self.cleanup.append(self.service_offering)
+            self.assertEqual(resource_count_after_delete, expected_resource_count,
+                "Resource count should be less than before after deleting the instance")
 
-        self.debug("Setting up account and domain hierarchy")
-        self.setup_Accounts()
-        users = {self.parent_domain: self.parentd_admin,
-                 self.sub_domain: self.childd_admin
-                 }
-        for domain, admin in users.items():
-            self.account = admin
-            self.domain = domain
-            self.debug("Creating an instance with service offering: %s" %
-                                                    self.service_offering.name)
-            vm_1 = self.create_Instance(service_off=self.service_offering)
-            vm_2 = self.create_Instance(service_off=self.service_offering)
-            vm_3 = self.create_Instance(service_off=self.service_offering)
-            vm_4 = self.create_Instance(service_off=self.service_offering)
-
-            self.debug("Deploying instance - CPU capacity is fully utilized")
-#            with self.assertRaises(Exception):
-#                self.create_Instance(service_off=self.service_offering)
-
-            self.check_Resource_Count(account=self.account, rtype=9)
-            self.debug("Destroying instance: %s" % vm_1.name)
-            try:
-                vm_1.delete(self.apiclient)
-            except Exception as e:
-                self.fail("Failed to delete instance: %s" % e)
-            self.check_Resource_Count(account=self.account, rtype=9)
-
-            host = self.find_Suitable_Host(vm_2)
+            host = find_suitable_host(self.apiclient, vm_2)
             self.debug("Migrating instance: %s to host: %s" % (vm_2.name,
                                                                host.name))
             try:
                 vm_2.migrate(self.apiclient, host.id)
             except Exception as e:
                 self.fail("Failed to migrate instance: %s" % e)
-            self.check_Resource_Count(account=self.account, rtype=9)
-        return
-
-
-class TestMultipleChildDomains(cloudstackTestCase):
-
-    @classmethod
-    def setUpClass(cls):
-        cls.api_client = super(TestMultipleChildDomains,
-                               cls).getClsTestClient().getApiClient()
-        cls.services = Services().services
-        # Get Zone, Domain and templates
-        cls.domain = get_domain(cls.api_client, cls.services)
-        cls.zone = get_zone(cls.api_client, cls.services)
-
-        cls.template = get_template(
-                            cls.api_client,
-                            cls.zone.id,
-                            cls.services["ostype"]
-                            )
-
-        cls.services["virtual_machine"]["zoneid"] = cls.zone.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 = []
-        return
-
-    def tearDown(self):
-        try:
-            # Clean up, terminate the created instance, volumes and snapshots
-            cleanup_resources(self.apiclient, self.cleanup)
-            pass
-        except Exception as e:
-            raise Exception("Warning: Exception during cleanup : %s" % e)
-        return
-
-    def create_Instance(self, account, service_off, networks=None):
-        """Creates an instance in account"""
-        self.debug("Deploying an instance in account: %s" %
-                                                self.account.account.name)
-        try:
-            vm = VirtualMachine.create(
-                                self.apiclient,
-                                self.services["virtual_machine"],
-                                templateid=self.template.id,
-                                accountid=account.account.name,
-                                domainid=account.account.domainid,
-                                networkids=networks,
-                                serviceofferingid=service_off.id)
-            vms = VirtualMachine.list(self.apiclient, id=vm.id, listall=True)
-            self.assertIsInstance(vms,
-                                  list,
-                                  "List VMs should return a valid response")
-            self.assertEqual(vms[0].state, "Running",
-                             "Vm state should be running after deployment")
-            return vm
-        except Exception as e:
-            self.fail("Failed to deploy an instance: %s" % e)
-
-    def get_Network(self, account):
-        """Returns a network for account"""
-
-        networks = Network.list(
-                                self.apiclient,
-                                account=account.account.name,
-                                domainid=account.account.domainid,
-                                listall=True
-                                )
-        self.assertIsInstance(networks,
-                              list,
-                              "List networks should return a valid response")
-        return networks[0]
-
-    def get_Resource_Type(self, resource_id):
-        """Returns resource type"""
-
-        lookup = {1: "VM", 2: "Public IP", 3: "Volume", 4: "Snapshot",
-                     5: "Template", 6: "Projects", 7: "Network", 8: "VPC",
-                     9: "CPUs", 10: "RAM",
-                     11: "Primary (shared) storage (Volumes)",
-                     12: "Secondary storage (Snapshots, Templates & ISOs)",
-                     13: "Network bandwidth rate (in bps)",
-                     14: "Number of times a OS template can be deployed"}
-        return lookup[resource_id]
-
-    def check_Resource_Count(self, account, rtype, delete=False):
-        """Validates the resource count
-            9     - CPUs
-            10    - RAM
-            11    - Primary (shared) storage (Volumes)
-            12    - Secondary storage (Snapshots, Templates & ISOs)
-            13    - Network bandwidth rate (in bps)
-            14    - Number of times a OS template can be deployed"""
-
-        self.debug("Updating the CPU resource count for account: %s" %
-                                                    account.account.name)
-        responses = Resources.updateCount(self.apiclient,
-                              domainid=account.account.domainid,
-                              account=account.account.name,
-                              resourcetype=rtype
-                              )
-        self.assertIsInstance(responses, list,
-                        "Update resource count should return valid response")
-        response = responses[0]
-        self.debug(response.resourcecount)
-        if delete:
-            self.assertEqual(response.resourcecount,
-                         0,
-                         "Resource count for %s should be 0" %
-                                        self.get_Resource_Type(rtype))
-        else:
-            self.assertNotEqual(response.resourcecount,
-                         0,
-                         "Resource count for %s should not be 0" %
-                                        self.get_Resource_Type(rtype))
-        return
-
-    def setup_Accounts(self):
-
-        self.debug("Creating a domain under: %s" % self.domain.name)
-        self.parent_domain = Domain.create(self.apiclient,
-                                        services=self.services["domain"],
-                                        parentdomainid=self.domain.id)
-        self.parentd_admin = Account.create(
-                            self.apiclient,
-                            self.services["account"],
-                            admin=True,
-                            domainid=self.domain.id
-                            )
-        # Cleanup the resources created at end of test
-        self.cleanup.append(self.parentd_admin)
-        self.cleanup.append(self.parent_domain)
-
-        self.debug("Updating the CPU resource count for domain: %s" %
-                                                            self.domain.name)
-        Resources.updateLimit(self.apiclient,
-                              resourcetype=9,
-                              max=(128 * 2),
-                              account=self.parentd_admin.account.name,
-                              domainid=self.parentd_admin.account.domainid)
-        self.debug("Creating a sub-domain under: %s" % self.parent_domain.name)
-        self.cdomain_1 = Domain.create(self.apiclient,
-                                        services=self.services["domain"],
-                                        parentdomainid=self.parent_domain.id)
-
-        self.debug("Creating a sub-domain under: %s" % self.parent_domain.name)
-        self.cdomain_2 = Domain.create(self.apiclient,
-                                        services=self.services["domain"],
-                                        parentdomainid=self.parent_domain.id)
-
-        self.cadmin_1 = Account.create(
-                                        self.apiclient,
-                                        self.services["account"],
-                                        admin=True,
-                                        domainid=self.cdomain_1.id
-                                        )
-        # Cleanup the resources created at end of test
-        self.cleanup.append(self.cadmin_1)
-        self.cleanup.append(self.cadmin_2)
-        self.cleanup.append(self.cdomain_1)
-        self.cleanup.append(self.cdomain_2)
-
-        self.debug("Updating the CPU resource count for domain: %s" %
-                                                        self.cdomain_1.name)
-        Resources.updateLimit(self.apiclient,
-                              resourcetype=9,
-                              max=(128 * 1),
-                              account=self.cadmin_1.account.name,
-                              domainid=self.cadmin_1.account.domainid)
-
-        self.cadmin_2 = Account.create(
-                                        self.apiclient,
-                                        self.services["account"],
-                                        admin=True,
-                                        domainid=self.cdomain_2.id
-                                        )
-        self.debug("Updating the CPU resource count for domain: %s" %
-                                                        self.cdomain_2.name)
-        Resources.updateLimit(self.apiclient,
-                              resourcetype=9,
-                              max=(128 * 1),
-                              account=self.cadmin_2.account.name,
-                              domainid=self.cadmin_2.account.domainid)
-        users = {
-                 self.parent_domain: self.parentd_admin,
-                 self.cdomain_1: self.cadmin_1,
-                 self.cdomain_2: self.cadmin_2
-                 }
-        return users
-
-    @attr(tags=["advanced", "advancedns"])
-    def test_01_multiple_child_domains(self):
-        """Test CPU limits with multiple child domains"""
-
-        # Validate the following
-        # 1. Create Domain1 with 10 core CPU and 2 child domains with 5 core
-        #    each.Assign 2 cores for Domain1 admin1 & Domain1 User1 .Assign 2
-        #    cores for Domain2 admin1 & Domain2 User1
-        # 2. Deploy VM's by Domain1 admin1/user1/ Domain2 user1/Admin1 account
-        #    and verify the resource updates
-        # 3. Deploy VM by admin account after reaching max parent domain limit
-        # 4. Deploy VM with child account after reaching max child domain limit
-        # 5. Delete user account and verify the resource updates
-        # 6. Destroy user/admin account VM's and verify the child & Parent
-        #    domain resource updates
-
-        self.debug("Creating service offering with 5 CPU cores")
-        self.services["service_offering"]["cpunumber"] = self.services["service_offering"]["cpumaxnumber"]
-        self.service_offering = ServiceOffering.create(
-                                            self.apiclient,
-                                            self.services["service_offering"]
-                                            )
-        # Adding to cleanup list after execution
-        self.cleanup.append(self.service_offering)
-
-        self.debug("Setting up account and domain hierarchy")
-        self.setup_Accounts()
-
-        self.debug("Creating an instance with service offering: %s" %
-                                                self.service_offering.name)
-        vm_1 = self.create_Instance(account=self.cadmin_1,
-                                  service_off=self.service_offering)
-
-        vm_2 = self.create_Instance(account=self.cadmin_2,
-                                  service_off=self.service_offering)
-
-        self.check_Resource_Count(account=self.cadmin_1, rtype=9)
-        self.check_Resource_Count(account=self.cadmin_2, rtype=9)
-
-        self.debug(
-            "Creating instance when CPU limit is fully used in parent domain")
-        with self.assertRaises(Exception):
-            self.create_Instance(account=self.cadmin_1,
-                                  service_off=self.service_offering)
-
-        self.debug(
-            "Creating instance when CPU limit is fully used in child domain")
-        with self.assertRaises(Exception):
-            self.create_Instance(account=self.cadmin_1,
-                                  service_off=self.service_offering)
-        self.debug("Destroying instances: %s, %s" % (vm_1.name, vm_2.name))
-        try:
-            vm_1.delete(self.apiclient)
-            vm_2.delete(self.apiclient)
-        except Exception as e:
-            self.fail("Failed to delete instance: %s" % e)
-        self.check_Resource_Count(account=self.cadmin_1, rtype=9, delete=True)
-        self.check_Resource_Count(account=self.cadmin_2, rtype=9, delete=True)
-        return
-
-
-class TestProjectsCPULimits(cloudstackTestCase):
-
-    @classmethod
-    def setUpClass(cls):
-        cls.api_client = super(TestProjectsCPULimits,
-                               cls).getClsTestClient().getApiClient()
-        cls.services = Services().services
-        # Get Zone, Domain and templates
-        cls.domain = get_domain(cls.api_client, cls.services)
-        cls.zone = get_zone(cls.api_client, cls.services)
-
-        cls.template = get_template(
-                            cls.api_client,
-                            cls.zone.id,
-                            cls.services["ostype"]
-                            )
-
-        cls.services["virtual_machine"]["zoneid"] = cls.zone.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 = []
-        return
-
-    def tearDown(self):
-        try:
-            # Clean up, terminate the created instance, volumes and snapshots
-            cleanup_resources(self.apiclient, self.cleanup)
-            pass
-        except Exception as e:
-            raise Exception("Warning: Exception during cleanup : %s" % e)
-        return
-
-    def create_Instance(self, project, service_off, networks=None):
-        """Creates an instance in account"""
-        self.debug("Deploying an instance in account: %s" %
-                                                self.account.account.name)
-        try:
-            vm = VirtualMachine.create(
-                                self.apiclient,
-                                self.services["virtual_machine"],
-                                templateid=self.template.id,
-                                projectid=project.id,
-                                networkids=networks,
-                                serviceofferingid=service_off.id)
-            vms = VirtualMachine.list(self.apiclient, id=vm.id, listall=True)
-            self.assertIsInstance(vms,
-                                  list,
-                                  "List VMs should return a valid response")
-            self.assertEqual(vms[0].state, "Running",
-                             "Vm state should be running after deployment")
-            return vm
-        except Exception as e:
-            self.fail("Failed to deploy an instance: %s" % e)
-
-    def get_Network(self, account):
-        """Returns a network for account"""
-
-        networks = Network.list(
-                                self.apiclient,
-                                account=account.account.name,
-                                domainid=account.account.domainid,
-                                listall=True
-                                )
-        self.assertIsInstance(networks,
-                              list,
-                              "List networks should return a valid response")
-        return networks[0]
-
-    def get_Resource_Type(self, resource_id):
-        """Returns resource type"""
-
-        lookup = {1: "VM", 2: "Public IP", 3: "Volume", 4: "Snapshot",
-                     5: "Template", 6: "Projects", 7: "Network", 8: "VPC",
-                     9: "CPUs", 10: "RAM",
-                     11: "Primary (shared) storage (Volumes)",
-                     12: "Secondary storage (Snapshots, Templates & ISOs)",
-                     13: "Network bandwidth rate (in bps)",
-                     14: "Number of times a OS template can be deployed"}
-        return lookup[resource_id]
-
-    def check_Resource_Count(self, project, rtype, delete=False):
-        """Validates the resource count
-            9     - CPUs
-            10    - RAM
-            11    - Primary (shared) storage (Volumes)
-            12    - Secondary storage (Snapshots, Templates & ISOs)
-            13    - Network bandwidth rate (in bps)
-            14    - Number of times a OS template can be deployed"""
-
-        self.debug("Updating the CPU resource count for project: %s" %
-                                                                project.name)
-        responses = Resources.updateCount(self.apiclient,
-                              projectid=self.project.id,
-                              resourcetype=rtype)
-
-        self.assertIsInstance(responses, list,
-                        "Update resource count should return valid response")
-        response = responses[0]
-        self.debug(response.resourcecount)
-        if delete:
-            self.assertEqual(response.resourcecount,
-                         0,
-                         "Resource count for %s should be 0" %
-                                        self.get_Resource_Type(rtype))
-        else:
-            self.assertNotEqual(response.resourcecount,
-                         0,
-                         "Resource count for %s should not be 0" %
-                                        self.get_Resource_Type(rtype))
-        return
-
-    def find_Suitable_Host(self, vm):
-        """Returns a suitable host for VM migration"""
-
-        try:
-            hosts = Host.list(self.apiclient,
-                              virtualmachineid=vm.id,
-                              listall=True)
-            self.assertIsInstance(hosts, list, "Failed to find suitable host")
-            return hosts[0]
-        except Exception as e:
-            self.fail("Failed to find suitable host vm migration: %s" % e)
-        return
-
-    def setup_Env(self):
-
-        self.debug("Creating a domain under: %s" % self.domain.name)
-        self.domain = Domain.create(self.apiclient,
-                                        services=self.services["domain"],
-                                        parentdomainid=self.domain.id)
-        self.admin = Account.create(
-                            self.apiclient,
-                            self.services["account"],
-                            admin=True,
-                            domainid=self.domain.id
-                            )
-
-        # Create project as a domain admin
-        self.project = Project.create(self.apiclient,
-                                 self.services["project"],
-                                 account=self.admin.account.name,
-                                 domainid=self.admin.account.domainid)
-        # Cleanup created project at end of test
-        self.cleanup.append(self.project)
-        self.cleanup.append(self.admin)
-        self.cleanup.append(self.domain)
-        self.debug("Created project with domain admin with name: %s" %
-                                                        self.project.name)
-
-        projects = Project.list(self.apiclient, id=self.project.id,
-                                listall=True)
-
-        self.assertEqual(isinstance(projects, list), True,
-                        "Check for a valid list projects response")
-        project = projects[0]
-        self.assertEqual(project.name, self.project.name,
-                        "Check project name from list response")
-        return
-
-    @attr(tags=["advanced", "advancedns"])
-    @attr(configuration='max.projects.cpus')
-    def test_01_project_limits_global_config(self):
-        """Test max.projects.cpus global configuration"""
-
-        # Validate the following
-        # 1. Set (max.project.cpus=10) as the max limit to
-        #    Domain1 (max.account.cpus=10)
-        # 2. Assign account to projects and verify the resource updates
-        # 3. Deploy VM with the accounts added to the project
-        # 4. Stop VM of an accounts added to the project to a new host
-        # 5. Assign VM of an accounts added to the project to a new host
-        # 6. Migrate VM of an accounts added to the project to a new host
-        # 7. Destroy VM of an accounts added to the project to a new host
-        # 8. Restore VM of an accounts added to the project to a new host
-        # 9. Recover VM of an accounts added to the project to a new host
-
-        self.service_offering = ServiceOffering.create(
-                                            self.apiclient,
-                                            self.services["service_offering"]
-                                            )
-        # Adding to cleanup list after execution
-        self.cleanup.append(self.service_offering)
-
-        self.debug("Setting up account and domain hierarchy")
-        self.setup_Env()
-        self.debug("Creating an instance with service offering: %s" %
-                                                    self.service_offering.name)
-        vm = self.create_Instance(project=self.project,
-                                  service_off=self.service_offering)
-
-        self.check_Resource_Count(project=self.project, rtype=9)
-        self.debug("Stopping instance: %s" % vm.name)
-        try:
-            vm.stop(self.apiclient)
-        except Exception as e:
-            self.fail("Failed to stop instance: %s" % e)
-        self.check_Resource_Count(project=self.project, rtype=9)
-
-        self.debug("Starting instance: %s" % vm.name)
-        try:
-            vm.start(self.apiclient)
-        except Exception as e:
-            self.fail("Failed to start instance: %s" % e)
-        self.check_Resource_Count(project=self.project, rtype=9)
-
-        host = self.find_Suitable_Host(vm)
-        self.debug("Migrating instance: %s to host: %s" %
-                                                    (vm.name, host.name))
-        try:
-            vm.migrate(self.apiclient, host.id)
-        except Exception as e:
-            self.fail("Failed to migrate instance: %s" % e)
-        self.check_Resource_Count(project=self.project, rtype=9)
-
-        self.debug("Destroying instance: %s" % vm.name)
-        try:
-            vm.delete(self.apiclient)
-        except Exception as e:
-            self.fail("Failed to delete instance: %s" % e)
-        self.check_Resource_Count(project=self.project, rtype=9, delete=True)
-        return
-
-
-class TestMaxCPULimits(cloudstackTestCase):
-
-    @classmethod
-    def setUpClass(cls):
-        cls.api_client = super(TestMaxCPULimits,
-                               cls).getClsTestClient().getApiClient()
-        cls.services = Services().services
-        # Get Zone, Domain and templates
-        cls.domain = get_domain(cls.api_client, cls.services)
-        cls.zone = get_zone(cls.api_client, cls.services)
-
-        cls.template = get_template(
-                            cls.api_client,
-                            cls.zone.id,
-                            cls.services["ostype"]
-                            )
-
-        cls.services["virtual_machine"]["zoneid"] = cls.zone.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 = []
-        return
-
-    def tearDown(self):
-        try:
-            # Clean up, terminate the created instance, volumes and snapshots
-            cleanup_resources(self.apiclient, self.cleanup)
-            pass
-        except Exception as e:
-            raise Exception("Warning: Exception during cleanup : %s" % e)
-        return
-
-    def create_Instance(self, account=None,
-                        project=None, service_off, networks=None):
-        """Creates an instance in account"""
-        self.debug("Deploying an instance in account: %s" %
-                                                self.account.account.name)
-        try:
-            if account:
-                vm = VirtualMachine.create(
-                                self.apiclient,
-                                self.services["virtual_machine"],
-                                templateid=self.template.id,
-                                accountid=account.account.name,
-                                domainid=account.account.domainid,
-                                networkids=networks,
-                                serviceofferingid=service_off.id)
-            elif project:
-                vm = VirtualMachine.create(
-                                self.apiclient,
-                                self.services["virtual_machine"],
-                                templateid=self.template.id,
-                                projectid=project.id,
-                                networkids=networks,
-                                serviceofferingid=service_off.id)
-            vms = VirtualMachine.list(self.apiclient, id=vm.id, listall=True)
-            self.assertIsInstance(vms,
-                                  list,
-                                  "List VMs should return a valid response")
-            self.assertEqual(vms[0].state, "Running",
-                             "Vm state should be running after deployment")
-            return vm
-        except Exception as e:
-            self.fail("Failed to deploy an instance: %s" % e)
-
-    def get_Network(self, account):
-        """Returns a network for account"""
-
-        networks = Network.list(
-                                self.apiclient,
-                                account=account.account.name,
-                                domainid=account.account.domainid,
-                                listall=True
-                                )
-        self.assertIsInstance(networks,
-                              list,
-                              "List networks should return a valid response")
-        return networks[0]
-
-    def get_Resource_Type(self, resource_id):
-        """Returns resource type"""
-
-        lookup = {1: "VM", 2: "Public IP", 3: "Volume", 4: "Snapshot",
-                     5: "Template", 6: "Projects", 7: "Network", 8: "VPC",
-                     9: "CPUs", 10: "RAM",
-                     11: "Primary (shared) storage (Volumes)",
-                     12: "Secondary storage (Snapshots, Templates & ISOs)",
-                     13: "Network bandwidth rate (in bps)",
-                     14: "Number of times a OS template can be deployed"}
-        return lookup[resource_id]
-
-    def check_Resource_Count(self, rtype, account=None, project=None,
-                             delete=False):
-        """Validates the resource count
-            9     - CPUs
-            10    - RAM
-            11    - Primary (shared) storage (Volumes)
-            12    - Secondary storage (Snapshots, Templates & ISOs)
-            13    - Network bandwidth rate (in bps)
-            14    - Number of times a OS template can be deployed"""
-
-        if account:
-            self.debug("Updating the CPU resource count for account: %s" %
-                                                    account.account.name)
-            responses = Resources.updateCount(self.apiclient,
-                              domainid=account.account.domainid,
-                              account=account.account.name,
-                              resourcetype=rtype)
-        elif project:
-            self.debug("Updating the CPU resource count for project: %s" %
-                                                                project.name)
-            responses = Resources.updateCount(self.apiclient,
-                                              projectid=project.id,
-                                              resourcetype=rtype)
-
-        self.assertIsInstance(responses, list,
-                        "Update resource count should return valid response")
-        response = responses[0]
-        self.debug(response.resourcecount)
-        if delete:
-            self.assertEqual(response.resourcecount,
-                         0,
-                         "Resource count for %s should be 0" %
-                                        self.get_Resource_Type(rtype))
-        else:
-            self.assertNotEqual(response.resourcecount,
-                         0,
-                         "Resource count for %s should not be 0" %
-                                        self.get_Resource_Type(rtype))
-        return
-
-    def find_Suitable_Host(self, vm):
-        """Returns a s

<TRUNCATED>

Mime
View raw message