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
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