Ejemplo n.º 1
0
    def test_validateState_succeeds_at_retry_limit(self):
        retries = 3
        timeout = 3
        api_client = MockApiClient(retries, 'initial state', 'final state')
        host = Host({'id': 'host_id'})
        state = host.validateState(api_client, ['final state', 'final state'],
                                   timeout=timeout,
                                   interval=1)

        self.assertEqual(state, [PASS, None])
        self.assertEqual(retries, api_client.retry_counter)
Ejemplo n.º 2
0
    def test_validateState_fails_after_retry_limit(self):
        retries = 3
        timeout = 2
        api_client = MockApiClient(retries, 'initial state', 'final state')
        host = Host({'id': 'host_id'})
        state = host.validateState(api_client, ['final state', 'final state'],
                                   timeout=timeout,
                                   interval=1)

        self.assertEqual(state, [
            FAIL,
            "Host state not trasited to %s, operation timed out" %
            ['final state', 'final state']
        ])
        self.assertEqual(retries, api_client.retry_counter)
    def _get_unique_vag_ids(self, hosts):
        all_vags = sf_util.get_all_vags(self.sfe)

        unique_vag_ids = []

        for host in hosts:
            host = Host(host.__dict__)

            host_iqn = self._get_host_iqn(host)

            host_vag = self._get_host_vag(host_iqn, all_vags)

            if host_vag != None and host_vag.volume_access_group_id not in unique_vag_ids:
                unique_vag_ids.append(host_vag.volume_access_group_id)

        return unique_vag_ids
Ejemplo n.º 4
0
    hosts = Host.list(apiClient)
    if hosts:
      for host in hosts:
        print "host name={}, id={}".format(host.name, host.id)
        if host.type == 'Routing':
          if host.resourcestate == 'PrepareForMaintenance' \
              or host.resourcestate == 'Maintenance':
            print "delete host"
            cmd = deleteHost.deleteHostCmd()
            cmd.id = host.id
#            cmd.forced = 'True'
            apiClient.deleteHost(cmd)
          else:
            print "Delete host"
            h = Host(tmp_dict)
#            h.forced = 'True'
            h.id = host.id
            h.delete(apiClient)

    clusters = Cluster.list(apiClient)
    if clusters:
      for cluster in clusters:
        print "cluster name={}, id={}".format(cluster.name, cluster.id)
        if cluster.allocationstate == 'Enabled':
          print "Delete Cluster"
          c = Cluster(tmp_dict)
          c.id = cluster.id
          c.delete(apiClient)

    ipranges = PublicIpRange.list(apiClient)
    def test_vag_per_host_5(self):
        hosts = list_hosts(self.apiClient, clusterid=self.cluster.id)

        self.assertTrue(
            len(hosts) >= 2, "There needs to be at least two hosts.")

        unique_vag_ids = self._get_unique_vag_ids(hosts)

        self.assertTrue(
            len(hosts) == len(unique_vag_ids),
            "To run this test, each host should be in its own VAG.")

        primarystorage = self.testdata[TestData.primaryStorage]

        primary_storage = StoragePool.create(
            self.apiClient,
            primarystorage,
            scope=primarystorage[TestData.scope],
            zoneid=self.zone.id,
            provider=primarystorage[TestData.provider],
            tags=primarystorage[TestData.tags],
            capacityiops=primarystorage[TestData.capacityIops],
            capacitybytes=primarystorage[TestData.capacityBytes],
            hypervisor=primarystorage[TestData.hypervisor])

        self.cleanup.append(primary_storage)

        self.virtual_machine = VirtualMachine.create(
            self.apiClient,
            self.testdata[TestData.virtualMachine],
            accountid=self.account.name,
            zoneid=self.zone.id,
            serviceofferingid=self.compute_offering.id,
            templateid=self.template.id,
            domainid=self.domain.id,
            startvm=True)

        root_volume = self._get_root_volume(self.virtual_machine)

        sf_account_id = sf_util.get_sf_account_id(
            self.cs_api, self.account.id, primary_storage.id, self,
            TestAddRemoveHosts._sf_account_id_should_be_non_zero_int_err_msg)

        sf_volumes = sf_util.get_active_sf_volumes(self.sfe, sf_account_id)

        sf_volume = sf_util.check_and_get_sf_volume(sf_volumes,
                                                    root_volume.name, self)

        sf_vag_ids = sf_util.get_vag_ids(self.cs_api, self.cluster.id,
                                         primary_storage.id, self)

        sf_util.check_vags(sf_volume, sf_vag_ids, self)

        host = Host(hosts[0].__dict__)

        host_iqn = self._get_host_iqn(host)

        all_vags = sf_util.get_all_vags(self.sfe)

        host_vag = self._get_host_vag(host_iqn, all_vags)

        self.assertTrue(host_vag != None, "The host should be in a VAG.")

        host.delete(self.apiClient)

        sf_volumes = sf_util.get_active_sf_volumes(self.sfe, sf_account_id)

        sf_volume = sf_util.check_and_get_sf_volume(sf_volumes,
                                                    root_volume.name, self)

        sf_util.check_vags(sf_volume, sf_vag_ids, self)

        all_vags = sf_util.get_all_vags(self.sfe)

        host_vag = self._get_host_vag(host_iqn, all_vags)

        self.assertTrue(host_vag == None, "The host should not be in a VAG.")

        details = {
            TestData.username: "******",
            TestData.password: "******",
            TestData.url: "http://" + host.ipaddress,
            TestData.podId: host.podid,
            TestData.zoneId: host.zoneid
        }

        host = Host.create(self.apiClient,
                           self.cluster,
                           details,
                           hypervisor=host.hypervisor)

        self.assertTrue(isinstance(host, Host), "'host' is not a 'Host'.")

        hosts = list_hosts(self.apiClient, clusterid=self.cluster.id)

        unique_vag_ids = self._get_unique_vag_ids(hosts)

        self.assertTrue(
            len(hosts) == len(unique_vag_ids) + 1,
            "There should be one more host than unique VAG.")
Ejemplo n.º 6
0
    def test_check_hypervisor_max_limit_effect(self):
        """ Test hypervisor max limits effect

        # 1. Read exsiting count of VM's on the host including SSVM and VR
                and modify maxguestcount accordingly
        # 2. Deploy a VM
        # 2. Try to deploy another vm
        # 3. Verify that second VM
                deployment fails (2 SSVMs 1 VR VM and 1 deployed VM)
        """

        hostList = Host.list(self.apiclient,
                             zoneid=self.zone.id,
                             type="Routing")
        event_validation_result = validateList(hostList)
        self.assertEqual(
            event_validation_result[0], PASS,
            "host list validation failed due to %s" %
            event_validation_result[2])

        self.host = Host(hostList[0])
        Host.update(self.apiclient, id=self.host.id, hosttags="host1")

        # Step 1
        # List VM's , SSVM's and VR on selected host
        listVm = list_virtual_machines(self.apiclient, hostid=self.host.id)

        listssvm = list_ssvms(self.apiclient, hostid=self.host.id)

        listvr = list_routers(self.apiclient, hostid=self.host.id)

        newValue = 1
        if listVm is not None:
            newValue = len(listVm) + newValue

        if listssvm is not None:
            newValue = len(listssvm) + newValue

        if listvr is not None:
            newValue = len(listvr) + newValue

        qresultset = self.dbclient.execute(
            "select hypervisor_version from host where uuid='%s'" %
            self.host.id)

        event_validation_result = validateList(qresultset)
        self.assertEqual(
            event_validation_result[0], PASS,
            "event list validation failed due to %s" %
            event_validation_result[2])

        cmdList = listHypervisorCapabilities.listHypervisorCapabilitiesCmd()
        cmdList.hypervisor = self.hypervisor
        config = self.apiclient.listHypervisorCapabilities(cmdList)

        for host in config:
            if host.hypervisorversion == qresultset[0][0]:
                self.hostCapId = host.id
                self.originalLimit = host.maxguestslimit
                break
        else:
            self.skipTest("No hypervisor capabilities found for %s \
                    with version %s" % (self.hypervisor, qresultset[0][0]))

        cmdUpdate = updateHypervisorCapabilities.\
            updateHypervisorCapabilitiesCmd()
        cmdUpdate.id = self.hostCapId
        cmdUpdate.maxguestslimit = newValue
        self.apiclient.updateHypervisorCapabilities(cmdUpdate)

        # Step 2
        vm = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
        )

        self.cleanup.append(vm)
        # Step 3
        with self.assertRaises(Exception):
            VirtualMachine.create(
                self.userapiclient,
                self.testdata["small"],
                templateid=self.template.id,
                accountid=self.account.name,
                domainid=self.account.domainid,
                serviceofferingid=self.service_offering.id,
                zoneid=self.zone.id,
            )