From 5c26805ee78cd856bec94aa036848647c783b913 Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Thu, 31 Jan 2013 17:23:10 -0500 Subject: [PATCH 1/3] test the repos in enablerepo/disablerepo and error out if they are broken --- library/yum | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/library/yum b/library/yum index 82059641b8..d992844de1 100644 --- a/library/yum +++ b/library/yum @@ -101,7 +101,7 @@ def yum_base(conf_file=None, cachedir=False): cachedir = yum.misc.getCacheDir() my.repos.setCacheDir(cachedir) my.conf.cache = 0 - + return my def po_to_nevra(po): @@ -174,7 +174,7 @@ def is_available(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=[], dis_ if rc == 0: return [ p for p in out.split('\n') if p.strip() ] else: - module.fail_json(msg='Error from repoquery: %s: %s' % (cmd, err + err2)) + module.fail_json(msg='Error from repoquery: %s: %s' % (cmd, err)) return [] @@ -216,7 +216,7 @@ def is_update(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=[], dis_rep if rc == 0: return set([ p for p in out.split('\n') if p.strip() ]) else: - module.fail_json(msg='Error from repoquery: %s: %s' % (cmd, err + err2)) + module.fail_json(msg='Error from repoquery: %s: %s' % (cmd, err)) return [] @@ -549,6 +549,22 @@ def ensure(module, state, pkgspec, conf_file, enablerepo, disablerepo): if repoq: repoq.extend(r_cmd) + if state in ['installed', 'present', 'latest']: + my = yum_base(conf_file) + try: + for r in dis_repos: + my.repos.disableRepo(r) + + for r in en_repos: + try: + my.repos.enableRepo(r) + rid = my.repos.getRepo(r) + a = rid.repoXML.repoid + except yum.Errors.YumBaseError, e: + module.fail_json(msg="Error setting/accessing repo %s: %s" % (r, e)) + except yum.Errors.YumBaseError, e: + module.fail_json(msg="Error accessing repos: %s" % e) + if state in ['installed', 'present']: install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos) elif state in ['removed', 'absent']: From 1c067845f21a31c46609a6fd973c8cf3b0cbfec1 Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Fri, 1 Feb 2013 12:39:02 -0500 Subject: [PATCH 2/3] don't apply enablerepo's to is_installed() to work around yum-utils/repoquery drift from all things good and proper --- library/yum | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/library/yum b/library/yum index d992844de1..2d96136b8d 100644 --- a/library/yum +++ b/library/yum @@ -168,6 +168,13 @@ def is_available(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=[], dis_ return [ po_to_nevra(p) for p in pkgs ] else: + for repoid in en_repos: + r_cmd = ['--enablerepo', repoid] + repoq.extend(r_cmd) + + for repoid in dis_repos: + r_cmd = ['--disablerepo', repoid] + repoq.extend(r_cmd) cmd = repoq + ["--qf", qf, pkgspec] rc,out,err = module.run_command(cmd) @@ -209,6 +216,14 @@ def is_update(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=[], dis_rep return set([ po_to_nevra(p) for p in retpkgs ]) else: + for repoid in en_repos: + r_cmd = ['--enablerepo', repoid] + repoq.extend(r_cmd) + + for repoid in dis_repos: + r_cmd = ['--disablerepo', repoid] + repoq.extend(r_cmd) + cmd = repoq + ["--pkgnarrow=updates", "--qf", qf, pkgspec] rc,out,err = module.run_command(cmd) @@ -247,6 +262,14 @@ def what_provides(module, repoq, req_spec, conf_file, qf=def_qf, en_repos=[], d else: + for repoid in en_repos: + r_cmd = ['--enablerepo', repoid] + repoq.extend(r_cmd) + + for repoid in dis_repos: + r_cmd = ['--disablerepo', repoid] + repoq.extend(r_cmd) + cmd = repoq + ["--qf", qf, "--whatprovides", req_spec] rc,out,err = module.run_command(cmd) cmd = repoq + ["--qf", qf, req_spec] @@ -539,16 +562,10 @@ def ensure(module, state, pkgspec, conf_file, enablerepo, disablerepo): r_cmd = ['--enablerepo', repoid] yum_basecmd.extend(r_cmd) - if repoq: - repoq.extend(r_cmd) - for repoid in dis_repos: r_cmd = ['--disablerepo', repoid] yum_basecmd.extend(r_cmd) - if repoq: - repoq.extend(r_cmd) - if state in ['installed', 'present', 'latest']: my = yum_base(conf_file) try: From 808554dee6bf612695ee44b85ddf103026b80aef Mon Sep 17 00:00:00 2001 From: Seth Vidal Date: Fri, 1 Feb 2013 16:47:53 -0500 Subject: [PATCH 3/3] use a local copy of repoq so we don't inadvertently pollute the one for is_installed --- library/yum | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/library/yum b/library/yum index 2d96136b8d..5c38052125 100644 --- a/library/yum +++ b/library/yum @@ -168,15 +168,17 @@ def is_available(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=[], dis_ return [ po_to_nevra(p) for p in pkgs ] else: + myrepoq = list(repoq) + for repoid in en_repos: r_cmd = ['--enablerepo', repoid] - repoq.extend(r_cmd) + myrepoq.extend(r_cmd) for repoid in dis_repos: r_cmd = ['--disablerepo', repoid] - repoq.extend(r_cmd) + myrepoq.extend(r_cmd) - cmd = repoq + ["--qf", qf, pkgspec] + cmd = myrepoq + ["--qf", qf, pkgspec] rc,out,err = module.run_command(cmd) if rc == 0: return [ p for p in out.split('\n') if p.strip() ] @@ -216,16 +218,17 @@ def is_update(module, repoq, pkgspec, conf_file, qf=def_qf, en_repos=[], dis_rep return set([ po_to_nevra(p) for p in retpkgs ]) else: + myrepoq = list(repoq) for repoid in en_repos: r_cmd = ['--enablerepo', repoid] - repoq.extend(r_cmd) + myrepoq.extend(r_cmd) for repoid in dis_repos: r_cmd = ['--disablerepo', repoid] - repoq.extend(r_cmd) + myrepoq.extend(r_cmd) - cmd = repoq + ["--pkgnarrow=updates", "--qf", qf, pkgspec] + cmd = myrepoq + ["--pkgnarrow=updates", "--qf", qf, pkgspec] rc,out,err = module.run_command(cmd) if rc == 0: @@ -261,18 +264,18 @@ def what_provides(module, repoq, req_spec, conf_file, qf=def_qf, en_repos=[], d return set([ po_to_nevra(p) for p in pkgs ]) else: - + myrepoq = list(repoq) for repoid in en_repos: r_cmd = ['--enablerepo', repoid] - repoq.extend(r_cmd) + myrepoq.extend(r_cmd) for repoid in dis_repos: r_cmd = ['--disablerepo', repoid] - repoq.extend(r_cmd) + myrepoq.extend(r_cmd) - cmd = repoq + ["--qf", qf, "--whatprovides", req_spec] + cmd = myrepoq + ["--qf", qf, "--whatprovides", req_spec] rc,out,err = module.run_command(cmd) - cmd = repoq + ["--qf", qf, req_spec] + cmd = myrepoq + ["--qf", qf, req_spec] rc2,out2,err2 = module.run_command(cmd) if rc == 0 and rc2 == 0: out += out2