[PATCH 1/1] Fix for old RHEL by shelling out to yum executable when python yum libraries are unavailable, and not using --nosignature option to rpm which is not present.

5 views
Skip to first unread message

Oliver Hookins

unread,
Sep 23, 2008, 2:47:26 AM9/23/08
to puppe...@googlegroups.com
Signed-off-by: Oliver Hookins <oliver....@anchor.com.au>
---
lib/puppet/provider/package/rpm.rb | 9 +++-
lib/puppet/provider/package/yumhelper.py | 102 ++++++++++++++++++++++++++---
2 files changed, 99 insertions(+), 12 deletions(-)

diff --git a/lib/puppet/provider/package/rpm.rb b/lib/puppet/provider/package/rpm.rb
index a303da4..b5a5c5d 100755
--- a/lib/puppet/provider/package/rpm.rb
+++ b/lib/puppet/provider/package/rpm.rb
@@ -23,9 +23,16 @@ Puppet::Type.type(:package).provide :rpm, :source => :rpm, :parent => Puppet::Pr
def self.instances
packages = []

+ # rpm < 4.1 don't support --nosignature
+ output = rpm "--version"
+ sig = "--nosignature"
+ if output =~ /RPM version (([123].*)|(4\.0.*))/
+ sig = ""
+ end
+
# list out all of the packages
begin
- execpipe("#{command(:rpm)} -qa --nosignature --nodigest --qf '#{NEVRAFORMAT}\n'") { |process|
+ execpipe("#{command(:rpm)} -qa #{sig} --nodigest --qf '#{NEVRAFORMAT}\n'") { |process|
# now turn each returned line into a package object
process.each { |line|
hash = nevra_to_hash(line)
diff --git a/lib/puppet/provider/package/yumhelper.py b/lib/puppet/provider/package/yumhelper.py
index 962b96c..d014e1e 100644
--- a/lib/puppet/provider/package/yumhelper.py
+++ b/lib/puppet/provider/package/yumhelper.py
@@ -4,8 +4,21 @@
# (C) 2007 Red Hat Inc.
# David Lutterkort <dlutter @redhat.com>

-import yum
import sys
+import string
+import re
+
+# this maintains compatibility with really old platforms with python 1.x
+from os import popen
+
+# try to use the yum libraries by default, but shell out to the yum executable
+# if they are not present (i.e. yum <= 2.0)
+try:
+ import yum
+except ImportError:
+ useyumlib = 0
+else:
+ useyumlib = 1

OVERRIDE_OPTS = {
'debuglevel': 0,
@@ -26,14 +39,81 @@ def pkg_lists(my):
my.doRpmDBSetup()
return my.doPackageLists('updates')

-try:
+def shell_out():
+ try:
+ p = popen("/usr/bin/env yum check-update 2>&1")
+ output = p.readlines()
+ rc = p.close()
+
+ if rc is not None:
+ # None represents exit code of 0, otherwise the exit code is in the
+ # format returned by wait(). The high 8-bits are what we want.
+ # Exit code of 100 from yum represents updates available.
+ rc = rc >> 8
+ if rc != 100:
+ return rc
+ else:
+ # Exit code is None (0), no updates waiting so don't both parsing output
+ return 0
+
+ # Yum prints a line of hyphens (old versions) or a blank line between
+ # headers and package data, so skip everything before them
+ skipheaders = 0
+ for line in output:
+ if not skipheaders:
+ if re.compile("^((-){80}|)$").search(line):
+ skipheaders = 1
+ continue
+
+ # Skip any blank lines
+ if re.compile("^( )?$").search(line):
+ continue
+
+ # Format is:
+ # Yum 1.x: name arch (epoch:)?version
+ # Yum 2.0: name arch (epoch:)?version repo
+ # epoch is optional if 0
+
+ p = string.split(line)
+ pname = p[0]
+ parch = p[1]
+ pevr = p[2]
+
+ # Separate out epoch:version-release
+ evr_re = re.compile("^(\d:)?(\S+)-(\S+)$")
+ evr = evr_re.match(pevr)
+
+ pepoch = ""
+ if evr.group(1) is None:
+ pepoch = "0"
+ else:
+ pepoch = evr.group(1).replace(":", "")
+ pversion = evr.group(2)
+ prelease = evr.group(3)
+
+ print "_pkg", pname, pepoch, pversion, prelease, parch
+
+ return 0
+ except:
+ print sys.exc_info()[0]
+ return 1
+
+if useyumlib:
try:
- my = yum.YumBase()
- ypl = pkg_lists(my)
- for pkg in ypl.updates:
- print "_pkg %s %s %s %s %s" % (pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch)
- finally:
- my.closeRpmDB()
-except IOError, e:
- print "_err IOError %d %s" % (e.errno, e)
- sys.exit(1)
+ try:
+ my = yum.YumBase()
+ ypl = pkg_lists(my)
+ for pkg in ypl.updates:
+ print "_pkg %s %s %s %s %s" % (pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch)
+ finally:
+ my.closeRpmDB()
+ except IOError, e:
+ print "_err IOError %d %s" % (e.errno, e)
+ sys.exit(1)
+ except AttributeError, e:
+ # catch yumlib errors in buggy 2.x versions of yum
+ print "_err AttributeError %s" % e
+ sys.exit(1)
+else:
+ rc = shell_out()
+ sys.exit(rc)
--
1.5.4.3

Luke Kanies

unread,
Sep 26, 2008, 5:01:37 PM9/26/08
to puppe...@googlegroups.com
Can someone who's familiar with RHEL test this?


--
The Ninety-Ninety Rule of Project Schedules:
The first 90% of the task takes 90% of the time, and the last
10% takes the other 90%.
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com

David Lutterkort

unread,
Oct 3, 2008, 2:41:40 PM10/3/08
to puppe...@googlegroups.com
On Tue, 2008-09-23 at 16:47 +1000, Oliver Hookins wrote:
> Signed-off-by: Oliver Hookins <oliver....@anchor.com.au>
> ---
> lib/puppet/provider/package/rpm.rb | 9 +++-
> lib/puppet/provider/package/yumhelper.py | 102 ++++++++++++++++++++++++++---
> 2 files changed, 99 insertions(+), 12 deletions(-)

I gave this a quick read and a spin on F9 and RHEL5, and it works for
me. Out of interest, since you're using puppet on RHEL3 and yum, you are
already on a fairly large set of self-supported packages. Why not use
the yum-2.4 port from CentOS 3[1] ?

David

[1]
http://lists.centos.org/pipermail/centos-announce/2007-November/014370.html


Oliver Hookins

unread,
Oct 6, 2008, 8:08:15 PM10/6/08
to puppe...@googlegroups.com
On Fri Oct 03, 2008 at 11:41:40 -0700, David Lutterkort wrote:
>
>On Tue, 2008-09-23 at 16:47 +1000, Oliver Hookins wrote:
>> Signed-off-by: Oliver Hookins <oliver....@anchor.com.au>
>> ---
>> lib/puppet/provider/package/rpm.rb | 9 +++-
>> lib/puppet/provider/package/yumhelper.py | 102 ++++++++++++++++++++++++++---
>> 2 files changed, 99 insertions(+), 12 deletions(-)
>
>I gave this a quick read and a spin on F9 and RHEL5, and it works for
>me. Out of interest, since you're using puppet on RHEL3 and yum, you are
>already on a fairly large set of self-supported packages. Why not use
>the yum-2.4 port from CentOS 3[1] ?

I was under the impression Yum 2.4 required Python 2.3, but if the CentOS
version will work as you suggest then I'll gladly use it. Sadly we also have
some RHEL 2.1 (which is not EOL yet) machines which this wouldn't be a
suitable fix for.

--
Regards,
Oliver Hookins
Anchor Systems

James Turnbull

unread,
Oct 6, 2008, 8:39:43 PM10/6/08
to puppe...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Oliver

If you could please update the patch with David's comments from the
ticket I can put this in for 0.24.6.

Regards

James

- --
Author of:
* Pulling Strings with Puppet
(http://www.amazon.com/gp/product/1590599780/)
* Pro Nagios 2.0
(http://www.amazon.com/gp/product/1590596099/)
* Hardening Linux
(http://www.amazon.com/gp/product/1590594444/)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFI6q/P9hTGvAxC30ARAjJMAJ9qdR3LC/U+BCgAIAw+9R0gwK0uuQCgr3+/
kbsU+YcA2m28tNuuKlXlgec=
=OKxH
-----END PGP SIGNATURE-----

Oliver Hookins

unread,
Oct 6, 2008, 9:34:45 PM10/6/08
to puppe...@googlegroups.com
On Tue Oct 07, 2008 at 11:39:43 +1100, James Turnbull wrote:
>
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>Oliver Hookins wrote:
>> On Fri Oct 03, 2008 at 11:41:40 -0700, David Lutterkort wrote:
>>> On Tue, 2008-09-23 at 16:47 +1000, Oliver Hookins wrote:
>>>> Signed-off-by: Oliver Hookins <oliver....@anchor.com.au>
>>>> ---
>>>> lib/puppet/provider/package/rpm.rb | 9 +++-
>>>> lib/puppet/provider/package/yumhelper.py | 102 ++++++++++++++++++++++++++---
>>>> 2 files changed, 99 insertions(+), 12 deletions(-)
>>> I gave this a quick read and a spin on F9 and RHEL5, and it works for
>>> me. Out of interest, since you're using puppet on RHEL3 and yum, you are
>>> already on a fairly large set of self-supported packages. Why not use
>>> the yum-2.4 port from CentOS 3[1] ?
>>
>> I was under the impression Yum 2.4 required Python 2.3, but if the CentOS
>> version will work as you suggest then I'll gladly use it. Sadly we also have
>> some RHEL 2.1 (which is not EOL yet) machines which this wouldn't be a
>> suitable fix for.
>>
>
>Oliver
>
>If you could please update the patch with David's comments from the
>ticket I can put this in for 0.24.6.

Certainly, will do this now.

Reply all
Reply to author
Forward
0 new messages