def test_cache(self, ssh_result): """Check get_host_sat_version() calls are cached""" ssh_result.return_value.stdout = [' SATELLITE_SHORT_VERSION = "6.2"'] assert '6.2' == host_info.get_host_sat_version() ssh_result.assert_called_once_with(host_info._SAT_6_2_VERSION_COMMAND) ssh_result.return_value.stdout = ['Doesnt matter because because its cached'] assert '6.2' == host_info.get_host_sat_version() # if called more than once cache didn't worked ssh_result.assert_called_once_with(host_info._SAT_6_2_VERSION_COMMAND)
def test_cache(self): """Check get_host_sat_version() calls are cached""" self._command.return_value.stdout = [ u' SATELLITE_SHORT_VERSION = "6.2"' ] self.assertEqual(u'6.2', host_info.get_host_sat_version()) self._command.assert_called_once_with( host_info._SAT_6_2_VERSION_COMMAND) self._command.return_value.stdout = [ u'Doesnt matter because because its cached' ] self.assertEqual(u'6.2', host_info.get_host_sat_version()) # if called more than once cache didn't worked self._command.assert_called_once_with( host_info._SAT_6_2_VERSION_COMMAND)
def _skip_flags_condition(flags): """Analyse bugzila flags returning False if host version is greater or equal to min positive flag version, True otherwise. :param flags: list :return: bool """ version_re = re.compile(r'sat-(?P<version>\d(\.\d){1})') def to_float_version(flag_name): result = version_re.search(flag_name) if result: return float(result.group('version')) positive_flag_versions = ( to_float_version(flag['name']) for flag in flags if flag['status'] == '+' ) try: min_positive_flag_version = min( filter(lambda version: version is not None, positive_flag_versions) ) except ValueError: # pragma: no cover # If flag regarding sat is not available return True else: try: sat_version = float(get_host_sat_version()) except ValueError: return False else: return sat_version < min_positive_flag_version
def test_cache(self): """Check get_host_sat_version() calls are cached""" self._command.return_value.stdout = [ u' SATELLITE_SHORT_VERSION = "6.2"' ] self.assertEqual(u'6.2', host_info.get_host_sat_version()) self._command.assert_called_once_with( host_info._SAT_6_2_VERSION_COMMAND ) self._command.return_value.stdout = [ u'Doesnt matter because because its cached' ] self.assertEqual(u'6.2', host_info.get_host_sat_version()) # if called more than once cache didn't worked self._command.assert_called_once_with( host_info._SAT_6_2_VERSION_COMMAND )
def _skip_downstream_condition(bug): """Analyse bugzila flags returning False if host version is greater or equal to min positive flag version, True otherwise. :param flags: list :return: bool """ flags = bug.get('flags', {}) positive_flags = [k for k, v in flags.items() if v == '+'] zstream_versions = list( filter(lambda version: version is not None, map(_to_zstream_version, positive_flags))) downstream_versions = list( filter(lambda version: version is not None, map(_to_downstream_version, positive_flags))) if len(downstream_versions) == 0 and len(zstream_versions) == 0: return True target_milestone_version = bug['target_milestone'] has_down_and_zstream = downstream_versions and zstream_versions if has_down_and_zstream and target_milestone_version is 'Unspecified': LOGGER.warning('Bugzilla with both downstream and zstream flags and ' 'unspecified target_milestone: {}'.format(bug)) return True flag_version = _to_target_milestone_version(target_milestone_version) if flag_version is None or not has_down_and_zstream: if downstream_versions: flag_version = min(downstream_versions) else: flag_version = min(zstream_versions) try: sat_version = float(get_host_sat_version()) except ValueError: return False else: return sat_version < flag_version
def get_sat_version(): """Try to read sat_version from envvar BUGZILLA_SAT_VERSION if not available fallback to ssh connection to get it.""" return os.environ.get('BUGZILLA_SAT_VERSION') or get_host_sat_version()