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,33 +569,34 @@ 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() try:
distribution = platform.dist() rsp, info = fetch_url(module, spec)
if distribution[0] == "redhat" and LooseVersion(distribution_version) < LooseVersion("6"): f = open(package, 'w')
package = os.path.join(tempdir, str(pkg.rsplit('/', 1)[1])) data = rsp.read(BUFSIZE)
try: while data:
rsp, info = fetch_url(module, pkg) f.write(data)
f = open(package, 'w')
data = rsp.read(BUFSIZE) data = rsp.read(BUFSIZE)
while data: f.close()
f.write(data) except Exception, e:
data = rsp.read(BUFSIZE) shutil.rmtree(tempdir)
f.close() module.fail_json(msg="Failure downloading %s, %s" % (spec, e))
pkg = package
except Exception, e: pkg_name = local_name(module, package)
shutil.rmtree(tempdir) if is_installed(module, repoq, pkg_name, conf_file, en_repos=en_repos, dis_repos=dis_repos):
module.fail_json(msg="Failure downloading %s, %s" % (spec, e)) # if it's there, skip it
continue
pkg = package
#groups :( #groups :(
elif spec.startswith('@'): elif spec.startswith('@'):