Pylint fixes for yum module

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
Abhijeet Kasurde 2017-04-10 17:11:12 +05:30 committed by Matt Clay
parent db6d818865
commit ba3295dd3f

View file

@ -772,10 +772,10 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos, i
lang_env = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C') lang_env = dict(LANG='C', LC_ALL='C', LC_MESSAGES='C')
rc, out, err = module.run_command(cmd, environ_update=lang_env) rc, out, err = module.run_command(cmd, environ_update=lang_env)
if (rc == 1): if rc == 1:
for spec in items: for spec in items:
# Fail on invalid urls: # Fail on invalid urls:
if ('://' in spec and ('No package %s available.' % spec in out or 'Cannot open: %s. Skipping.' % spec in err)): if '://' in spec and ('No package %s available.' % spec in out or 'Cannot open: %s. Skipping.' % spec in err):
module.fail_json(msg='Package at %s could not be installed' % spec, rc=1, changed=False) module.fail_json(msg='Package at %s could not be installed' % spec, rc=1, changed=False)
if (rc != 0 and 'Nothing to do' in err) or 'Nothing to do' in out: if (rc != 0 and 'Nothing to do' in err) or 'Nothing to do' in out:
# avoid failing in the 'Nothing To Do' case # avoid failing in the 'Nothing To Do' case
@ -1163,8 +1163,8 @@ def ensure(module, state, pkgs, conf_file, enablerepo, disablerepo,
res = latest(module, pkgs, repoq, yum_basecmd, conf_file, en_repos, dis_repos, installroot=installroot) res = latest(module, pkgs, repoq, yum_basecmd, conf_file, en_repos, dis_repos, installroot=installroot)
else: else:
# should be caught by AnsibleModule argument_spec # should be caught by AnsibleModule argument_spec
module.fail_json(msg="we should never get here unless this all" module.fail_json(msg="we should never get here unless this all failed",
" failed", changed=False, results='', errors='unexpected state') changed=False, results='', errors='unexpected state')
return res return res
@ -1181,13 +1181,14 @@ def main():
# list=repos # list=repos
# list=pkgspec # list=pkgspec
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
name=dict(aliases=['pkg'], type="list"), name=dict(aliases=['pkg'], type="list"),
exclude=dict(required=False, default=None), exclude=dict(required=False, default=None),
# removed==absent, installed==present, these are accepted as aliases # removed==absent, installed==present, these are accepted as aliases
state=dict(default='installed', choices=['absent','present','installed','removed','latest']), state=dict(default='installed', choices=['absent', 'present',
'installed', 'removed',
'latest']),
enablerepo=dict(), enablerepo=dict(),
disablerepo=dict(), disablerepo=dict(),
list=dict(), list=dict(),
@ -1254,8 +1255,8 @@ def main():
disable_gpg_check = params['disable_gpg_check'] disable_gpg_check = params['disable_gpg_check']
skip_broken = params['skip_broken'] skip_broken = params['skip_broken']
results = ensure(module, state, pkg, params['conf_file'], enablerepo, results = ensure(module, state, pkg, params['conf_file'], enablerepo,
disablerepo, disable_gpg_check, exclude, repoquery, skip_broken, disablerepo, disable_gpg_check, exclude, repoquery,
params['installroot']) skip_broken, params['installroot'])
if repoquery: if repoquery:
results['msg'] = '%s %s' % (results.get('msg', ''), results['msg'] = '%s %s' % (results.get('msg', ''),
'Warning: Due to potential bad behaviour with rhnplugin and certificates, used slower repoquery calls instead of Yum API.') 'Warning: Due to potential bad behaviour with rhnplugin and certificates, used slower repoquery calls instead of Yum API.')