diff --git a/test/integration/component/test_affinity_groups.py b/test/integration/component/test_affinity_groups.py index c41049b4471..f8677ec9291 100644 --- a/test/integration/component/test_affinity_groups.py +++ b/test/integration/component/test_affinity_groups.py @@ -9,7 +9,7 @@ # # http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, +# Unless required byswa 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 @@ -112,6 +112,7 @@ class TestCreateAffinityGroup(cloudstackTestCase): ) cls.services["account"] = cls.account.name + cls.services["domainid"] = cls.domain.id cls.service_offering = ServiceOffering.create( cls.api_client, @@ -202,7 +203,8 @@ class TestCreateAffinityGroup(cloudstackTestCase): acc=self.do_admin.name, domainid=self.new_domain.id) aff_grp.delete(domainapiclient) - @attr(tags=["simulator", "basic", "advanced"]) + #@attr(tags=["simulator", "basic", "advanced"]) + @attr(tags=["vogxn", "simulator", "basic", "advanced"]) def test_03_user_create_aff_grp(self): """ Test create affinity group as user @@ -304,6 +306,7 @@ class TestListAffinityGroups(cloudstackTestCase): ) cls.services["account"] = cls.account.name + cls.services["domainid"] = cls.domain.id cls.service_offering = ServiceOffering.create( cls.api_client, @@ -359,11 +362,18 @@ class TestListAffinityGroups(cloudstackTestCase): except Exception as e: raise Exception("Error: Creation of Affinity Group failed : %s" %e) - def create_vm_in_aff_grps(self, ag_list): + def create_vm_in_aff_grps(self, ag_list, account_name=None, domain_id=None): + if account_name == None: + account_name = "admin" + if domain_id == None: + domain_id = self.domain.id + self.debug('Creating VM in AffinityGroup=%s' % ag_list[0]) vm = VirtualMachine.create( self.api_client, self.services["virtual_machine"], + accountid=account_name, + domainid=domain_id, templateid=self.template.id, serviceofferingid=self.service_offering.id, affinitygroupnames=ag_list @@ -387,10 +397,10 @@ class TestListAffinityGroups(cloudstackTestCase): List affinity group for a vm """ - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) list_aff_grps = AffinityGroup.list(self.api_client) - vm, hostid = self.create_vm_in_aff_grps([self.aff_grp[0].name]) + vm, hostid = self.create_vm_in_aff_grps([self.aff_grp[0].name], account_name=self.account.name, domain_id=self.domain.id) list_aff_grps = AffinityGroup.list(self.api_client, virtualmachineid=vm.id) @@ -409,11 +419,11 @@ class TestListAffinityGroups(cloudstackTestCase): List multiple affinity groups associated with a vm """ - aff_grp_01 = self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) - aff_grp_02 = self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) + aff_grp_01 = self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) + aff_grp_02 = self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) aff_grps_names = [self.aff_grp[0].name, self.aff_grp[1].name] - vm, hostid = self.create_vm_in_aff_grps(aff_grps_names) + vm, hostid = self.create_vm_in_aff_grps(aff_grps_names, account_name=self.account.name, domain_id=self.domain.id) list_aff_grps = AffinityGroup.list(self.api_client, virtualmachineid=vm.id) @@ -495,9 +505,9 @@ class TestListAffinityGroups(cloudstackTestCase): List affinity group should list all for a vms associated with that group """ - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) - vm, hostid = self.create_vm_in_aff_grps([self.aff_grp[0].name]) + vm, hostid = self.create_vm_in_aff_grps([self.aff_grp[0].name], account_name=self.account.name, domain_id=self.domain.id) list_aff_grps = AffinityGroup.list(self.api_client, id=self.aff_grp[0].id) self.assertEqual(list_aff_grps[0].name, self.aff_grp[0].name, @@ -542,6 +552,7 @@ class TestDeleteAffinityGroups(cloudstackTestCase): ) cls.services["account"] = cls.account.name + cls.services["domainid"] = cls.domain.id cls.service_offering = ServiceOffering.create( cls.api_client, @@ -595,11 +606,17 @@ class TestDeleteAffinityGroups(cloudstackTestCase): except Exception as e: raise Exception("Error: Creation of Affinity Group failed : %s" %e) - def create_vm_in_aff_grps(self, ag_list): + def create_vm_in_aff_grps(self, ag_list, account_name=None, domain_id=None): + if account_name == None: + account_name = "admin" + if domain_id == None: + domain_id = self.domain.id self.debug('Creating VM in AffinityGroup=%s' % ag_list[0]) vm = VirtualMachine.create( self.api_client, self.services["virtual_machine"], + accountid=account_name, + domainid=domain_id, templateid=self.template.id, serviceofferingid=self.service_offering.id, affinitygroupnames=ag_list @@ -649,7 +666,7 @@ class TestDeleteAffinityGroups(cloudstackTestCase): aff_0.delete(self.api_client) with self.assertRaises(Exception): - self.create_vm_in_aff_grps([aff_0.name]) + self.create_vm_in_aff_grps([aff_0.name], account_name=self.account.name, domain_id=self.domain.id) aff_1.delete(self.api_client) @attr(tags=["simulator", "basic", "advanced", "multihost"]) @@ -658,10 +675,10 @@ class TestDeleteAffinityGroups(cloudstackTestCase): Delete Affinity Group which has vms in it """ - aff_0 = self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) - aff_1 = self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) + aff_0 = self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) + aff_1 = self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) - vm, hostid = self.create_vm_in_aff_grps([aff_0.name, aff_1.name]) + vm, hostid = self.create_vm_in_aff_grps([aff_0.name, aff_1.name], account_name=self.account.name, domain_id=self.domain.id) aff_0.delete(self.api_client) vm_list = list_virtual_machines(self.apiclient, id=vm.id) self.assert_(vm_list is not None) @@ -805,6 +822,7 @@ class TestUpdateVMAffinityGroups(cloudstackTestCase): ) cls.services["account"] = cls.account.name + cls.services["domainid"] = cls.domain.id cls.service_offering = ServiceOffering.create( cls.api_client, @@ -859,13 +877,18 @@ class TestUpdateVMAffinityGroups(cloudstackTestCase): except Exception as e: raise Exception("Error: Creation of Affinity Group failed : %s" %e) - def create_vm_in_aff_grps(self, ag_list): - + def create_vm_in_aff_grps(self, ag_list, account_name=None, domain_id=None): + if account_name == None: + account_name = "admin" + if domain_id == None: + domain_id = self.domain.id self.debug('Creating VM in AffinityGroup=%s' % ag_list) vm = VirtualMachine.create( self.api_client, self.services["virtual_machine"], + accountid=account_name, + domainid=domain_id, templateid=self.template.id, serviceofferingid=self.service_offering.id, affinitygroupnames=ag_list @@ -892,15 +915,15 @@ class TestUpdateVMAffinityGroups(cloudstackTestCase): Update the list of affinityGroups by using affinity groupids """ - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) - 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([self.aff_grp[0].name], account_name=self.account.name, domain_id=self.domain.id) + vm2, hostid2 = self.create_vm_in_aff_grps([self.aff_grp[0].name], account_name=self.account.name, domain_id=self.domain.id) vm1.stop(self.api_client) - list_aff_grps = AffinityGroup.list(self.api_client) + list_aff_grps = AffinityGroup.list(self.api_client, account=self.account.name, domainid=self.domain.id) self.assertEqual(len(list_aff_grps), 2 , "2 affinity groups should be present") @@ -940,10 +963,10 @@ class TestUpdateVMAffinityGroups(cloudstackTestCase): Update the list of affinityGroups by using affinity groupnames """ - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) - 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]) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) + vm1, hostid1 = self.create_vm_in_aff_grps([self.aff_grp[0].name], account_name=self.account.name, domain_id=self.domain.id) + vm2, hostid2 = self.create_vm_in_aff_grps([self.aff_grp[0].name], account_name=self.account.name, domain_id=self.domain.id) vm1.stop(self.api_client) @@ -984,10 +1007,10 @@ class TestUpdateVMAffinityGroups(cloudstackTestCase): with any affinity groups. """ - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) - vm1, hostid1 = self.create_vm_in_aff_grps([]) - vm2, hostid2 = self.create_vm_in_aff_grps([self.aff_grp[0].name]) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) + vm1, hostid1 = self.create_vm_in_aff_grps([], account_name=self.account.name, domain_id=self.domain.id) + vm2, hostid2 = self.create_vm_in_aff_grps([self.aff_grp[0].name], account_name=self.account.name, domain_id=self.domain.id) vm1.stop(self.api_client) @@ -1018,7 +1041,7 @@ class TestUpdateVMAffinityGroups(cloudstackTestCase): self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) - vm1, hostid1 = self.create_vm_in_aff_grps([self.aff_grp[0].name]) + vm1, hostid1 = self.create_vm_in_aff_grps([self.aff_grp[0].name], account_name=self.account.name, domain_id=self.domain.id) aff_grps = [self.aff_grp[0], self.aff_grp[1]] vm1.stop(self.api_client) @@ -1042,9 +1065,9 @@ class TestUpdateVMAffinityGroups(cloudstackTestCase): Update the list of Affinity Groups on running vm """ - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) - vm1, hostid1 = self.create_vm_in_aff_grps([self.aff_grp[0].name]) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) + vm1, hostid1 = self.create_vm_in_aff_grps([self.aff_grp[0].name], account_name=self.account.name, domain_id=self.domain.id) aff_grps = [self.aff_grp[0], self.aff_grp[1]] with self.assertRaises(Exception): @@ -1083,6 +1106,7 @@ class TestDeployVMAffinityGroups(cloudstackTestCase): ) cls.services["account"] = cls.account.name + cls.services["domainid"] = cls.domain.id cls.service_offering = ServiceOffering.create( cls.api_client, @@ -1137,14 +1161,19 @@ class TestDeployVMAffinityGroups(cloudstackTestCase): except Exception as e: raise Exception("Error: Creation of Affinity Group failed : %s" %e) - def create_vm_in_aff_grps(self, api_client=None, ag_list=None, ag_ids=None): - + def create_vm_in_aff_grps(self, api_client=None, ag_list=None, ag_ids=None, account_name=None, domain_id=None): + if account_name == None: + account_name = "admin" + if domain_id == None: + domain_id = self.domain.id if api_client == None: api_client = self.api_client self.debug('Creating VM in AffinityGroup=%s' % ag_list) vm = VirtualMachine.create( api_client, self.services["virtual_machine"], + accountid=account_name, + domainid=domain_id, templateid=self.template.id, serviceofferingid=self.service_offering.id, affinitygroupnames=ag_list, @@ -1171,7 +1200,7 @@ class TestDeployVMAffinityGroups(cloudstackTestCase): """ Deploy VM without affinity group """ - vm1, hostid1 = self.create_vm_in_aff_grps() + vm1, hostid1 = self.create_vm_in_aff_grps(account_name=self.account.name, domain_id=self.domain.id) vm1.delete(self.api_client) #Wait for expunge interval to cleanup VM @@ -1182,8 +1211,8 @@ class TestDeployVMAffinityGroups(cloudstackTestCase): """ Deploy VM by aff grp name """ - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) - vm1, hostid1 = self.create_vm_in_aff_grps(ag_list=[self.aff_grp[0].name]) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) + vm1, hostid1 = self.create_vm_in_aff_grps(ag_list=[self.aff_grp[0].name], account_name=self.account.name, domain_id=self.domain.id) vm1.delete(self.api_client) wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"]) @@ -1194,12 +1223,12 @@ class TestDeployVMAffinityGroups(cloudstackTestCase): """ Deploy VM by aff grp id """ - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) list_aff_grps = AffinityGroup.list(self.api_client, - name=self.aff_grp[0].name) + name=self.aff_grp[0].name, account=self.account.name, domainid=self.domain.id) - vm1, hostid1 = self.create_vm_in_aff_grps(ag_ids=[list_aff_grps[0].id]) + vm1, hostid1 = self.create_vm_in_aff_grps(ag_ids=[list_aff_grps[0].id], account_name=self.account.name, domain_id=self.domain.id) vm1.delete(self.api_client) wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"]) @@ -1213,9 +1242,9 @@ class TestDeployVMAffinityGroups(cloudstackTestCase): deploy VM1 and VM2 in the same host-anti-affinity groups Verify that the vms are deployed on separate hosts """ - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) - vm1, hostid1 = self.create_vm_in_aff_grps(ag_list=[self.aff_grp[0].name]) - vm2, hostid2 = self.create_vm_in_aff_grps(ag_list=[self.aff_grp[0].name]) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) + vm1, hostid1 = self.create_vm_in_aff_grps(ag_list=[self.aff_grp[0].name], account_name=self.account.name, domain_id=self.domain.id) + vm2, hostid2 = self.create_vm_in_aff_grps(ag_list=[self.aff_grp[0].name], account_name=self.account.name, domain_id=self.domain.id) self.assertNotEqual(hostid1, hostid2, msg="Both VMs of affinity group %s are on the same host" @@ -1231,13 +1260,13 @@ class TestDeployVMAffinityGroups(cloudstackTestCase): """ Deploy vms by affinity group id """ - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) list_aff_grps = AffinityGroup.list(self.api_client, - name=self.aff_grp[0].name) + name=self.aff_grp[0].name, acc=self.account.name, domainid=self.domain.id) - vm1, hostid1 = self.create_vm_in_aff_grps(ag_ids=[list_aff_grps[0].id]) - vm2, hostid2 = self.create_vm_in_aff_grps(ag_ids=[list_aff_grps[0].id]) + vm1, hostid1 = self.create_vm_in_aff_grps(ag_ids=[list_aff_grps[0].id], account_name=self.account.name, domain_id=self.domain.id) + vm2, hostid2 = self.create_vm_in_aff_grps(ag_ids=[list_aff_grps[0].id], account_name=self.account.name, domain_id=self.domain.id) self.assertNotEqual(hostid1, hostid2, msg="Both VMs of affinity group %s are on the same host" @@ -1275,7 +1304,7 @@ class TestDeployVMAffinityGroups(cloudstackTestCase): with self.assertRaises(Exception): vm1, hostid1 = self.create_vm_in_aff_grps(api_client=userapiclient, - ag_list=[self.aff_grp[0].name]) + ag_list=[self.aff_grp[0].name], account_name=self.account.name, domain_id=self.domain.id) self.aff_grp[0].delete(self.api_client) @@ -1312,7 +1341,7 @@ class TestDeployVMAffinityGroups(cloudstackTestCase): # Deploy VM in Affinity group belonging to different user by id with self.assertRaises(Exception): vm1, hostid1 = self.create_vm_in_aff_grps(api_client=userapiclient, - ag_ids=[list_aff_grps[0].id]) + ag_ids=[list_aff_grps[0].id], account_name=self.account.name, domain_id=self.domain.id) self.aff_grp[0].delete(self.api_client) self.aff_grp[1].delete(userapiclient) @@ -1323,11 +1352,11 @@ class TestDeployVMAffinityGroups(cloudstackTestCase): Deploy vm in multiple affinity groups """ - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) vm1, hostid1 = self.create_vm_in_aff_grps(ag_list=[self.aff_grp[0].name, - self.aff_grp[1].name]) + self.aff_grp[1].name], account_name=self.account.name, domain_id=self.domain.id) list_aff_grps = AffinityGroup.list(self.api_client, virtualmachineid=vm1.id) @@ -1352,13 +1381,13 @@ class TestDeployVMAffinityGroups(cloudstackTestCase): Deploy multiple vms in multiple affinity groups """ - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) vm1, hostid1 = self.create_vm_in_aff_grps(ag_list=[self.aff_grp[0].name, - self.aff_grp[1].name]) + self.aff_grp[1].name], account_name=self.account.name, domain_id=self.domain.id) vm2, hostid2 = self.create_vm_in_aff_grps(ag_list=[self.aff_grp[0].name, - self.aff_grp[1].name]) + self.aff_grp[1].name], account_name=self.account.name, domain_id=self.domain.id) aff_grps_names = [self.aff_grp[0].name, self.aff_grp[1].name] aff_grps_names.sort() @@ -1387,14 +1416,14 @@ class TestDeployVMAffinityGroups(cloudstackTestCase): Deploy VM by aff grp name and id """ - self.create_aff_grp(aff_grp=self.services["host_anti_affinity"]) + self.create_aff_grp(aff_grp=self.services["host_anti_affinity"], acc=self.account.name, domainid=self.domain.id) list_aff_grps = AffinityGroup.list(self.api_client, name=self.aff_grp[0].name) with self.assertRaises(Exception): vm1, hostid1 = self.create_vm_in_aff_grps(ag_list=[self.aff_grp[0].name], - ag_ids=[list_aff_grps[0].id]) + ag_ids=[list_aff_grps[0].id], account_name=self.account.name, domain_id=self.domain.id) self.aff_grp[0].delete(self.api_client) @@ -1425,6 +1454,7 @@ class TestAffinityGroupsAdminUser(cloudstackTestCase): ) cls.services["account"] = cls.account.name + cls.services["domainid"] = cls.domain.id cls.service_offering = ServiceOffering.create( cls.api_client, @@ -1478,8 +1508,11 @@ class TestAffinityGroupsAdminUser(cloudstackTestCase): except Exception as e: raise Exception("Error: Creation of Affinity Group failed : %s" %e) - def create_vm_in_aff_grps(self, api_client=None, ag_list=None, ag_ids=None): - + def create_vm_in_aff_grps(self, api_client=None, ag_list=None, ag_ids=None, account_name=None, domain_id=None): + if account_name == None: + account_name = "admin" + if domain_id == None: + domain_id = self.domain.id if api_client == None: api_client = self.api_client self.debug('Creating VM in AffinityGroup=%s' % ag_list) @@ -1530,6 +1563,7 @@ class TestAffinityGroupsAdminUser(cloudstackTestCase): aff_grp.delete(userapiclient) @attr(tags=["simulator", "basic", "advanced", "multihost"]) + def test_02_create_aff_grp_user(self): """ Create Affinity Group as admin for regular user @@ -1692,4 +1726,4 @@ class TestAffinityGroupsAdminUser(cloudstackTestCase): %(aff_grp.name, aff_grp_by_id[0].name ) ) - aff_grp.delete(self.api_client) \ No newline at end of file + aff_grp.delete(self.api_client)