You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by sa...@apache.org on 2013/09/17 12:28:07 UTC

[1/7] Automation: Adding Memory limits tests from Resource Limits Tests

Updated Branches:
  refs/heads/4.2 b183efe80 -> 20b1a2c5c


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/909b2879/test/integration/component/memory_limits/test_project_limits.py
----------------------------------------------------------------------
diff --git a/test/integration/component/memory_limits/test_project_limits.py b/test/integration/component/memory_limits/test_project_limits.py
new file mode 100644
index 0000000..505f031
--- /dev/null
+++ b/test/integration/component/memory_limits/test_project_limits.py
@@ -0,0 +1,321 @@
+# 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
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# 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 memory resource limits
+"""
+# Import Local Modules
+from nose.plugins.attrib import attr
+from marvin.cloudstackTestCase import cloudstackTestCase, unittest
+from marvin.integration.lib.base import (
+                                        Account,
+                                        ServiceOffering,
+                                        VirtualMachine,
+                                        Domain,
+                                        Project
+                                        )
+from marvin.integration.lib.common import (get_domain,
+                                        get_zone,
+                                        get_template,
+                                        cleanup_resources,
+					wait_for_cleanup,
+                                        get_updated_resource_count,
+                                        find_suitable_host,
+                                        get_resource_type
+                                        )
+
+class Services:
+    """Test memory resource limit services
+    """
+
+    def __init__(self):
+        self.services = {
+                        "account": {
+                                "email": "test@test.com",
+                                "firstname": "Test",
+                                "lastname": "User",
+                                "username": "resource",
+                                # Random characters are appended for unique
+                                # username
+                                "password": "password",
+                         },
+                         "service_offering": {
+                                "name": "Tiny Instance",
+                                "displaytext": "Tiny Instance",
+                                "cpunumber": 1,
+                                "cpuspeed": 100,    # in MHz
+                                "memory": 5120,    # In MBs
+                        },
+                        "virtual_machine": {
+                                "displayname": "TestVM",
+                                "username": "root",
+                                "password": "password",
+                                "ssh_port": 22,
+                                "hypervisor": 'KVM',
+                                "privateport": 22,
+                                "publicport": 22,
+                                "protocol": 'TCP',
+                                },
+                         "network": {
+                                "name": "Test Network",
+                                "displaytext": "Test Network",
+                                "netmask": '255.255.255.0'
+                                },
+                         "project": {
+                                "name": "Project",
+                                "displaytext": "Test project",
+                                },
+                         "domain": {
+                                "name": "Domain",
+                                },
+                        "ostype": 'CentOS 5.3 (64-bit)',
+                        "sleep": 60,
+                        "timeout": 10,
+                        "mode": 'advanced',
+                        # Networking mode: Advanced, Basic
+                    }
+
+class TestProjectsMemoryLimits(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(TestProjectsMemoryLimits,
+                               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.services["virtual_machine"]["zoneid"] = cls.zone.id
+
+        cls.service_offering = ServiceOffering.create(
+                                            cls.api_client,
+                                            cls.services["service_offering"]
+                                            )
+
+        cls._cleanup = [cls.service_offering, ]
+        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.account = Account.create(
+             self.apiclient,
+             self.services["account"],
+             admin=True
+             )
+        self.cleanup = [self.account, ]
+
+        self.debug("Setting up account and domain hierarchy")
+        self.setupProjectAccounts()
+
+	api_client = self.testClient.createUserApiClient(
+                            UserName=self.admin.name,
+                            DomainName=self.admin.domain)
+
+        self.debug("Creating an instance with service offering: %s" %
+                                                    self.service_offering.name)
+        self.vm = self.createInstance(project=self.project,
+                                  service_off=self.service_offering, api_client=api_client) 
+        return
+
+    def tearDown(self):
+        try:
+            # Clean up, terminate the created instance, volumes and snapshots
+            cleanup_resources(self.apiclient, self.cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def createInstance(self, project, service_off, networks=None, api_client=None):
+        """Creates an instance in account"""
+        self.debug("Deploying an instance in account: %s" %
+                                                self.account.name)
+
+	if api_client is None:
+	    api_client = self.apiclient
+
+        try:
+            vm = VirtualMachine.create(
+                                api_client,
+                                self.services["virtual_machine"],
+                                templateid=self.template.id,
+                                projectid=project.id,
+                                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")
+            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 setupProjectAccounts(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.name,
+                                 domainid=self.admin.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","simulator"])
+    @attr(configuration='max.projects.memory')
+    def test_01_project_vmlifecycle_reboot_instance(self):
+        """Test max.projects.memory global configuration"""
+
+        # Validate the following
+        # 1. Set (max.project.memory=10) as the max limit to
+        #    Domain1 (max.account.memory=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. Resource count should list properly
+        # 6. Start VM of an accounts added to the project to a new host
+        # 7. Resource count should list properly
+
+        self.debug("Checking memory resource count for project: %s" % self.project.name)
+        resource_count = get_updated_resource_count(self.apiclient, account=self.admin, project=self.project, rtype=9)#RAM
+        self.debug(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)
+
+        self.debug("Checking memory resource count for project: %s" % self.project.name)
+        resource_count = get_updated_resource_count(self.apiclient, account=self.admin, project=self.project, rtype=9)#RAM
+        self.debug(resource_count)
+
+        self.debug("Starting instance: %s" % self.vm.name)
+        try:
+            self.vm.start(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to start instance: %s" % e)
+
+        self.debug("Checking memory resource count for project: %s" % self.project.name)
+        get_updated_resource_count(self.apiclient, account=self.admin, project=self.project, rtype=9)#RAM 
+        self.debug(resource_count)
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    @attr(configuration='max.projects.memory')
+    def test_02_project_vmlifecycle_migrate_instance(self):
+        """Test max.projects.memory global configuration"""
+
+        # Validate the following
+        # 1. Set (max.project.memory=10) as the max limit to
+        #    Domain1 (max.account.memory=10)
+        # 2. Assign account to projects and verify the resource updates
+        # 3. Deploy VM with the accounts added to the project
+        # 4. Migrate VM of an accounts added to the project to a new host
+        # 5. Resource count should list properly.
+
+        self.debug("Checking memory resource count for project: %s" % self.project.name)
+        resource_count = get_updated_resource_count(self.apiclient, account=self.admin, project=self.project, rtype=9)#RAM 
+        self.debug(resource_count)        
+
+        host = find_suitable_host(self.apiclient, self.vm)
+        self.debug("Migrating instance: %s to host: %s" %
+                                                    (self.vm.name, host.name))
+        try:
+            self.vm.migrate(self.apiclient, host.id)
+        except Exception as e:
+            self.fail("Failed to migrate instance: %s" % e)
+    
+        self.debug("Checking memory resource count for project: %s" % self.project.name)
+        resource_count = get_updated_resource_count(self.apiclient, account=self.admin, project=self.project, rtype=9)#RAM 
+        self.debug(resource_count) 
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    @attr(configuration='max.projects.memory')
+    def test_03_project_vmlifecycle_delete_instance(self):
+        """Test max.projects.memory global configuration"""
+
+        # Validate the following
+        # 1. Set (max.project.memory=10) as the max limit to
+        #    Domain1 (max.account.memory=10)
+        # 2. Assign account to projects and verify the resource updates
+        # 3. Deploy VM with the accounts added to the project 
+        # 4. Destroy VM of an accounts added to the project
+        # 5. Resource count should list as 0 after destroying the instance
+
+        self.debug("Checking memory resource count for project: %s" % self.project.name)
+        resource_count = get_updated_resource_count(self.apiclient, account=self.admin, project=self.project, rtype=9)#RAM 
+        self.debug(resource_count) 
+
+        self.debug("Destroying instance: %s" % self.vm.name)
+        try:
+            self.vm.delete(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to delete instance: %s" % e)
+
+	# Wait for expunge interval to cleanup Memory
+	wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
+
+        self.debug("Checking memory resource count for project: %s" % self.project.name)
+        resource_count = get_updated_resource_count(self.apiclient, account=self.admin, project=self.project, rtype=9)#RAM 
+        self.debug(resource_count)
+        self.assertEqual(resource_count, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=9))#RAM         
+        return
+
+ 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/909b2879/tools/marvin/marvin/integration/lib/base.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/integration/lib/base.py b/tools/marvin/marvin/integration/lib/base.py
index 48c49ab..6b84029 100755
--- a/tools/marvin/marvin/integration/lib/base.py
+++ b/tools/marvin/marvin/integration/lib/base.py
@@ -3416,3 +3416,33 @@ class ApplicationLoadBalancer:
         cmd = listLoadBalancers.listLoadBalancersCmd()
         [setattr(cmd, k, v) for k, v in kwargs.items()]
         return(apiclient.listLoadBalancerRules(cmd))
+
+class Resources:
+    """Manage resource limits"""
+
+    def __init__(self, items, services):
+        self.__dict__.update(items)
+
+    @classmethod
+    def list(cls, apiclient, **kwargs):
+        """Lists resource limits"""
+
+        cmd = listResourceLimits.listResourceLimitsCmd()
+        [setattr(cmd, k, v) for k, v in kwargs.items()]
+        return(apiclient.listResourceLimits(cmd))
+
+    @classmethod
+    def updateLimit(cls, apiclient, **kwargs):
+        """Updates resource limits"""
+
+        cmd = updateResourceLimit.updateResourceLimitCmd()
+        [setattr(cmd, k, v) for k, v in kwargs.items()]
+        return(apiclient.updateResourceLimit(cmd))
+
+    @classmethod
+    def updateCount(cls, apiclient, **kwargs):
+        """Updates resource count"""
+
+        cmd = updateResourceCount.updateResourceCountCmd()
+        [setattr(cmd, k, v) for k, v in kwargs.items()]
+        return(apiclient.updateResourceCount(cmd))

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/909b2879/tools/marvin/marvin/integration/lib/common.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/integration/lib/common.py b/tools/marvin/marvin/integration/lib/common.py
index 4f5acef..9fbed83 100644
--- a/tools/marvin/marvin/integration/lib/common.py
+++ b/tools/marvin/marvin/integration/lib/common.py
@@ -576,3 +576,75 @@ def list_vpc_offerings(apiclient, **kwargs):
     cmd = listVPCOfferings.listVPCOfferingsCmd()
     [setattr(cmd, k, v) for k, v in kwargs.items()]
     return(apiclient.listVPCOfferings(cmd))
+
+def get_updated_resource_count(apiclient, rtype, account, project=None):
+        """Validates the resource count
+            0     - VM
+            1     - Public IP
+            2     - Volume
+            3     - Snapshot
+            4     - Template
+            5     - Projects
+            6     - Network
+            7     - VPC
+            8     - CPUs
+            9     - RAM
+            10    - Primary (shared) storage (Volumes)
+            11    - Secondary storage (Snapshots, Templates & ISOs)
+            12    - Network bandwidth rate (in bps)
+            13    - Number of times a OS template can be deployed"""	
+
+        if project: 
+            responses = Resources.updateCount(apiclient,
+                                              domainid=account.domainid, 
+                                              projectid = project.id,
+                                              resourcetype=rtype
+                                              )
+
+        else:
+            responses = Resources.updateCount(apiclient,
+                                              domainid=account.domainid,
+                                              account=account.name, 
+                                              resourcetype=rtype
+                                              )
+
+        if isinstance(responses, list):
+            assert len(responses) > 0, "Update resource count should return valid response" 
+        else:
+            raise Exception("Exception: Update resource count should return valid response")	
+
+        return responses[0].resourcecount
+
+def find_suitable_host(apiclient, vm):
+        """Returns a suitable host for VM migration"""
+
+        hosts = Host.list(apiclient,
+                          virtualmachineid=vm.id,
+                          listall=True) 
+
+        if isinstance(hosts, list):
+            assert len(hosts) > 0, "List host should return valid response" 
+        else:
+            raise Exception("Exception: List host should return valid response")
+        return hosts[0]
+
+def get_resource_type(resource_id):
+        """Returns resource type"""
+
+        lookup = {  0: "VM",
+                    1: "Public IP",
+                    2: "Volume",
+                    3: "Snapshot",
+                    4: "Template", 
+                    5: "Projects", 
+                    6: "Network", 
+                    7: "VPC",
+                    8: "CPUs",
+                    9: "RAM",
+                    10: "Primary (shared) storage (Volumes)",
+                    11: "Secondary storage (Snapshots, Templates & ISOs)",
+                    12: "Network bandwidth rate (in bps)",
+                    13: "Number of times a OS template can be deployed"
+                 }
+
+        return lookup[resource_id]


[6/7] git commit: updated refs/heads/4.2 to 20b1a2c

Posted by sa...@apache.org.
Merge branch '4.2' of https://git-wip-us.apache.org/repos/asf/cloudstack into 4.2


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

Branch: refs/heads/4.2
Commit: e546fe0e7119ff9a85614278be92f10eb4b39b72
Parents: 681eba5 9162b3c
Author: sailajam <sa...@citrix.com>
Authored: Thu Sep 12 10:59:47 2013 +0530
Committer: sailajam <sa...@citrix.com>
Committed: Thu Sep 12 10:59:47 2013 +0530

----------------------------------------------------------------------
 CHANGES                                         |    2 +-
 LICENSE                                         |   13 +-
 .../tomcatconf/commands-simulator.properties.in |    2 +-
 agent/bindir/cloudstack-agent-upgrade.in        |   50 +
 agent/bindir/libvirtqemuhook.in                 |   53 +
 agent/conf/agent.properties                     |   20 +
 agent/pom.xml                                   |    2 +-
 api/pom.xml                                     |    2 +-
 api/src/com/cloud/agent/api/to/VolumeTO.java    |    4 +
 api/src/com/cloud/dc/DedicatedResources.java    |    2 +-
 api/src/com/cloud/deploy/DeploymentPlanner.java |    7 +
 api/src/com/cloud/network/NetworkService.java   |    2 +-
 api/src/com/cloud/network/vpc/VpcGateway.java   |    2 +-
 api/src/com/cloud/storage/S3.java               |   50 -
 api/src/com/cloud/storage/Swift.java            |   37 -
 api/src/com/cloud/storage/VolumeApiService.java |    1 +
 .../cloudstack/affinity/AffinityGroup.java      |    2 +
 .../affinity/AffinityGroupProcessor.java        |   30 +
 .../affinity/AffinityGroupService.java          |    7 +
 .../affinity/AffinityProcessorBase.java         |   21 +
 .../cloudstack/api/ResponseGenerator.java       |    8 -
 .../command/admin/cluster/AddClusterCmd.java    |   18 +-
 .../api/command/admin/ldap/LDAPConfigCmd.java   |    3 +-
 .../admin/network/UpdatePhysicalNetworkCmd.java |    8 +-
 .../admin/region/ListPortableIpRangesCmd.java   |    2 -
 .../command/admin/storage/AddImageStoreCmd.java |   36 +-
 .../api/command/admin/storage/AddS3Cmd.java     |   49 +-
 .../admin/storage/UpdateStoragePoolCmd.java     |   15 +
 .../api/command/admin/swift/AddSwiftCmd.java    |  122 +
 .../api/command/admin/swift/ListSwiftsCmd.java  |   70 +
 .../api/command/admin/vm/AssignVMCmd.java       |    2 +-
 .../user/config/ListCapabilitiesCmd.java        |    3 +
 .../firewall/UpdatePortForwardingRuleCmd.java   |   19 +
 .../CreateLBStickinessPolicyCmd.java            |   15 +
 .../loadbalancer/CreateLoadBalancerRuleCmd.java |   10 +
 .../loadbalancer/UpdateLoadBalancerRuleCmd.java |   15 +
 .../command/user/network/UpdateNetworkCmd.java  |   10 +
 .../AuthorizeSecurityGroupIngressCmd.java       |    7 -
 .../RevokeSecurityGroupEgressCmd.java           |   10 +-
 .../RevokeSecurityGroupIngressCmd.java          |   10 +-
 .../api/command/user/vm/ListVMsCmd.java         |    6 +-
 .../command/user/volume/MigrateVolumeCmd.java   |    1 +
 .../api/command/user/vpc/DeleteVPCCmd.java      |    9 +
 .../api/command/user/vpc/RestartVPCCmd.java     |   10 +
 .../api/command/user/vpc/UpdateVPCCmd.java      |   10 +
 .../api/response/AccountResponse.java           |   20 +-
 .../api/response/CapabilitiesResponse.java      |   14 +
 .../api/response/CreateCmdResponse.java         |    5 +
 .../api/response/NetworkOfferingResponse.java   |    6 +
 .../api/response/NetworkResponse.java           |    9 +-
 .../api/response/ProjectResponse.java           |   22 +-
 .../cloudstack/api/response/RegionResponse.java |   15 +-
 .../response/ResourceLimitAndCountResponse.java |    6 +
 .../cloudstack/api/response/S3Response.java     |  218 --
 .../api/response/SecurityGroupRuleResponse.java |    4 +-
 .../cloudstack/api/response/SwiftResponse.java  |   86 -
 .../cloudstack/api/response/ZoneResponse.java   |    8 +
 .../org/apache/cloudstack/region/Region.java    |    4 +-
 .../api/command/test/ScaleVMCmdTest.java        |    5 +-
 awsapi/conf/applicationContext.xml.in           |    2 +-
 awsapi/pom.xml                                  |   12 +-
 .../classes/resources/messages.properties       |   10 +
 .../classes/resources/messages_ja.properties    |  548 +++--
 .../classes/resources/messages_zh_CN.properties |  518 ++--
 client/pom.xml                                  |    2 +-
 client/tomcatconf/applicationContext.xml.in     |    9 +-
 client/tomcatconf/commands.properties.in        |    7 +-
 client/tomcatconf/componentContext.xml.in       |    3 +-
 client/tomcatconf/nonossComponentContext.xml.in |    3 +-
 .../tomcatconf/simulatorComponentContext.xml.in |    1 +
 core/pom.xml                                    |    2 +-
 .../GlobalLoadBalancerConfigCommand.java        |    4 +
 .../virtualnetwork/VirtualRoutingResource.java  |   70 +
 .../StorageSubsystemCommandHandlerBase.java     |    2 +-
 .../cloud/storage/template/IsoProcessor.java    |    5 +
 .../com/cloud/storage/template/Processor.java   |    5 +
 .../cloud/storage/template/QCOW2Processor.java  |   23 +
 .../storage/template/RawImageProcessor.java     |    5 +
 .../storage/template/TemplateLocation.java      |    4 +-
 .../cloud/storage/template/VhdProcessor.java    |   28 +
 .../cloud/storage/template/VmdkProcessor.java   |   11 +
 debian/rules                                    |   10 +-
 deps/XenServerJava/pom.xml                      |    4 +-
 developer/pom.xml                               |    2 +-
 docs/en-US/Book_Info_Release_Notes_4-0.xml      |   38 -
 docs/en-US/Book_Info_Release_Notes_4.xml        |   38 +
 docs/en-US/Developers_Guide.xml                 |    2 +
 docs/en-US/Release_Notes.xml                    | 2274 +++++++++++++++++-
 docs/en-US/about-primary-storage.xml            |    5 +-
 docs/en-US/about-regions.xml                    |    5 +-
 docs/en-US/about-secondary-storage.xml          |   22 +-
 docs/en-US/about-zones.xml                      |   22 +-
 docs/en-US/accessing-system-vms.xml             |   66 +
 docs/en-US/accounts-users-domains.xml           |   88 +-
 docs/en-US/add-gateway-vpc.xml                  |   74 +-
 docs/en-US/add-ip-range.xml                     |  173 +-
 docs/en-US/add-load-balancer-rule.xml           |   16 +
 docs/en-US/add-loadbalancer-rule-vpc.xml        |   47 +-
 docs/en-US/add-remove-nic-ui.xml                |    6 +-
 docs/en-US/add-tier.xml                         |    3 +-
 docs/en-US/added-API-commands-4.2.xml           |  342 ++-
 docs/en-US/admin-alerts.xml                     |   95 +-
 docs/en-US/attaching-volume.xml                 |    2 +-
 docs/en-US/basic-zone-configuration.xml         |    2 +-
 docs/en-US/best-practices-for-vms.xml           |   56 +-
 docs/en-US/best-practices-primary-storage.xml   |    6 +-
 ...change-network-offering-on-guest-network.xml |   75 +-
 docs/en-US/changed-API-commands-4.2.xml         |   27 +-
 docs/en-US/changing-service-offering-for-vm.xml |  195 +-
 docs/en-US/configure-acl.xml                    |   14 +-
 docs/en-US/configure-vpn.xml                    |    2 +-
 docs/en-US/creating-compute-offerings.xml       |    4 +
 docs/en-US/creating-disk-offerings.xml          |   10 +-
 docs/en-US/creating-network-offerings.xml       |   15 +-
 docs/en-US/creating-shared-network.xml          |    2 +-
 docs/en-US/delete-event-alerts.xml              |   47 +-
 docs/en-US/detach-move-volumes.xml              |    5 +-
 docs/en-US/egress-firewall-rule.xml             |  220 +-
 docs/en-US/global-config.xml                    |  189 +-
 docs/en-US/guest-traffic.xml                    |   24 +-
 docs/en-US/health-checks-for-lb-rules.xml       |   51 +
 docs/en-US/host-allocation.xml                  |  105 +-
 docs/en-US/hypervisor-host-install-agent.xml    |   45 +
 docs/en-US/hypervisor-host-install-libvirt.xml  |    5 +
 docs/en-US/images/add-tier.png                  |  Bin 14891 -> 19054 bytes
 docs/en-US/images/addAccount-icon.png           |  Bin 0 -> 605 bytes
 docs/en-US/images/change-affinity-button.png    |  Bin 0 -> 7300 bytes
 docs/en-US/images/dedicate-resource-button.png  |  Bin 0 -> 7144 bytes
 docs/en-US/images/gslb.png                      |  Bin 60354 -> 68556 bytes
 docs/en-US/images/plugin1.jpg                   |  Bin 0 -> 32999 bytes
 docs/en-US/images/plugin2.jpg                   |  Bin 0 -> 35149 bytes
 docs/en-US/images/plugin3.jpg                   |  Bin 0 -> 41983 bytes
 docs/en-US/images/plugin4.jpg                   |  Bin 0 -> 32125 bytes
 docs/en-US/images/plugin_intro.jpg              |  Bin 0 -> 22247 bytes
 docs/en-US/images/replace-acl-icon.png          |  Bin 930 -> 982 bytes
 docs/en-US/images/vds-name.png                  |  Bin 0 -> 64739 bytes
 docs/en-US/images/view-systemvm-details.png     |  Bin 0 -> 25483 bytes
 docs/en-US/ip-forwarding-firewalling.xml        |    9 +-
 docs/en-US/ip-vlan-tenant.xml                   |   15 +-
 docs/en-US/limit-accounts-domains.xml           |    2 +-
 docs/en-US/linux-installation.xml               |   73 +-
 docs/en-US/load-balancer-rules.xml              |    1 +
 docs/en-US/manual-live-migration.xml            |   13 +-
 ...migrate-datadisk-volume-new-storage-pool.xml |   61 +-
 ...te-vm-rootvolume-volume-new-storage-pool.xml |   34 +-
 docs/en-US/multiple-ip-nic.xml                  |    6 +-
 docs/en-US/networks.xml                         |    9 +-
 docs/en-US/non-contiguous-vlan.xml              |   81 +-
 ...ver-provisioning-service-offering-limits.xml |  138 +-
 docs/en-US/password-storage-engine.xml          |   30 +-
 docs/en-US/portable-ip.xml                      |   35 +-
 docs/en-US/primary-storage-add.xml              |   99 +-
 docs/en-US/pvlan.xml                            |   28 +-
 docs/en-US/region-add.xml                       |   69 +-
 docs/en-US/reserved-ip-addresses-non-csvms.xml  |    7 +-
 docs/en-US/reset-volume-on-reboot.xml           |   32 +
 .../runtime-behavior-of-primary-storage.xml     |    5 +-
 docs/en-US/secondary-storage-add.xml            |   45 +-
 docs/en-US/shared-networks.xml                  |   10 +-
 docs/en-US/site-to-site-vpn.xml                 |   11 +-
 docs/en-US/snapshot-performance-vmware.xml      |   39 +
 docs/en-US/stopping-and-starting-vms.xml        |    2 +-
 docs/en-US/storage-plugins.xml                  |  144 ++
 docs/en-US/third-party-ui-plugin.xml            |  364 +++
 docs/en-US/update-iso-vm.xml                    |   47 +
 docs/en-US/user-data-and-meta-data.xml          |    2 +-
 docs/en-US/user-services-overview.xml           |    6 +-
 docs/en-US/using-vpn-with-mac.xml               |    2 +-
 docs/en-US/using-vpn-with-windows.xml           |    2 +-
 docs/en-US/virtual-machines.xml                 |    6 +
 docs/en-US/vlan-assign-isolated-nw.xml          |    8 +-
 docs/en-US/vm-storage-migration.xml             |   26 +-
 docs/en-US/vmware-cluster-config-dvswitch.xml   |  168 +-
 docs/en-US/vmware-install.xml                   |    2 +-
 docs/en-US/vnmc-cisco.xml                       |  207 +-
 docs/en-US/vpn.xml                              |   57 +-
 docs/en-US/whats-new.xml                        |    2 +-
 docs/en-US/working-with-hosts.xml               |    2 +-
 docs/en-US/working-with-iso.xml                 |    1 +
 docs/en-US/working-with-snapshots.xml           |    3 +-
 docs/en-US/working-with-system-vm.xml           |    1 +
 docs/en-US/working-with-volumes.xml             |    1 +
 docs/en-US/zone-add.xml                         |   33 +-
 docs/qig/en-US/Book_Info.xml                    |    2 +-
 engine/api/pom.xml                              |    2 +-
 .../subsystem/api/storage/TemplateService.java  |    2 +
 .../cloudstack/storage/command/CopyCommand.java |   27 +-
 .../storage/datastore/db/ImageStoreDao.java     |    2 +
 .../datastore/db/PrimaryDataStoreDao.java       |   16 +-
 .../datastore/db/PrimaryDataStoreDaoImpl.java   |    9 +-
 .../datastore/db/SnapshotDataStoreDao.java      |    1 +
 .../datastore/db/SnapshotDataStoreVO.java       |    2 +-
 .../datastore/db/TemplateDataStoreVO.java       |    2 +-
 .../storage/datastore/db/VolumeDataStoreVO.java |    2 +-
 .../cloudstack/storage/to/SnapshotObjectTO.java |   13 +-
 .../cloudstack/storage/to/TemplateObjectTO.java |    9 +
 .../cloudstack/storage/to/VolumeObjectTO.java   |    4 +-
 engine/components-api/pom.xml                   |    2 +-
 engine/compute/pom.xml                          |    2 +-
 engine/network/pom.xml                          |    2 +-
 engine/orchestration/pom.xml                    |    2 +-
 .../orchestration/CloudOrchestrator.java        |    3 +-
 engine/pom.xml                                  |    2 +-
 engine/schema/pom.xml                           |    2 +-
 .../schema/src/com/cloud/dc/dao/ClusterDao.java |    1 +
 .../src/com/cloud/dc/dao/ClusterDaoImpl.java    |   20 +-
 .../src/com/cloud/dc/dao/DataCenterVnetDao.java |    4 +-
 .../com/cloud/dc/dao/DataCenterVnetDaoImpl.java |   30 +-
 .../schema/src/com/cloud/dc/dao/HostPodDao.java |    7 +-
 .../src/com/cloud/dc/dao/HostPodDaoImpl.java    |   22 +-
 .../src/com/cloud/dc/dao/VlanDaoImpl.java       |    2 +-
 .../schema/src/com/cloud/host/dao/HostDao.java  |   13 +-
 .../src/com/cloud/host/dao/HostDaoImpl.java     |   16 +-
 .../cloud/network/dao/PhysicalNetworkVO.java    |    2 +-
 .../security/dao/SecurityGroupRulesDaoImpl.java |    8 -
 .../src/com/cloud/network/vpc/VpcGatewayVO.java |    6 +-
 .../cloud/network/vpc/dao/VpcGatewayDao.java    |    5 +-
 .../network/vpc/dao/VpcGatewayDaoImpl.java      |    8 -
 .../com/cloud/offerings/NetworkOfferingVO.java  |    7 +-
 engine/schema/src/com/cloud/storage/S3VO.java   |  205 --
 .../schema/src/com/cloud/storage/SwiftVO.java   |  113 -
 .../src/com/cloud/storage/VMTemplateS3VO.java   |  194 --
 .../cloud/storage/VMTemplateStoragePoolVO.java  |    5 +
 .../schema/src/com/cloud/storage/VolumeVO.java  |   12 +
 .../schema/src/com/cloud/storage/dao/S3Dao.java |   29 -
 .../src/com/cloud/storage/dao/S3DaoImpl.java    |   51 -
 .../com/cloud/storage/dao/VMTemplateDao.java    |    2 +-
 .../cloud/storage/dao/VMTemplateDaoImpl.java    |   45 +-
 .../com/cloud/storage/dao/VMTemplateS3Dao.java  |   36 -
 .../cloud/storage/dao/VMTemplateS3DaoImpl.java  |   96 -
 .../src/com/cloud/storage/dao/VolumeDao.java    |   10 +-
 .../com/cloud/storage/dao/VolumeDaoImpl.java    |   94 +-
 .../com/cloud/upgrade/dao/Upgrade2214to30.java  |  135 +-
 .../com/cloud/upgrade/dao/Upgrade302to40.java   |   89 +-
 .../com/cloud/upgrade/dao/Upgrade304to305.java  |   50 +-
 .../com/cloud/upgrade/dao/Upgrade410to420.java  | 1381 +++++++++--
 .../src/com/cloud/usage/dao/UsageDaoImpl.java   |    2 +-
 engine/schema/src/com/cloud/user/AccountVO.java |    6 +-
 engine/schema/src/com/cloud/vm/dao/NicDao.java  |    2 +
 .../schema/src/com/cloud/vm/dao/NicDaoImpl.java |   53 +-
 .../src/com/cloud/vm/dao/VMInstanceDaoImpl.java |   28 +-
 .../affinity/AffinityGroupDomainMapVO.java      |   73 +
 .../cloudstack/affinity/AffinityGroupVO.java    |   15 +-
 .../affinity/dao/AffinityGroupDao.java          |   10 +-
 .../affinity/dao/AffinityGroupDaoImpl.java      |   66 +-
 .../affinity/dao/AffinityGroupDomainMapDao.java |   31 +
 .../dao/AffinityGroupDomainMapDaoImpl.java      |   67 +
 .../org/apache/cloudstack/region/RegionVO.java  |   39 +-
 engine/service/pom.xml                          |    2 +-
 engine/storage/cache/pom.xml                    |    2 +-
 engine/storage/datamotion/pom.xml               |    2 +-
 .../motion/AncientDataMotionStrategy.java       |   55 +-
 engine/storage/image/pom.xml                    |    2 +-
 .../storage/image/TemplateServiceImpl.java      |  365 +--
 .../storage/image/store/TemplateObject.java     |   15 +-
 engine/storage/integration-test/pom.xml         |    2 +-
 .../storage/allocator/StorageAllocatorTest.java |   66 +-
 .../storage/test/ChildTestConfiguration.java    |   10 +-
 .../test/DirectAgentManagerSimpleImpl.java      |   15 +-
 .../storage/test/EndpointSelectorTest.java      |  327 +++
 .../test/FakeDriverTestConfiguration.java       |   67 +
 .../test/FakePrimaryDataStoreDriver.java        |  107 +
 .../storage/test/MockStorageMotionStrategy.java |   41 +-
 .../storage/test/SnapshotTestWithFakeData.java  |  359 +++
 .../test/resource/fakeDriverTestContext.xml     |   91 +
 .../test/resource/storageContext.xml            |    3 -
 engine/storage/pom.xml                          |    2 +-
 engine/storage/snapshot/pom.xml                 |    2 +-
 .../storage/snapshot/SnapshotObject.java        |   20 +-
 .../storage/snapshot/SnapshotServiceImpl.java   |    6 -
 .../snapshot/XenserverSnapshotStrategy.java     |  191 +-
 .../allocator/AbstractStoragePoolAllocator.java |    8 -
 .../allocator/ZoneWideStoragePoolAllocator.java |   34 +
 .../datastore/ObjectInDataStoreManager.java     |    2 +
 .../datastore/ObjectInDataStoreManagerImpl.java |   54 +
 .../endpoint/DefaultEndPointSelector.java       |   36 +-
 .../storage/image/BaseImageStoreDriverImpl.java |    3 +-
 .../storage/image/db/ImageStoreDaoImpl.java     |   16 +-
 .../image/db/SnapshotDataStoreDaoImpl.java      |   18 +-
 .../cloudstack/storage/image/format/RAW.java    |   32 +
 engine/storage/volume/pom.xml                   |    2 +-
 .../storage/datastore/PrimaryDataStoreImpl.java |   55 +-
 .../storage/volume/VolumeDataFactoryImpl.java   |    3 +
 .../cloudstack/storage/volume/VolumeObject.java |   44 +-
 .../storage/volume/VolumeServiceImpl.java       |  288 ++-
 framework/events/pom.xml                        |    2 +-
 framework/ipc/pom.xml                           |    2 +-
 framework/jobs/pom.xml                          |    2 +-
 framework/pom.xml                               |    2 +-
 framework/rest/pom.xml                          |    2 +-
 packaging/centos63/cloud.spec                   |   41 +-
 packaging/centos63/package.sh                   |    7 +-
 patches/pom.xml                                 |    2 +-
 .../debian/config/etc/dnsmasq.conf.tmpl         |    2 +
 .../debian/config/etc/init.d/cloud-early-config |   34 +-
 .../debian/config/opt/cloud/bin/ipassoc.sh      |   18 +-
 .../config/opt/cloud/bin/passwd_server_ip       |    2 +-
 .../config/opt/cloud/bin/serve_password.sh      |    2 +-
 .../debian/config/root/createIpAlias.sh         |   54 +
 .../debian/config/root/deleteIpAlias.sh         |   17 +-
 patches/systemvm/debian/config/root/dnsmasq.sh  |   17 +-
 .../root/redundant_router/enable_pubip.sh.templ |    8 +-
 plugins/acl/static-role-based/pom.xml           |    2 +-
 .../explicit-dedication/pom.xml                 |    2 +-
 .../affinity/ExplicitDedicationProcessor.java   |  325 ++-
 .../host-anti-affinity/pom.xml                  |    2 +-
 plugins/alert-handlers/snmp-alerts/pom.xml      |    2 +-
 plugins/alert-handlers/syslog-alerts/pom.xml    |    2 +-
 plugins/api/discovery/pom.xml                   |    2 +-
 plugins/api/rate-limit/pom.xml                  |    2 +-
 plugins/dedicated-resources/pom.xml             |    2 +-
 .../api/commands/ListDedicatedClustersCmd.java  |    9 +
 .../api/commands/ListDedicatedHostsCmd.java     |    9 +
 .../api/commands/ListDedicatedPodsCmd.java      |    9 +
 .../api/commands/ListDedicatedZonesCmd.java     |    9 +
 .../api/response/DedicateClusterResponse.java   |   14 +
 .../api/response/DedicateHostResponse.java      |   12 +
 .../api/response/DedicatePodResponse.java       |   12 +
 .../api/response/DedicateZoneResponse.java      |   11 +
 .../dedicated/DedicatedResourceManagerImpl.java |  143 +-
 .../dedicated/manager/DedicatedApiUnitTest.java |   20 +-
 .../implicit-dedication/pom.xml                 |    2 +-
 .../user-concentrated-pod/pom.xml               |    2 +-
 .../deployment-planners/user-dispersing/pom.xml |    2 +-
 plugins/event-bus/rabbitmq/pom.xml              |    2 +-
 plugins/file-systems/netapp/pom.xml             |    2 +-
 plugins/host-allocators/random/pom.xml          |    2 +-
 plugins/hypervisors/baremetal/pom.xml           |    2 +-
 .../BareMetalPingServiceImpl.java               |   29 +-
 .../networkservice/BaremetalDhcpElement.java    |    3 +-
 .../BaremetalDhcpManagerImpl.java               |   43 +-
 .../BaremetalDhcpResourceBase.java              |   13 -
 .../networkservice/BaremetalDhcpResponse.java   |   11 +
 .../BaremetalDnsmasqResource.java               |    4 +-
 .../BaremetalKickStartServiceImpl.java          |   38 +-
 .../networkservice/BaremetalPxeManager.java     |    5 +-
 .../networkservice/BaremetalPxeManagerImpl.java |    8 +-
 .../networkservice/BaremetalPxeResponse.java    |   18 +-
 .../networkservice/BaremetalPxeService.java     |    5 +-
 .../cloudstack/api/AddBaremetalDhcpCmd.java     |   14 +-
 .../cloudstack/api/AddBaremetalPxeCmd.java      |    6 +-
 .../cloudstack/api/ListBaremetalDhcpCmd.java    |   14 +-
 .../api/ListBaremetalPxePingServersCmd.java     |   97 -
 .../api/ListBaremetalPxeServersCmd.java         |   79 +
 plugins/hypervisors/kvm/pom.xml                 |    8 +-
 .../kvm/src/com/cloud/ha/KVMInvestigator.java   |   79 +
 .../kvm/resource/BridgeVifDriver.java           |   19 +-
 .../kvm/resource/LibvirtComputingResource.java  |  446 +++-
 .../hypervisor/kvm/resource/LibvirtVMDef.java   |   29 +-
 .../hypervisor/kvm/storage/KVMPhysicalDisk.java |    6 +-
 .../kvm/storage/KVMStoragePoolManager.java      |   91 +-
 .../kvm/storage/KVMStorageProcessor.java        |  451 +++-
 .../kvm/storage/LibvirtStorageAdaptor.java      |  298 ++-
 .../kvm/storage/LibvirtStoragePool.java         |   32 +-
 .../hypervisor/kvm/storage/StorageAdaptor.java  |    2 -
 .../resource/LibvirtComputingResourceTest.java  |   29 +-
 .../kvm/resource/LibvirtVMDefTest.java          |   20 +
 .../kvm/storage/KVMStorageProcessorTest.java    |   42 +
 plugins/hypervisors/ovm/pom.xml                 |    2 +-
 plugins/hypervisors/simulator/pom.xml           |    2 +-
 .../agent/manager/SimulatorManagerImpl.java     |   15 +-
 .../cloud/api/commands/ConfigureSimulator.java  |   84 -
 .../api/commands/ConfigureSimulatorCmd.java     |   84 +
 .../resource/SimulatorStorageProcessor.java     |   13 +-
 .../server/ManagementServerSimulatorImpl.java   |   31 -
 plugins/hypervisors/ucs/pom.xml                 |    4 +-
 .../src/com/cloud/ucs/manager/UcsManager.java   |    2 +
 .../com/cloud/ucs/manager/UcsManagerImpl.java   |   95 +-
 .../cloudstack/api/DeleteUcsManagerCmd.java     |   74 +
 .../cloudstack/api/ListUcsManagerCmd.java       |   16 +-
 plugins/hypervisors/vmware/pom.xml              |    4 +-
 .../com/cloud/hypervisor/guru/VMwareGuru.java   |   23 +-
 .../vmware/VmwareServerDiscoverer.java          |   66 +-
 .../vmware/manager/VmwareManagerImpl.java       |   27 +-
 .../vmware/manager/VmwareStorageManager.java    |    1 +
 .../manager/VmwareStorageManagerImpl.java       | 1107 ++++-----
 .../vmware/resource/VmwareContextFactory.java   |   25 +-
 .../vmware/resource/VmwareResource.java         | 1799 ++++++++------
 .../com/cloud/network/VmwareTrafficLabel.java   |   16 +-
 .../network/element/CiscoNexusVSMElement.java   |   36 +-
 .../element/CiscoNexusVSMElementService.java    |    7 +-
 .../VmwareSecondaryStorageContextFactory.java   |   58 +-
 .../VmwareSecondaryStorageResourceHandler.java  |  116 +-
 .../resource/VmwareStorageLayoutHelper.java     |  299 +++
 .../resource/VmwareStorageLayoutType.java       |   22 +
 .../resource/VmwareStorageProcessor.java        |  630 ++---
 .../VmwareStorageSubsystemCommandHandler.java   |  150 ++
 plugins/hypervisors/xen/pom.xml                 |    2 +-
 .../hypervisor/xen/resource/CitrixHelper.java   |  212 +-
 .../xen/resource/CitrixResourceBase.java        |  341 ++-
 .../hypervisor/xen/resource/XcpOssResource.java |  105 +-
 .../xen/resource/XenServer56FP1Resource.java    |    5 +-
 .../xen/resource/XenServerStorageProcessor.java |  398 ++-
 .../xen/resource/CitrixResourceBaseTest.java    |    4 +-
 plugins/network-elements/bigswitch-vns/pom.xml  |    2 +-
 plugins/network-elements/cisco-vnmc/pom.xml     |    2 +-
 plugins/network-elements/dns-notifier/pom.xml   |    2 +-
 .../elastic-loadbalancer/pom.xml                |    2 +-
 plugins/network-elements/f5/pom.xml             |    2 +-
 .../internal-loadbalancer/pom.xml               |    2 +-
 plugins/network-elements/juniper-srx/pom.xml    |    2 +-
 plugins/network-elements/midonet/pom.xml        |    8 +-
 .../cloud/network/element/MidoNetElement.java   |  153 +-
 .../network/element/SimpleFirewallRule.java     |   20 +-
 .../network/guru/MidoNetGuestNetworkGuru.java   |   11 -
 .../network/resource/MidoNetVifDriver.java      |   18 +-
 .../network/element/MidoNetElementTest.java     |    4 +-
 plugins/network-elements/netscaler/pom.xml      |    2 +-
 .../network/resource/NetscalerResource.java     |  142 +-
 plugins/network-elements/nicira-nvp/pom.xml     |    2 +-
 plugins/network-elements/ovs/pom.xml            |    2 +-
 .../network-elements/stratosphere-ssp/pom.xml   |    2 +-
 plugins/pom.xml                                 |    2 +-
 plugins/storage-allocators/random/pom.xml       |    2 +-
 plugins/storage/image/default/pom.xml           |    2 +-
 plugins/storage/image/s3/pom.xml                |    2 +-
 .../driver/S3ImageStoreDriverImpl.java          |    7 +-
 plugins/storage/image/sample/pom.xml            |    2 +-
 plugins/storage/image/swift/pom.xml             |    2 +-
 plugins/storage/volume/default/pom.xml          |    2 +-
 .../CloudStackPrimaryDataStoreDriverImpl.java   |   41 +-
 ...CloudStackPrimaryDataStoreLifeCycleImpl.java |   42 +-
 plugins/storage/volume/sample/pom.xml           |    2 +-
 plugins/storage/volume/solidfire/pom.xml        |    2 +-
 .../driver/SolidfirePrimaryDataStoreDriver.java |   17 +-
 .../SolidFirePrimaryDataStoreLifeCycle.java     |   11 +
 .../storage/datastore/util/SolidFireUtil.java   |    2 +
 plugins/user-authenticators/ldap/pom.xml        |    2 +-
 plugins/user-authenticators/md5/pom.xml         |    2 +-
 plugins/user-authenticators/plain-text/pom.xml  |    2 +-
 .../user-authenticators/sha256salted/pom.xml    |    2 +-
 .../auth/SHA256SaltedUserAuthenticator.java     |   39 +-
 .../server/auth/test/AuthenticatorTest.java     |   78 +-
 pom.xml                                         |    6 +-
 python/lib/cloudutils/networkConfig.py          |    5 +
 .../storage/secondary/cloud-install-sys-tmplt   |    2 +-
 scripts/vm/hypervisor/xenserver/s3xen           |   29 +-
 scripts/vm/hypervisor/xenserver/vmops           |   31 +-
 scripts/vm/hypervisor/xenserver/xcposs/vmops    |   31 +-
 .../hypervisor/xenserver/xcposs/vmopsSnapshot   |   65 +-
 server/pom.xml                                  |    2 +-
 .../cloud/acl/AffinityGroupAccessChecker.java   |   82 +
 server/src/com/cloud/acl/DomainChecker.java     |   19 +
 .../cloud/agent/manager/AgentManagerImpl.java   |   20 +-
 .../manager/ClusteredAgentManagerImpl.java      |   18 +-
 .../cloud/agent/manager/DirectAgentAttache.java |    4 +
 server/src/com/cloud/api/ApiDBUtils.java        |   24 +-
 server/src/com/cloud/api/ApiResponseHelper.java |   97 +-
 server/src/com/cloud/api/ApiServer.java         |    2 +-
 server/src/com/cloud/api/ApiServlet.java        |   10 +-
 .../com/cloud/api/query/QueryManagerImpl.java   |  179 +-
 .../cloud/api/query/dao/AccountJoinDaoImpl.java |    6 +-
 .../api/query/dao/DataCenterJoinDaoImpl.java    |    1 +
 .../cloud/api/query/dao/ProjectJoinDaoImpl.java |    2 +-
 .../cloud/api/query/dao/VolumeJoinDaoImpl.java  |   19 +-
 .../cloud/api/query/vo/AffinityGroupJoinVO.java |   16 +
 .../cloud/api/query/vo/DataCenterJoinVO.java    |   23 +
 .../com/cloud/api/query/vo/UserVmJoinVO.java    |    2 +-
 .../com/cloud/capacity/CapacityManagerImpl.java |   52 +-
 server/src/com/cloud/configuration/Config.java  |   31 +-
 .../configuration/ConfigurationManagerImpl.java |  143 +-
 .../consoleproxy/ConsoleProxyManagerImpl.java   |   52 +-
 .../src/com/cloud/dc/DedicatedResourceVO.java   |   21 +-
 .../com/cloud/dc/dao/DedicatedResourceDao.java  |   17 +-
 .../cloud/dc/dao/DedicatedResourceDaoImpl.java  |   84 +-
 .../deploy/DeploymentPlanningManagerImpl.java   |  117 +-
 .../cloud/ha/HighAvailabilityManagerImpl.java   |   10 +-
 .../cloud/hypervisor/HypervisorGuruBase.java    |    1 -
 .../metadata/ResourceMetaDataManagerImpl.java   |    4 +-
 .../src/com/cloud/network/NetworkManager.java   |    4 +-
 .../com/cloud/network/NetworkManagerImpl.java   |  375 ++-
 .../src/com/cloud/network/NetworkModelImpl.java |    7 +
 .../com/cloud/network/NetworkServiceImpl.java   |  392 ++-
 .../network/element/VirtualRouterElement.java   |   17 +-
 .../element/VpcVirtualRouterElement.java        |    2 -
 .../cloud/network/guru/DirectNetworkGuru.java   |    7 +
 .../network/guru/ExternalGuestNetworkGuru.java  |   16 +
 .../VirtualNetworkApplianceManagerImpl.java     |   59 +-
 .../VpcVirtualNetworkApplianceManagerImpl.java  |   34 +-
 .../cloud/network/rules/RulesManagerImpl.java   |   17 +-
 .../security/SecurityGroupManagerImpl.java      |    8 +
 .../network/vpc/PrivateGatewayProfile.java      |    2 +-
 .../com/cloud/network/vpc/VpcManagerImpl.java   |    2 +-
 .../com/cloud/resource/ResourceManagerImpl.java |  172 +-
 .../com/cloud/server/ManagementServerImpl.java  |  322 ++-
 .../com/cloud/servlet/ConsoleProxyServlet.java  |    2 +-
 .../com/cloud/storage/StorageManagerImpl.java   |   95 +-
 server/src/com/cloud/storage/VolumeManager.java |    8 +-
 .../com/cloud/storage/VolumeManagerImpl.java    |  227 +-
 .../storage/download/DownloadListener.java      |    2 +
 .../storage/download/DownloadMonitorImpl.java   |   20 -
 .../secondary/SecondaryStorageManagerImpl.java  |  193 +-
 .../storage/snapshot/SnapshotManagerImpl.java   |   88 +-
 .../template/HypervisorTemplateAdapter.java     |   49 +-
 .../com/cloud/template/TemplateAdapterBase.java |  482 ++--
 .../com/cloud/template/TemplateManagerImpl.java |  146 +-
 .../src/com/cloud/user/AccountManagerImpl.java  |    5 +-
 server/src/com/cloud/vm/UserVmManagerImpl.java  |  167 +-
 .../com/cloud/vm/VirtualMachineManagerImpl.java |  260 +-
 .../affinity/AffinityGroupServiceImpl.java      |  188 +-
 .../GlobalLoadBalancingRulesServiceImpl.java    |    9 +-
 .../cloud/network/MockNetworkManagerImpl.java   |    9 +-
 .../network/UpdatePhysicalNetworkTest.java      |    2 +-
 .../vm/DeploymentPlanningManagerImplTest.java   |    6 +
 server/test/com/cloud/vm/UserVmManagerTest.java |    7 +-
 .../com/cloud/vpc/MockNetworkManagerImpl.java   |    9 +-
 .../affinity/AffinityApiUnitTest.java           |   22 +-
 .../networkoffering/ChildTestConfiguration.java |   15 +-
 services/console-proxy/plugin/pom.xml           |    2 +-
 services/console-proxy/pom.xml                  |    2 +-
 services/console-proxy/server/js/ajaxkeys.js    |    4 +-
 services/console-proxy/server/js/ajaxviewer.js  |    8 +-
 services/console-proxy/server/pom.xml           |    2 +-
 services/pom.xml                                |    2 +-
 services/secondary-storage/pom.xml              |    2 +-
 .../resource/NfsSecondaryStorageResource.java   |  140 +-
 setup/bindir/cloud-set-guest-sshkey.in          |   49 +-
 setup/db/db/schema-307to410.sql                 |   15 +-
 setup/db/db/schema-40to410.sql                  |    3 +-
 setup/db/db/schema-410to420.sql                 |  230 +-
 setup/db/db/vmwaretmplinsert-304to305.sql       |   22 -
 setup/db/templates.sql                          |   44 +-
 .../component/maint/test_redundant_router.py    | 1589 ++++++++++++
 ...test_redundant_router_deployment_planning.py | 1012 ++++++++
 .../test_redundant_router_network_rules.py      | 1427 +++++++++++
 test/integration/component/test_accounts.py     |  186 +-
 .../component/test_affinity_groups.py           |  563 +++--
 test/integration/component/test_asa1000v_fw.py  |    2 +
 test/integration/component/test_blocker_bugs.py |    7 +-
 .../component/test_custom_hostname.py           |  483 ++++
 .../component/test_egress_fw_rules.py           |  952 ++++++++
 .../component/test_explicit_dedication.py       |    4 +
 .../component/test_implicit_planner.py          |   44 +-
 .../component/test_netscaler_configs.py         |   41 +-
 test/integration/component/test_netscaler_lb.py |  340 ++-
 .../component/test_netscaler_lb_algo.py         |  345 ++-
 .../component/test_netscaler_lb_sticky.py       |   49 +-
 .../component/test_netscaler_nw_off.py          |   11 -
 .../component/test_network_offering.py          |  143 ++
 .../component/test_project_resources.py         |    2 +-
 .../integration/component/test_project_usage.py |    5 +-
 .../component/test_redundant_router.py          | 1589 ------------
 ...test_redundant_router_deployment_planning.py | 1015 --------
 .../test_redundant_router_network_rules.py      | 1426 -----------
 test/integration/component/test_routers.py      |  143 +-
 .../component/test_shared_networks.py           |  252 +-
 test/integration/component/test_snapshot_gc.py  |  271 +--
 .../component/test_snapshot_limits.py           |  179 +-
 test/integration/component/test_snapshots.py    |  346 +--
 test/integration/component/test_stopped_vm.py   |  215 +-
 .../component/test_storage_motion.py            |   15 +-
 test/integration/component/test_tags.py         |   13 +-
 test/integration/component/test_usage.py        |   38 +-
 .../component/test_vm_passwdenabled.py          |   58 +-
 test/integration/component/test_volumes.py      |  249 +-
 test/integration/component/test_vpc.py          |    3 +-
 test/integration/component/test_vpc_network.py  |   16 +-
 .../component/test_vpc_network_lbrules.py       |  137 +-
 .../component/test_vpc_network_pfrules.py       |   14 +-
 .../component/test_vpc_network_staticnatrule.py |   46 +-
 test/integration/component/test_vpc_routers.py  |   70 +-
 .../component/test_vpc_vm_life_cycle.py         |  258 +-
 .../component/test_vpc_vms_deployment.py        |  100 +-
 test/integration/component/test_vpn_users.py    |   53 +-
 .../smoke/test_deploy_vm_with_userdata.py       |    3 +-
 test/integration/smoke/test_guest_vlan_range.py |   12 +-
 .../smoke/test_multipleips_per_nic.py           |  181 ++
 test/integration/smoke/test_network.py          |    3 +
 test/integration/smoke/test_nic.py              |   13 +-
 .../smoke/test_non_contigiousvlan.py            |    7 +-
 .../integration/smoke/test_portable_publicip.py |    8 +-
 test/integration/smoke/test_routers.py          |   66 +-
 test/integration/smoke/test_volumes.py          |   10 +-
 test/pom.xml                                    |    2 +-
 tools/apidoc/gen_toc.py                         |    4 +-
 tools/apidoc/generatetoc_header.xsl             |    2 +-
 tools/apidoc/pom.xml                            |    4 +-
 tools/build/setnextversion.sh                   |    4 +-
 tools/cli/pom.xml                               |    2 +-
 tools/devcloud-kvm/devcloud-kvm-advanced.cfg    |    4 +
 tools/devcloud-kvm/pom.xml                      |    2 +-
 tools/devcloud/pom.xml                          |    2 +-
 tools/marvin/marvin/cloudstackTestCase.py       |    3 -
 tools/marvin/marvin/deployAndRun.py             |   32 +-
 tools/marvin/marvin/deployDataCenter.py         |   20 +
 tools/marvin/marvin/integration/lib/base.py     |  153 +-
 tools/marvin/marvin/integration/lib/common.py   |   29 +
 tools/marvin/marvin/integration/lib/utils.py    |  118 +-
 tools/marvin/marvin/marvinPlugin.py             |   21 +-
 tools/marvin/marvin/remoteSSHClient.py          |   23 +-
 tools/marvin/pom.xml                            |    2 +-
 tools/pom.xml                                   |    2 +-
 tools/whisker/LICENSE                           |    7 +
 tools/whisker/descriptor-for-packaging.xml      |   11 +
 tools/whisker/descriptor.xml                    |   13 +-
 ui/css/cloudstack3.css                          |   34 +-
 ui/dictionary.jsp                               |   10 +
 ui/index.jsp                                    |   18 +-
 .../vnmcNetworkProvider/vnmcNetworkProvider.js  |   29 +-
 ui/scripts/accounts.js                          |    8 +
 ui/scripts/affinity.js                          |   11 +
 ui/scripts/cloudStack.js                        |   92 +-
 ui/scripts/docs.js                              |   53 +-
 ui/scripts/events.js                            |  165 +-
 ui/scripts/globalSettings.js                    |    2 +-
 ui/scripts/instanceWizard.js                    |   24 +-
 ui/scripts/instances.js                         |   27 +-
 ui/scripts/network.js                           |  789 +++---
 ui/scripts/sharedFunctions.js                   |    4 +-
 ui/scripts/storage.js                           |   20 +-
 ui/scripts/system.js                            | 1384 ++++-------
 ui/scripts/templates.js                         |  136 +-
 ui/scripts/ui-custom/autoscaler.js              |    3 +
 ui/scripts/ui-custom/instanceWizard.js          |   13 +-
 ui/scripts/ui-custom/zoneWizard.js              |   98 +-
 ui/scripts/ui/dialog.js                         |    8 +-
 ui/scripts/ui/utils.js                          |    3 +-
 ui/scripts/ui/widgets/detailView.js             |    4 +-
 ui/scripts/ui/widgets/listView.js               |    8 +-
 ui/scripts/ui/widgets/multiEdit.js              |   11 +-
 ui/scripts/vm_snapshots.js                      |    2 +-
 ui/scripts/vpc.js                               |   82 +-
 ui/scripts/zoneWizard.js                        |  319 +--
 usage/pom.xml                                   |    2 +-
 .../cloud/usage/parser/NetworkUsageParser.java  |    7 +-
 .../cloud/usage/parser/VmDiskUsageParser.java   |    6 +-
 utils/pom.xml                                   |    2 +-
 utils/src/com/cloud/utils/ProcessUtil.java      |    2 +-
 utils/src/com/cloud/utils/ReflectUtil.java      |   88 +-
 utils/src/com/cloud/utils/StringUtils.java      |    6 +-
 utils/src/com/cloud/utils/UriUtils.java         |   15 +-
 .../cloud/utils/component/ComponentContext.java |    2 +-
 utils/src/com/cloud/utils/db/Transaction.java   |    4 +-
 utils/test/com/cloud/utils/ReflectUtilTest.java |   91 +
 vmware-base/pom.xml                             |    2 +-
 .../cloud/hypervisor/vmware/mo/ClusterMO.java   |   35 +-
 .../vmware/mo/CustomFieldConstants.java         |    1 +
 .../cloud/hypervisor/vmware/mo/DatastoreMO.java |   58 +-
 .../com/cloud/hypervisor/vmware/mo/HostMO.java  |  136 +-
 .../vmware/mo/HypervisorHostHelper.java         |   98 +-
 .../vmware/mo/VirtualMachineDiskInfo.java       |   42 +
 .../mo/VirtualMachineDiskInfoBuilder.java       |   97 +
 .../hypervisor/vmware/mo/VirtualMachineMO.java  |  139 +-
 .../vmware/mo/VmwareHypervisorHost.java         |    2 +-
 .../hypervisor/vmware/util/VmwareClient.java    |  363 +--
 .../hypervisor/vmware/util/VmwareContext.java   |   92 +-
 .../vmware/util/VmwareContextPool.java          |  202 ++
 .../hypervisor/vmware/util/VmwareHelper.java    |   69 +-
 .../vmware/mo/TestVmwareContextFactory.java     |   68 +
 649 files changed, 30857 insertions(+), 17463 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e546fe0e/tools/marvin/marvin/integration/lib/base.py
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/e546fe0e/tools/marvin/marvin/integration/lib/common.py
----------------------------------------------------------------------


[4/7] git commit: updated refs/heads/4.2 to 20b1a2c

Posted by sa...@apache.org.
Automation: Limit Resources - Adding tests related to CPU limits


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

Branch: refs/heads/4.2
Commit: 95273e1c31b3977d0883163e3906664a9cb94012
Parents: 909b287
Author: Gaurav Aradhye <ga...@clogeny.com>
Authored: Mon Jul 29 04:00:08 2013 -0400
Committer: sailajam <sa...@citrix.com>
Committed: Tue Aug 6 13:33:50 2013 +0530

----------------------------------------------------------------------
 .../component/cpu_limits/test_cpu_limits.py     | 624 ++++++++++++++++++
 .../component/cpu_limits/test_domain_limits.py  | 659 +++++++++++++++++++
 .../component/cpu_limits/test_maximum_limits.py | 381 +++++++++++
 .../component/cpu_limits/test_project_limits.py | 307 +++++++++
 4 files changed, 1971 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/95273e1c/test/integration/component/cpu_limits/test_cpu_limits.py
----------------------------------------------------------------------
diff --git a/test/integration/component/cpu_limits/test_cpu_limits.py b/test/integration/component/cpu_limits/test_cpu_limits.py
new file mode 100644
index 0000000..4c8e8e6
--- /dev/null
+++ b/test/integration/component/cpu_limits/test_cpu_limits.py
@@ -0,0 +1,624 @@
+# 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
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# 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.
+
+""" Tests for cpu resource limits
+"""
+# Import Local Modules
+from nose.plugins.attrib import attr
+from marvin.cloudstackTestCase import cloudstackTestCase, unittest
+from marvin.integration.lib.base import (
+                                        Account,
+                                        ServiceOffering,
+                                        VirtualMachine,
+                                        Domain
+                                        )
+from marvin.integration.lib.common import (get_domain,
+                                        get_zone,
+                                        get_template,
+                                        cleanup_resources,
+                                        get_updated_resource_count,
+                                        find_suitable_host,
+                                        get_resource_type
+                                        )
+
+
+class Services:
+    """Test resource limit services
+    """
+
+    def __init__(self):
+        self.services = {
+                        "account": {
+                                "email": "test@test.com",
+                                "firstname": "Test",
+                                "lastname": "User",
+                                "username": "resource",
+                                # Random characters are appended for unique
+                                # username
+                                "password": "password",
+                         },
+                         "service_offering": {
+                                "name": "Tiny Instance",
+                                "displaytext": "Tiny Instance",
+                                "cpunumber": 4,
+                                "cpuspeed": 100,    # in MHz
+                                "memory": 128,    # In MBs
+                        },
+                        "virtual_machine": {
+                                "displayname": "TestVM",
+                                "username": "root",
+                                "password": "password",
+                                "ssh_port": 22,
+                                "hypervisor": 'KVM',
+                                "privateport": 22,
+                                "publicport": 22,
+                                "protocol": 'TCP',
+                                },
+                         "network": {
+                                "name": "Test Network",
+                                "displaytext": "Test Network",
+                                "netmask": '255.255.255.0'
+                                },
+                         "project": {
+                                "name": "Project",
+                                "displaytext": "Test project",
+                                },
+                         "domain": {
+                                "name": "Domain",
+                                },
+                        "ostype": 'CentOS 5.3 (64-bit)',
+                        "sleep": 60,
+                        "timeout": 10,
+                        "mode": 'advanced',
+                        # Networking mode: Advanced, Basic
+                    }
+
+class TestCPULimits(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(TestCPULimits,
+                               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.services["virtual_machine"]["zoneid"] = cls.zone.id
+ 
+        cls.service_offering = ServiceOffering.create(
+                                            cls.api_client,
+                                            cls.services["service_offering"]
+                                            ) 
+
+        cls._cleanup = [cls.service_offering, ]
+        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.account = Account.create(
+                            self.apiclient,
+                            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
+
+    def tearDown(self):
+        try:
+            # Clean up, terminate the created instance, volumes and snapshots
+            cleanup_resources(self.apiclient, self.cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    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.name)
+        try:
+            vm = VirtualMachine.create(
+                                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")
+            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) 
+
+    @attr(tags=["advanced", "advancedns","simulator"]) 
+    def test_01_multiplecore_reboot_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. Stop VM & verify the update resource limit of Root Admin Account
+        # 3. Start VM & verify the update resource limit of Root Admin Account
+        # 4. Resource count should list properly. 
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+        self.debug(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)
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+        self.debug(resource_count)
+
+        self.debug("Starting instance: %s" % self.vm.name)
+        try:
+            self.vm.start(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to start instance: %s" % e)
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+        self.debug(resource_count) 
+        return
+
+    @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 multiple core CPU & verify the usage 
+        # 2. Migrate VM & verify update resource limit of Root Admin Account
+        # 3. Resource count should list properly. 
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+        self.debug(resource_count) 
+
+        host = find_suitable_host(self.apiclient, self.vm)
+        self.debug("Migrating instance: %s to host: %s" % (self.vm.name, host.name))
+        try:
+            self.vm.migrate(self.apiclient, host.id)
+        except Exception as e:
+            self.fail("Failed to migrate instance: %s" % e)
+    
+        resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+        self.debug(resource_count) 
+        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 limit of Root Admin Account 
+        # 3. Resource count should list properly.
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+        self.debug(resource_count)
+
+        self.debug("Destroying instance: %s" % self.vm.name)
+        try:
+            self.vm.delete(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to delete instance: %s" % e)
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+        self.debug(resource_count)
+        self.assertEqual(resource_count, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=8))#CPU
+        return
+
+    @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 4 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
+        # 5. Destroy one VM among multiple VM's and verify the resource limit
+        # 6. Migrate VM from & verify resource updates
+        # 7. List resources of Root Admin for CPU
+        # 8. Failed to deploy VM and verify the resource usage
+
+        self.debug("Creating service offering with 4 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.debug("Creating an instance with service offering: %s" %
+                                                    self.service_offering.name)
+        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) 
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+        self.debug(resource_count)
+
+        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)
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+        self.debug(resource_count)
+
+        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)
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+        self.debug(resource_count)
+
+        return
+
+class TestDomainCPULimitsConfiguration(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        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.service_offering, ]
+        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)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    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.name)
+        try:
+            vm = VirtualMachine.create(
+                                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")
+            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 setupAccounts(self):
+
+        self.debug("Creating a sub-domain under: %s" % self.domain.name)
+	self.child_domain = Domain.create(
+				self.apiclient,
+                                services=self.services["domain"],
+                                parentdomainid=self.domain.id
+				)
+	self.child_do_admin = Account.create(
+                                self.apiclient,
+                                self.services["account"],
+                                admin=True,
+                                domainid=self.child_domain.id
+                                )
+	# Cleanup the resources created at end of test
+	self.cleanup.append(self.child_do_admin)
+	self.cleanup.append(self.child_domain)	
+
+	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
+			    )
+
+	# Cleanup the resources created at end of test
+	self.cleanup.append(self.admin)
+	self.cleanup.append(self.domain)
+   
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    @attr(configuration='max.account.cpus') 
+    def test_01_reboot_instance(self):
+        """Test Deploy VM with 4 core CPU & verify the usage"""
+	#keep the configuration value - max.account.cpus number = 10
+        # Validate the following
+        # 1. Create compute offering with 4 core CPU & Deploy VM
+        # 2. Update Resource count CPU usage 
+        # 3. Reboot instance, check resource count.
+        # 4. Resource count should list properly.
+
+        self.debug("Setting up account and domain hierarchy")
+        self.setupAccounts()
+        users = {self.domain: self.admin,
+                 self.child_domain: self.child_do_admin
+                 }
+        for domain, admin in users.items():
+            self.account = admin
+            self.domain = domain
+
+	    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.createInstance(service_off=self.service_offering, api_client=api_client)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(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)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count)
+
+            self.debug("Starting instance: %s" % vm.name)
+            try:
+                vm.start(self.apiclient)
+            except Exception as e:
+                self.fail("Failed to start instance: %s" % e)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count) 
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    @attr(configuration='max.account.cpus') 
+    def test_02_migrate_instance(self):
+        """Test Deploy VM with 4 core CPU & verify the usage"""
+	#keep the configuration value - max.account.cpus number = 10
+        # Validate the following
+        # 1. Create compute offering with 4 core CPU & Deploy VM
+        # 2. Update Resource count
+        # 3. Migrate instance to another host
+        # 4. Resource count should list properly.
+
+        self.debug("Setting up account and domain hierarchy")
+        self.setupAccounts()
+        users = {self.domain: self.admin,
+                 self.child_domain: self.child_do_admin
+                 }
+        for domain, admin in users.items():
+            self.account = admin
+            self.domain = domain
+
+	    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.createInstance(service_off=self.service_offering, api_client=api_client)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count) 
+
+            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)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count) 
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    @attr(configuration='max.account.cpus') 
+    def test_03_delete_instance(self):
+        """Test Deploy VM with 4 core CPU & verify the usage"""
+	#keep the configuration value - max.account.cpus number = 10
+        # Validate the following
+        # 1. Create compute offering with 4 core CPU & Deploy VM
+        # 2. Update Resource count for te CPU usage
+        # 3. Delete instance
+        # 4. Resource count should list as 0
+
+        self.debug("Setting up account and domain hierarchy")
+        self.setupAccounts()
+        users = {self.domain: self.admin,
+                 self.child_domain: self.child_do_admin
+                 }
+        for domain, admin in users.items():
+            self.account = admin
+            self.domain = domain
+
+	    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.createInstance(service_off=self.service_offering, api_client=api_client)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count) 
+
+            self.debug("Destroying instance: %s" % vm.name)
+            try:
+                vm.delete(self.apiclient)
+            except Exception as e:
+                self.fail("Failed to delete instance: %s" % e)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count)
+            self.assertEqual(resource_count, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=8))#CPU
+        return
+
+    @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 4 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 4 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.debug("Setting up account and domain hierarchy")
+        self.setupAccounts()
+        users = {self.domain: self.admin,
+                 self.child_domain: self.child_do_admin
+                 }
+        for domain, admin in users.items():
+            self.account = admin
+            self.domain = domain
+
+	    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_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.debug("Deploying instance - CPU capacity is fully utilized")
+            with self.assertRaises(Exception):
+                self.createInstance(service_off=self.service_offering, api_client=api_client)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count)
+
+            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)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count)
+
+            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)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count)
+        return

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/95273e1c/test/integration/component/cpu_limits/test_domain_limits.py
----------------------------------------------------------------------
diff --git a/test/integration/component/cpu_limits/test_domain_limits.py b/test/integration/component/cpu_limits/test_domain_limits.py
new file mode 100644
index 0000000..05deaff
--- /dev/null
+++ b/test/integration/component/cpu_limits/test_domain_limits.py
@@ -0,0 +1,659 @@
+# 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
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# 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.
+
+""" Tests for cpu resource limits related to domains
+"""
+# Import Local Modules
+from nose.plugins.attrib import attr
+from marvin.cloudstackTestCase import cloudstackTestCase, unittest
+from marvin.integration.lib.base import (
+                                        Account,
+                                        ServiceOffering,
+                                        VirtualMachine,
+                                        Resources,
+                                        Domain
+                                        )
+from marvin.integration.lib.common import (get_domain,
+                                        get_zone,
+                                        get_template,
+                                        cleanup_resources,
+                                        get_updated_resource_count,
+                                        find_suitable_host,
+                                        get_resource_type
+                                        )
+
+class Services:
+    """Test resource limit services
+    """
+
+    def __init__(self):
+        self.services = {
+                        "account": {
+                                "email": "test@test.com",
+                                "firstname": "Test",
+                                "lastname": "User",
+                                "username": "resource",
+                                # Random characters are appended for unique
+                                # username
+                                "password": "password",
+                         },
+                         "service_offering": {
+                                "name": "Tiny Instance",
+                                "displaytext": "Tiny Instance",
+                                "cpunumber": 4,
+                                "cpuspeed": 100,    # in MHz
+                                "memory": 128,    # In MBs
+                        },
+                        "virtual_machine": {
+                                "displayname": "TestVM",
+                                "username": "root",
+                                "password": "password",
+                                "ssh_port": 22,
+                                "hypervisor": 'KVM',
+                                "privateport": 22,
+                                "publicport": 22,
+                                "protocol": 'TCP',
+                                },
+                         "network": {
+                                "name": "Test Network",
+                                "displaytext": "Test Network",
+                                "netmask": '255.255.255.0'
+                                },
+                         "project": {
+                                "name": "Project",
+                                "displaytext": "Test project",
+                                },
+                         "domain": {
+                                "name": "Domain",
+                                },
+                        "ostype": 'CentOS 5.3 (64-bit)',
+                        "sleep": 60,
+                        "timeout": 10,
+                        "mode": 'advanced',
+                        # Networking mode: Advanced, Basic
+                    }
+
+class TestDomainCPULimitsUpdateResources(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(TestDomainCPULimitsUpdateResources,
+                               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.services["virtual_machine"]["zoneid"] = cls.zone.id
+
+        cls.service_offering = ServiceOffering.create(
+                                            cls.api_client,
+                                            cls.services["service_offering"]
+                                            )
+
+        cls._cleanup = [cls.service_offering, ]
+        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)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    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.name)
+        try:
+            vm = VirtualMachine.create(
+                                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")
+            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 setupAccounts(self):
+
+        self.debug("Creating a sub-domain under: %s" % self.domain.name)
+	self.child_domain = Domain.create(
+				self.apiclient,
+                                services=self.services["domain"],
+                                parentdomainid=self.domain.id
+				)
+	self.child_do_admin = Account.create(
+                                self.apiclient,
+                                self.services["account"],
+                                admin=True,
+                                domainid=self.child_domain.id
+                                )
+	# Cleanup the resources created at end of test
+	self.cleanup.append(self.child_do_admin)
+	self.cleanup.append(self.child_domain)
+
+	Resources.updateLimit(
+		self.apiclient,
+                resourcetype=8,
+                max=16,
+                account=self.child_do_admin.name,
+                domainid=self.child_do_admin.domainid
+		)
+
+	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
+			    )
+
+	# Cleanup the resources created at end of test
+	self.cleanup.append(self.admin)
+	self.cleanup.append(self.domain)
+
+	Resources.updateLimit(
+		      self.apiclient,
+                      resourcetype=8,
+                      max=16,
+                      account=self.admin.name,
+                      domainid=self.admin.domainid
+		      )	
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"]) 
+    def test_01_multiple_core_vm_reboot_instance(self):
+        """Test Deploy VM with 4 core CPU & verify the usage"""
+
+        # Validate the following
+        # 1. Create two domains and set specific resource (cpu) limit for them
+        # 2. Create compute offering with 4 core CPU & deploy vm 
+        # 3. Update Resource count for the domains
+        # 4. Reboot instance and check resource count
+        # 5. Resource count should list properly.
+
+        self.debug("Setting up account and domain hierarchy")
+        self.setupAccounts()
+        users = {self.domain: self.admin,
+                 self.child_domain: self.child_do_admin
+                 }
+        for domain, admin in users.items():
+            self.account = admin
+            self.domain = domain
+
+	    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.createInstance(service_off=self.service_offering, api_client=api_client)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(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)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count)
+
+            self.debug("Starting instance: %s" % vm.name)
+            try:
+                vm.start(self.apiclient)
+            except Exception as e:
+                self.fail("Failed to start instance: %s" % e)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count) 
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"]) 
+    def test_02_multiple_core_vm_migrate_instance(self):
+        """Test Deploy VM with 4 core CPU & verify the usage"""
+
+        # Validate the following
+        # 1. Create two domains and set specific resource (cpu) limit for them
+        # 2. Create compute offering with 4 core CPU & deploy vm 
+        # 3. Update Resource count for the domains
+        # 4. Migrate instance to new host and check resource count
+        # 5. Resource count should list properly. 
+
+        self.debug("Setting up account and domain hierarchy")
+        self.setupAccounts()
+        users = {self.domain: self.admin,
+                 self.child_domain: self.child_do_admin
+                 }
+        for domain, admin in users.items():
+            self.account = admin
+            self.domain = domain
+
+	    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.createInstance(service_off=self.service_offering, api_client=api_client)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count) 
+
+            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)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count) 
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"]) 
+    def test_03_multiple_core_vm_delete_instance(self):
+        """Test Deploy VM with 4 core CPU & verify the usage"""
+
+        # Validate the following
+        # 1. Create two domains and set specific resource (cpu) limit for them
+        # 2. Create compute offering with 4 core CPU & deploy vm 
+        # 3. Update Resource count for the domains
+        # 4. delete instance and check resource count
+        # 5. Resource count should list properly. 
+
+        self.debug("Setting up account and domain hierarchy")
+        self.setupAccounts()
+        users = {self.domain: self.admin,
+                 self.child_domain: self.child_do_admin
+                 }
+        for domain, admin in users.items():
+            self.account = admin
+            self.domain = domain
+
+	    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.createInstance(service_off=self.service_offering, api_client=api_client)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count) 
+
+            self.debug("Destroying instance: %s" % vm.name)
+            try:
+                vm.delete(self.apiclient)
+            except Exception as e:
+                self.fail("Failed to delete instance: %s" % e)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count)
+            self.assertEqual(resource_count, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=8))#CPU
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"]) 
+    def test_04_deploy_multiple_vm_with_multiple_core(self):
+        """Test Deploy multiple VM with 4 core CPU & verify the usage"""
+
+        # Validate the following
+        # 1. Create compute offering with 4 core CPU
+        # 2. Deploy multiple VMs within domain with this service offering
+        # 3. Update Resource count for the domain
+        # 4. CPU usage should list properly
+
+        self.debug("Creating service offering with 4 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.debug("Setting up account and domain hierarchy")
+        self.setupAccounts()
+        users = {self.domain: self.admin,
+                 self.child_domain: self.child_do_admin
+                 }
+        for domain, admin in users.items():
+            self.account = admin
+            self.domain = domain
+
+	    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_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.debug("Deploying instance - CPU capacity is fully utilized")
+            with self.assertRaises(Exception):
+                self.createInstance(service_off=self.service_offering, api_client=api_client)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count)
+
+            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)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count)
+
+            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)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=8)#CPU
+            self.debug(resource_count)
+        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.services["mode"] = cls.zone.networktype
+        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)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def createInstance(self, account, 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" %
+                                                account.name)
+        try:
+            vm = VirtualMachine.create(
+                                api_client,
+                                self.services["virtual_machine"],
+                                templateid=self.template.id,
+                                accountid=account.name,
+                                domainid=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")
+            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 setupAccounts(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
+                    )
+
+	self.debug("Updating the Memory resource limit for domain: %s" %
+                                                    self.domain.name)
+	Resources.updateLimit(self.apiclient,
+                      resourcetype=8,
+                      max=10, 
+                      domainid=self.parentd_admin.domainid,
+                      account=self.parentd_admin.name)
+	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
+                                )
+
+	self.debug("Updating the Memory resource count for domain: %s" %
+                                                self.cdomain_1.name)
+	Resources.updateLimit(self.apiclient,
+                      resourcetype=8,
+                      max=4, 
+                      domainid=self.cadmin_1.domainid)
+
+        self.debug("Updating the Memory resource count for account: %s" %
+                                                self.cadmin_1.name)
+	Resources.updateLimit(self.apiclient,
+                      resourcetype=8,
+                      max=2,
+                      account=self.cadmin_1.name,
+                      domainid=self.cadmin_1.domainid)
+
+	self.cadmin_2 = Account.create(
+                                self.apiclient,
+                                self.services["account"],
+                                admin=True,
+                                domainid=self.cdomain_2.id
+                                ) 
+
+        self.debug("Updating the Memory resource count for domain: %s" %
+                                                self.cdomain_2.name)
+	Resources.updateLimit(self.apiclient,
+                      resourcetype=8,
+                      max=4, 
+                      domainid=self.cadmin_2.domainid)
+
+        self.debug("Updating the Memory resource count for account: %s" %
+                                                self.cadmin_2.name)
+	Resources.updateLimit(self.apiclient,
+                      resourcetype=8,
+                      max=2,
+                      account=self.cadmin_2.name,
+                      domainid=self.cadmin_2.domainid)	
+
+	# 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.cleanup.append(self.parentd_admin)
+	self.cleanup.append(self.parent_domain)
+	
+	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","simulator"]) 
+    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 4 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. Destroy user/admin account VM's and verify the child & Parent
+        #    domain resource updates
+
+        self.debug("Creating service offering with 2 CPU cores")
+        self.services["service_offering"]["cpunumber"] = 2
+        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.setupAccounts()
+
+	api_client_cadmin_1 = self.testClient.createUserApiClient(
+                             UserName=self.cadmin_1.name,
+                             DomainName=self.cadmin_1.domain)
+
+	api_client_cadmin_2 = self.testClient.createUserApiClient(
+                             UserName=self.cadmin_2.name,
+                             DomainName=self.cadmin_2.domain)
+
+        self.debug("Creating an instance with service offering: %s" %
+                                                self.service_offering.name)
+        vm_1 = self.createInstance(account=self.cadmin_1,
+                                  service_off=self.service_offering, api_client=api_client_cadmin_1)
+
+        vm_2 = self.createInstance(account=self.cadmin_2,
+                                  service_off=self.service_offering, api_client=api_client_cadmin_2)
+
+        self.debug("Checking resource count for account: %s" % self.cadmin_1.name)
+        resource_count_cadmin_1 = get_updated_resource_count(self.apiclient, account=self.cadmin_1, rtype=8)#CPU
+        self.debug(resource_count_cadmin_1)
+
+        self.debug("Checking resource count for account: %s" % self.cadmin_2.name)
+        resource_count_cadmin_2 = get_updated_resource_count(self.apiclient, account=self.cadmin_2, rtype=8)#CPU
+        self.debug(resource_count_cadmin_2)
+
+        self.debug(
+            "Creating instance when CPU limit is fully used in parent domain")
+        with self.assertRaises(Exception):
+            self.createInstance(account=self.cadmin_1,
+                                  service_off=self.service_offering, api_client=api_client_cadmin_1)
+
+        self.debug(
+            "Creating instance when CPU limit is fully used in child domain")
+        with self.assertRaises(Exception):
+            self.createInstance(account=self.cadmin_1,
+                                  service_off=self.service_offering, api_client=api_client_cadmin_1)
+        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.debug("Checking resource count for account: %s" % self.cadmin_1.name)
+        resource_count_cadmin_1 = get_updated_resource_count(self.apiclient, account=self.cadmin_1, rtype=8)#CPU
+        self.debug(resource_count_cadmin_1)
+        self.assertEqual(resource_count_cadmin_1, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=8))#CPU
+
+        self.debug("Checking resource count for account: %s" % self.cadmin_2.name)
+        resource_count_cadmin_2 = get_updated_resource_count(self.apiclient, account=self.cadmin_2, rtype=8)#CPU
+        self.debug(resource_count_cadmin_2)
+        self.assertEqual(resource_count_cadmin_2, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=8))#CPU
+        return

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/95273e1c/test/integration/component/cpu_limits/test_maximum_limits.py
----------------------------------------------------------------------
diff --git a/test/integration/component/cpu_limits/test_maximum_limits.py b/test/integration/component/cpu_limits/test_maximum_limits.py
new file mode 100644
index 0000000..914ecec
--- /dev/null
+++ b/test/integration/component/cpu_limits/test_maximum_limits.py
@@ -0,0 +1,381 @@
+# 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
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# 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.
+
+""" Tests for cpu resource limits - Maximum Limits
+"""
+# Import Local Modules
+from nose.plugins.attrib import attr
+from marvin.cloudstackTestCase import cloudstackTestCase, unittest
+from marvin.integration.lib.base import (
+                                        Account,
+                                        ServiceOffering,
+                                        VirtualMachine,
+                                        Resources,
+                                        Domain,
+                                        Project
+                                        )
+from marvin.integration.lib.common import (get_domain,
+                                        get_zone,
+                                        get_template,
+                                        cleanup_resources,
+                                        get_updated_resource_count
+                                        )
+
+class Services:
+    """Test resource limit services
+    """
+
+    def __init__(self):
+        self.services = {
+                        "account": {
+                                "email": "test@test.com",
+                                "firstname": "Test",
+                                "lastname": "User",
+                                "username": "resource",
+                                # Random characters are appended for unique
+                                # username
+                                "password": "password",
+                         },
+                         "service_offering": {
+                                "name": "Tiny Instance",
+                                "displaytext": "Tiny Instance",
+                                "cpunumber": 5,
+                                "cpuspeed": 100,    # in MHz
+                                "memory": 128,    # In MBs
+                        },
+                        "virtual_machine": {
+                                "displayname": "TestVM",
+                                "username": "root",
+                                "password": "password",
+                                "ssh_port": 22,
+                                "hypervisor": 'KVM',
+                                "privateport": 22,
+                                "publicport": 22,
+                                "protocol": 'TCP',
+                                },
+                         "network": {
+                                "name": "Test Network",
+                                "displaytext": "Test Network",
+                                "netmask": '255.255.255.0'
+                                },
+                         "project": {
+                                "name": "Project",
+                                "displaytext": "Test project",
+                                },
+                         "domain": {
+                                "name": "Domain",
+                                },
+                        "ostype": 'CentOS 5.3 (64-bit)',
+                        "sleep": 60,
+                        "timeout": 10,
+                        "mode": 'advanced',
+                        # Networking mode: Advanced, Basic
+                    }
+
+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.services["mode"] = cls.zone.networktype
+        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)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def createInstance(self, service_off, account=None,
+                        project=None, networks=None, api_client=None):
+        """Creates an instance in account"""
+
+	if api_client is None:
+    	    api_client = self.apiclient
+
+        self.debug("Deploying instance")
+        try:
+            if account:
+                vm = VirtualMachine.create(
+                                api_client,
+                                self.services["virtual_machine"],
+                                templateid=self.template.id,
+                                accountid=account.name,
+                                domainid=account.domainid,
+                                networkids=networks,
+                                serviceofferingid=service_off.id)
+            elif project:
+                vm = VirtualMachine.create(
+                                api_client,
+                                self.services["virtual_machine"],
+                                templateid=self.template.id,
+                                projectid=project.id,
+                                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")
+            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 setupAccounts(self, account_limit=2, domain_limit=2, project_limit=2):
+
+       	self.debug("Creating a domain under: %s" % self.domain.name)
+	self.child_domain = Domain.create(self.apiclient,
+	                                  services=self.services["domain"],
+               		                  parentdomainid=self.domain.id)
+
+
+	self.debug("domain crated with domain id %s" % self.child_domain.id)
+
+	self.child_do_admin = Account.create(self.apiclient,
+			                     self.services["account"],
+			                     admin=True,
+		        	             domainid=self.child_domain.id)
+
+	self.debug("domain admin created for domain id %s" %
+                self.child_do_admin.domainid)
+
+	# Create project as a domain admin
+	self.project = Project.create(self.apiclient,
+		                      self.services["project"],
+                 		      account=self.child_do_admin.name,
+		                      domainid=self.child_do_admin.domainid)
+	# Cleanup created project at end of test
+	self.cleanup.append(self.project)
+
+	# Cleanup accounts created
+	self.cleanup.append(self.child_do_admin)
+	self.cleanup.append(self.child_domain)
+
+	self.debug("Updating the CPU resource count for domain: %s" %
+                                                self.child_domain.name)
+	# Update resource limits for account 1
+	responses = Resources.updateLimit(self.apiclient,
+			                  resourcetype=8,
+                			  max=account_limit,
+		                	  account=self.child_do_admin.name,
+	                		  domainid=self.child_do_admin.domainid)
+
+	self.debug("CPU Resource count for child domain admin account is now: %s" %
+                                                                 responses.max)
+
+	self.debug("Updating the CPU limit for project")
+	responses = Resources.updateLimit(self.apiclient,
+			                  resourcetype=8,
+                			  max=project_limit,
+		        	          projectid=self.project.id)
+
+	self.debug("CPU Resource count for project is now")
+	self.debug(responses.max)
+
+	self.debug("Updating the CPU limit for domain only")
+	responses = Resources.updateLimit(self.apiclient,
+        		                  resourcetype=8,
+			                  max=domain_limit,
+			                  domainid=self.child_domain.id)
+
+	self.debug("CPU Resource count for domain %s with id %s is now %s" %
+                    (responses.domain, responses.domainid, responses.max))
+
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    def test_01_deploy_vm_domain_limit_reached(self):
+        """Test Try to deploy VM with admin account where account has not used
+            the resources but @ domain they are not available"""
+
+        # Validate the following
+        # 1. Try to deploy VM with admin account where account has not used the
+        #    resources but @ domain they are not available
+        # 2. Deploy VM should error out saying  ResourceAllocationException
+        #    with "resource limit exceeds"
+
+        self.debug("Creating service offering with 3 CPU cores")
+	self.services["service_offering"]["cpunumber"] = 3
+        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.setupAccounts(account_limit=4, domain_limit=2)
+
+	api_client_admin = self.testClient.createUserApiClient(
+                           UserName=self.child_do_admin.name,
+                           DomainName=self.child_do_admin.domain)	 
+
+        with self.assertRaises(Exception):
+            self.createInstance(account=self.child_do_admin,
+                                  service_off=self.service_offering, api_client=api_client_admin)
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    def test_02_deploy_vm_account_limit_reached(self):
+        """Test Try to deploy VM with admin account where account has used
+            the resources but @ domain they are available"""
+
+        # Validate the following
+        # 1. Try to deploy VM with admin account where account has used the
+        #    resources but @ domain they are available
+        # 2. Deploy VM should error out saying  ResourceAllocationException
+        #    with "resource limit exceeds"
+
+        self.debug("Creating service offering with 4 CPU cores")
+	self.services["service_offering"]["cpunumber"] = 4
+        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.setupAccounts(account_limit=6, domain_limit=8)
+	
+	api_client_admin = self.testClient.createUserApiClient(
+                             UserName=self.child_do_admin.name,
+                             DomainName=self.child_do_admin.domain)
+
+	self.debug("Deploying instance with account: %s" %
+                                                    self.child_do_admin.name)
+
+        self.createInstance(account=self.child_do_admin,
+                                  service_off=self.service_offering, api_client=api_client_admin)
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.child_do_admin, rtype=8)#CPU
+        self.debug(resource_count)
+
+        self.debug("Deploying instance when CPU limit is reached in account") 
+
+        with self.assertRaises(Exception):
+            self.createInstance(account=self.chid_do_admin,
+                                  service_off=self.service_offering, api_client=api_client_admin)
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    def test_03_deploy_vm_project_limit_reached(self):
+        """Test TTry to deploy VM with admin account where account has not used
+        the resources but @ project they are not available"""
+
+        # Validate the following
+        # 1. Try to deploy VM with admin account where account has not used the
+        #    resources but @ project they are not available
+        # 2. Deploy VM should error out saying  ResourceAllocationException
+        #    with "resource limit exceeds"
+
+        self.debug("Creating service offering with 3 CPU cores")
+	self.services["service_offering"]["cpunumber"] = 3
+        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.setupAccounts(account_limit=4, domain_limit=4, project_limit=2)
+
+	api_client_admin = self.testClient.createUserApiClient(
+                             UserName=self.child_do_admin.name,
+                             DomainName=self.child_do_admin.domain) 
+
+        self.debug("Deploying instance in account 2 when CPU limit is reached")
+
+        with self.assertRaises(Exception):
+            self.createInstance(project=self.project,
+                                  service_off=self.service_offering, api_client=api_client_admin)
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    def test_04_deployVm__account_limit_reached(self):
+        """Test Try to deploy VM with admin account where account has used
+            the resources but @ project they are available"""
+
+        # Validate the following
+        # 1. Try to deploy VM with admin account where account has used the
+        #    resources but @ project they are not available
+        # 2. Deploy VM should error out saying  ResourceAllocationException
+        #    with "resource limit exceeds"
+
+        self.debug("Creating service offering with 4 CPU cores")
+	self.services["service_offering"]["cpunumber"] = 4
+        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.setupAccounts(account_limit=6, domain_limit=6, project_limit=6)
+
+	api_client_admin = self.testClient.createUserApiClient(
+                             UserName=self.child_do_admin.name,
+                             DomainName=self.child_do_admin.domain)
+
+        self.debug("Deploying instance with account: %s" %
+                                                    self.child_do_admin.name)
+        self.createInstance(account=self.child_do_admin,
+                                  service_off=self.service_offering, api_client=api_client_admin)
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.child_do_admin, rtype=8)#CPU
+        self.debug(resource_count)
+
+        self.debug("Deploying instance in project when CPU limit is reached in account")
+
+        with self.assertRaises(Exception):
+            self.createInstance(project=self.project,
+                                  service_off=self.service_offering)
+        return


[7/7] git commit: updated refs/heads/4.2 to 20b1a2c

Posted by sa...@apache.org.
Merge branch '4.2' of https://git-wip-us.apache.org/repos/asf/cloudstack into 4.2


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

Branch: refs/heads/4.2
Commit: 20b1a2c5cdc5dd8adaf6920bea517f7918da5127
Parents: e546fe0 b183efe
Author: sailajam <sa...@citrix.com>
Authored: Mon Sep 16 16:17:42 2013 +0530
Committer: sailajam <sa...@citrix.com>
Committed: Mon Sep 16 16:17:42 2013 +0530

----------------------------------------------------------------------
 docs/en-US/Release_Notes.xml                    | 7470 +++++-------------
 docs/en-US/advanced-zone-configuration.xml      |   17 +-
 docs/en-US/basic-zone-configuration.xml         |  414 +-
 docs/en-US/global-config.xml                    |  172 +-
 docs/en-US/images/edit-traffic-type.png         |  Bin 0 -> 93662 bytes
 docs/en-US/images/traffic-type.png              |  Bin 0 -> 19159 bytes
 docs/en-US/images/workloads.png                 |  Bin 0 -> 69265 bytes
 docs/en-US/manage-cloud.xml                     |    2 +-
 docs/en-US/removed-api-4.2.xml                  |    2 +-
 docs/en-US/vmware-cluster-config-dvswitch.xml   |   78 +-
 .../cloud/upgrade/DatabaseUpgradeChecker.java   |    2 +
 .../com/cloud/upgrade/dao/Upgrade410to420.java  |    2 +-
 packaging/centos63/cloud.spec                   |   16 +
 .../networkservice/BaremetalDhcpElement.java    |   11 +-
 .../BaremetalDhcpManagerImpl.java               |    7 +-
 .../kvm/storage/KVMStorageProcessor.java        |   31 +-
 .../CloudStackPrimaryDataStoreDriverImpl.java   |   57 +-
 python/bindir/cloud-setup-baremetal             |  217 -
 scripts/storage/qcow2/managesnapshot.sh         |    4 +-
 setup/bindir/cloud-setup-baremetal.in           |  232 +
 setup/db/db/schema-410to420.sql                 |  180 +-
 21 files changed, 2758 insertions(+), 6156 deletions(-)
----------------------------------------------------------------------



[5/7] git commit: updated refs/heads/4.2 to 20b1a2c

Posted by sa...@apache.org.
Add cpu limits tests from Resource Limits Test set


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

Branch: refs/heads/4.2
Commit: 681eba5c817cf56719b4a8708a8496a291da4bf5
Parents: 95273e1
Author: Chirag Jog <ch...@clogeny.com>
Authored: Mon Apr 29 07:53:38 2013 +0530
Committer: sailajam <sa...@citrix.com>
Committed: Tue Aug 6 13:42:26 2013 +0530

----------------------------------------------------------------------
 test/integration/component/test_cpu_limits.py | 1780 ++++++++++++++++++++
 1 file changed, 1780 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/681eba5c/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
new file mode 100644
index 0000000..0673b32
--- /dev/null
+++ b/test/integration/component/test_cpu_limits.py
@@ -0,0 +1,1780 @@
+
+""" P1 tests for resource limits
+"""
+# Import Local Modules
+from nose.plugins.attrib import attr
+from marvin.cloudstackTestCase import cloudstackTestCase, unittest
+from marvin.integration.lib.base import (
+                                        Account,
+                                        ServiceOffering,
+                                        VirtualMachine,
+                                        Network,
+                                        Resources,
+                                        Host
+                                        )
+from marvin.integration.lib.common import (get_domain,
+                                        get_zone,
+                                        get_template,
+                                        cleanup_resources,
+                                        )
+
+
+class Services:
+    """Test resource limit services
+    """
+
+    def __init__(self):
+        self.services = {
+                        "account": {
+                                "email": "test@test.com",
+                                "firstname": "Test",
+                                "lastname": "User",
+                                "username": "resource",
+                                # Random characters are appended for unique
+                                # username
+                                "password": "password",
+                         },
+                         "service_offering": {
+                                "name": "Tiny Instance",
+                                "displaytext": "Tiny Instance",
+                                "cpunumber": 2,
+                                "cpuspeed": 100,    # in MHz
+                                "memory": 128,    # In MBs
+                        },
+                        "virtual_machine": {
+                                "displayname": "TestVM",
+                                "username": "root",
+                                "password": "password",
+                                "ssh_port": 22,
+                                "hypervisor": 'KVM',
+                                "privateport": 22,
+                                "publicport": 22,
+                                "protocol": 'TCP',
+                                },
+                         "network": {
+                                "name": "Test Network",
+                                "displaytext": "Test Network",
+                                "netmask": '255.255.255.0'
+                                },
+                         "project": {
+                                "name": "Project",
+                                "displaytext": "Test project",
+                                },
+                         "domain": {
+                                "name": "Domain",
+                                },
+                        "ostype": 'CentOS 5.3 (64-bit)',
+                        "sleep": 60,
+                        "timeout": 10,
+                        "mode": 'advanced',
+                        # Networking mode: Advanced, Basic
+                    }
+
+
+@unittest.skip("Skipping - Work in progress")
+class TestCPULimits(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(TestCPULimits,
+                               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.account = Account.create(
+                            self.apiclient,
+                            self.services["account"],
+                            admin=True
+                            )
+        self.cleanup = [self.account, ]
+        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, 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)
+
+    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 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
+
+    @attr(tags=["advanced", "advancedns"])
+    def test_01_deploy_vm_with_5_cpus(self):
+        """Test Deploy VM with 5 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)
+
+        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)
+
+        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)
+
+        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)
+
+        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)
+        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"""
+
+        # 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
+        # 5. Destroy one VM among multiple VM's and verify the resource limit
+        # 6. Migrate VM from & verify resource updates
+        # 7. List resources of Root Admin for CPU
+        # 8. Failed to deploy VM and verify the resource 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)
+
+        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)
+
+        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)
+        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 TestDomainCPULimits(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(TestDomainCPULimits,
+                               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, 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)
+
+    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 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
+                                        )
+        # Cleanup the resources created at end of test
+        self.cleanup.append(self.childd_admin)
+        self.cleanup.append(self.sub_domain)
+        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"""
+
+        # 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)
+
+        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 = 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)
+
+            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)
+
+            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)
+
+            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)
+        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"""
+
+        # 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)
+
+        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)
+            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 TestCPULimitsUpdateResources(cloudstackTestCase):
+
+    @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)
+
+        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, 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)
+
+    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 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
+                                        )
+
+        # 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)
+        return
+
+    @attr(tags=["advanced", "advancedns"])
+    def test_01_deploy_vm_with_5_cpus(self):
+        """Test Deploy VM with 5 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)
+
+        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 = 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)
+
+            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)
+
+            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)
+
+            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)
+        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"""
+
+        # 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)
+
+        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)
+            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 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, account_limit=2, domain_limit=2, project_limit=2):
+
+        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_1 = 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_1.account.name,
+                                 domainid=self.admin_1.account.domainid)
+        # Cleanup created project at end of test
+        self.cleanup.append(self.project)
+
+        self.admin_2 = Account.create(
+                            self.apiclient,
+                            self.services["account"],
+                            admin=True,
+                            domainid=self.domain.id
+                            )
+
+        # Cleanup accounts created
+        self.cleanup.append(self.admin_1)
+        self.cleanup.append(self.admin_2)
+        self.cleanup.append(self.domain)
+
+        self.debug("Updating the CPU resource count for domain: %s" %
+                                                            self.domain.name)
+        # Update resource limits for account 1
+        Resources.updateLimit(self.apiclient,
+                              resourcetype=9,
+                              max=(account_limit * 128),
+                              account=self.admin_1.account.name,
+                              domainid=self.admin_1.account.domainid)
+
+        # Update resource limits for account 2
+        Resources.updateLimit(self.apiclient,
+                              resourcetype=9,
+                              max=(account_limit * 128),
+                              account=self.admin_2.account.name,
+                              domainid=self.admin_2.account.domainid)
+
+        # Update resource limits for project
+        Resources.updateLimit(self.apiclient,
+                              resourcetype=9,
+                              max=(project_limit * 128),
+                              projectid=self.project.id)
+        # TODO: Update the CPU limit for domain only
+        Resources.updateLimit(self.apiclient,
+                              resourcetype=9,
+                              max=(domain_limit * 128),
+                              domainid=self.domain.id)
+
+        return
+
+    @attr(tags=["advanced", "advancedns"])
+    def test_01_deploy_vm_domain_limit_reached(self):
+        """Test Try to deploy VM with admin account where account has not used
+            the resources but @ domain they are not available"""
+
+        # Validate the following
+        # 1. Try to deploy VM with admin account where account has not used the
+        #    resources but @ domain they are not available
+        # 2. Deploy VM should error out saying  ResourceAllocationException
+        #    with "resource limit exceeds"
+
+        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.debug("Setting up account and domain hierarchy")
+        self.setup_Accounts(account_limit=1, domain_limit=1)
+
+        self.debug("Deploying instance with account 1: %s" %
+                                                    self.admin_1.account.name)
+        self.create_Instance(account=self.admin_1,
+                                  service_off=self.service_offering)
+
+        self.check_Resource_Count(account=self.admin_1, rtype=9)
+
+        self.debug("Deploying instance in account 2 when CPU limit is reached")
+
+        with self.assertRaises(Exception):
+            self.create_Instance(account=self.admin_2,
+                                  service_off=self.service_offering)
+        return
+
+    @attr(tags=["advanced", "advancedns"])
+    def test_02_deploy_vm_account_limit_reached(self):
+        """Test Try to deploy VM with admin account where account has used
+            the resources but @ domain they are available"""
+
+        # Validate the following
+        # 1. Try to deploy VM with admin account where account has not used the
+        #    resources but @ domain they are not available
+        # 2. Deploy VM should error out saying  ResourceAllocationException
+        #    with "resource limit exceeds"
+
+        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.debug("Setting up account and domain hierarchy")
+        self.setup_Accounts(account_limit=1, domain_limit=2)
+
+        self.debug("Deploying instance with account 1: %s" %
+                                                    self.admin_1.account.name)
+        self.create_Instance(account=self.admin_1,
+                                  service_off=self.service_offering)
+
+        self.check_Resource_Count(account=self.admin_1, rtype=9)
+
+        self.debug("Deploying instance in account 2 when CPU limit is reached")
+
+        with self.assertRaises(Exception):
+            self.create_Instance(account=self.admin_1,
+                                  service_off=self.service_offering)
+        return
+
+    @attr(tags=["advanced", "advancedns"])
+    def test_03_deploy_vm_project_limit_reached(self):
+        """Test TTry to deploy VM with admin account where account has not used
+        the resources but @ project they are not available"""
+
+        # Validate the following
+        # 1. Try to deploy VM with admin account where account has not used the
+        #    resources but @ project they are not available
+        # 2. Deploy VM should error out saying  ResourceAllocationException
+        #    with "resource limit exceeds"
+
+        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.debug("Setting up account and domain hierarchy")
+        self.setup_Accounts(account_limit=1, project_limit=1)
+
+        self.debug("Deploying instance with project: %s" % self.project.name)
+        self.create_Instance(project=self.project,
+                             service_off=self.service_offering)
+
+        self.check_Resource_Count(project=self.project, rtype=9)
+
+        self.debug("Deploying instance in account 2 when CPU limit is reached")
+
+        with self.assertRaises(Exception):
+            self.create_Instance(account=self.admin_1,
+                                  service_off=self.service_offering)
+        return
+
+    @attr(tags=["advanced", "advancedns"])
+    def test_04_deployVm__account_limit_reached(self):
+        """Test Try to deploy VM with admin account where account has used
+            the resources but @ project they are available"""
+
+        # Validate the following
+        # 1. Try to deploy VM with admin account where account has used the
+        #    resources but @ project they are not available
+        # 2. Deploy VM should error out saying  ResourceAllocationException
+        #    with "resource limit exceeds"
+
+        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.debug("Setting up account and domain hierarchy")
+        self.setup_Accounts(account_limit=1, project_limit=2)
+
+        self.debug("Deploying instance with account: %s" %
+                                                    self.admin_1.account.name)
+        self.create_Instance(account=self.admin_1,
+                                  service_off=self.service_offering)
+
+        self.check_Resource_Count(account=self.admin_1, rtype=9)
+
+        self.debug("Deploying instance in account 2 when CPU limit is reached")
+
+        with self.assertRaises(Exception):
+            self.create_Instance(project=self.project,
+                                  service_off=self.service_offering)
+        return


[2/7] git commit: updated refs/heads/4.2 to 20b1a2c

Posted by sa...@apache.org.
Automation: Adding Memory limits tests from Resource Limits Tests


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

Branch: refs/heads/4.2
Commit: 909b28793c96d2e635446c1214241891b36bc961
Parents: 7894f55
Author: Gaurav Aradhye <ga...@clogeny.com>
Authored: Fri Jul 26 00:37:19 2013 -0400
Committer: sailajam <sa...@citrix.com>
Committed: Tue Aug 6 09:42:41 2013 +0530

----------------------------------------------------------------------
 .../memory_limits/test_domain_limits.py         | 689 +++++++++++++++++++
 .../memory_limits/test_maximum_limits.py        | 359 ++++++++++
 .../memory_limits/test_memory_limits.py         | 626 +++++++++++++++++
 .../memory_limits/test_project_limits.py        | 321 +++++++++
 tools/marvin/marvin/integration/lib/base.py     |  30 +
 tools/marvin/marvin/integration/lib/common.py   |  72 ++
 6 files changed, 2097 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/909b2879/test/integration/component/memory_limits/test_domain_limits.py
----------------------------------------------------------------------
diff --git a/test/integration/component/memory_limits/test_domain_limits.py b/test/integration/component/memory_limits/test_domain_limits.py
new file mode 100644
index 0000000..ee997f3
--- /dev/null
+++ b/test/integration/component/memory_limits/test_domain_limits.py
@@ -0,0 +1,689 @@
+# 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
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# 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 memory resource limits
+"""
+# Import Local Modules
+from nose.plugins.attrib import attr
+from marvin.cloudstackTestCase import cloudstackTestCase, unittest
+from marvin.integration.lib.base import (
+                                        Account,
+                                        ServiceOffering,
+                                        VirtualMachine,
+                                        Resources,
+                                        Domain
+                                        )
+from marvin.integration.lib.common import (get_domain,
+                                        get_zone,
+                                        get_template,
+                                        cleanup_resources,
+					wait_for_cleanup,
+                                        get_updated_resource_count,
+                                        find_suitable_host,
+                                        get_resource_type
+                                        )
+
+class Services:
+    """Test memory resource limit services
+    """
+
+    def __init__(self):
+        self.services = {
+                        "account": {
+                                "email": "test@test.com",
+                                "firstname": "Test",
+                                "lastname": "User",
+                                "username": "resource",
+                                # Random characters are appended for unique
+                                # username
+                                "password": "password",
+                         },
+                         "service_offering": {
+                                "name": "Tiny Instance",
+                                "displaytext": "Tiny Instance",
+                                "cpunumber": 1,
+                                "cpuspeed": 100,    # in MHz
+                                "memory": 5120,    # In MBs
+                        },
+                        "virtual_machine": {
+                                "displayname": "TestVM",
+                                "username": "root",
+                                "password": "password",
+                                "ssh_port": 22,
+                                "hypervisor": 'KVM',
+                                "privateport": 22,
+                                "publicport": 22,
+                                "protocol": 'TCP',
+                                },
+                         "network": {
+                                "name": "Test Network",
+                                "displaytext": "Test Network",
+                                "netmask": '255.255.255.0'
+                                },
+                         "project": {
+                                "name": "Project",
+                                "displaytext": "Test project",
+                                },
+                         "domain": {
+                                "name": "Domain",
+                                },
+                        "ostype": 'CentOS 5.3 (64-bit)',
+                        "sleep": 60,
+                        "timeout": 10,
+                        "mode": 'advanced',
+                        # Networking mode: Advanced, Basic
+                    }
+
+class TestDomainMemoryLimits(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(TestDomainMemoryLimits,
+                               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.services["virtual_machine"]["zoneid"] = cls.zone.id
+
+        cls.service_offering = ServiceOffering.create(
+                                            cls.api_client,
+                                            cls.services["service_offering"]
+                                            )
+
+        cls._cleanup = [cls.service_offering, ]
+        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)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def createInstance(self, service_off, networks=None, api_client=None):
+        """Creates an instance in account"""
+        self.debug("Deploying an instance in account: %s" %
+                                                self.account.name)
+
+	if api_client is None:
+	    api_client = self.apiclient	
+        try:
+            vm = VirtualMachine.create(
+                                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")
+            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 setupAccounts(self):
+
+        self.debug("Creating a sub-domain under: %s" % self.domain.name)
+        self.child_domain = Domain.create(self.apiclient,
+                                        services=self.services["domain"],
+                                        parentdomainid=self.domain.id)
+        self.child_do_admin = Account.create(
+                                        self.apiclient,
+                                        self.services["account"],
+                                        admin=True,
+                                        domainid=self.child_domain.id
+                                        )
+        # Cleanup the resources created at end of test
+        self.cleanup.append(self.child_do_admin)
+        self.cleanup.append(self.child_domain)
+
+        Resources.updateLimit(self.apiclient,
+                              resourcetype=9,
+                              max=5120,
+                              account=self.child_do_admin.name,
+                              domainid=self.child_do_admin.domainid)
+	
+	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)
+	
+        # Cleanup the resources created at end of test
+        self.cleanup.append(self.admin)
+	self.cleanup.append(self.domain)
+
+        Resources.updateLimit(self.apiclient,
+                              resourcetype=9,
+                              max=5120,
+                              account=self.admin.name,
+                              domainid=self.admin.domainid)
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    @attr(configuration='max.account.memory')
+    def test_01_change_service_offering(self):
+        """Test Deploy VM with 5 GB RAM & verify the usage"""
+	#Keep max account memory (configuration) as 5 GB
+        # Validate the following
+        # 1. Create compute offering with 5 GB RAM & Deploy VM in the created domain
+        # 2. Update Resource count for the root admin Memory usage
+        # 3. Upgrade and downgrade service offering
+        # 4. Resource count should list properly for the domain 
+ 
+	#Keep max account memory (configuration) as 5 GB
+
+        self.debug("Setting up account and domain hierarchy")
+        self.setupAccounts()
+        users =  { self.domain: self.admin,
+                   self.child_domain: self.child_do_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)
+
+ 	    api_client = self.testClient.createUserApiClient(
+                            UserName=self.account.name,
+                            DomainName=self.account.domain)
+ 		
+            vm = self.createInstance(service_off=self.service_offering, api_client=api_client)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(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)
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count)
+
+            self.debug("Creating service offering with 7 GB RAM")
+            self.services["service_offering"]["memory"] = 7168
+            self.service_offering_7gb = ServiceOffering.create(
+                                            self.apiclient,
+                                            self.services["service_offering"]
+                                            )
+            # Adding to cleanup list after execution
+            self.cleanup.append(self.service_offering_7gb)
+
+            self.debug(
+                "Upgrade service offering of instance %s from %s to %s" %
+                                            (vm.name,
+                                             self.service_offering.name,
+                                             self.service_offering_7gb.name))
+
+            try:
+                vm.change_service_offering(self.apiclient,
+                                serviceOfferingId=self.service_offering_7gb.id)
+            except Exception as e:
+                self.fail("Failed to change service offering of vm %s - %s" %
+                                                                (vm.name, e))
+            resource_count  = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count)
+
+            self.debug(
+                "Down grade service offering of instance %s from %s to %s" %
+                                            (vm.name,
+                                             self.service_offering_7gb.name,
+                                             self.service_offering.name))
+
+            try:
+                vm.change_service_offering(self.apiclient,
+                                serviceOfferingId=self.service_offering.id)
+            except Exception as e:
+                self.fail("Failed to change service offering of vm %s - %s" %
+                                                                (vm.name, e))
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count)
+
+            self.debug("Starting instance: %s" % vm.name)
+            try:
+                vm.start(self.apiclient)
+            except Exception as e:
+                self.fail("Failed to start instance: %s" % e)
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count)
+ 
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    @attr(configuration='max.account.memory')
+    def test_02_migrate_vm(self):
+        """Test Deploy VM with 5 GB RAM & verify the usage"""
+	#Keep max account memory (configuration) as 5 GB
+        # Validate the following
+        # 1. Create compute offering with 5 GB RAM & Deploy VM in the created domain
+        # 2. Update Resource count for the root admin Memory usage
+        # 3. Migrate vm to another host, resource count should list properly.
+ 
+	#Keep max account memory (configuration) as 5 GB
+        self.debug("Setting up account and domain hierarchy")
+        self.setupAccounts()
+        users =  { self.domain: self.admin,
+                   self.child_domain: self.child_do_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)
+
+ 	    api_client = self.testClient.createUserApiClient(
+                            UserName=self.account.name,
+                            DomainName=self.account.domain)
+ 		
+            vm = self.createInstance(service_off=self.service_offering, api_client=api_client)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count) 
+
+            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)
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count) 
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    @attr(configuration='max.account.memory')
+    def test_03_delete_vm(self):
+        """Test Deploy VM with 5 GB RAM & verify the usage"""
+	#Keep max account memory (configuration) as 5 GB
+        # Validate the following
+        # 1. Create compute offering with 5 GB RAM & Deploy VM in the created domain
+        # 2. Update Resource count for the root admin Memory usage
+        # 3. Delete vm, resource count should list as 0 after delete operation.
+ 
+	#Keep max account memory (configuration) as 5 GB
+
+        self.debug("Setting up account and domain hierarchy")
+        self.setupAccounts()
+        users =  { self.domain: self.admin,
+                   self.child_domain: self.child_do_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)
+
+ 	    api_client = self.testClient.createUserApiClient(
+                            UserName=self.account.name,
+                            DomainName=self.account.domain)
+ 		
+            vm = self.createInstance(service_off=self.service_offering, api_client=api_client)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count) 
+
+            self.debug("Destroying instance: %s" % vm.name)
+            try:
+                vm.delete(self.apiclient)
+            except Exception as e:
+                self.fail("Failed to delete instance: %s" % e)
+
+	    # Wait for expunge interval to cleanup Memory
+	    wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count)
+            self.assertEqual(resource_count, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=9))#RAM
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    @attr(configuration='max.account.memory')
+    def test_04_deploy_multiple_vm(self):
+        """Test Deploy multiple VM with 5 GB RAM & verify the usage"""
+	#Keep max account memory (configuration) as 5 GB
+        # Validate the following
+        # 1. Create compute offering with 5 GB RAM
+        # 2. Deploy multiple VMs with this service offering
+        # 3. Update Resource count for the root admin Memory usage
+        # 4. Memory usage should list properly
+
+        self.debug("Setting up account and domain hierarchy")
+        self.setupAccounts()
+        users =  { self.domain: self.admin,
+                   self.child_domain: self.child_do_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)
+
+	    api_client = self.testClient.createUserApiClient(
+                            UserName=self.account.name,
+                            DomainName=self.account.domain)
+
+            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)
+            vm_3 = self.createInstance(service_off=self.service_offering, api_client=api_client) 
+
+            self.debug("Deploying instance - Memory capacity is fully utilized")
+            with self.assertRaises(Exception):
+                self.createInstance(service_off=self.service_offering, api_client=api_client)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count)
+            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)
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count)
+
+            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)
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count)
+	    vm_2.delete(self.apiclient)
+	    vm_3.delete(self.apiclient)
+        return
+
+
+class TestMultipleChildDomainsMemory(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(TestMultipleChildDomainsMemory,
+                               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.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)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def createInstance(self, account, service_off, networks=None, api_client=None):
+        """Creates an instance in account"""
+        self.debug("Deploying an instance in account: %s" %
+                                                account.name)
+
+	if api_client is None:
+	    api_client = self.apiclient
+
+        try:
+            vm = VirtualMachine.create(
+                                api_client,
+                                self.services["virtual_machine"],
+                                templateid=self.template.id,
+                                accountid=account.name,
+                                domainid=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")
+            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 setupAccounts(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
+                            )
+         
+        self.debug("Updating the Memory resource count for domain: %s" %
+                                                            self.domain.name)
+        Resources.updateLimit(self.apiclient,
+                              resourcetype=9,
+                              max=10240,
+                              account=self.parentd_admin.name,
+                              domainid=self.parentd_admin.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
+                                        )
+                
+        self.debug("Updating the Memory resource count for domain: %s" %
+                                                        self.cdomain_1.name)
+        Resources.updateLimit(self.apiclient,
+                              resourcetype=9,
+                              max=5120, 
+                              domainid=self.cadmin_1.domainid)
+
+        self.debug("Updating the Memory resource count for account: %s" %
+                                                        self.cadmin_1.name)
+        Resources.updateLimit(self.apiclient,
+                              resourcetype=9,
+                              max=2148,
+                              account=self.cadmin_1.name,
+                              domainid=self.cadmin_1.domainid)
+
+        self.cadmin_2 = Account.create(
+                                        self.apiclient,
+                                        self.services["account"],
+                                        admin=True,
+                                        domainid=self.cdomain_2.id
+                                        )
+
+        self.debug("Updating the Memory resource count for domain: %s" %
+                                                        self.cdomain_2.name)
+        Resources.updateLimit(self.apiclient,
+                              resourcetype=9,
+                              max=5120, 
+                              domainid=self.cadmin_2.domainid)
+
+        self.debug("Updating the Memory resource count for domain: %s" %
+                                                        self.cadmin_2.name)
+        Resources.updateLimit(self.apiclient,
+                              resourcetype=9,
+                              max=2148,
+                              account=self.cadmin_2.name,
+                              domainid=self.cadmin_2.domainid)
+
+	# 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.cleanup.append(self.parentd_admin)
+        self.cleanup.append(self.parent_domain)
+	 
+        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","simulator"])
+    def test_01_multiple_child_domains(self):
+        """Test memory limits with multiple child domains"""
+
+        # Validate the following
+        # 1. Create Domain1 with 10 GB RAM and 2 child domains with 5 GB
+        #    each.Assign 2 GB for Domain1 admin1 & Domain1 User1 .Assign 2
+        #    GB 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 2 GB RAM")
+        self.services["service_offering"]["memory"] = 2048
+        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.setupAccounts()
+
+	api_client_cadmin_1 = self.testClient.createUserApiClient(
+                            UserName=self.cadmin_1.name,
+                            DomainName=self.cadmin_1.domain)
+
+	api_client_cadmin_2 = self.testClient.createUserApiClient(
+                            UserName=self.cadmin_2.name,
+                            DomainName=self.cadmin_2.domain)
+
+        self.debug("Creating an instance with service offering: %s" %
+                                                self.service_offering.name)
+        vm_1 = self.createInstance(account=self.cadmin_1,
+                                  service_off=self.service_offering, api_client=api_client_cadmin_1)
+
+        vm_2 = self.createInstance(account=self.cadmin_2,
+                                  service_off=self.service_offering, api_client=api_client_cadmin_2)
+
+        resource_count_cadmin_1 = get_updated_resource_count(self.apiclient, account=self.cadmin_1, rtype=9)#RAM
+        self.debug(resource_count_cadmin_1)
+
+        resource_count_cadmin_2 = get_updated_resource_count(self.apiclient, account=self.cadmin_2, rtype=9)#RAM
+        self.debug(resource_count_cadmin_2)
+
+        self.debug(
+            "Creating instance when Memory limit is fully used in parent domain")
+        with self.assertRaises(Exception):
+            self.createInstance(account=self.cadmin_1,
+                                  service_off=self.service_offering, api_client=api_client_cadmin_1)
+
+        self.debug(
+            "Creating instance when Memory limit is fully used in child domain")
+        with self.assertRaises(Exception):
+            self.createInstance(account=self.cadmin_1,
+                                  service_off=self.service_offering, api_client=api_client_cadmin_1)
+        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.debug("Checking resource count for account: %s" % self.cadmin_1.name)
+
+        resource_count_cadmin_1 = get_updated_resource_count(self.apiclient, account=self.cadmin_1, rtype=9)#RAM
+        self.debug(resource_count_cadmin_1)
+
+        self.assertEqual(resource_count_cadmin_1, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=9))#RAM
+
+        self.debug("Checking resource count for account: %s" % self.cadmin_2.name)
+
+        resource_count_cadmin_2 = get_updated_resource_count(self.apiclient, account=self.cadmin_2, rtype=9)#RAM
+        self.debug(resource_count_cadmin_2)
+
+        self.assertEqual(resource_count_cadmin_2, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=9))#RAM
+        return

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/909b2879/test/integration/component/memory_limits/test_maximum_limits.py
----------------------------------------------------------------------
diff --git a/test/integration/component/memory_limits/test_maximum_limits.py b/test/integration/component/memory_limits/test_maximum_limits.py
new file mode 100644
index 0000000..9aaadff
--- /dev/null
+++ b/test/integration/component/memory_limits/test_maximum_limits.py
@@ -0,0 +1,359 @@
+# 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
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# 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 memory resource limits
+"""
+# Import Local Modules
+from nose.plugins.attrib import attr
+from marvin.cloudstackTestCase import cloudstackTestCase, unittest
+from marvin.integration.lib.base import (
+                                        Account,
+                                        ServiceOffering,
+                                        VirtualMachine,
+                                        Resources,
+                                        Domain,
+                                        Project
+                                        )
+from marvin.integration.lib.common import (get_domain,
+                                        get_zone,
+                                        get_template,
+                                        cleanup_resources
+                                        )
+
+class Services:
+    """Test memory resource limit services
+    """
+
+    def __init__(self):
+        self.services = {
+                        "account": {
+                                "email": "test@test.com",
+                                "firstname": "Test",
+                                "lastname": "User",
+                                "username": "resource",
+                                # Random characters are appended for unique
+                                # username
+                                "password": "password",
+                         },
+                         "service_offering": {
+                                "name": "Tiny Instance",
+                                "displaytext": "Tiny Instance",
+                                "cpunumber": 1,
+                                "cpuspeed": 100,    # in MHz
+                                "memory": 5120,    # In MBs
+                        },
+                        "virtual_machine": {
+                                "displayname": "TestVM",
+                                "username": "root",
+                                "password": "password",
+                                "ssh_port": 22,
+                                "hypervisor": 'KVM',
+                                "privateport": 22,
+                                "publicport": 22,
+                                "protocol": 'TCP',
+                                },
+                         "network": {
+                                "name": "Test Network",
+                                "displaytext": "Test Network",
+                                "netmask": '255.255.255.0'
+                                },
+                         "project": {
+                                "name": "Project",
+                                "displaytext": "Test project",
+                                },
+                         "domain": {
+                                "name": "Domain",
+                                },
+                        "ostype": 'CentOS 5.3 (64-bit)',
+                        "sleep": 60,
+                        "timeout": 10,
+                        "mode": 'advanced',
+                        # Networking mode: Advanced, Basic
+                    }
+
+class TestMaxMemoryLimits(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(TestMaxMemoryLimits,
+                               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.services["virtual_machine"]["zoneid"] = cls.zone.id
+
+        cls.service_offering = ServiceOffering.create(
+                                        cls.api_client,
+                                        cls.services["service_offering"]
+                                        )
+
+        cls._cleanup = [cls.service_offering, ]
+        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.account = Account.create(
+                     self.apiclient,
+                     self.services["account"],
+                     admin=True
+                     )
+
+        self.debug("Creating service offering with 5 GB RAM")
+    		
+        self.cleanup = [self.account, ]
+        return
+
+    def tearDown(self):
+        try:
+            # Clean up, terminate the created instance, volumes and snapshots
+            cleanup_resources(self.apiclient, self.cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def createInstance(self, service_off, account=None,
+                        project=None, networks=None, api_client=None):
+        """Creates an instance in account"""
+        self.debug("Deploying an instance in account: %s" %
+                                                self.account.name)
+
+	if api_client is None:
+	    api_client = self.apiclient
+
+        try:
+            if account:
+                vm = VirtualMachine.create(
+                                api_client,
+                                self.services["virtual_machine"],
+                                templateid=self.template.id,
+                                accountid=account.name,
+                                domainid=account.domainid,
+                                networkids=networks,
+                                serviceofferingid=service_off.id)
+            elif project:
+                vm = VirtualMachine.create(
+                                api_client,
+                                self.services["virtual_machine"],
+                                templateid=self.template.id,
+                                projectid=project.id,
+                                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")
+            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 setupAccounts(self, account_limit=2, domain_limit=2, project_limit=2):
+
+        self.debug("Creating a domain under: %s" % self.domain.name)
+    	self.child_domain = Domain.create(self.apiclient,
+                                    services=self.services["domain"],
+                                    parentdomainid=self.domain.id)
+
+
+    	self.debug("domain crated with domain id %s" % self.child_domain.id)
+
+    	self.child_do_admin = Account.create(
+                        self.apiclient,
+                        self.services["account"],
+                        admin=True,
+                        domainid=self.child_domain.id
+                        )
+
+    	self.debug("domain admin created for domain id %s" % 
+			self.child_do_admin.domainid)
+
+    	# Create project as a domain admin
+    	self.project = Project.create(self.apiclient,
+                             self.services["project"],
+                             account=self.child_do_admin.name,
+                             domainid=self.child_do_admin.domainid)
+
+   	# Cleanup created project at end of test
+    	self.cleanup.append(self.project)
+
+
+    	# Cleanup accounts created
+    	self.cleanup.append(self.child_do_admin)
+    	self.cleanup.append(self.child_domain)
+
+    	self.debug("Updating the Memory resource count for domain: %s" %
+                                                        self.child_domain.name)
+    	# Update resource limits for account 1
+    	responses = Resources.updateLimit(self.apiclient,
+                          resourcetype=9,
+                          max=(account_limit * 1024),
+                          account=self.child_do_admin.name,
+                          domainid=self.child_do_admin.domainid
+                          )
+
+    	self.debug("Memory Resource count for child domain admin account is now: %s" %
+									 responses.max)
+
+    	# Update resource limits for project
+    	responses = Resources.updateLimit(self.apiclient,
+                          resourcetype=9,
+                          max=(project_limit * 1024),
+                          projectid=self.project.id)
+
+    	self.debug("Memory Resource count for project is now")
+    	self.debug(responses.max)
+
+    	# TODO: Update the Memory limit for domain only
+    	responses = Resources.updateLimit(self.apiclient,
+                                          resourcetype=9,
+                                          max=(domain_limit * 1024),
+                                          domainid=self.child_domain.id)
+
+     	self.debug("Memory Resource count for domain %s with id %s is now %s" % 
+			    (responses.domain, responses.domainid, responses.max))
+     	return	
+ 
+    @attr(tags=["advanced", "advancedns","simulator"])
+    def test_01_deploy_vm_domain_limit_reached(self):
+    	"""Test Try to deploy VM with admin account where account has not used
+           the resources but @ domain they are not available"""
+
+    	# Validate the following
+    	# 1. Try to deploy VM with admin account where account has not used the
+    	#    resources but @ domain they are not available
+    	# 2. Deploy VM should error out saying  ResourceAllocationException
+    	#    with "resource limit exceeds"	
+
+    	self.debug("Setting up account and domain hierarchy")
+    	self.setupAccounts(account_limit=8, domain_limit=4)
+
+	api_client = self.testClient.createUserApiClient(
+                            UserName=self.child_do_admin.name,
+                            DomainName=self.child_do_admin.domain)
+
+    	self.debug("Creating instance with domain %s and admin account %s" % 
+		  			(self.child_do_admin.domainid,
+					     self.child_do_admin.name))
+
+    	with self.assertRaises(Exception):
+        	self.createInstance(account=self.child_do_admin,
+                              service_off=self.service_offering, api_client=api_client)
+    	return 
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    def test_02_deploy_vm_account_limit_reached(self):
+    	"""Test Try to deploy VM with admin account where account has used
+           the resources but @ domain they are available"""
+
+    	# Validate the following
+    	# 1. Try to deploy VM with admin account where account has used the
+    	#    resources but @ domain they are available
+    	# 2. Deploy VM should error out saying  ResourceAllocationException
+    	#    with "resource limit exceeds"	
+
+    	self.debug("Setting up account and domain hierarchy")
+    	self.setupAccounts(account_limit=7, domain_limit=14)
+
+	api_client = self.testClient.createUserApiClient(
+                            UserName=self.child_do_admin.name,
+                            DomainName=self.child_do_admin.domain)
+
+    	self.debug("Deploying instance with account: %s" %
+                                                self.child_do_admin.name)
+    	self.createInstance(account=self.child_do_admin,
+                              service_off=self.service_offering, api_client=api_client)	
+
+    	self.debug("Deploying instance in account 1 when Memory limit is reached")
+
+    	with self.assertRaises(Exception):
+        	self.createInstance(account=self.child_do_admin,
+                              service_off=self.service_offering, api_client=api_client)
+    	return 
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    def test_03_deploy_vm_project_limit_reached(self):
+    	"""Test TTry to deploy VM with admin account where account has not used
+   	   the resources but @ project they are not available"""
+
+    	# Validate the following
+    	# 1. Try to deploy VM with admin account where account has not used the
+    	#    resources but @ project they are not available
+    	# 2. Deploy VM should error out saying  ResourceAllocationException
+    	#    with "resource limit exceeds"	
+
+    	self.debug("Setting up account and domain hierarchy")
+    	self.setupAccounts(account_limit=8,domain_limit=8, project_limit=4)
+
+	api_client = self.testClient.createUserApiClient(
+                            UserName=self.child_do_admin.name,
+                            DomainName=self.child_do_admin.domain)
+
+    	self.debug("Deploying instance with project: %s" % self.project.name)
+    	with self.assertRaises(Exception):
+        	self.createInstance(project = self.project,
+                            service_off=self.service_offering, api_client=api_client)
+    	return 
+
+    @attr(tags=["advanced", "advancedns"])
+    def test_04_deployVm__account_limit_reached(self):
+    	"""Test Try to deploy VM with admin account where account has used
+           the resources but @ project they are available"""
+
+    	# Validate the following
+    	# 1. Try to deploy VM with admin account where account has used the
+    	#    resources but @ project they are available
+    	# 2. Deploy VM should error out saying  ResourceAllocationException
+    	#    with "resource limit exceeds"
+
+    	self.debug("Setting up account and domain hierarchy")
+    	self.setupAccounts(account_limit=6, project_limit=12, domain_limit=12)
+
+	api_client = self.testClient.createUserApiClient(
+                            UserName=self.child_do_admin.name,
+                            DomainName=self.child_do_admin.domain)
+
+    	self.debug("Deploying instance with account: %s" %
+                                                self.child_do_admin.name)
+    	self.createInstance(account=self.child_do_admin,
+                              service_off=self.service_offering, api_client=api_client)	
+
+    	self.debug("Deploying instance in account: %s when memory limit is reached" %
+                                                self.child_do_admin.name)
+
+    	with self.assertRaises(Exception):
+        	self.createInstance(project=self.project,
+                             service_off=self.service_offering, api_client=api_client)
+    	return 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/909b2879/test/integration/component/memory_limits/test_memory_limits.py
----------------------------------------------------------------------
diff --git a/test/integration/component/memory_limits/test_memory_limits.py b/test/integration/component/memory_limits/test_memory_limits.py
new file mode 100644
index 0000000..3276407
--- /dev/null
+++ b/test/integration/component/memory_limits/test_memory_limits.py
@@ -0,0 +1,626 @@
+# 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
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# 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 memory resource limits
+"""
+# Import Local Modules
+from nose.plugins.attrib import attr
+from marvin.cloudstackTestCase import cloudstackTestCase, unittest
+from marvin.integration.lib.base import (
+                                        Account,
+                                        ServiceOffering,
+                                        VirtualMachine,
+                                        Resources,
+                                        Domain
+                                        )
+from marvin.integration.lib.common import (get_domain,
+                                        get_zone,
+                                        get_template,
+                                        cleanup_resources,
+					wait_for_cleanup,
+                                        get_updated_resource_count,
+                                        find_suitable_host,
+                                        get_resource_type 
+                                        )
+
+class Services:
+    """Test memory resource limit services
+    """
+
+    def __init__(self):
+        self.services = {
+                        "account": {
+                                "email": "test@test.com",
+                                "firstname": "Test",
+                                "lastname": "User",
+                                "username": "resource",
+                                # Random characters are appended for unique
+                                # username
+                                "password": "password",
+                         },
+                         "service_offering": {
+                                "name": "Tiny Instance",
+                                "displaytext": "Tiny Instance",
+                                "cpunumber": 1,
+                                "cpuspeed": 100,    # in MHz
+                                "memory": 5120,    # In MBs
+                        },
+                        "virtual_machine": {
+                                "displayname": "TestVM",
+                                "username": "root",
+                                "password": "password",
+                                "ssh_port": 22,
+                                "hypervisor": 'KVM',
+                                "privateport": 22,
+                                "publicport": 22,
+                                "protocol": 'TCP',
+                                },
+                         "network": {
+                                "name": "Test Network",
+                                "displaytext": "Test Network",
+                                "netmask": '255.255.255.0'
+                                },
+                         "project": {
+                                "name": "Project",
+                                "displaytext": "Test project",
+                                },
+                         "domain": {
+                                "name": "Domain",
+                                },
+                        "ostype": 'CentOS 5.3 (64-bit)',
+                        "sleep": 60,
+                        "timeout": 10,
+                        "mode": 'advanced',
+                        # Networking mode: Advanced, Basic
+                    }
+
+class TestMemoryLimits(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(TestMemoryLimits,
+                               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.services["virtual_machine"]["zoneid"] = cls.zone.id
+
+        cls.service_offering = ServiceOffering.create(
+                                            cls.api_client,
+                                            cls.services["service_offering"]
+                                            )
+
+        cls._cleanup = [cls.service_offering, ]
+        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.account = Account.create(
+                            self.apiclient,
+                            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)
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+        self.debug(resource_count) 
+ 
+        self.cleanup = [self.account, ]
+        return
+
+    def tearDown(self):
+        try:
+            # Clean up, terminate the created instance, volumes and snapshots
+            cleanup_resources(self.apiclient, self.cleanup)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def createInstance(self, service_off, networks=None, api_client=None):
+        """Creates an instance in account"""
+        self.debug("Deploying an instance in account: %s" %
+                                                self.account.name)
+
+	if api_client is None:
+	    api_client = self.apiclient
+
+        try:
+            vm = VirtualMachine.create(
+                                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")
+            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)   
+
+    @attr(tags=["advanced", "advancedns","simulator"]) 
+    def test_01_reboot_instance(self):
+        """Test Deploy VM with 5 GB RAM & verify the usage"""
+
+        # Validate the following
+        # 1. Create compute offering with 5 GB RAM & Deploy VM as root admin
+        # 2. Update Resource count for the root admin Memory usage
+        # 3. Stop and start instance, resource count should list properly. 
+ 
+        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)
+        resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+        self.debug(resource_count)
+
+        self.debug("Starting instance: %s" % self.vm.name)
+        try:
+            self.vm.start(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to start instance: %s" % e)
+        resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+        self.debug(resource_count) 
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"]) 
+    def test_02_migrate_instance(self):
+        """Test Deploy VM with 5 GB RAM & verify the usage"""
+
+        # Validate the following
+        # 1. Create compute offering with 5 GB RAM & Deploy VM as root admin
+        # 2. Update Resource count for the root admin Memory usage
+        # 3. Migrate vm, resource count should list properly.
+
+        host = find_suitable_host(self.apiclient, self.vm)
+        self.debug("Migrating instance: %s to host: %s" % (self.vm.name, host.name))
+        try:
+            self.vm.migrate(self.apiclient, host.id)
+        except Exception as e:
+            self.fail("Failed to migrate instance: %s" % e)
+        resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+        self.debug(resource_count) 
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"]) 
+    def test_03_delete_instance(self):
+        """Test Deploy VM with 5 GB RAM & verify the usage"""
+
+        # Validate the following
+        # 1. Create compute offering with 5 GB RAM & Deploy VM as root admin
+        # 2. Update Resource count for the root admin Memory usage
+        # 3. Delete instance, resource count should be 0 after delete operation. 
+
+        self.debug("Destroying instance: %s" % self.vm.name)
+        try:
+            self.vm.delete(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to delete instance: %s" % e)
+
+	# Wait for expunge interval to cleanup Memory
+	wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+        self.debug(resource_count)
+        self.assertEqual(resource_count, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=9))#RAM
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"]) 
+    def test_04_deploy_multiple_vm_with_5gb_ram(self):
+        """Test Deploy multiple VM with 5 GB RAM & verify the usage"""
+
+        # Validate the following
+        # 1. Create compute offering with 5 GB RAM
+        # 2. Deploy multiple VMs with this service offering
+        # 3. Update Resource count for the root admin Memory usage
+        # 4. Memory usage should list properly 
+
+        self.debug("Creating instances with service offering: %s" %
+                                                    self.service_offering.name)
+        vm_1 = self.createInstance(service_off=self.service_offering)
+        self.createInstance(service_off=self.service_offering) 
+ 
+        resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+        self.debug(resource_count)
+        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)
+        resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+        self.debug(resource_count)
+        return
+
+class TestMemoryUpdateResources(cloudstackTestCase):
+
+    @classmethod
+    def setUpClass(cls):
+        cls.api_client = super(TestMemoryUpdateResources,
+                               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.services["virtual_machine"]["zoneid"] = cls.zone.id
+
+        cls.service_offering = ServiceOffering.create(
+                                            cls.api_client,
+                                            cls.services["service_offering"]
+                                            )
+
+        cls._cleanup = [cls.service_offering, ]
+        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)
+        except Exception as e:
+            raise Exception("Warning: Exception during cleanup : %s" % e)
+        return
+
+    def createInstance(self, service_off, networks=None, api_client=None):
+        """Creates an instance in account"""
+        self.debug("Deploying an instance in account: %s" %
+                                                self.account.name)
+
+	if api_client is None:
+	    api_client = self.apiclient
+
+        try:
+            vm = VirtualMachine.create(
+                                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")
+            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 setupAccounts(self):
+
+        self.debug("Creating a domain under: %s" % self.domain.name)
+        self.child_domain = Domain.create(self.apiclient,
+                                        services=self.services["domain"],
+                                        parentdomainid=self.domain.id)
+        self.child_do_admin = Account.create(
+                            self.apiclient,
+                            self.services["account"],
+                            admin=True,
+                            domainid=self.child_domain.id
+                            )
+        # Cleanup the resources created at end of test
+        self.cleanup.append(self.child_do_admin)
+        self.cleanup.append(self.child_domain)
+
+        self.debug("Updating the Memory resource count for domain: %s" %
+                                                            self.domain.name)
+        Resources.updateLimit(self.apiclient,
+                              resourcetype=9,
+                              max=15360,
+                              account=self.child_do_admin.name,
+                              domainid=self.child_do_admin.domainid)
+
+        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)
+        # Cleanup the resources created at end of test	
+	self.cleanup.append(self.admin)
+        self.cleanup.append(self.domain)
+
+        Resources.updateLimit(self.apiclient,
+                              resourcetype=9,
+                              max=15360,
+                              account=self.admin.name,
+                              domainid=self.admin.domainid)
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"]) 
+    def test_01_change_service_offering(self):
+        """Test Deploy VM with 5 GB RAM & verify the usage"""
+
+        # Validate the following
+        # 1. Create compute offering with 5 GB RAM & Deploy VM as root admin
+        # 2. Update Resource count for the root admin Memory usage
+        # 3. Upgrade service offering, resource count should list properly.
+        # 4. Downgrade service offering, resource count should list properly.
+
+        self.debug("Setting up account and domain hierarchy")
+        self.setupAccounts()
+        users = {self.domain: self.admin,
+                 self.child_domain: self.child_do_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)
+
+	    api_client = self.testClient.createUserApiClient(
+                            UserName=self.account.name,
+                            DomainName=self.account.domain)
+
+            vm = self.createInstance(service_off=self.service_offering, api_client=api_client)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(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)
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count)
+
+            self.debug("Creating service offering with 7 GB RAM")
+            self.services["service_offering"]["memory"] = 7168
+            self.service_offering_7gb = ServiceOffering.create(
+                                            self.apiclient,
+                                            self.services["service_offering"])
+            # Adding to cleanup list after execution
+            self.cleanup.append(self.service_offering_7gb)
+
+            self.debug(
+                "Upgrade service offering of instance %s from %s to %s" %
+                                            (vm.name,
+                                             self.service_offering.name,
+                                             self.service_offering_7gb.name))
+
+            try:
+                vm.change_service_offering(self.apiclient,
+                                serviceOfferingId=self.service_offering_7gb.id)
+            except Exception as e:
+                self.fail("Failed to change service offering of vm %s - %s" %
+                                                                (vm.name, e))
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count)
+
+            self.debug(
+                "Down grade service offering of instance %s from %s to %s" %
+                                            (vm.name,
+                                             self.service_offering_7gb.name,
+                                             self.service_offering.name))
+
+            try:
+                vm.change_service_offering(self.apiclient,
+                                serviceOfferingId=self.service_offering.id)
+            except Exception as e:
+                self.fail("Failed to change service offering of vm %s - %s" %
+                                                                (vm.name, e))
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count)
+
+            self.debug("Starting instance: %s" % vm.name)
+            try:
+                vm.start(self.apiclient)
+            except Exception as e:
+                self.fail("Failed to start instance: %s" % e)
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count) 
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"]) 
+    def test_02_migrate_instance(self):
+        """Test Deploy VM with 5 GB RAM & verify the usage"""
+
+        # Validate the following
+        # 1. Create compute offering with 5 GB RAM & Deploy VM as root admin
+        # 2. Update Resource count for the root admin Memory usage 
+        # 3. Migrate vm, resource count should list properly.
+
+        self.debug("Setting up account and domain hierarchy")
+        self.setupAccounts()
+        users = {self.domain: self.admin,
+                 self.child_domain: self.child_do_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)
+
+	    api_client = self.testClient.createUserApiClient(
+                            UserName=self.account.name,
+                            DomainName=self.account.domain)
+
+            vm = self.createInstance(service_off=self.service_offering, api_client=api_client)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count)
+        
+            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)
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count)
+
+            self.debug("Assigning VM to account: %s in domain: %s" %
+                                                (self.admin.name,
+                                                self.admin.domain))
+            # TODO: Assign Virtual Machine function implementation 
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"]) 
+    def test_03_delete_instance(self):
+        """Test Deploy VM with 5 GB RAM & verify the usage"""
+
+        # Validate the following
+        # 1. Create compute offering with 5 GB RAM & Deploy VM as root admin
+        # 2. Update Resource count for the root admin Memory usage
+        # 3. Delete instance, resource count should be 0 after delete operation. 
+
+        self.debug("Setting up account and domain hierarchy")
+        self.setupAccounts()
+        users = {self.domain: self.admin,
+                 self.child_domain: self.child_do_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)
+
+	    api_client = self.testClient.createUserApiClient(
+                            UserName=self.account.name,
+                            DomainName=self.account.domain)
+
+            vm = self.createInstance(service_off=self.service_offering, api_client=api_client)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count) 
+
+            self.debug("Destroying instance: %s" % vm.name)
+            try:
+                vm.delete(self.apiclient)
+            except Exception as e:
+                self.fail("Failed to delete instance: %s" % e)
+
+	    # Wait for expunge interval to cleanup Memory
+            wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count)
+            self.assertEqual(resource_count, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=9))#RAM
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"]) 
+    def test_04_deploy_multiple_vm_with_5gb_ram(self):
+        """Test Deploy multiple VM with 5 GB RAM& verify the usage"""
+
+        # Validate the following
+        # 1. Create compute offering with 5 GB RAM
+        # 2. Deploy multiple VMs with this service offering
+        # 3. Update Resource count for the root admin Memory usage
+        # 4. Memory usage should list properly 
+
+        self.debug("Setting up account and domain hierarchy")
+        self.setupAccounts()
+        users =  { self.domain: self.admin,
+                   self.child_domain: self.child_do_admin
+                 }
+        for domain, admin in users.items():
+            self.account = admin
+            self.domain = domain
+
+	    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_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)
+            vm_3 = self.createInstance(service_off=self.service_offering, api_client=api_client) 
+
+            self.debug("Deploying instance - Memory capacity is fully utilized")
+            with self.assertRaises(Exception):
+                self.createInstance(service_off=self.service_offering, api_client=api_client)
+
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count)
+            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)
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count)
+
+            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)
+            resource_count = get_updated_resource_count(self.apiclient, account=self.account, rtype=9)#RAM
+            self.debug(resource_count)
+
+	    vm_2.delete(self.apiclient)
+	    vm_3.delete(self.apiclient)  
+        return 


[3/7] Automation: Limit Resources - Adding tests related to CPU limits

Posted by sa...@apache.org.
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/95273e1c/test/integration/component/cpu_limits/test_project_limits.py
----------------------------------------------------------------------
diff --git a/test/integration/component/cpu_limits/test_project_limits.py b/test/integration/component/cpu_limits/test_project_limits.py
new file mode 100644
index 0000000..c4ae1e9
--- /dev/null
+++ b/test/integration/component/cpu_limits/test_project_limits.py
@@ -0,0 +1,307 @@
+# 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
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# 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.
+
+""" Tests for cpu resource limits related to projects
+"""
+# Import Local Modules
+from nose.plugins.attrib import attr
+from marvin.cloudstackTestCase import cloudstackTestCase, unittest
+from marvin.integration.lib.base import (
+                                        Account,
+                                        ServiceOffering,
+                                        VirtualMachine,
+                                        Domain,
+                                        Project
+                                        )
+from marvin.integration.lib.common import (get_domain,
+                                        get_zone,
+                                        get_template,
+                                        cleanup_resources,
+                                        get_updated_resource_count,
+                                        find_suitable_host,
+                                        get_resource_type
+                                        )
+
+class Services:
+    """Test resource limit services
+    """
+
+    def __init__(self):
+        self.services = {
+                        "account": {
+                                "email": "test@test.com",
+                                "firstname": "Test",
+                                "lastname": "User",
+                                "username": "resource",
+                                # Random characters are appended for unique
+                                # username
+                                "password": "password",
+                         },
+                         "service_offering": {
+                                "name": "Tiny Instance",
+                                "displaytext": "Tiny Instance",
+                                "cpunumber": 4,
+                                "cpuspeed": 100,    # in MHz
+                                "memory": 128,    # In MBs
+                        },
+                        "virtual_machine": {
+                                "displayname": "TestVM",
+                                "username": "root",
+                                "password": "password",
+                                "ssh_port": 22,
+                                "hypervisor": 'KVM',
+                                "privateport": 22,
+                                "publicport": 22,
+                                "protocol": 'TCP',
+                                },
+                         "network": {
+                                "name": "Test Network",
+                                "displaytext": "Test Network",
+                                "netmask": '255.255.255.0'
+                                },
+                         "project": {
+                                "name": "Project",
+                                "displaytext": "Test project",
+                                },
+                         "domain": {
+                                "name": "Domain",
+                                },
+                        "ostype": 'CentOS 5.3 (64-bit)',
+                        "sleep": 60,
+                        "timeout": 10,
+                        "mode": 'advanced',
+                        # Networking mode: Advanced, Basic
+                    }
+
+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.services["mode"] = cls.zone.networktype
+        cls.template = get_template(
+                            cls.api_client,
+                            cls.zone.id,
+                            cls.services["ostype"]
+                            )
+
+        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
+
+        cls.service_offering = ServiceOffering.create(
+                                            cls.api_client,
+                                            cls.services["service_offering"]
+                                            ) 
+
+        cls._cleanup = [cls.service_offering, ]
+        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.account = Account.create(
+                            self.apiclient,
+                            self.services["account"],
+                            admin=True
+                            )
+
+        self.cleanup = [self.account, ]
+
+        self.debug("Setting up account and domain hierarchy")
+        self.setupProjectAccounts()
+
+	api_client = self.testClient.createUserApiClient(
+                             UserName=self.admin.name,
+                             DomainName=self.admin.domain)
+
+        self.debug("Creating an instance with service offering: %s" %
+                                                    self.service_offering.name)
+        self.vm = self.createInstance(project=self.project,
+                                  service_off=self.service_offering, api_client=api_client)
+ 
+        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 createInstance(self, project, service_off, networks=None, api_client=None):
+        """Creates an instance in account"""
+
+	if api_client is None:
+	    api_client = self.api_client
+ 
+        try:
+            self.vm = VirtualMachine.create(
+                                api_client,
+                                self.services["virtual_machine"],
+                                templateid=self.template.id,
+                                projectid=project.id, 
+                                networkids=networks,
+                                serviceofferingid=service_off.id)
+            vms = VirtualMachine.list(api_client, id=self.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 self.vm
+        except Exception as e:
+            self.fail("Failed to deploy an instance: %s" % e) 
+
+    def setupProjectAccounts(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.name,
+                                 domainid=self.admin.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","simulator"])
+    @attr(configuration='max.projects.cpus') 
+    def test_01_project_counts_reboot_instance(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.
+        # 5. Resource count should list properly.  
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.admin, project=self.project, rtype=8)#CPU
+        self.debug(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)
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.admin, project=self.project, rtype=8)#CPU
+        self.debug(resource_count)
+
+        self.debug("Starting instance: %s" % self.vm.name)
+        try:
+            self.vm.start(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to start instance: %s" % e)
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.admin, project=self.project, rtype=8)#CPU
+        self.debug(resource_count) 
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    @attr(configuration='max.projects.cpus') 
+    def test_02_project_counts_migrate_instance(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. Migrate VM of an accounts added to the project to a new host
+        # 5. Resource count should list properly.
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.admin, project=self.project, rtype=8)#CPU
+        self.debug(resource_count) 
+
+        host = find_suitable_host(self.apiclient, self.vm)
+        self.debug("Migrating instance: %s to host: %s" %
+                                                    (self.vm.name, host.name))
+        try:
+            self.vm.migrate(self.apiclient, host.id)
+        except Exception as e:
+            self.fail("Failed to migrate instance: %s" % e)
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.admin, project=self.project, rtype=8)#CPU
+        self.debug(resource_count) 
+        return
+
+    @attr(tags=["advanced", "advancedns","simulator"])
+    @attr(configuration='max.projects.cpus') 
+    def test_03_project_counts_delete_instance(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. Destroy VM of an accounts added to the project to a new host  
+        # 5. Resource count should list properly.
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.admin, project=self.project, rtype=8)#CPU
+        self.debug(resource_count)
+
+        self.debug("Destroying instance: %s" % self.vm.name)
+        try:
+            self.vm.delete(self.apiclient)
+        except Exception as e:
+            self.fail("Failed to delete instance: %s" % e)
+
+        resource_count = get_updated_resource_count(self.apiclient, account=self.admin, project=self.project, rtype=8)#CPU
+        self.debug(resource_count)
+        self.assertEqual(resource_count, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=8))#CPU
+        return