Fix pylint violations (sanity)
Story: TRIPLEOCI-559 Change-Id: I01c4bd54621bd8084d989f71a1c7835de84f432a
This commit is contained in:
parent
1525e5e1fa
commit
854ca64d47
|
@ -31,6 +31,8 @@ build_ignore:
|
||||||
# excluded because galaxy server refuses uploads with __main___ inside
|
# excluded because galaxy server refuses uploads with __main___ inside
|
||||||
- plugins/module_utils/tripleo_repos/get_hash/__main__.py
|
- plugins/module_utils/tripleo_repos/get_hash/__main__.py
|
||||||
- plugins/module_utils/tripleo_repos/yum_config/__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
|
repository: https://opendev.org/openstack/tripleo-repos
|
||||||
license_file: LICENSE
|
license_file: LICENSE
|
||||||
|
|
|
@ -96,7 +96,7 @@ def main():
|
||||||
args.tag,
|
args.tag,
|
||||||
config,
|
config,
|
||||||
)
|
)
|
||||||
tripleo_hash_info.pretty_print()
|
print(tripleo_hash_info)
|
||||||
return tripleo_hash_info
|
return tripleo_hash_info
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -121,18 +121,18 @@ class TripleOHashInfo:
|
||||||
config_path = local_config
|
config_path = local_config
|
||||||
else:
|
else:
|
||||||
raise TripleOHashMissingConfig(
|
raise TripleOHashMissingConfig(
|
||||||
"Configuration file not found at {} or {}".format(
|
"Configuration file not found at {0} or {1}".format(
|
||||||
CONFIG_PATH, local_config
|
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:
|
with open(config_path, 'r') as config_yaml:
|
||||||
loaded_config = yaml.safe_load(config_yaml)
|
loaded_config = yaml.safe_load(config_yaml)
|
||||||
for k in CONFIG_KEYS:
|
for k in CONFIG_KEYS:
|
||||||
if k not in loaded_config:
|
if k not in loaded_config:
|
||||||
error_str = (
|
error_str = (
|
||||||
"Malformed config file - missing {}. Expected all"
|
"Malformed config file - missing {0}. Expected all"
|
||||||
"of these configuration items: {}"
|
"of these configuration items: {1}"
|
||||||
).format(
|
).format(
|
||||||
k, ", ".join(CONFIG_KEYS)
|
k, ", ".join(CONFIG_KEYS)
|
||||||
)
|
)
|
||||||
|
@ -213,7 +213,7 @@ class TripleOHashInfo:
|
||||||
self.release,
|
self.release,
|
||||||
self.tag,
|
self.tag,
|
||||||
)
|
)
|
||||||
logging.debug("repo_url is {}".format(repo_url))
|
logging.debug("repo_url is %s", repo_url)
|
||||||
return repo_url
|
return repo_url
|
||||||
|
|
||||||
def _hashes_from_commit_yaml(self, delorean_result):
|
def _hashes_from_commit_yaml(self, delorean_result):
|
||||||
|
@ -229,10 +229,10 @@ class TripleOHashInfo:
|
||||||
full = "%s_%s" % (commit, distro[0:8])
|
full = "%s_%s" % (commit, distro[0:8])
|
||||||
extended = parsed_yaml['commits'][0]['extended_hash']
|
extended = parsed_yaml['commits'][0]['extended_hash']
|
||||||
logging.debug(
|
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
|
return full, commit, distro, extended
|
||||||
|
|
||||||
def pretty_print(self):
|
def __repr__(self) -> str:
|
||||||
|
"""Returns a string representation of the object"""
|
||||||
attrs = vars(self)
|
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())
|
||||||
|
|
|
@ -141,7 +141,7 @@ def _get_distro():
|
||||||
|
|
||||||
if (distro_id, distro_major_version_id) not in SUPPORTED_DISTROS:
|
if (distro_id, distro_major_version_id) not in SUPPORTED_DISTROS:
|
||||||
print(
|
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."
|
" centos7 will be used unless you use CLI param to change it."
|
||||||
"".format(distro_id, distro_major_version_id), file=sys.stderr)
|
"".format(distro_id, distro_major_version_id), file=sys.stderr)
|
||||||
distro_id = 'centos'
|
distro_id = 'centos'
|
||||||
|
@ -149,7 +149,7 @@ def _get_distro():
|
||||||
|
|
||||||
if distro_id == 'ubi':
|
if distro_id == 'ubi':
|
||||||
print(
|
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))
|
"this UBI distro".format(distro_major_version_id))
|
||||||
|
|
||||||
return distro_id, distro_major_version_id, distro_name
|
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):
|
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
|
# Calculating arguments default from constants
|
||||||
default_mirror = DEFAULT_MIRROR_MAP.get(distro_id, None)
|
default_mirror = DEFAULT_MIRROR_MAP.get(distro_id, None)
|
||||||
|
@ -262,9 +262,9 @@ def _validate_distro_repos(args):
|
||||||
'opstools', 'current-tripleo-rdo']
|
'opstools', 'current-tripleo-rdo']
|
||||||
invalid_repos = [x for x in args.repos if x not in valid_repos]
|
invalid_repos = [x for x in args.repos if x not in valid_repos]
|
||||||
if len(invalid_repos) > 0:
|
if len(invalid_repos) > 0:
|
||||||
raise InvalidArguments('{} repo(s) are not valid for {}. Valid repos '
|
raise InvalidArguments(
|
||||||
'are: {}'.format(invalid_repos, args.distro,
|
'{0} repo(s) are not valid for {1}. Valid repos '
|
||||||
valid_repos))
|
'are: {2}'.format(invalid_repos, args.distro, valid_repos))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,9 +35,9 @@ class DnfModuleManager:
|
||||||
"""Return a module spec string based on stream and/or profile."""
|
"""Return a module spec string based on stream and/or profile."""
|
||||||
module_spec = name
|
module_spec = name
|
||||||
if stream:
|
if stream:
|
||||||
module_spec += ':{}'.format(stream)
|
module_spec += ':{0}'.format(stream)
|
||||||
if profile:
|
if profile:
|
||||||
module_spec += '/{}'.format(profile)
|
module_spec += '/{0}'.format(profile)
|
||||||
return module_spec
|
return module_spec
|
||||||
|
|
||||||
def _do_transaction(self):
|
def _do_transaction(self):
|
||||||
|
@ -55,7 +55,7 @@ class DnfModuleManager:
|
||||||
[self._get_module_spec(name, stream=stream, profile=profile)]
|
[self._get_module_spec(name, stream=stream, profile=profile)]
|
||||||
)
|
)
|
||||||
self._do_transaction()
|
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):
|
def disable_module(self, name, stream=None, profile=None):
|
||||||
"""Disable a module stream."""
|
"""Disable a module stream."""
|
||||||
|
@ -63,7 +63,7 @@ class DnfModuleManager:
|
||||||
[self._get_module_spec(name, stream=stream, profile=profile)]
|
[self._get_module_spec(name, stream=stream, profile=profile)]
|
||||||
)
|
)
|
||||||
self._do_transaction()
|
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):
|
def reset_module(self, name, stream=None, profile=None):
|
||||||
"""Reset a module. It will no longer be enabled or disabled."""
|
"""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._get_module_spec(name, stream=stream, profile=profile)]
|
||||||
)
|
)
|
||||||
self._do_transaction()
|
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):
|
def install_module(self, name, stream=None, profile=None):
|
||||||
"""Install packages of a module profile."""
|
"""Install packages of a module profile."""
|
||||||
|
@ -81,7 +81,7 @@ class DnfModuleManager:
|
||||||
self.base.resolve()
|
self.base.resolve()
|
||||||
self.base.download_packages(self.base.transaction.install_set)
|
self.base.download_packages(self.base.transaction.install_set)
|
||||||
self._do_transaction()
|
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):
|
def remove_module(self, name, stream=None, profile=None):
|
||||||
"""Remove packages of a module profile."""
|
"""Remove packages of a module profile."""
|
||||||
|
@ -89,4 +89,4 @@ class DnfModuleManager:
|
||||||
[self._get_module_spec(name, stream=stream, profile=profile)]
|
[self._get_module_spec(name, stream=stream, profile=profile)]
|
||||||
)
|
)
|
||||||
self._do_transaction()
|
self._do_transaction()
|
||||||
logging.info("Module {} was removed.".format(name))
|
logging.info("Module %s was removed.", name)
|
||||||
|
|
|
@ -101,17 +101,17 @@ class TripleOYumConfig:
|
||||||
|
|
||||||
if file_path:
|
if file_path:
|
||||||
if not os.path.isfile(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)
|
'provided path.').format(file_path)
|
||||||
raise TripleOYumConfigNotFound(error_msg=msg)
|
raise TripleOYumConfigNotFound(error_msg=msg)
|
||||||
if not os.access(file_path, os.W_OK):
|
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))
|
'writable.'.format(file_path))
|
||||||
raise TripleOYumConfigPermissionDenied(error_msg=msg)
|
raise TripleOYumConfigPermissionDenied(error_msg=msg)
|
||||||
|
|
||||||
if dir_path:
|
if dir_path:
|
||||||
if not os.path.isdir(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)
|
'provided path.').format(dir_path)
|
||||||
raise TripleOYumConfigNotFound(error_msg=msg)
|
raise TripleOYumConfigNotFound(error_msg=msg)
|
||||||
|
|
||||||
|
@ -132,13 +132,13 @@ class TripleOYumConfig:
|
||||||
try:
|
try:
|
||||||
config.read(self.config_file_path)
|
config.read(self.config_file_path)
|
||||||
except configparser.Error:
|
except configparser.Error:
|
||||||
msg = 'Unable to parse configuration file {}.'.format(
|
msg = 'Unable to parse configuration file {0}.'.format(
|
||||||
self.config_file_path)
|
self.config_file_path)
|
||||||
raise TripleOYumConfigFileParseError(error_msg=msg)
|
raise TripleOYumConfigFileParseError(error_msg=msg)
|
||||||
|
|
||||||
if section not in config.sections():
|
if section not in config.sections():
|
||||||
msg = ('The provided section "{}" was not found in the '
|
msg = ('The provided section "{0}" was not found in the '
|
||||||
'configuration file {}.').format(
|
'configuration file {1}.').format(
|
||||||
section, self.config_file_path)
|
section, self.config_file_path)
|
||||||
raise TripleOYumConfigInvalidSection(error_msg=msg)
|
raise TripleOYumConfigInvalidSection(error_msg=msg)
|
||||||
|
|
||||||
|
@ -163,8 +163,8 @@ class TripleOYumConfig:
|
||||||
continue
|
continue
|
||||||
if section in tmp_config.sections():
|
if section in tmp_config.sections():
|
||||||
if section_found:
|
if section_found:
|
||||||
logging.warning('Section "{}" is listed more than once in '
|
logging.warning('Section "%s" is listed more than once in '
|
||||||
'configuration files.'.format(section))
|
'configuration files.', section)
|
||||||
else:
|
else:
|
||||||
# Read the first occurrence of 'section'
|
# Read the first occurrence of 'section'
|
||||||
config_file_path = os.path.join(self.dir_path, file)
|
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)
|
config, config_file_path = self._read_config_file(section)
|
||||||
if not (config and config_file_path):
|
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)
|
'configuration file.').format(section)
|
||||||
raise TripleOYumConfigNotFound(error_msg=msg)
|
raise TripleOYumConfigNotFound(error_msg=msg)
|
||||||
|
|
||||||
|
@ -198,7 +198,7 @@ class TripleOYumConfig:
|
||||||
with open(config_file_path, 'w') as file:
|
with open(config_file_path, 'w') as file:
|
||||||
config.write(file)
|
config.write(file)
|
||||||
|
|
||||||
logging.info("Section '{}' was successfully updated.".format(section))
|
logging.info("Section '%s' was successfully updated.", section)
|
||||||
|
|
||||||
|
|
||||||
class TripleOYumRepoConfig(TripleOYumConfig):
|
class TripleOYumRepoConfig(TripleOYumConfig):
|
||||||
|
@ -207,7 +207,7 @@ class TripleOYumRepoConfig(TripleOYumConfig):
|
||||||
def __init__(self, file_path=None, dir_path=None):
|
def __init__(self, file_path=None, dir_path=None):
|
||||||
if file_path:
|
if file_path:
|
||||||
logging.info(
|
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
|
conf_dir_path = dir_path or YUM_REPO_DIR
|
||||||
|
|
||||||
super(TripleOYumRepoConfig, self).__init__(
|
super(TripleOYumRepoConfig, self).__init__(
|
||||||
|
@ -228,8 +228,8 @@ class TripleOYumGlobalConfig(TripleOYumConfig):
|
||||||
|
|
||||||
def __init__(self, file_path=None):
|
def __init__(self, file_path=None):
|
||||||
conf_file_path = file_path or YUM_GLOBAL_CONFIG_FILE_PATH
|
conf_file_path = file_path or YUM_GLOBAL_CONFIG_FILE_PATH
|
||||||
logging.info("Using '{}' as yum global configuration "
|
logging.info("Using '%s' as yum global configuration "
|
||||||
"file.".format(conf_file_path))
|
"file.", conf_file_path)
|
||||||
if file_path is None:
|
if file_path is None:
|
||||||
# If there is no default 'yum.conf' configuration file, we need to
|
# If there is no default 'yum.conf' configuration file, we need to
|
||||||
# create it. If the user specify another conf file that doesn't
|
# create it. If the user specify another conf file that doesn't
|
||||||
|
|
|
@ -232,7 +232,7 @@ def run_module():
|
||||||
# Successful module execution
|
# Successful module execution
|
||||||
result['changed'] = True
|
result['changed'] = True
|
||||||
result['msg'] = (
|
result['msg'] = (
|
||||||
"Yum {} configuration was successfully updated.".format(m_type)
|
"Yum {0} configuration was successfully updated.".format(m_type)
|
||||||
)
|
)
|
||||||
module.exit_json(**result)
|
module.exit_json(**result)
|
||||||
|
|
||||||
|
|
|
@ -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 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/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 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
|
|
||||||
|
|
Loading…
Reference in New Issue