From 6a537a6451233f42ffff70953972c1c04c5eeb29 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 2 Aug 2011 07:32:38 -0400 Subject: don't add gpg-pubkey package unless there are instances to install --- src/lib/Server/Plugins/Packages.py | 71 +++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/lib/Server/Plugins/Packages.py b/src/lib/Server/Plugins/Packages.py index 1c960b212..eab7721a3 100644 --- a/src/lib/Server/Plugins/Packages.py +++ b/src/lib/Server/Plugins/Packages.py @@ -1202,47 +1202,48 @@ class Packages(Bcfg2.Server.Plugin.Plugin, def _build_gpgkeys(self, metadata, independent): """ build list of gpg keys to be added to the specification by validate_structures() """ - keypkg = lxml.etree.Element('BoundPackage', name="gpg-pubkey", - type=self.get_ptype(metadata), - origin='Packages') - needkeys = set() for source in self.get_matching_sources(metadata): for key in source.gpgkeys: needkeys.add(key) - for key in needkeys: - # figure out the path of the key on the client - try: - keydir = self.config.get("global", "gpg_keypath") - except ConfigParser.NoOptionError: - keydir = "/etc/pki/rpm-gpg" - remotekey = os.path.join(keydir, os.path.basename(key)) - localkey = os.path.join(self.keypath, os.path.basename(key)) - kdata = open(localkey).read() + if len(needkeys): + keypkg = lxml.etree.Element('BoundPackage', name="gpg-pubkey", + type=self.get_ptype(metadata), + origin='Packages') + + for key in needkeys: + # figure out the path of the key on the client + try: + keydir = self.config.get("global", "gpg_keypath") + except ConfigParser.NoOptionError: + keydir = "/etc/pki/rpm-gpg" + remotekey = os.path.join(keydir, os.path.basename(key)) + localkey = os.path.join(self.keypath, os.path.basename(key)) + kdata = open(localkey).read() - # copy the key to the client - keypath = lxml.etree.Element("BoundPath", name=remotekey, - encoding='ascii', - owner='root', group='root', - type='file', perms='0644', - important='true') - keypath.text = kdata - independent.append(keypath) - - if has_yum: - # add the key to the specification to ensure it gets - # installed - kinfo = yum.misc.getgpgkeyinfo(kdata) - version = yum.misc.keyIdToRPMVer(kinfo['keyid']) - release = yum.misc.keyIdToRPMVer(kinfo['timestamp']) - - lxml.etree.SubElement(keypkg, 'Instance', version=version, - release=release, simplefile=remotekey) - else: - self.logger.info("Yum libraries not found; GPG keys will not " - "be handled automatically") - independent.append(keypkg) + # copy the key to the client + keypath = lxml.etree.Element("BoundPath", name=remotekey, + encoding='ascii', + owner='root', group='root', + type='file', perms='0644', + important='true') + keypath.text = kdata + independent.append(keypath) + + if has_yum: + # add the key to the specification to ensure it + # gets installed + kinfo = yum.misc.getgpgkeyinfo(kdata) + version = yum.misc.keyIdToRPMVer(kinfo['keyid']) + release = yum.misc.keyIdToRPMVer(kinfo['timestamp']) + + lxml.etree.SubElement(keypkg, 'Instance', version=version, + release=release, simplefile=remotekey) + else: + self.logger.info("Yum libraries not found; GPG keys will " + "not be handled automatically") + independent.append(keypkg) def Refresh(self): '''Packages.Refresh() => True|False\nReload configuration -- cgit v1.2.3-1-g7c22