You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ts...@apache.org on 2013/07/25 19:21:48 UTC

git commit: updated refs/heads/master to 23e7753

Updated Branches:
  refs/heads/master 7df0d3a23 -> 23e775374


Fix bunch of affinity group tests

Signed-off-by: Prasanna Santhanam <ts...@apache.org>
(cherry picked from commit 2b0a97267617608e6695973bc768eec499b69eca)


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

Branch: refs/heads/master
Commit: 23e7753741cf515240ed66e371cfdbd5d15b0baa
Parents: 7df0d3a
Author: Prasanna Santhanam <ts...@apache.org>
Authored: Thu Jul 25 22:50:45 2013 +0530
Committer: Prasanna Santhanam <ts...@apache.org>
Committed: Thu Jul 25 22:51:35 2013 +0530

----------------------------------------------------------------------
 .../component/test_affinity_groups.py           | 208 +++++++++----------
 tools/marvin/marvin/cloudstackTestClient.py     |   6 +-
 tools/marvin/marvin/integration/lib/base.py     |  14 +-
 3 files changed, 96 insertions(+), 132 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/23e77537/test/integration/component/test_affinity_groups.py
----------------------------------------------------------------------
diff --git a/test/integration/component/test_affinity_groups.py b/test/integration/component/test_affinity_groups.py
index 3f257c3..3ecab6f 100644
--- a/test/integration/component/test_affinity_groups.py
+++ b/test/integration/component/test_affinity_groups.py
@@ -153,34 +153,34 @@ class TestCreateAffinityGroup(cloudstackTestCase):
     def create_aff_grp(self, api_client=None, aff_grp=None,
                   acc=None, domainid=None):
 
-        if api_client == None:
+        if not api_client:
             api_client = self.api_client
-        if aff_grp == None:
+        if not aff_grp:
             self.services["host_anti_affinity_0"]
-        if acc == None:
+        if not acc:
             acc = self.account.name
-        if domainid == None:
+        if not domainid:
             domainid = self.domain.id
 
         try:
-            self.aff_grp = AffinityGroup.create(api_client, aff_grp, acc, domainid)
+            return AffinityGroup.create(api_client, aff_grp, acc, domainid)
         except Exception as e:
             raise Exception("Error: Creation of Affinity Group failed : %s" %e)
 
-    @attr(tags=["simulator", "basic", "advanced", "needle"])
+    @attr(tags=["simulator", "basic", "advanced"])
     def test_01_admin_create_aff_grp(self):
         """
         Test create affinity group as admin
         @return:
         """
 
-        self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
-                                        acc=self.account.name, domainid=self.account.domainid)
-        self.debug("Created Affinity Group: %s" % self.aff_grp.name)
-
-        list_aff_grps = AffinityGroup.list(self.api_client, id=self.aff_grp.id)
-        AffinityGroup.delete(self.api_client, id=list_aff_grps[0].id)
-        self.debug("Deleted Affinity Group: %s" % list_aff_grps[0].name)
+        aff_grp = self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
+            acc=self.account.name, domainid=self.account.domainid)
+        self.debug("Created Affinity Group: %s" % aff_grp.name)
+        list_aff_grps = AffinityGroup.list(self.api_client, id=aff_grp.id)
+        self.assert_(isinstance(list_aff_grps, list) and len(list_aff_grps) > 0)
+        self.assert_(list_aff_grps[0].id == aff_grp.id)
+        self.cleanup.append(aff_grp)
 
     @attr(tags=["simulator", "basic", "advanced"])
     def test_02_doadmin_create_aff_grp(self):
@@ -195,13 +195,11 @@ class TestCreateAffinityGroup(cloudstackTestCase):
         self.cleanup.append(self.do_admin)
         self.cleanup.append(self.new_domain)
 
-        self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
-                            acc=self.do_admin.name, domainid=self.new_domain.id)
-
-        AffinityGroup.delete(self.api_client, name=self.aff_grp.name,
-                             account=self.do_admin.name, domainid=self.new_domain.id)
-        self.debug("Deleted Affinity Group: %s" %self.aff_grp.name)
+        domainapiclient = self.testClient.createUserApiClient(self.do_admin.name, self.new_domain.name, 2)
 
+        aff_grp = self.create_aff_grp(api_client=domainapiclient, aff_grp=self.services["host_anti_affinity_0"],
+                                            acc=self.do_admin.name, domainid=self.new_domain.id)
+        aff_grp.delete(domainapiclient)
 
     @attr(tags=["simulator", "basic", "advanced"])
     def test_03_user_create_aff_grp(self):
@@ -213,13 +211,12 @@ class TestCreateAffinityGroup(cloudstackTestCase):
         self.user = Account.create(self.api_client, self.services["new_account"],
                                   domainid=self.domain.id)
 
+        userapiclient = self.testClient.createUserApiClient(self.user.name, self.domain.name)
+
         self.cleanup.append(self.user)
-        self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
+        aff_grp = self.create_aff_grp(api_client=userapiclient, aff_grp=self.services["host_anti_affinity_0"],
                             acc=self.user.name, domainid=self.domain.id)
-
-        AffinityGroup.delete(self.api_client, name=self.aff_grp.name,
-                             account=self.user.name, domainid=self.domain.id)
-        self.debug("Deleted Affinity Group: %s" %self.aff_grp.name)
+        aff_grp.delete(userapiclient)
 
 
     @attr(tags=["simulator", "basic", "advanced"])
@@ -233,15 +230,14 @@ class TestCreateAffinityGroup(cloudstackTestCase):
                                   domainid=self.domain.id)
 
         self.cleanup.append(self.user)
-        self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
+        aff_grp = self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
                             acc=self.user.name, domainid=self.domain.id)
         with self.assertRaises(Exception):
             self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
                             acc=self.user.name, domainid=self.domain.id)
 
-        AffinityGroup.delete(self.api_client, name=self.aff_grp.name,
-                             account=self.user.name, domainid=self.domain.id)
-        self.debug("Deleted Affinity Group: %s" %self.aff_grp.name)
+        self.debug("Deleted Affinity Group: %s" %aff_grp.name)
+        aff_grp.delete(self.api_client)
 
     @attr(tags=["simulator", "basic", "advanced"])
     def test_05_create_aff_grp_same_name_diff_acc(self):
@@ -254,7 +250,7 @@ class TestCreateAffinityGroup(cloudstackTestCase):
                                   domainid=self.domain.id)
 
         self.cleanup.append(self.user)
-        self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
+        aff_grp = self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
                             acc=self.user.name, domainid=self.domain.id)
 
         try:
@@ -262,9 +258,8 @@ class TestCreateAffinityGroup(cloudstackTestCase):
         except Exception:
             self.debug("Error: Creating affinity group with same name from different account failed.")
 
-        AffinityGroup.delete(self.api_client, name=self.aff_grp.name,
-                             account=self.user.name, domainid=self.domain.id)
-        self.debug("Deleted Affinity Group: %s" %self.aff_grp.name)
+        self.debug("Deleted Affinity Group: %s" %aff_grp.name)
+        aff_grp.delete(self.api_client)
 
     @attr(tags=["simulator", "basic", "advanced"])
     def test_06_create_aff_grp_nonexisting_type(self):
@@ -554,8 +549,7 @@ class TestDeleteAffinityGroups(cloudstackTestCase):
         if aff_grp == None:
             self.services["host_anti_affinity_0"]
         try:
-            self.aff_grp.append(AffinityGroup.create(api_client,
-                                                     aff_grp, acc, domainid))
+            return AffinityGroup.create(api_client, aff_grp, acc, domainid)
         except Exception as e:
             raise Exception("Error: Creation of Affinity Group failed : %s" %e)
 
@@ -584,99 +578,83 @@ class TestDeleteAffinityGroups(cloudstackTestCase):
 
         return vm, vm_response.hostid
 
-    def test_01_delete_aff_grp_by_id(self):
+    def delete_aff_group(self, apiclient, **kwargs):
+        cmd = deleteAffinityGroup.deleteAffinityGroupCmd()
+        [setattr(cmd, k, v) for k, v in kwargs.items()]
+        return apiclient.deleteAffinityGroup(cmd)
+
+    @attr(tags=["simulator", "basic", "advanced", "multihost"])
+    def test_01_delete_aff_grp_by_name(self):
         """
-            Delete Affinity Group by id.
+            Delete Affinity Group by name
         """
 
-        self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"])
-        self.create_aff_grp(aff_grp=self.services["host_anti_affinity_1"])
-
-        list_aff_grps = AffinityGroup.list(self.api_client,
-                                           name=self.aff_grp[0].name)
-
-        AffinityGroup.delete(self.api_client, id=list_aff_grps[0].id)
-
-        AffinityGroup.delete(self.api_client, name=self.aff_grp[1].name)
+        aff_0 = self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"])
+        AffinityGroup.list(self.api_client, name=aff_0.name)
+        self.delete_aff_group(self.api_client, name=aff_0.name)
+        self.assert_(AffinityGroup.list(self.api_client, name=aff_0.name) is None)
 
+    @attr(tags=["simulator", "basic", "advanced", "multihost"])
     def test_02_delete_aff_grp_for_acc(self):
         """
-            Delete Affinity Group for an account.
+            Delete Affinity Group as admin for an account
         """
 
-        self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
+        aff_0 = self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
                             acc=self.account.name, domainid=self.domain.id)
-        self.create_aff_grp(aff_grp=self.services["host_anti_affinity_1"],
+        aff_1 = self.create_aff_grp(aff_grp=self.services["host_anti_affinity_1"],
                             acc=self.account.name, domainid=self.domain.id)
 
-        AffinityGroup.delete(self.api_client, account=self.account.name,
-                             domainid=self.domain.id, name=self.aff_grp[0].name)
-
+        aff_0.delete(self.api_client)
         with self.assertRaises(Exception):
-            vm, hostid = self.create_vm_in_aff_grps([self.aff_grp[0].name])
-
-        AffinityGroup.delete(self.api_client, account=self.account.name,
-                             domainid=self.domain.id, name=self.aff_grp[1].name)
+            self.create_vm_in_aff_grps([aff_0.name])
+        aff_1.delete(self.api_client)
 
+    @attr(tags=["simulator", "basic", "advanced", "multihost"])
     def test_03_delete_aff_grp_with_vms(self):
         """
-            Delete Affinity Group which has vms in it.
+            Delete Affinity Group which has vms in it
         """
 
-        self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
+        aff_0 = self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
                             acc=self.account.name, domainid=self.domain.id)
-        self.create_aff_grp(aff_grp=self.services["host_anti_affinity_1"],
+        aff_1 = self.create_aff_grp(aff_grp=self.services["host_anti_affinity_1"],
                             acc=self.account.name, domainid=self.domain.id)
 
-        vm, hostid = self.create_vm_in_aff_grps([self.aff_grp[0].name,
-                                                 self.aff_grp[1].name])
-
-        AffinityGroup.delete(self.api_client, account=self.account.name,
-                             domainid=self.domain.id, name=self.aff_grp[0].name)
-
-        vm_list = list_virtual_machines(self.apiclient,
-                                                 id=self.virtual_machine.id)
-
-
+        vm, hostid = self.create_vm_in_aff_grps([aff_0.name, aff_1.name])
+        aff_0.delete(self.api_client)
+        vm_list = list_virtual_machines(self.apiclient, id=self.virtual_machine.id)
+        self.assert_(vm_list is not None)
         vm.delete(self.api_client)
         #Wait for expunge interval to cleanup VM
         wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
+        aff_1.delete(self.api_client)
 
-        AffinityGroup.delete(self.api_client, account=self.account.name,
-                             domainid=self.domain.id, name=self.aff_grp[0].name)
-        AffinityGroup.delete(self.api_client, account=self.account.name,
-                             domainid=self.domain.id, name=self.aff_grp[1].name)
-
+    @attr(tags=["simulator", "basic", "advanced", "multihost"])
     def test_04_delete_aff_grp_with_vms(self):
         """
-            Delete Affinity Group which has after updating affinity group for
-            vms in it.
+            Delete Affinity Group which has vms after updating affinity group for vms in it
         """
 
-        self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"])
+        aff_0 = self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"])
 
-        vm1, hostid1 = self.create_vm_in_aff_grps([self.aff_grp[0].name])
-        vm2, hostid2 = self.create_vm_in_aff_grps([self.aff_grp[0].name])
+        vm1, hostid1 = self.create_vm_in_aff_grps([aff_0.name])
+        vm2, hostid2 = self.create_vm_in_aff_grps([aff_0.name])
+        self.cleanup.extend([vm1, vm2])
 
         with self.assertRaises(Exception):
-            AffinityGroup.delete(self.api_client, name=self.aff_grp[0].name)
+            aff_0.delete(self.api_client)
 
         vm1.update_affinity_group(self.api_client, affinitygroupnames=[])
 
         with self.assertRaises(Exception):
-            AffinityGroup.delete(self.api_client, name=self.aff_grp[0].name)
+            aff_0.delete(self.api_client)
 
         vm2.update_affinity_group(self.api_client, affinitygroupnames=[])
 
-        AffinityGroup.delete(self.api_client, name=self.aff_grp[0].name)
-
-        vm1.delete(self.api_client)
-        vm2.delete(self.api_client)
-        #Wait for expunge interval to cleanup VM
-        wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
-
-        AffinityGroup.delete(self.api_client, name=self.aff_grp[1].name)
+        aff_0.delete(self.api_client)
 
+    @attr(tags=["simulator", "basic", "advanced", "multihost"])
     def test_05_delete_aff_grp_id(self):
         """
             Delete Affinity Group with id which does not belong to this user
@@ -686,7 +664,7 @@ class TestDeleteAffinityGroups(cloudstackTestCase):
                                        self.services["new_account"])
 
         self.cleanup.append(self.user1)
-        self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
+        aff_0 = self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
                             acc=self.user1.name,
                             domainid=self.domain.id)
 
@@ -698,20 +676,21 @@ class TestDeleteAffinityGroups(cloudstackTestCase):
                                         DomainName=self.user2.domain,
                                         acctType=0)
 
-        self.create_aff_grp(api_client=userapiclient,
+        aff_1 = self.create_aff_grp(api_client=userapiclient,
                             aff_grp=self.services["host_anti_affinity_1"])
 
         list_aff_grps = AffinityGroup.list(self.api_client,
-                                           name=self.aff_grp[0].name)
+                                           name=aff_0.name)
 
         # Delete Affinity group belonging to different user by id
         with self.assertRaises(Exception):
-            AffinityGroup.delete(userapiclient, name=list_aff_grps.id)
+            self.delete_aff_group(userapiclient, name=list_aff_grps.id)
 
         #Cleanup
-        AffinityGroup.delete(self.api_client, name=self.aff_grp[0].name)
-        AffinityGroup.delete(userapiclient, name=self.aff_grp[1].name)
+        aff_0.delete(self.api_client)
+        aff_1.delete(userapiclient)
 
+    @attr(tags=["simulator", "basic", "advanced", "multihost"])
     def test_06_delete_aff_grp_name(self):
         """
             Delete Affinity Group by name which does not belong to this user
@@ -721,7 +700,7 @@ class TestDeleteAffinityGroups(cloudstackTestCase):
                                        self.services["new_account"])
 
         self.cleanup.append(self.user1)
-        self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
+        aff_0 = self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
                             acc=self.user1.name,
                             domainid=self.domain.id)
 
@@ -733,16 +712,19 @@ class TestDeleteAffinityGroups(cloudstackTestCase):
                                         DomainName=self.user2.domain,
                                         acctType=0)
 
-        self.create_aff_grp(api_client=userapiclient,
+        aff_1 = self.create_aff_grp(api_client=userapiclient,
                             aff_grp=self.services["host_anti_affinity_1"])
 
+        list_aff_grps = AffinityGroup.list(self.api_client,
+                                           name=aff_0.name)
+
         # Delete Affinity group belonging to different user by name
         with self.assertRaises(Exception):
-            AffinityGroup.delete(userapiclient, name=self.aff_grp[0].name)
+            self.delete_aff_group(userapiclient, name=list_aff_grps.name)
 
         #Cleanup
-        AffinityGroup.delete(self.api_client, name=self.aff_grp[0].name)
-        AffinityGroup.delete(userapiclient, name=self.aff_grp[1].name)
+        aff_0.delete(self.api_client)
+        aff_1.delete(userapiclient)
 
 class TestUpdateVMAffinityGroups(cloudstackTestCase):
 
@@ -1424,8 +1406,7 @@ class TestAffinityGroupsAdminUser(cloudstackTestCase):
             self.services["host_anti_affinity_0"]
 
         try:
-            self.aff_grp.append(AffinityGroup.create(api_client,
-                                                     aff_grp, acc, domainid))
+            return AffinityGroup.create(api_client, aff_grp, acc, domainid)
         except Exception as e:
             raise Exception("Error: Creation of Affinity Group failed : %s" %e)
 
@@ -1440,7 +1421,7 @@ class TestAffinityGroupsAdminUser(cloudstackTestCase):
                templateid=self.template.id,
                serviceofferingid=self.service_offering.id,
                affinitygroupnames=ag_list,
-                affinitygroupids=ag_ids
+               affinitygroupids=ag_ids
             )
         self.debug('Created VM=%s in Affinity Group=%s' %
                    (vm.id, ag_list))
@@ -1461,7 +1442,7 @@ class TestAffinityGroupsAdminUser(cloudstackTestCase):
     @attr(tags=["simulator", "basic", "advanced", "multihost"])
     def test_01_deploy_vm_another_user(self):
         """
-            Deploy vm in Affinity Group belonging to regular user
+            Deploy vm as Admin in Affinity Group belonging to regular user (should fail)
         """
         self.user1 = Account.create(self.api_client,
                                        self.services["new_account"])
@@ -1472,35 +1453,33 @@ class TestAffinityGroupsAdminUser(cloudstackTestCase):
                                         DomainName=self.user1.domain,
                                         acctType=0)
 
-        self.create_aff_grp(api_client=userapiclient,
+        aff_grp = self.create_aff_grp(api_client=userapiclient,
                             aff_grp=self.services["host_anti_affinity_0"])
 
         with self.assertRaises(Exception):
-            vm1, hostid1 = self.create_vm_in_aff_grps(ag_list=[self.aff_grp[0].name])
+            self.create_vm_in_aff_grps(api_client=self.apiclient, ag_list=[self.aff_grp[0].name])
 
-        AffinityGroup.delete(userapiclient, self.aff_grp[0].name)
+        aff_grp.delete(userapiclient)
 
     @attr(tags=["simulator", "basic", "advanced", "multihost"])
     def test_02_create_aff_grp_user(self):
         """
-            Create Affinity Group for regular user
+            Create Affinity Group as admin for regular user
         """
 
         self.user = Account.create(self.api_client, self.services["new_account"],
                                   domainid=self.domain.id)
 
         self.cleanup.append(self.user)
-        self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
+        aff_grp = self.create_aff_grp(aff_grp=self.services["host_anti_affinity_0"],
                             acc=self.user.name, domainid=self.domain.id)
+        aff_grp.delete(self.apiclient)
 
-        AffinityGroup.delete(self.api_client, name=self.aff_grp[0].name,
-                             account=self.user.name, domainid=self.domain.id)
-        self.debug("Deleted Affinity Group: %s" %self.aff_grp[0].name)
 
     @attr(tags=["simulator", "basic", "advanced", "multihost"])
     def test_03_list_aff_grp_all_users(self):
         """
-            List Affinity Groups for all the users
+            List Affinity Groups as admin for all the users
         """
 
         self.user1 = Account.create(self.api_client,
@@ -1512,11 +1491,10 @@ class TestAffinityGroupsAdminUser(cloudstackTestCase):
                                         DomainName=self.user1.domain,
                                         acctType=0)
 
-        self.create_aff_grp(api_client=userapiclient,
+        aff_grp = self.create_aff_grp(api_client=userapiclient,
                             aff_grp=self.services["host_anti_affinity_0"])
 
         list_aff_grps = AffinityGroup.list(self.api_client)
-        print list_aff_grps
         self.assertNotEqual(list_aff_grps, [], "Admin not able to list Affinity "
                          "Groups of users")
-        AffinityGroup.delete(userapiclient, self.aff_grp[0].name)
+        aff_grp.delete(userapiclient)

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/23e77537/tools/marvin/marvin/cloudstackTestClient.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/cloudstackTestClient.py b/tools/marvin/marvin/cloudstackTestClient.py
index eba53a1..f8c13d4 100644
--- a/tools/marvin/marvin/cloudstackTestClient.py
+++ b/tools/marvin/marvin/cloudstackTestClient.py
@@ -94,10 +94,6 @@ class cloudstackTestClient(object):
             domain = self.apiClient.createDomain(cdomain)
             domId = domain.id
 
-        mdf = hashlib.md5()
-        mdf.update("password")
-        mdf_pass = mdf.hexdigest()
-
         cmd = listAccounts.listAccountsCmd()
         cmd.name = UserName
         cmd.domainid = domId
@@ -112,7 +108,7 @@ class cloudstackTestClient(object):
                 + "@cloudstack.org"
             createAcctCmd.firstname = UserName
             createAcctCmd.lastname = UserName
-            createAcctCmd.password = mdf_pass
+            createAcctCmd.password = 'password'
             createAcctCmd.username = UserName
             acct = self.apiClient.createAccount(createAcctCmd)
             acctId = acct.id

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/23e77537/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 0f6fdc5..8d9a25d 100755
--- a/tools/marvin/marvin/integration/lib/base.py
+++ b/tools/marvin/marvin/integration/lib/base.py
@@ -3011,19 +3011,9 @@ class AffinityGroup:
     def update(self, apiclient):
         pass
 
-    @classmethod
-    def delete(cls, apiclient, name=None, id=None, account=None,
-               domainid=None):
+    def delete(self, apiclient):
         cmd = deleteAffinityGroup.deleteAffinityGroupCmd()
-        if id is not None:
-            cmd.id = id
-        if name is not None:
-            cmd.name = name
-        if account is not None:
-            cmd.account = account
-        if domainid is not None:
-            cmd.domainid = domainid
-
+        cmd.id = self.id
         return apiclient.deleteAffinityGroup(cmd)
 
     @classmethod