contrib/rhn-clone-errata.py | 112 --------------
scripts/clone-errata/README | 15 +
scripts/clone-errata/rhn-clone-errata.py | 235 ++++++++++++++++++-------------
3 files changed, 156 insertions(+), 206 deletions(-)
New commits:
commit 82788f843583c33827dc660d0f64960c419c4d76
Author: Speagle, Andy <andy.speagle(a)wichita.edu>
Date: Wed Nov 23 16:28:24 2011 +0100
Users can choose to sync all configured channels at once; default behavior has been
changed with regard to errata missing packages.
diff --git a/scripts/clone-errata/README b/scripts/clone-errata/README
index 0ea1010..8076ed2 100644
--- a/scripts/clone-errata/README
+++ b/scripts/clone-errata/README
@@ -36,6 +36,13 @@ options:
-e EDATE, --end-date=EDATE
Ending Date: ie. "19001231" (defaults to TODAY)
-i, --publish Publish Errata (into destination channels)
+ -I, --ignoremissing Default behavior is to skip errata for which
+ there are missing packages, this option
+ allows the errata to be created without
+ packages that it should have.
+ -A, --sync-all-channels
+ This option clones errata for all channels
+ configured in the config file.
-x PROXY, --proxy=PROXY
Proxy server and port to use (e.g.
proxy.company.com:3128)
@@ -54,3 +61,11 @@ options:
I'm presently working on adding in support for CVEs
but am running into an issue. Probably done in
version 1.6 ...
+
+2011/11/17 - Andy speagle
+
+ Default behavior of how errata with missing packages
+ are handled has been changed. If an errata is missing
+ packages, the script will now, by default, skip creating
+ that errata. You can use "-I" to ignore missing packages
+ and continue creating the errata.
diff --git a/scripts/clone-errata/rhn-clone-errata.py
b/scripts/clone-errata/rhn-clone-errata.py
index 0ddfe87..1374858 100644
--- a/scripts/clone-errata/rhn-clone-errata.py
+++ b/scripts/clone-errata/rhn-clone-errata.py
@@ -90,6 +90,18 @@
#
# Add some code to handle transparent proxies.
#
+# 0.9.0 - 2011-11-17 - Andy Speagle
+#
+# Included patch from Pierre Casenove <pcasenove(a)gmail.com> that gives an option
for a
+# full sync of all channels listed in the configuration file.
+#
+# Thanks, Pierre!
+#
+# Additionally, changed the default behaviour of how the script handles errata that are
+# missing packages on the system. The script now skips any errata that is missing one
+# or more packages on the system. However, I've added an option to allow the script
+# to ignore missing packages so that the old behaviour remains.
+#
import xmlrpclib, httplib
from optparse import OptionParser
@@ -559,6 +571,8 @@ def parse_args():
help="Ending Date: ie. \"19001231\" (defaults to TODAY)")
parser.add_option("-i", "--publish",
action="store_true", dest="publish", default=False,
help="Publish Errata (into destination channels)")
+ parser.add_option("-I", "--ignore-missing-packages",
action="store_true", dest="ignoremissing", default=False,
+ help="Ignore Missing Packages")
parser.add_option("-x", "--proxy", type="string",
dest="proxy",
help="Proxy server and port to use (e.g. proxy.company.com:3128)")
parser.add_option("--no-spw-proxy", action="store_true",
dest="nospwproxy", default=False,
@@ -567,6 +581,8 @@ def parse_args():
help="Don't proxy the RHN server connection. (Proxy by default, if proxy is
set)")
parser.add_option("-F", "--format-header",
action="store_true", dest="format", default=False,
help="Format header for logfiles")
+ parser.add_option("-A", "--sync-all-channels",
action="store_true", dest="fullsync", default=False,
+ help="Synchronize erratas of all channels listed in the provided configuration
file")
parser.add_option("-v", "--verbose",
action="store_true", dest="verbose", default=False)
parser.add_option("-q", "--quiet", action="store_true",
dest="quiet", default=False)
@@ -616,8 +632,14 @@ def main():
chanMap = {}
- for chan in config.options('ChanMap'):
- chanMap[chan] = config.get('ChanMap', chan)
+ if options.fullsync:
+ for chan in config.options('ChanMap'):
+ chanMap[chan] = config.get('ChanMap', chan)
+ else:
+ if options.src_channel is None:
+ print "Source channel not given, aborting"
+ sys.exit(2)
+ chanMap[options.src_channel] = config.get('ChanMap', options.src_channel)
# Here we also setup mappings from RHN channels to errata suffixes.
# Since we can't easily publish automagically, while ensuring that
@@ -643,10 +665,6 @@ def main():
print "try: "+sys.argv[0]+" --help"
sys.exit(2)
- if chanMap[options.src_channel] is None:
- print "Invalid Channel!"
- sys.exit(2)
-
rhnProxy = 0
spwProxy = 0
@@ -663,98 +681,127 @@ def main():
dateToday = strftime("%Y%m%d", localtime())
dateEnd = options.edate or dateToday
- if options.format:
- print >>sys.stdout, "%s:CLONE:%s" % (dateToday, options.src_channel)
- print >>sys.stderr, "%s:CLONE:%s" % (dateToday, options.src_channel)
-
- for rhnErrata in myRHN.listChannelErrata(options.src_channel,dateStart,dateEnd,0):
- if not options.quiet and not options.format:
- print rhnErrata['errata_advisory']
-
-# Now, let's check if we already have this errata locally...
- spwErrataName =
rhnErrata['errata_advisory']+':'+chanSuffixMap[options.src_channel]
- spwErrCheck = mySPW.getErrataDetails (spwErrataName,0)
-
- if not spwErrCheck:
-# Ok, so the errata doesn't already exists... let's get busy creating
it.
- spwErrSolution = "Before applying this update, make sure that all "+\
- "previously-released errata relevant to your system have been
applied."
-
- spwErrPackages = []
- for pkg in myRHN.getErrataPackages(rhnErrata['errata_advisory'],0):
- pkgFind = mySPW.searchNVREA(pkg['package_name'],\
- pkg['package_version'],\
- pkg['package_release'],\
- '',\
- pkg['package_arch_label'],\
- 0)
-
- for pkgChan in pkg['providing_channels']:
- if pkgChan != options.src_channel:
- continue
- else:
- if not pkgFind:
- if options.format:
- print >>sys.stderr, "%s:%s:Hmmm... "+\
- "Package Missing: %s" % (dateToday,
rhnErrata['errata_advisory'], pkg['package_name'])
- else:
- print "Hmmm... Package Missing: %s" % pkg['package_name']
- else:
- spwErrPackages.append(pkgFind[0]['id'])
- break
+ for chan in chanMap:
+ if chanMap[chan] is None:
+ print "Invalid Channel!"
+ sys.exit(2)
- spwErrDetails = myRHN.getErrataDetails(rhnErrata['errata_advisory'],0)
- spwErrKeywords =
myRHN.getErrataKeywords(rhnErrata['errata_advisory'],0)
- spwErrCVEs = myRHN.getErrataCVEs(rhnErrata['errata_advisory'],0)
+ if options.format:
+ print >>sys.stdout, "%s:CLONE:%s" % (dateToday, chan)
+ print >>sys.stderr, "%s:CLONE:%s" % (dateToday, chan)
- spwErrBugs = []
- tmpBugs = myRHN.getErrataBugs(rhnErrata['errata_advisory'],0)
+ for rhnErrata in myRHN.listChannelErrata(chan,dateStart,dateEnd,0):
+ if not options.quiet and not options.format:
+ print rhnErrata['errata_advisory']
- for bug in tmpBugs:
- spwErrBugs.append({'id': int(bug), 'summary':
tmpBugs[bug]})
+# Now, let's check if we already have this errata locally...
+ spwErrataName =
rhnErrata['errata_advisory']+':'+chanSuffixMap[chan]
+ spwErrCheck = mySPW.getErrataDetails (spwErrataName,0)
- if not options.quiet and not options.format:
- print "\t%s - %s" %
(spwErrDetails['errata_issue_date'],spwErrDetails['errata_synopsis'])
-
- spwErrObject = mySPW.errataCreate ({ 'synopsis':
spwErrDetails['errata_synopsis'],\
- 'advisory_name': spwErrataName,\
- 'advisory_release': 1,\
- 'advisory_type': spwErrDetails['errata_type'],\
- 'product': 'RHEL',\
- 'topic': spwErrDetails['errata_topic'],\
- 'description': spwErrDetails['errata_description'],\
- 'references': spwErrDetails['errata_references'],\
- 'notes': spwErrDetails['errata_notes'],\
- 'solution': spwErrSolution },\
- spwErrBugs,\
- spwErrKeywords,\
- spwErrPackages,\
- 0,\
- [chanMap[options.src_channel]],\
- 0)
-
- if options.format:
- print "%s#%s#Errata Created#" % (dateToday, spwErrataName),
- else:
- print "\tErrata Created: %d" % spwErrObject['id']
-
- if options.publish:
- spwPublish = mySPW.errataPublish (spwErrataName, [chanMap[options.src_channel]], 0)
- if options.format:
- print "Errata Published"
- else:
- print "\tErrata Published!"
- else:
- if options.format:
- print "Errata Not Published"
- else:
- print "\tErrata Not Published!"
- else:
- if options.format:
- print "%s#%s#Errata Already Exists" % (dateToday, spwErrataName)
- elif not options.quiet:
- print "\tErrata Already Exists. %s" % spwErrataName
- continue
+ if not spwErrCheck:
+# Ok, so the errata doesn't already exists... let's get busy
creating it.
+ spwErrSolution = "Before applying this update, make sure that all "+\
+ "previously-released errata relevant to your system have been
applied."
+
+ spwErrPackages = []
+
+ missingcheck = 0
+
+ for pkg in myRHN.getErrataPackages(rhnErrata['errata_advisory'],0):
+ pkgFind = mySPW.searchNVREA(pkg['package_name'],\
+ pkg['package_version'],\
+ pkg['package_release'],\
+ '',\
+ pkg['package_arch_label'],\
+ 0)
+
+ for pkgChan in pkg['providing_channels']:
+ if pkgChan != chan:
+ continue
+ else:
+ if not pkgFind:
+ missingcheck += 1
+
+ if options.format:
+ print >>sys.stderr, "%s:%s:Hmmm... "+\
+ "Package Missing: %s" % (dateToday,
rhnErrata['errata_advisory'], pkg['package_name'])
+ else:
+ print "Hmmm... Package Missing: %s" % pkg['package_name']
+
+ else:
+ spwErrPackages.append(pkgFind[0]['id'])
+ break
+
+ if missingcheck:
+ if options.ignoremissing:
+ skiptext = "Ignoring missing package(s) and
continuing..."
+
+ if options.format:
+ print >>sys.stderr, "%s" % skiptext
+ else:
+ print "%s" % skiptext
+ else:
+ skiptext = "Skipping errata due to missing
package(s)..."
+
+ if options.format:
+ print >>sys.stderr, "%s" % skiptext
+ else:
+ print "%s" % skiptext
+
+ continue
+
+ spwErrDetails = myRHN.getErrataDetails(rhnErrata['errata_advisory'],0)
+ spwErrKeywords =
myRHN.getErrataKeywords(rhnErrata['errata_advisory'],0)
+ spwErrCVEs = myRHN.getErrataCVEs(rhnErrata['errata_advisory'],0)
+
+ spwErrBugs = []
+ tmpBugs = myRHN.getErrataBugs(rhnErrata['errata_advisory'],0)
+
+ for bug in tmpBugs:
+ spwErrBugs.append({'id': int(bug), 'summary':
tmpBugs[bug]})
+
+ if not options.quiet and not options.format:
+ print "\t%s - %s" %
(spwErrDetails['errata_issue_date'],spwErrDetails['errata_synopsis'])
+
+ spwErrObject = mySPW.errataCreate ({ 'synopsis':
spwErrDetails['errata_synopsis'],\
+ 'advisory_name': spwErrataName,\
+ 'advisory_release': 1,\
+ 'advisory_type': spwErrDetails['errata_type'],\
+ 'product': 'RHEL',\
+ 'topic': spwErrDetails['errata_topic'],\
+ 'description': spwErrDetails['errata_description'],\
+ 'references': spwErrDetails['errata_references'],\
+ 'notes': spwErrDetails['errata_notes'],\
+ 'solution': spwErrSolution },\
+ spwErrBugs,\
+ spwErrKeywords,\
+ spwErrPackages,\
+ 0,\
+ [chanMap[chan]],\
+ 0)
+
+ if options.format:
+ print "%s#%s#Errata Created#" % (dateToday, spwErrataName),
+ else:
+ print "\tErrata Created: %d" % spwErrObject['id']
+
+ if options.publish:
+ spwPublish = mySPW.errataPublish (spwErrataName, [chanMap[chan]], 0)
+ if options.format:
+ print "Errata Published"
+ else:
+ print "\tErrata Published!"
+ else:
+ if options.format:
+ print "Errata Not Published"
+ else:
+ print "\tErrata Not Published!"
+ else:
+ if options.format:
+ print "%s#%s#Errata Already Exists" % (dateToday, spwErrataName)
+ elif not options.quiet:
+ print "\tErrata Already Exists. %s" % spwErrataName
+ continue
if __name__ == "__main__":
main()
commit 4662c52e523c6e8b595458aa9f909fba6c6b4be9
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Wed Nov 23 16:22:15 2011 +0100
Removing contrib/rhn-clone-errata.py, it now lives in
scripts/clone-errata/rhn-clone-errata.py.
diff --git a/contrib/rhn-clone-errata.py b/contrib/rhn-clone-errata.py
deleted file mode 100755
index e929975..0000000
--- a/contrib/rhn-clone-errata.py
+++ /dev/null
@@ -1,112 +0,0 @@
-#!/bin/env python
-# API Script used to communicate with RHN Satellite
-# Copyright (C) 2008 Red Hat
-#
-# Author: Lars Jonsson (ljonsson(a)redhat.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
-
-import xmlrpclib
-from optparse import OptionParser
-import sys
-
-class RHNServer:
- def __init__(self,servername,user,passwd):
- self.rhnServerName = servername
- self.login = user
- self.password = passwd
- self.rhnUrl = 'https://'+self.rhnServerName+'/rpc/api'
- self.server = xmlrpclib.Server(self.rhnUrl)
- self.rhnSession=self.rhnLogin(self.login,self.password)
-
- def rhnLogin(self, login, password):
- try:
- rhnSession=self.server.auth.login(login,password)
- except xmlrpclib.Fault, f:
- if f.faultCode==-20:
- print "Session expired"
- self.rhnLogin(login,password)
- else:
- print "Failed to login",f
- raise
- return rhnSession
-
- def cloneErrata(self,dest_chan,errata):
- out=[]
- try:
- print "Clone errata in progress, please be patient.."
- out = self.server.errata.clone(self.rhnSession,dest_chan,errata)
- except xmlrpclib.Fault, f:
- if f.faultCode==-20:
- self.rhnLogin(self.login,self.password)
- return self.server.errata.clone(self.rhnSession,dest_chan,errata)
- else:
- raise
- return out
-
- def listChannelErrata(self,channel_label):
- out=[]
- try:
- out = self.server.errata.listByDate(self.rhnSession,channel_label)
- except xmlrpclib.Fault, f:
- if f.faultCode==-20:
- self.rhnLogin(self.login,self.password)
- return self.server.errata.listByDate(self.rhnSession,channel_label)
- else:
- raise
- return out
-
-def parse_args():
- parser = OptionParser()
- parser.add_option("-s", "--server", type="string",
dest="servername",
- help="RHN Satellite server hostname")
- parser.add_option("-l", "--login", type="string",
dest="login",
- help="RHN Login")
- parser.add_option("-p", "--password", type="string",
dest="passwd",
- help="RHN password")
- parser.add_option("", "--src-channel", type="string",
dest="src_channel",
- help="channel label: ie.\"rhel-i386-as-4\"")
- parser.add_option("", "--dest-channel", type="string",
dest="dest_channel",
- help="channel label: ie.\"my-rhel-i386-as-4\"")
- parser.add_option("", "--clone-up-to-date",
type="string", dest="cdate",
- help="Date: ie. \"20080403T16:53:00\"")
- parser.add_option("", "--list", action="store_true",
dest="list", default=False,
- help="List source channel errata by date")
-
- (options,args) = parser.parse_args()
- return options
-
-def main():
-
- options = parse_args()
-
- if (options.servername and options.login and options.passwd) is None:
- print "try: "+sys.argv[0]+" --help"
- sys.exit(2)
- myserver = RHNServer(options.servername,options.login,options.passwd)
-
- if options.list and options.src_channel:
- for c in myserver.listChannelErrata(options.src_channel):
- print "%s\t%s (%s)" %
(c['date'],c['advisory_synopsis'],c['advisory_name'])
- if options.cdate:
- aerrata = []
- for c in myserver.listChannelErrata(options.src_channel):
- if c['date'] <= options.cdate:
- aerrata.append(c['advisory_name'])
- myserver.cloneErrata(options.dest_channel, aerrata)
-
-if __name__ == "__main__":
- main()