コード例 #1
0
 def test_04_list_aff_grps_by_name(self):
     """
        List Affinity Groups by name for projects
     """
     aff_grp = self.create_aff_grp(self.account_api_client)
     list_aff_grps = AffinityGroup.list(self.account_api_client, name=aff_grp.name, projectid=self.project.id)
     self.assertEqual(list_aff_grps[0].name, aff_grp.name,"Listing Affinity Group by name failed")
     with self.assertRaises(Exception):
        AffinityGroup.list(self.account_not_in_project_api_client, id=aff_grp.id, projectid=self.project.id)
     self.cleanup.append(aff_grp)
コード例 #2
0
 def test_05_list_aff_grps_by_non_existing_id(self):
     """
        List Affinity Groups by non-existing id for projects
     """
     aff_grp = self.create_aff_grp(self.account_api_client)
     list_aff_grps = AffinityGroup.list(self.account_api_client, id=1234, projectid=self.project.id)
     self.assertEqual(list_aff_grps, None, "Listing Affinity Group by non-existing id succeeded.")
     self.cleanup.append(aff_grp)
コード例 #3
0
    def test_06_list_aff_grps_by_non_existing_name(self):
        """
           List Affinity Groups by non-existing name for projects
        """

        aff_grp = self.create_aff_grp(self.account_api_client)
        list_aff_grps = AffinityGroup.list(self.account_api_client, name="inexistantName", projectid=self.project.id)
        self.assertEqual(list_aff_grps, None, "Listing Affinity Group by non-existing name succeeded.")
        self.cleanup.append(aff_grp)
コード例 #4
0
 def test_03_user_create_aff_grp_for_project(self):
     """
     Test create affinity group as user for projects
     @return:
     """
     aff_grp = self.create_aff_grp(api_client=self.account_api_client)
     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.assert_(list_aff_grps[0].projectid == self.project.id)
     self.cleanup.append(aff_grp)
コード例 #5
0
 def test_01_admin_create_aff_grp_for_project(self):
    """
    Test create affinity group as admin in project
    @return:
    """
    aff_grp = self.create_aff_grp()
    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.assert_(list_aff_grps[0].projectid == self.project.id)
    self.cleanup.append(aff_grp)
コード例 #6
0
    def test_01_update_aff_grp_by_ids(self):
        """
           Update the list of affinityGroups by using affinity groupids

        """
        aff_grp1 = self.create_aff_grp(self.account_api_client)
        aff_grp2 = self.create_aff_grp(self.account_api_client)

        vm1, hostid1 = self.create_vm_in_aff_grps(ag_list=[aff_grp1.name])
        vm2, hostid2 = self.create_vm_in_aff_grps(ag_list=[aff_grp1.name])

        vm1.stop(self.api_client)

        list_aff_grps = AffinityGroup.list(self.api_client, projectid=self.project.id)

        self.assertEqual(len(list_aff_grps), 2 , "2 affinity groups should be present")

        vm1.update_affinity_group(self.api_client,affinitygroupids=[list_aff_grps[0].id,list_aff_grps[1].id])

        list_aff_grps = AffinityGroup.list(self.api_client,virtualmachineid=vm1.id)

        list_aff_grps_names = [list_aff_grps[0].name, list_aff_grps[1].name]

        aff_grps_names = [aff_grp1.name, aff_grp2.name]
        aff_grps_names.sort()
        list_aff_grps_names.sort()
        self.assertEqual(aff_grps_names, list_aff_grps_names,"One of the Affinity Groups is missing %s" % list_aff_grps_names)

        vm1.start(self.api_client)

        vm_status = VirtualMachine.list(self.api_client, id=vm1.id)
        self.assertNotEqual(vm_status[0].hostid, hostid2, "The virtual machine started on host %s violating the host anti-affinity rule" %vm_status[0].hostid)

        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"])
        aff_grp1.delete(self.api_client)
        aff_grp2.delete(self.api_client)
コード例 #7
0
    def test_01_delete_aff_grp_by_id(self):
        """
           #Delete Affinity Group by id.
        """

        aff_grp1 = self.create_aff_grp(self.account_api_client)
        aff_grp2 = self.create_aff_grp(self.account_api_client)

        aff_grp1.delete(self.account_api_client)
        
        with self.assertRaises(Exception):
           list_aff_grps = AffinityGroup.list(self.api_client, id=aff_grp1.id)
        
        self.cleanup.append(aff_grp2)
コード例 #8
0
    def test_01_list_aff_grps_for_vm(self):
        """
          List affinity group for a vm for projects
        """
        aff_grps = []
        aff_grps.append(self.create_aff_grp(self.domain_api_client, projectid=self.project.id))

        vm, hostid = self.create_vm_in_aff_grps(self.account_api_client,ag_list=[aff_grps[0].name])
        list_aff_grps = AffinityGroup.list(self.api_client,virtualmachineid=vm.id)

        self.assertEqual(list_aff_grps[0].name, aff_grps[0].name,"Listing Affinity Group by VM id failed")
        self.assertEqual(list_aff_grps[0].projectid, self.project.id,"Listing Affinity Group by VM id failed, vm was not in project")

        vm.delete(self.api_client)
        #Wait for expunge interval to cleanup VM
        wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
        self.cleanup.append(aff_grps[0])
コード例 #9
0
    def test_07_list_all_vms_in_aff_grp(self):
        """
          List affinity group should list all for a vms associated with that group for projects
        """

        aff_grp = self.create_aff_grp(self.account_api_client)

        vm1, hostid1 = self.create_vm_in_aff_grps(ag_list=[aff_grp.name])
        vm2, hostid2 = self.create_vm_in_aff_grps(ag_list=[aff_grp.name])
        list_aff_grps = AffinityGroup.list(self.api_client, id=aff_grp.id, projectid=self.project.id)

        self.assertEqual(list_aff_grps[0].name, aff_grp.name, "Listing Affinity Group by id failed")

        self.assertEqual(list_aff_grps[0].virtualmachineIds[0], vm1.id, "List affinity group response.virtualmachineIds for group: %s doesn't contain vmid : %s" % (aff_grp.name, vm1.id))
        self.assertEqual(list_aff_grps[0].virtualmachineIds[1], vm2.id, "List affinity group response.virtualmachineIds for group: %s doesn't contain vmid : %s" % (aff_grp.name, vm2.id))


        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"])
        self.cleanup.append(aff_grp)
コード例 #10
0
    def test_02_list_multiple_aff_grps_for_vm(self):
        """
          List multiple affinity groups associated with a vm for projects
        """

        aff_grp_01 = self.create_aff_grp(self.account_api_client)
        aff_grp_02 = self.create_aff_grp(self.account_api_client)

        aff_grps_names = [aff_grp_01.name, aff_grp_02.name]
        vm, hostid = self.create_vm_in_aff_grps(ag_list=aff_grps_names)
        list_aff_grps = AffinityGroup.list(self.api_client,
                                    virtualmachineid=vm.id)

        list_aff_grps_names = [list_aff_grps[0].name, list_aff_grps[1].name]

        aff_grps_names.sort()
        list_aff_grps_names.sort()
        self.assertEqual(aff_grps_names, list_aff_grps_names,"One of the Affinity Groups is missing %s" % list_aff_grps_names)

        vm.delete(self.api_client)
        #Wait for expunge interval to cleanup VM
        wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
        self.cleanup.append(aff_grp_01)
        self.cleanup.append(aff_grp_02)
コード例 #11
0
    def test_01_list_aff_grps_for_vm(self):
        """
          List affinity group for a vm for projects
        """
        aff_grps = []
        aff_grps.append(
            self.create_aff_grp(self.domain_api_client,
                                projectid=self.project.id))

        vm, hostid = self.create_vm_in_aff_grps(self.account_api_client,
                                                ag_list=[aff_grps[0].name])
        list_aff_grps = AffinityGroup.list(self.api_client,
                                           virtualmachineid=vm.id)

        self.assertEqual(list_aff_grps[0].name, aff_grps[0].name,
                         "Listing Affinity Group by VM id failed")
        self.assertEqual(
            list_aff_grps[0].projectid, self.project.id,
            "Listing Affinity Group by VM id failed, vm was not in project")

        vm.delete(self.api_client)
        #Wait for expunge interval to cleanup VM
        wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])
        self.cleanup.append(aff_grps[0])
コード例 #12
0
    def test_01_deploy_vm_with_explicit_dedication(self):
        """Test explicit dedication is placing vms of an account on dedicated hosts.
        """
        # Validate the following
        # 1. Find and dedicate an empty host to an account.
        # 2. Create a vm deployment by passing the affinity group as a
        #    parameter.
        # 3. Validate the vm got deployed on the dedicated host.
        # 4. Cleanup.

        # list and find an empty hosts
        all_hosts = list_hosts(
            self.apiclient,
            type='Routing',
        )

        empty_host = None
        for host in all_hosts:
            vms_on_host = list_virtual_machines(self.api_client,
                                                hostid=host.id)
            if not vms_on_host:
                empty_host = host
                break

        # If no empty host is found, return
        if empty_host is None:
            self.skipTest("Did not find any empty hosts, Skipping")

        # dedicate the empty host to this account.
        dedicateCmd = dedicateHost.dedicateHostCmd()
        dedicateCmd.hostid = empty_host.id
        dedicateCmd.domainid = self.domain.id
        self.api_client.dedicateHost(dedicateCmd)
        affinitygroup = AffinityGroup.list(self.apiclient,
                                           type="ExplicitDedication")

        # deploy vm on the dedicated resource.
        vm = VirtualMachine.create(self.api_client,
                                   self.services["small"],
                                   accountid=self.account.name,
                                   domainid=self.account.domainid,
                                   serviceofferingid=self.small_offering.id,
                                   affinitygroupids=affinitygroup[0].id,
                                   mode=self.services["mode"])

        list_vm_response = list_virtual_machines(self.apiclient, id=vm.id)

        vm_response = list_vm_response[0]

        self.assertEqual(vm_response.hostid, empty_host.id,
                         "Check destination hostID of deployed VM")

        # release the dedicated host to this account.
        releaseCmd = releaseDedicatedHost.releaseDedicatedHostCmd()
        releaseCmd.hostid = empty_host.id
        releaseCmd.domainid = self.domain.id
        self.apiclient.releaseDedicatedHost(releaseCmd)

        # Deletion of the created VM and affinity group is taken care as part
        # of account clean

        return
コード例 #13
0
    def test_01_deploy_vm_with_explicit_dedication(self):
        """Test explicit dedication is placing vms of an account on dedicated hosts.
        """
        # Validate the following
        # 1. Find and dedicate an empty host to an account.
        # 2. Create a vm deployment by passing the affinity group as a
        #    parameter.
        # 3. Validate the vm got deployed on the dedicated host.
        # 4. Cleanup.

        # list and find an empty hosts
        all_hosts = list_hosts(
            self.apiclient,
            type='Routing',
        )

        empty_host = None
        for host in all_hosts:
            vms_on_host = list_virtual_machines(
                self.api_client,
                hostid=host.id)
            if not vms_on_host:
                empty_host = host
                break

        # If no empty host is found, return
        if empty_host is None:
            self.skipTest("Did not find any empty hosts, Skipping")

        # dedicate the empty host to this account.
        dedicateCmd = dedicateHost.dedicateHostCmd()
        dedicateCmd.hostid = empty_host.id
        dedicateCmd.domainid = self.domain.id
        self.api_client.dedicateHost(dedicateCmd)
        affinitygroup = AffinityGroup.list(
            self.apiclient,
            type="ExplicitDedication")

        # deploy vm on the dedicated resource.
        vm = VirtualMachine.create(
            self.api_client,
            self.services["small"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.small_offering.id,
            affinitygroupids=affinitygroup[0].id,
            mode=self.services["mode"]
        )

        list_vm_response = list_virtual_machines(
            self.apiclient,
            id=vm.id
        )

        vm_response = list_vm_response[0]

        self.assertEqual(
            vm_response.hostid,
            empty_host.id,
            "Check destination hostID of deployed VM"
        )

        # release the dedicated host to this account.
        releaseCmd = releaseDedicatedHost.releaseDedicatedHostCmd()
        releaseCmd.hostid = empty_host.id
        releaseCmd.domainid = self.domain.id
        self.apiclient.releaseDedicatedHost(releaseCmd)

        # Deletion of the created VM and affinity group is taken care as part
        # of account clean

        return