diff --git a/galaxy.yml b/galaxy.yml index 508548b..525c1f6 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -31,6 +31,8 @@ build_ignore: # excluded because galaxy server refuses uploads with __main___ inside - plugins/module_utils/tripleo_repos/get_hash/__main__.py - plugins/module_utils/tripleo_repos/yum_config/__main__.py + # that is not needed for ansible modules and it would upset sanity (pylint) + - plugins/module_utils/tripleo_repos/main.py repository: https://opendev.org/openstack/tripleo-repos license_file: LICENSE diff --git a/plugins/module_utils/tripleo_repos/get_hash/__main__.py b/plugins/module_utils/tripleo_repos/get_hash/__main__.py index 1542b25..e99033f 100644 --- a/plugins/module_utils/tripleo_repos/get_hash/__main__.py +++ b/plugins/module_utils/tripleo_repos/get_hash/__main__.py @@ -96,7 +96,7 @@ def main(): args.tag, config, ) - tripleo_hash_info.pretty_print() + print(tripleo_hash_info) return tripleo_hash_info diff --git a/plugins/module_utils/tripleo_repos/get_hash/tripleo_hash_info.py b/plugins/module_utils/tripleo_repos/get_hash/tripleo_hash_info.py index d1db5c9..1e3c49d 100644 --- a/plugins/module_utils/tripleo_repos/get_hash/tripleo_hash_info.py +++ b/plugins/module_utils/tripleo_repos/get_hash/tripleo_hash_info.py @@ -121,18 +121,18 @@ class TripleOHashInfo: config_path = local_config else: raise TripleOHashMissingConfig( - "Configuration file not found at {} or {}".format( + "Configuration file not found at {0} or {1}".format( CONFIG_PATH, local_config ) ) - logging.info("Using config file at {}".format(config_path)) + logging.info("Using config file at %s", config_path) with open(config_path, 'r') as config_yaml: loaded_config = yaml.safe_load(config_yaml) for k in CONFIG_KEYS: if k not in loaded_config: error_str = ( - "Malformed config file - missing {}. Expected all" - "of these configuration items: {}" + "Malformed config file - missing {0}. Expected all" + "of these configuration items: {1}" ).format( k, ", ".join(CONFIG_KEYS) ) @@ -213,7 +213,7 @@ class TripleOHashInfo: self.release, self.tag, ) - logging.debug("repo_url is {}".format(repo_url)) + logging.debug("repo_url is %s", repo_url) return repo_url def _hashes_from_commit_yaml(self, delorean_result): @@ -229,10 +229,10 @@ class TripleOHashInfo: full = "%s_%s" % (commit, distro[0:8]) extended = parsed_yaml['commits'][0]['extended_hash'] logging.debug( - "delorean commit.yaml results {}".format(parsed_yaml['commits'][0]) - ) + "delorean commit.yaml results %s", parsed_yaml['commits'][0]) return full, commit, distro, extended - def pretty_print(self): + def __repr__(self) -> str: + """Returns a string representation of the object""" attrs = vars(self) - print(',\n'.join('%s: %s' % item for item in attrs.items())) + return ',\n'.join('%s: %s' % item for item in attrs.items()) diff --git a/plugins/module_utils/tripleo_repos/main.py b/plugins/module_utils/tripleo_repos/main.py index 2b00b01..eba21c6 100755 --- a/plugins/module_utils/tripleo_repos/main.py +++ b/plugins/module_utils/tripleo_repos/main.py @@ -141,7 +141,7 @@ def _get_distro(): if (distro_id, distro_major_version_id) not in SUPPORTED_DISTROS: print( - "WARNING: Unsupported platform '{}{}' detected by tripleo-repos," + "WARNING: Unsupported platform '{0}{1}' detected by tripleo-repos," " centos7 will be used unless you use CLI param to change it." "".format(distro_id, distro_major_version_id), file=sys.stderr) distro_id = 'centos' @@ -149,7 +149,7 @@ def _get_distro(): if distro_id == 'ubi': print( - "WARNING: Centos{} Base and AppStream will be installed for " + "WARNING: Centos{0} Base and AppStream will be installed for " "this UBI distro".format(distro_major_version_id)) return distro_id, distro_major_version_id, distro_name @@ -157,7 +157,7 @@ def _get_distro(): def _parse_args(distro_id, distro_major_version_id): - distro = "{}{}".format(distro_id, distro_major_version_id) + distro = "{0}{1}".format(distro_id, distro_major_version_id) # Calculating arguments default from constants default_mirror = DEFAULT_MIRROR_MAP.get(distro_id, None) @@ -262,9 +262,9 @@ def _validate_distro_repos(args): 'opstools', 'current-tripleo-rdo'] invalid_repos = [x for x in args.repos if x not in valid_repos] if len(invalid_repos) > 0: - raise InvalidArguments('{} repo(s) are not valid for {}. Valid repos ' - 'are: {}'.format(invalid_repos, args.distro, - valid_repos)) + raise InvalidArguments( + '{0} repo(s) are not valid for {1}. Valid repos ' + 'are: {2}'.format(invalid_repos, args.distro, valid_repos)) return True diff --git a/plugins/module_utils/tripleo_repos/yum_config/dnf_manager.py b/plugins/module_utils/tripleo_repos/yum_config/dnf_manager.py index ee33c52..4843cba 100644 --- a/plugins/module_utils/tripleo_repos/yum_config/dnf_manager.py +++ b/plugins/module_utils/tripleo_repos/yum_config/dnf_manager.py @@ -35,9 +35,9 @@ class DnfModuleManager: """Return a module spec string based on stream and/or profile.""" module_spec = name if stream: - module_spec += ':{}'.format(stream) + module_spec += ':{0}'.format(stream) if profile: - module_spec += '/{}'.format(profile) + module_spec += '/{0}'.format(profile) return module_spec def _do_transaction(self): @@ -55,7 +55,7 @@ class DnfModuleManager: [self._get_module_spec(name, stream=stream, profile=profile)] ) self._do_transaction() - logging.info("Module {} was enabled.".format(name)) + logging.info("Module %s was enabled.", name) def disable_module(self, name, stream=None, profile=None): """Disable a module stream.""" @@ -63,7 +63,7 @@ class DnfModuleManager: [self._get_module_spec(name, stream=stream, profile=profile)] ) self._do_transaction() - logging.info("Module {} was disabled.".format(name)) + logging.info("Module %s was disabled.", name) def reset_module(self, name, stream=None, profile=None): """Reset a module. It will no longer be enabled or disabled.""" @@ -71,7 +71,7 @@ class DnfModuleManager: [self._get_module_spec(name, stream=stream, profile=profile)] ) self._do_transaction() - logging.info("Module {} was reset.".format(name)) + logging.info("Module %s was reset.", name) def install_module(self, name, stream=None, profile=None): """Install packages of a module profile.""" @@ -81,7 +81,7 @@ class DnfModuleManager: self.base.resolve() self.base.download_packages(self.base.transaction.install_set) self._do_transaction() - logging.info("Module {} was installed.".format(name)) + logging.info("Module %s was installed.", name) def remove_module(self, name, stream=None, profile=None): """Remove packages of a module profile.""" @@ -89,4 +89,4 @@ class DnfModuleManager: [self._get_module_spec(name, stream=stream, profile=profile)] ) self._do_transaction() - logging.info("Module {} was removed.".format(name)) + logging.info("Module %s was removed.", name) diff --git a/plugins/module_utils/tripleo_repos/yum_config/yum_config.py b/plugins/module_utils/tripleo_repos/yum_config/yum_config.py index bc7edab..ac48f92 100644 --- a/plugins/module_utils/tripleo_repos/yum_config/yum_config.py +++ b/plugins/module_utils/tripleo_repos/yum_config/yum_config.py @@ -101,17 +101,17 @@ class TripleOYumConfig: if file_path: if not os.path.isfile(file_path): - msg = ('The configuration file "{}" was not found in the ' + msg = ('The configuration file "{0}" was not found in the ' 'provided path.').format(file_path) raise TripleOYumConfigNotFound(error_msg=msg) if not os.access(file_path, os.W_OK): - msg = ('The configuration file {} is not ' + msg = ('The configuration file {0} is not ' 'writable.'.format(file_path)) raise TripleOYumConfigPermissionDenied(error_msg=msg) if dir_path: if not os.path.isdir(dir_path): - msg = ('The configuration dir "{}" was not found in the ' + msg = ('The configuration dir "{0}" was not found in the ' 'provided path.').format(dir_path) raise TripleOYumConfigNotFound(error_msg=msg) @@ -132,13 +132,13 @@ class TripleOYumConfig: try: config.read(self.config_file_path) except configparser.Error: - msg = 'Unable to parse configuration file {}.'.format( + msg = 'Unable to parse configuration file {0}.'.format( self.config_file_path) raise TripleOYumConfigFileParseError(error_msg=msg) if section not in config.sections(): - msg = ('The provided section "{}" was not found in the ' - 'configuration file {}.').format( + msg = ('The provided section "{0}" was not found in the ' + 'configuration file {1}.').format( section, self.config_file_path) raise TripleOYumConfigInvalidSection(error_msg=msg) @@ -163,8 +163,8 @@ class TripleOYumConfig: continue if section in tmp_config.sections(): if section_found: - logging.warning('Section "{}" is listed more than once in ' - 'configuration files.'.format(section)) + logging.warning('Section "%s" is listed more than once in ' + 'configuration files.', section) else: # Read the first occurrence of 'section' config_file_path = os.path.join(self.dir_path, file) @@ -188,7 +188,7 @@ class TripleOYumConfig: config, config_file_path = self._read_config_file(section) if not (config and config_file_path): - msg = ('The provided section "{}" was not found within any ' + msg = ('The provided section "{0}" was not found within any ' 'configuration file.').format(section) raise TripleOYumConfigNotFound(error_msg=msg) @@ -198,7 +198,7 @@ class TripleOYumConfig: with open(config_file_path, 'w') as file: config.write(file) - logging.info("Section '{}' was successfully updated.".format(section)) + logging.info("Section '%s' was successfully updated.", section) class TripleOYumRepoConfig(TripleOYumConfig): @@ -207,7 +207,7 @@ class TripleOYumRepoConfig(TripleOYumConfig): def __init__(self, file_path=None, dir_path=None): if file_path: logging.info( - "Using '{}' as yum repo configuration file.".format(file_path)) + "Using '%s' as yum repo configuration file.", file_path) conf_dir_path = dir_path or YUM_REPO_DIR super(TripleOYumRepoConfig, self).__init__( @@ -228,8 +228,8 @@ class TripleOYumGlobalConfig(TripleOYumConfig): def __init__(self, file_path=None): conf_file_path = file_path or YUM_GLOBAL_CONFIG_FILE_PATH - logging.info("Using '{}' as yum global configuration " - "file.".format(conf_file_path)) + logging.info("Using '%s' as yum global configuration " + "file.", conf_file_path) if file_path is None: # If there is no default 'yum.conf' configuration file, we need to # create it. If the user specify another conf file that doesn't diff --git a/plugins/modules/yum_config.py b/plugins/modules/yum_config.py index aac6f75..df42423 100644 --- a/plugins/modules/yum_config.py +++ b/plugins/modules/yum_config.py @@ -232,7 +232,7 @@ def run_module(): # Successful module execution result['changed'] = True result['msg'] = ( - "Yum {} configuration was successfully updated.".format(m_type) + "Yum {0} configuration was successfully updated.".format(m_type) ) module.exit_json(**result) diff --git a/tests/sanity/ignore-2.9.txt b/tests/sanity/ignore-2.9.txt index ac03ca1..829e019 100644 --- a/tests/sanity/ignore-2.9.txt +++ b/tests/sanity/ignore-2.9.txt @@ -1,13 +1,3 @@ plugins/module_utils/tripleo_repos/get_hash/tripleo_hash_info.py import -plugins/module_utils/tripleo_repos/get_hash/tripleo_hash_info.py pylint:ansible-bad-function -plugins/module_utils/tripleo_repos/get_hash/tripleo_hash_info.py pylint:ansible-format-automatic-specification -plugins/module_utils/tripleo_repos/get_hash/tripleo_hash_info.py pylint:logging-format-interpolation plugins/module_utils/tripleo_repos/get_hash/tripleo_hash_info.py replace-urlopen # we did it right plugins/module_utils/tripleo_repos/main.py import:traceback -plugins/module_utils/tripleo_repos/main.py pylint:ansible-bad-function -plugins/module_utils/tripleo_repos/main.py pylint:ansible-format-automatic-specification -plugins/module_utils/tripleo_repos/yum_config/dnf_manager.py pylint:ansible-format-automatic-specification -plugins/module_utils/tripleo_repos/yum_config/dnf_manager.py pylint:logging-format-interpolation -plugins/module_utils/tripleo_repos/yum_config/yum_config.py pylint:ansible-format-automatic-specification -plugins/module_utils/tripleo_repos/yum_config/yum_config.py pylint:logging-format-interpolation -plugins/modules/yum_config.py pylint:ansible-format-automatic-specification