public
Rubygem
Description: James Turnbull's Puppet remote
Homepage: http://reductivelabs.com/trac/puppet
Clone URL: git://github.com/jamtur01/puppet.git
Fxied #1354 - yum provider problems with RHEL 3
jamtur01 (author)
Mon Oct 06 19:51:59 -0700 2008
commit  7275d7cb9083b4183f394a5d6798e1675def6d28
tree    a92bd14cbd1233c9e9b2cc97150462b76a420dbb
parent  0c297be5dad784e305ef194cee29b11a92d31b6b
...
1
 
 
2
3
4
...
12
13
14
15
 
 
16
17
 
 
18
19
20
...
1
2
3
4
5
6
...
14
15
16
 
17
18
19
 
20
21
22
23
24
0
@@ -1,4 +1,6 @@
0
 0.24.x
0
+ Fixed #1354 - yum provider problems with RHEL 3
0
+
0
     Fixed #381 - Allow Allow multiple overrides in one statement
0
 
0
     Fixing #947 - pluginsync no longer fails poorly when no plugins exist
0
@@ -12,9 +14,11 @@
0
 
0
     Fixing #1614 - Environments no longer have to be listed out
0
 
0
- Fixed #1628 - Changed node search to use certname rather than Facter hostname
0
+ Fixed #1628 - Changed node search to use certname rather than Facter
0
+ hostname
0
     
0
- Fixed #1613 - The client environment will be substituted when looking up settings.
0
+ Fixed #1613 - The client environment will be substituted when looking
0
+ up settings.
0
 
0
     Updated puppet binary documentation
0
 
...
23
24
25
 
 
 
 
 
 
 
26
27
28
 
29
30
31
...
23
24
25
26
27
28
29
30
31
32
33
34
 
35
36
37
38
0
@@ -23,9 +23,16 @@ Puppet::Type.type(:package).provide :rpm, :source => :rpm, :parent => Puppet::Pr
0
     def self.instances
0
         packages = []
0
 
0
+ # rpm < 4.1 don't support --nosignature
0
+ output = rpm "--version"
0
+ sig = "--nosignature"
0
+ if output =~ /RPM version (([123].*)|(4\.0.*))/
0
+ sig = ""
0
+ end
0
+
0
         # list out all of the packages
0
         begin
0
- execpipe("#{command(:rpm)} -qa --nosignature --nodigest --qf '#{NEVRAFORMAT}\n'") { |process|
0
+ execpipe("#{command(:rpm)} -qa #{sig} --nodigest --qf '#{NEVRAFORMAT}\n'") { |process|
0
                 # now turn each returned line into a package object
0
                 process.each { |line|
0
                     hash = nevra_to_hash(line)
...
4
5
6
7
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
10
11
...
26
27
28
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
31
32
33
34
35
36
37
38
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
4
5
6
 
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
...
41
42
43
 
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
 
 
 
 
 
 
 
 
 
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
0
@@ -4,8 +4,23 @@
0
 # (C) 2007 Red Hat Inc.
0
 # David Lutterkort <dlutter @redhat.com>
0
 
0
-import yum
0
 import sys
0
+import string
0
+import re
0
+
0
+# this maintains compatibility with really old platforms with python 1.x
0
+from os import popen, WEXITSTATUS
0
+
0
+# Try to use the yum libraries by default, but shell out to the yum executable
0
+# if they are not present (i.e. yum <= 2.0). This is only required for RHEL3
0
+# and earlier that do not support later versions of Yum. Once RHEL3 is EOL,
0
+# shell_out() and related code can be removed.
0
+try:
0
+ import yum
0
+except ImportError:
0
+ useyumlib = 0
0
+else:
0
+ useyumlib = 1
0
 
0
 OVERRIDE_OPTS = {
0
     'debuglevel': 0,
0
@@ -26,14 +41,80 @@ def pkg_lists(my):
0
     my.doRpmDBSetup()
0
     return my.doPackageLists('updates')
0
 
0
-try:
0
+def shell_out():
0
+ try:
0
+ p = popen("/usr/bin/env yum check-update 2>&1")
0
+ output = p.readlines()
0
+ rc = p.close()
0
+
0
+ if rc is not None:
0
+ # None represents exit code of 0, otherwise the exit code is in the
0
+ # format returned by wait(). Exit code of 100 from yum represents
0
+ # updates available.
0
+ if WEXITSTATUS(rc) != 100:
0
+ return WEXITSTATUS(rc)
0
+ else:
0
+ # Exit code is None (0), no updates waiting so don't both parsing output
0
+ return 0
0
+
0
+ # Yum prints a line of hyphens (old versions) or a blank line between
0
+ # headers and package data, so skip everything before them
0
+ skipheaders = 0
0
+ for line in output:
0
+ if not skipheaders:
0
+ if re.compile("^((-){80}|)$").search(line):
0
+ skipheaders = 1
0
+ continue
0
+
0
+ # Skip any blank lines
0
+ if re.compile("^[ \t]*$").search(line):
0
+ continue
0
+
0
+ # Format is:
0
+ # Yum 1.x: name arch (epoch:)?version
0
+ # Yum 2.0: name arch (epoch:)?version repo
0
+ # epoch is optional if 0
0
+
0
+ p = string.split(line)
0
+ pname = p[0]
0
+ parch = p[1]
0
+ pevr = p[2]
0
+
0
+ # Separate out epoch:version-release
0
+ evr_re = re.compile("^(\d:)?(\S+)-(\S+)$")
0
+ evr = evr_re.match(pevr)
0
+
0
+ pepoch = ""
0
+ if evr.group(1) is None:
0
+ pepoch = "0"
0
+ else:
0
+ pepoch = evr.group(1).replace(":", "")
0
+ pversion = evr.group(2)
0
+ prelease = evr.group(3)
0
+
0
+ print "_pkg", pname, pepoch, pversion, prelease, parch
0
+
0
+ return 0
0
+ except:
0
+ print sys.exc_info()[0]
0
+ return 1
0
+
0
+if useyumlib:
0
     try:
0
- my = yum.YumBase()
0
- ypl = pkg_lists(my)
0
- for pkg in ypl.updates:
0
- print "_pkg %s %s %s %s %s" % (pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch)
0
- finally:
0
- my.closeRpmDB()
0
-except IOError, e:
0
- print "_err IOError %d %s" % (e.errno, e)
0
- sys.exit(1)
0
+ try:
0
+ my = yum.YumBase()
0
+ ypl = pkg_lists(my)
0
+ for pkg in ypl.updates:
0
+ print "_pkg %s %s %s %s %s" % (pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch)
0
+ finally:
0
+ my.closeRpmDB()
0
+ except IOError, e:
0
+ print "_err IOError %d %s" % (e.errno, e)
0
+ sys.exit(1)
0
+ except AttributeError, e:
0
+ # catch yumlib errors in buggy 2.x versions of yum
0
+ print "_err AttributeError %s" % e
0
+ sys.exit(1)
0
+else:
0
+ rc = shell_out()
0
+ sys.exit(rc)

Comments

    No one has commented yet.