Пример #1
0
    def validate_stats(self, ui=False):
        """ Validates that the detail page matches the physical rack's information.

        This method logs into the provider using the mgmt_system interface and collects
        a set of statistics to be matched against the UI. An exception will be raised
        if the stats retrieved from the UI do not match those retrieved from wrapanapi.
        """

        # Make sure we are on the physical rack detail page
        if ui:
            self.load_details()

        # Retrieve the client and the stats and inventory to match
        client = self.provider.mgmt
        stats_to_match = self.STATS_TO_MATCH
        inventory_to_match = self.INVENTORY_TO_MATCH

        # Retrieve the stats and inventory from wrapanapi
        rack_stats = client.rack_stats(self, stats_to_match)
        rack_inventory = client.rack_inventory(self, inventory_to_match)

        # Refresh the browser
        if ui:
            self.browser.selenium.refresh()

        # Verify that the stats retrieved from wrapanapi match those retrieved
        # from the UI
        for stat in stats_to_match:
            try:
                cfme_stat = int(getattr(self, stat)(method='ui' if ui else None))
                rack_stat = int(rack_stats[stat])

                if rack_stat != cfme_stat:
                    msg = "The {} stat does not match. (server: {}, server stat: {}, cfme stat: {})"
                    raise StatsDoNotMatch(msg.format(stat, self.name, rack_stat, cfme_stat))
            except KeyError:
                raise HostStatsNotContains(
                    "Server stats information does not contain '{}'".format(stat))
            except AttributeError:
                raise ProviderHasNoProperty("Provider does not know how to get '{}'".format(stat))

        # Verify that the inventory retrieved from wrapanapi match those retrieved
        # from the UI
        for inventory in inventory_to_match:
            try:
                cfme_inventory = getattr(self, inventory)(method='ui' if ui else None)
                rack_inventory = rack_inventory[inventory]

                if rack_inventory != cfme_inventory:
                    msg = "The {} inventory does not match. (server: {}, server inventory: {}, " \
                          "cfme inventory: {})"
                    raise StatsDoNotMatch(msg.format(inventory, self.name, rack_inventory,
                                                     cfme_inventory))
            except KeyError:
                raise HostStatsNotContains(
                    "Server inventory information does not contain '{}'".format(inventory))
            except AttributeError:
                msg = "Provider does not know how to get '{}'"
                raise ProviderHasNoProperty(msg.format(inventory))
Пример #2
0
    def _do_stats_match(self, client, stats_to_match=None):
        """ A private function to match a set of statistics, with a Provider.

        This function checks if the list of stats match, if not, the page is refreshed.

        Note: Provider mgmt_system uses the same key names as this Provider class to avoid
            having to map keyname/attributes e.g. ``num_template``, ``num_vm``.

        Args:
            client: A provider mgmt_system instance.
            stats_to_match: A list of key/attribute names to match.

        Raises:
            KeyError: If the host stats does not contain the specified key.
            ProviderHasNoProperty: If the provider does not have the property defined.
        """
        host_stats = client.stats(*stats_to_match)

        for stat in stats_to_match:
            try:
                cfme_stat = getattr(self, stat)
                logger.info(' Matching stat [%s], Host(%s), CFME(%s)' %
                    (stat, host_stats[stat], cfme_stat))
                if host_stats[stat] != cfme_stat:
                    return False
            except KeyError:
                raise HostStatsNotContains("Host stats information does not contain '%s'" % stat)
            except AttributeError:
                raise ProviderHasNoProperty("Provider does not know how to get '%s'" % stat)
        else:
            return True
Пример #3
0
    def _do_stats_match(self,
                        client,
                        stats_to_match=None,
                        refresh_timer=None,
                        db=True):
        """ A private function to match a set of statistics, with a Provider.

        This function checks if the list of stats match, if not, the page is refreshed.

        Note: Provider mgmt_system uses the same key names as this Provider class to avoid
            having to map keyname/attributes e.g. ``num_template``, ``num_vm``.

        Args:
            client: A provider mgmt_system instance.
            stats_to_match: A list of key/attribute names to match.

        Raises:
            KeyError: If the host stats does not contain the specified key.
            ProviderHasNoProperty: If the provider does not have the property defined.
        """
        host_stats = client.stats(*stats_to_match)
        if not db:
            sel.refresh()

        if refresh_timer:
            if refresh_timer.is_it_time():
                logger.info(' Time for a refresh!')
                sel.force_navigate('{}_provider'.format(self.page_name),
                                   context={'provider': self})
                tb.select("Configuration",
                          "Refresh Relationships and Power States",
                          invokes_alert=True)
                sel.handle_alert(cancel=False)
                refresh_timer.reset()

        for stat in stats_to_match:
            try:
                cfme_stat = getattr(self, stat)(db=db)
                success, value = tol_check(host_stats[stat],
                                           cfme_stat,
                                           min_error=0.05,
                                           low_val_correction=2)
                logger.info(' Matching stat [{}], Host({}), CFME({}), '
                            'with tolerance {} is {}'.format(
                                stat, host_stats[stat], cfme_stat, value,
                                success))
                if not success:
                    return False
            except KeyError:
                raise HostStatsNotContains(
                    "Host stats information does not contain '%s'" % stat)
            except AttributeError:
                raise ProviderHasNoProperty(
                    "Provider does not know how to get '%s'" % stat)
        else:
            return True
Пример #4
0
    def _do_stats_match(self,
                        client,
                        stats_to_match=None,
                        refresh_timer=None,
                        ui=False):
        """ A private function to match a set of statistics, with a Provider.

        This function checks if the list of stats match, if not, the page is refreshed.

        Note: Provider mgmt_system uses the same key names as this Provider class to avoid
            having to map keyname/attributes e.g. ``num_template``, ``num_vm``.

        Args:
            client: A provider mgmt_system instance.
            stats_to_match: A list of key/attribute names to match.

        Raises:
            KeyError: If the host stats does not contain the specified key.
            ProviderHasNoProperty: If the provider does not have the property defined.
        """
        host_stats = client.stats(*stats_to_match)
        method = None
        if ui:
            self.browser.selenium.refresh()
            method = 'ui'

        if refresh_timer:
            if refresh_timer.is_it_time():
                logger.info(' Time for a refresh!')
                self.refresh_provider_relationships()
                refresh_timer.reset()

        for stat in stats_to_match:
            try:
                cfme_stat = getattr(self, stat)(method=method)
                success, value = tol_check(host_stats[stat],
                                           cfme_stat,
                                           min_error=0.05,
                                           low_val_correction=2)
                logger.info(
                    ' Matching stat [%s], Host(%s), CFME(%s), '
                    'with tolerance %s is %s', stat, host_stats[stat],
                    cfme_stat, value, success)
                if not success:
                    return False
            except KeyError:
                raise HostStatsNotContains(
                    "Host stats information does not contain '{}'".format(
                        stat))
            except AttributeError:
                raise ProviderHasNoProperty(
                    "Provider does not know how to get '{}'".format(stat))
        else:
            return True
Пример #5
0
    def validate_stats(self, ui=False):
        """ Validates that the detail page matches the physical rack's information.

        This method logs into the provider using the mgmt_system interface and collects
        a set of statistics to be matched against the UI. An exception will be raised
        if the stats retrieved from the UI do not match those retrieved from wrapanapi.
        """

        # Retrieve the client and the stats and inventory to match
        client = self.provider.mgmt
        stats_to_match = self.STATS_TO_MATCH
        inventory_to_match = self.INVENTORY_TO_MATCH

        # Retrieve the stats and inventory from wrapanapi
        rack_stats = client.stats(*stats_to_match, requester=self)
        rack_inventory = client.inventory(*inventory_to_match, requester=self)

        # Refresh the browser
        if ui:
            navigate_to(self, 'Details', wait_for_view=True)

        # Verify that the stats retrieved from wrapanapi match those retrieved
        # from the UI
        for stat in stats_to_match:
            try:
                cfme_stat = int(
                    getattr(self, stat)(method='ui' if ui else None))
                rack_stat = int(rack_stats[stat])

                if rack_stat != cfme_stat:
                    msg = "The {} stat does not match. (rack: {}, rack stat: {}, cfme stat: {})"
                    raise StatsDoNotMatch(
                        msg.format(stat, self.name, rack_stat, cfme_stat))
            except KeyError:
                raise RackStatsDoesNotContain(
                    f"Rack stats information does not contain '{stat}'")
            except AttributeError:
                raise ProviderHasNoProperty(
                    f"Provider does not know how to get '{stat}'")

        # Verify that the inventory retrieved from wrapanapi match those retrieved
        # from the UI
        for inventory in inventory_to_match:
            try:
                cfme_inventory = getattr(
                    self, inventory)(method='ui' if ui else None)
                rack_inventory = rack_inventory[inventory]

                if rack_inventory != cfme_inventory:
                    msg = "The {} inventory does not match. (rack: {}, rack inventory: {}, " \
                          "cfme inventory: {})"
                    raise StatsDoNotMatch(
                        msg.format(inventory, self.name, rack_inventory,
                                   cfme_inventory))
            except KeyError:
                raise RackStatsDoesNotContain(
                    f"Rack inventory information does not contain '{inventory}'"
                )
            except AttributeError:
                msg = "Provider does not know how to get '{}'"
                raise ProviderHasNoProperty(msg.format(inventory))