Merge pull request #3311 from kustodian/yum-fix-changed-in-check-mode

Yum module always downloads remote rpms. fixes #1452
This commit is contained in:
Toshio Kuratomi 2016-03-25 07:40:36 -07:00
commit 0268864211

View file

@ -482,6 +482,19 @@ def local_nvra(module, path):
header[rpm.RPMTAG_RELEASE], header[rpm.RPMTAG_RELEASE],
header[rpm.RPMTAG_ARCH]) header[rpm.RPMTAG_ARCH])
def local_name(module, path):
"""return package name of a local rpm passed in"""
ts = rpm.TransactionSet()
ts.setVSFlags(rpm._RPMVSF_NOSIGNATURES)
fd = os.open(path, os.O_RDONLY)
try:
header = ts.hdrFromFdno(fd)
finally:
os.close(fd)
return header[rpm.RPMTAG_NAME]
def pkg_to_dict(pkgstr): def pkg_to_dict(pkgstr):
if pkgstr.strip(): if pkgstr.strip():
@ -556,34 +569,35 @@ def install(module, items, repoq, yum_basecmd, conf_file, en_repos, dis_repos):
res['msg'] += "No Package file matching '%s' found on system" % spec res['msg'] += "No Package file matching '%s' found on system" % spec
module.fail_json(**res) module.fail_json(**res)
nvra = local_nvra(module, spec) pkg_name = local_name(module, spec)
# look for them in the rpmdb # look for them in the rpmdb
if is_installed(module, repoq, nvra, conf_file, en_repos=en_repos, dis_repos=dis_repos): if is_installed(module, repoq, pkg_name, conf_file, en_repos=en_repos, dis_repos=dis_repos):
# if they are there, skip it # if they are there, skip it
continue continue
pkg = spec pkg = spec
# URL # URL
elif '://' in spec: elif '://' in spec:
pkg = spec # download package so that we can check if it's already installed
# Check if Enterprise Linux 5 or less, as yum on those versions do not support installing via url package = os.path.join(tempdir, str(spec.rsplit('/', 1)[1]))
distribution_version = get_distribution_version()
distribution = platform.dist()
if distribution[0] == "redhat" and LooseVersion(distribution_version) < LooseVersion("6"):
package = os.path.join(tempdir, str(pkg.rsplit('/', 1)[1]))
try: try:
rsp, info = fetch_url(module, pkg) rsp, info = fetch_url(module, spec)
f = open(package, 'w') f = open(package, 'w')
data = rsp.read(BUFSIZE) data = rsp.read(BUFSIZE)
while data: while data:
f.write(data) f.write(data)
data = rsp.read(BUFSIZE) data = rsp.read(BUFSIZE)
f.close() f.close()
pkg = package
except Exception, e: except Exception, e:
shutil.rmtree(tempdir) shutil.rmtree(tempdir)
module.fail_json(msg="Failure downloading %s, %s" % (spec, e)) module.fail_json(msg="Failure downloading %s, %s" % (spec, e))
pkg_name = local_name(module, package)
if is_installed(module, repoq, pkg_name, conf_file, en_repos=en_repos, dis_repos=dis_repos):
# if it's there, skip it
continue
pkg = package
#groups :( #groups :(
elif spec.startswith('@'): elif spec.startswith('@'):
# complete wild ass guess b/c it's a group # complete wild ass guess b/c it's a group