From f804bb801d4002aa95d6326a7b19b29a9dc13670 Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Tue, 27 Mar 2012 12:38:50 -0500 Subject: launchd: Remove popen2 calls Signed-off-by: Sol Jerome --- src/lib/Client/Tools/launchd.py | 50 ++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/lib/Client/Tools/launchd.py b/src/lib/Client/Tools/launchd.py index 03dd97e71..e70d7d83e 100644 --- a/src/lib/Client/Tools/launchd.py +++ b/src/lib/Client/Tools/launchd.py @@ -2,7 +2,6 @@ __revision__ = '$Revision$' import os -import popen2 import Bcfg2.Client.Tools @@ -27,7 +26,8 @@ class launchd(Bcfg2.Client.Tools.Tool): /Library/LaunchDaemons System wide daemons provided by the administrator. /System/Library/LaunchAgents Mac OS X Per-user agents. /System/Library/LaunchDaemons Mac OS X System wide daemons.''' - plistLocations = ["/Library/LaunchDaemons", "/System/Library/LaunchDaemons"] + plistLocations = ["/Library/LaunchDaemons", + "/System/Library/LaunchDaemons"] self.plistMapping = {} for directory in plistLocations: for daemon in os.listdir(directory): @@ -36,10 +36,10 @@ class launchd(Bcfg2.Client.Tools.Tool): d = daemon[:-6] else: d = daemon - (stdout, _) = popen2.popen2('defaults read %s/%s Label' % (directory, d)) - label = stdout.read().strip() + label = self.cmd.run('defaults read %s/%s Label' % + (directory, d))[1] self.plistMapping[label] = "%s/%s" % (directory, daemon) - except KeyError: #perhaps this could be more robust + except KeyError: # perhaps this could be more robust pass def FindPlist(self, entry): @@ -61,20 +61,26 @@ class launchd(Bcfg2.Client.Tools.Tool): """Verify launchd service entry.""" try: services = self.cmd.run("/bin/launchctl list")[1] - except IndexError:#happens when no services are running (should be never) + except IndexError: + # happens when no services are running (should be never) services = [] # launchctl output changed in 10.5 - # It is now three columns, with the last column being the name of the # service + # It is now three columns, with the last + # column being the name of the # service version = self.os_version() if version.startswith('10.5') or version.startswith('10.6'): services = [s.split()[-1] for s in services] - if entry.get('name') in services:#doesn't check if non-spawning services are Started + if entry.get('name') in services: + # doesn't check if non-spawning services are Started return entry.get('status') == 'on' else: - self.logger.debug("Didn't find service Loaded (launchd running under same user as bcfg)") + self.logger.debug("Launchd: Didn't find service Loaded " + "(launchd running under same user as bcfg)") return entry.get('status') == 'off' - try: #Perhaps add the "-w" flag to load and unload to modify the file itself! + try: + # Perhaps add the "-w" flag to load and + # unload to modify the file itself! self.cmd.run("/bin/launchctl load -w %s" % self.FindPlist(entry)) except IndexError: return 'on' @@ -90,12 +96,14 @@ class launchd(Bcfg2.Client.Tools.Tool): name = entry.get('name') if entry.get('status') == 'on': self.logger.error("Installing service %s" % name) - cmdrc = self.cmd.run("/bin/launchctl load -w %s" % self.FindPlist(entry)) + cmdrc = self.cmd.run("/bin/launchctl load -w %s" % + self.FindPlist(entry)) cmdrc = self.cmd.run("/bin/launchctl start %s" % name) else: self.logger.error("Uninstalling service %s" % name) cmdrc = self.cmd.run("/bin/launchctl stop %s" % name) - cmdrc = self.cmd.run("/bin/launchctl unload -w %s" % self.FindPlist(entry)) + cmdrc = self.cmd.run("/bin/launchctl unload -w %s" % + self.FindPlist(entry)) return cmdrc[0] == 0 def Remove(self, svcs): @@ -120,17 +128,23 @@ class launchd(Bcfg2.Client.Tools.Tool): """Reload launchd plist.""" for entry in [entry for entry in bundle if self.handlesEntry(entry)]: if not self.canInstall(entry): - self.logger.error("Insufficient information to restart service %s" % (entry.get('name'))) + self.logger.error("Insufficient information to restart service %s" % + (entry.get('name'))) else: name = entry.get('name') if entry.get('status') == 'on' and self.FindPlist(entry): self.logger.info("Reloading launchd service %s" % name) - #stop? + # stop? self.cmd.run("/bin/launchctl stop %s" % name) - self.cmd.run("/bin/launchctl unload -w %s" % (self.FindPlist(entry)))#what if it disappeared? how do we stop services that are currently running but the plist disappeared?! - self.cmd.run("/bin/launchctl load -w %s" % (self.FindPlist(entry))) + # what if it disappeared? how do we stop services + # that are currently running but the plist disappeared?! + self.cmd.run("/bin/launchctl unload -w %s" % + (self.FindPlist(entry))) + self.cmd.run("/bin/launchctl load -w %s" % + (self.FindPlist(entry))) self.cmd.run("/bin/launchctl start %s" % name) else: - #only if necessary.... + # only if necessary.... self.cmd.run("/bin/launchctl stop %s" % name) - self.cmd.run("/bin/launchctl unload -w %s" % (self.FindPlist(entry))) + self.cmd.run("/bin/launchctl unload -w %s" % + (self.FindPlist(entry))) -- cgit v1.2.3-1-g7c22 From e6d9984baf3fc9788ac82ba75e4ea17d38d80b42 Mon Sep 17 00:00:00 2001 From: Luke Cyca Date: Fri, 13 Apr 2012 17:38:08 -0700 Subject: Fixed MacPorts pkgtool tuple and cleaned up logger output --- src/lib/Client/Tools/MacPorts.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lib/Client/Tools/MacPorts.py b/src/lib/Client/Tools/MacPorts.py index 23b536451..e84d3e553 100644 --- a/src/lib/Client/Tools/MacPorts.py +++ b/src/lib/Client/Tools/MacPorts.py @@ -11,7 +11,7 @@ class MacPorts(Bcfg2.Client.Tools.PkgTool): __handles__ = [('Package', 'macport')] __req__ = {'Package': ['name', 'version']} pkgtype = 'macport' - pkgtool = ("/opt/local/bin/port install %s") + pkgtool = ('/opt/local/bin/port install %s', ('%s', ['name'])) def __init__(self, logger, setup, config): Bcfg2.Client.Tools.PkgTool.__init__(self, logger, setup, config) @@ -27,7 +27,7 @@ class MacPorts(Bcfg2.Client.Tools.PkgTool): continue pkgname = pkg.split('@')[0].strip() version = pkg.split('@')[1].split(' ')[0] - self.logger.info(" pkgname: %s\n version: %s" % (pkgname, version)) + self.logger.info(" pkgname: %s version: %s" % (pkgname, version)) self.installed[pkgname] = version def VerifyPackage(self, entry, modlist): -- cgit v1.2.3-1-g7c22 From 0ec333243a90cce12f12397dd95ed13a89d36ea0 Mon Sep 17 00:00:00 2001 From: Luke Cyca Date: Mon, 16 Apr 2012 14:39:38 -0700 Subject: MacPorts now respects version="any" and logs version mismatches like other plugins. --- src/lib/Client/Tools/MacPorts.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib/Client/Tools/MacPorts.py b/src/lib/Client/Tools/MacPorts.py index e84d3e553..2a7ba9eb9 100644 --- a/src/lib/Client/Tools/MacPorts.py +++ b/src/lib/Client/Tools/MacPorts.py @@ -38,13 +38,20 @@ class MacPorts(Bcfg2.Client.Tools.PkgTool): return False if entry.attrib['name'] in self.installed: - if self.installed[entry.attrib['name']] == entry.attrib['version']: + if (self.installed[entry.attrib['name']] == entry.attrib['version'] or + entry.attrib['version'] == 'any'): #if not self.setup['quick'] and \ # entry.get('verify', 'true') == 'true': #FIXME: We should be able to check this once # http://trac.macports.org/ticket/15709 is implemented return True else: + self.logger.info(" %s: Wrong version installed. " + "Want %s, but have %s" % (entry.get("name"), + entry.get("version"), + self.installed[entry.get("name")], + )) + entry.set('current_version', self.installed[entry.get('name')]) return False entry.set('current_exists', 'false') -- cgit v1.2.3-1-g7c22 From 74be9f46696308e05b6097c7968043a90df06de4 Mon Sep 17 00:00:00 2001 From: Luke Cyca Date: Mon, 16 Apr 2012 14:43:15 -0700 Subject: Fixed launchd to correctly parse label from plist, and added a warning when it can't be parsed. --- src/lib/Client/Tools/launchd.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/lib/Client/Tools/launchd.py b/src/lib/Client/Tools/launchd.py index e70d7d83e..d7cbfa07f 100644 --- a/src/lib/Client/Tools/launchd.py +++ b/src/lib/Client/Tools/launchd.py @@ -37,10 +37,11 @@ class launchd(Bcfg2.Client.Tools.Tool): else: d = daemon label = self.cmd.run('defaults read %s/%s Label' % - (directory, d))[1] + (directory, d))[1][0] self.plistMapping[label] = "%s/%s" % (directory, daemon) - except KeyError: # perhaps this could be more robust - pass + except KeyError: + self.logger.warning("Could not get label from %s/%s" % + (directory, daemon)) def FindPlist(self, entry): return self.plistMapping.get(entry.get('name'), None) -- cgit v1.2.3-1-g7c22 From 3824f10c6edaa7ee1cfff65d1eb17343a5b20b9c Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Thu, 19 Apr 2012 09:34:30 -0500 Subject: bcfg2-info: Fix packagesources command Signed-off-by: Sol Jerome --- src/lib/Server/Plugins/Packages/Source.py | 5 +++-- src/sbin/bcfg2-info | 34 ++++++++++++++++++------------- 2 files changed, 23 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/lib/Server/Plugins/Packages/Source.py b/src/lib/Server/Plugins/Packages/Source.py index 1dfeecc40..f13267da1 100644 --- a/src/lib/Server/Plugins/Packages/Source.py +++ b/src/lib/Server/Plugins/Packages/Source.py @@ -135,8 +135,9 @@ class Source(Bcfg2.Server.Plugin.Debuggable): def get_repo_name(self, url_map): # try to find a sensible name for a repo - if url_map['component']: - rname = url_map['component'] + if url_map['components']: + # use the first component as the name + rname = url_map['components'][0] else: name = None for repo_re in (self.mrepo_re, diff --git a/src/sbin/bcfg2-info b/src/sbin/bcfg2-info index 808761d7e..3c1a0a3da 100755 --- a/src/sbin/bcfg2-info +++ b/src/sbin/bcfg2-info @@ -46,7 +46,7 @@ groups - List groups help - Print this list of available commands mappings - Print generator mappings for optional type and name packageresolve [...] - Resolve the specified set of packages -packagesources - Show package sources +packagesources - Show package sources profile - Profile a single bcfg2-info command quit - Exit the bcfg2-info command line showentries - Show abstract configuration entries for a given host @@ -508,20 +508,26 @@ class infoCore(cmd.Cmd, Bcfg2.Server.Core.Core): # get_urls() loads url_map as a side-effect source.get_urls() for url_map in source.url_map: - if url_map['arch'] in metadata.groups: - reponame = source.get_repo_name(url_map) - print("Name: %s" % reponame) - print(" Type: %s" % source.ptype) + for arch in url_map['arches']: + # make sure client is in all the proper arch groups + if arch not in metadata.groups: + continue + reponame = source.get_repo_name(url_map) + print("Name: %s" % reponame) + print(" Type: %s" % source.ptype) + if url_map['url'] != '': print(" URL: %s" % url_map['url']) - if source.gpgkeys: - print(" GPG Key(s): %s" % ", ".join(source.gpgkeys)) - else: - print(" GPG Key(s): None") - if len(source.blacklist): - print(" Blacklist: %s" % ", ".join(source.blacklist)) - if len(source.whitelist): - print(" Whitelist: %s" % ", ".join(source.whitelist)) - print("") + elif url_map['rawurl'] != '': + print(" RAWURL: %s" % url_map['rawurl']) + if source.gpgkeys: + print(" GPG Key(s): %s" % ", ".join(source.gpgkeys)) + else: + print(" GPG Key(s): None") + if len(source.blacklist): + print(" Blacklist: %s" % ", ".join(source.blacklist)) + if len(source.whitelist): + print(" Whitelist: %s" % ", ".join(source.whitelist)) + print("") def do_profile(self, arg): """.""" -- cgit v1.2.3-1-g7c22