summaryrefslogtreecommitdiffstats
path: root/src/lib/Client
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Client')
-rw-r--r--src/lib/Client/Debian.py27
-rw-r--r--src/lib/Client/Gentoo.py16
-rw-r--r--src/lib/Client/Redhat.py27
-rw-r--r--src/lib/Client/Solaris.py25
-rw-r--r--src/lib/Client/Toolset.py257
5 files changed, 145 insertions, 207 deletions
diff --git a/src/lib/Client/Debian.py b/src/lib/Client/Debian.py
index a78027cf0..d02252180 100644
--- a/src/lib/Client/Debian.py
+++ b/src/lib/Client/Debian.py
@@ -17,7 +17,7 @@ class ToolsetImpl(Bcfg2.Client.Toolset.Toolset):
def __init__(self, cfg, setup):
Bcfg2.Client.Toolset.Toolset.__init__(self, cfg, setup)
self.cfg = cfg
- self.CondPrint('debug', 'Configuring Debian toolset')
+ self.logger.debug('Configuring Debian toolset')
os.environ["DEBIAN_FRONTEND"] = 'noninteractive'
# dup /dev/null on top of stdin
null = open('/dev/null', 'w+')
@@ -32,7 +32,7 @@ class ToolsetImpl(Bcfg2.Client.Toolset.Toolset):
for pkg in [cpkg for cpkg in self.cfg.findall(".//Package") if not cpkg.attrib.has_key('type')]:
pkg.set('type', 'deb')
self.Refresh()
- self.CondPrint('debug', 'Done configuring Debian toolset')
+ self.logger.debug('Done configuring Debian toolset')
def Refresh(self):
'''Refresh memory hashes of packages'''
@@ -62,11 +62,11 @@ class ToolsetImpl(Bcfg2.Client.Toolset.Toolset):
def InstallService(self, entry):
'''Install Service for entry'''
cmdrc = 1
- self.CondPrint('verbose', "Installing Service %s" % (entry.get('name')))
+ self.logger.info("Installing Service %s" % (entry.get('name')))
try:
os.stat('/etc/init.d/%s' % entry.get('name'))
except OSError:
- self.CondPrint('debug', "Init script for service %s does not exist" % entry.get('name'))
+ self.logger.debug("Init script for service %s does not exist" % entry.get('name'))
return False
if entry.attrib['status'] == 'off':
@@ -87,8 +87,8 @@ class ToolsetImpl(Bcfg2.Client.Toolset.Toolset):
def VerifyPackage(self, entry, modlist):
'''Verify package for entry'''
if not entry.attrib.has_key('version'):
- self.CondPrint('verbose', "Cannot verify unversioned package %s" %
- (entry.attrib['name']))
+ self.logger.info("Cannot verify unversioned package %s" %
+ (entry.attrib['name']))
return False
if self.installed.has_key(entry.attrib['name']):
if self.installed[entry.attrib['name']] == entry.attrib['version']:
@@ -105,7 +105,8 @@ class ToolsetImpl(Bcfg2.Client.Toolset.Toolset):
allsrv = []
[allsrv.append(self.svcre.match(fname).group('name')) for fname in
glob.glob("/etc/rc[12345].d/S*") if self.svcre.match(fname).group('name') not in allsrv]
- self.CondDisplayList('debug', "Found active services:", allsrv)
+ self.logger.debug("Found active services:")
+ self.logger.debug(allsrv)
csrv = self.cfg.findall(".//Service")
[allsrv.remove(svc.get('name')) for svc in csrv if
svc.get('status') == 'on' and svc.get('name') in allsrv]
@@ -118,17 +119,21 @@ class ToolsetImpl(Bcfg2.Client.Toolset.Toolset):
if len(self.pkgwork) > 0:
if self.setup['remove'] in ['all', 'packages']:
- self.CondDisplayList('verbose', "Removing packages", self.pkgwork['remove'])
+ self.logger.info('Removing packages:')
+ self.logger.info(self.pkgwork['remove'])
if not self.saferun("apt-get remove -y --force-yes %s" % " ".join(self.pkgwork['remove']))[0]:
self.pkgwork['remove'] = []
else:
- self.CondDisplayList('verbose', "Need to remove packages:", self.pkgwork['remove'])
+ self.logger.info("Need to remove packages:")
+ self.logger.info(self.pkgwork['remove'])
if len(self.extra_services) > 0:
if self.setup['remove'] in ['all', 'services']:
- self.CondDisplayList('verbose', "Removing services:", self.extra_services)
+ self.logger.info('Removing services:')
+ self.logger.info(self.extra_services)
[self.extra_services.remove(serv) for serv in self.extra_services if
not self.saferun("rm -f /etc/rc*.d/S??%s" % serv)[0]]
else:
- self.CondDisplayList('verbose', "Need to remove services:", self.extra_services)
+ self.logger.info('Need to remove services:')
+ self.logger.info(self.extra_services)
diff --git a/src/lib/Client/Gentoo.py b/src/lib/Client/Gentoo.py
index 84ca313c5..a42d4b1b6 100644
--- a/src/lib/Client/Gentoo.py
+++ b/src/lib/Client/Gentoo.py
@@ -53,11 +53,11 @@ class Gentoo(Toolset):
def InstallService(self, entry):
'''Install Service entry'''
- self.CondPrint('verbose', "Installing Service %s" % (entry.get('name')))
+ self.logger.info("Installing Service %s" % (entry.get('name')))
try:
stat('/etc/init.d/%s' % entry.get('name'))
except OSError:
- self.CondPrint('debug', "Init script for service %s does not exist" % entry.get('name'))
+ self.logger.debug("Init script for service %s does not exist" % entry.get('name'))
return False
if entry.attrib['status'] == 'off':
@@ -85,7 +85,7 @@ class Gentoo(Toolset):
if installed_package:
installed_package = installed_package[0].strip("\n").split('/')[-1]
if installed_package != "%s-%s" % (entry.get('name'), entry.get('version')):
- self.CondPrint('debug', "Package %s-%s version incorrect" % (entry.get('name'), entry.get('version')))
+ self.logger.debug("Package %s-%s version incorrect" % (entry.get('name'), entry.get('version')))
if entry.attrib.get('verify', 'true') == 'true':
if self.setup['quick']:
return True
@@ -104,7 +104,7 @@ class Gentoo(Toolset):
else:
for line in output[1:-1]:
if line.split()[0] not in modlist:
- self.CondPrint('debug', "Package %s content verification failed" % (entry.get('name')))
+ self.logger.debug("Package %s content verification failed" % (entry.get('name')))
return False
return True
return False
@@ -121,14 +121,14 @@ class Gentoo(Toolset):
'''Deal with extra configuration detected'''
if len(self.pkgwork) > 0:
if self.setup['remove'] in ['all', 'packages']:
- self.CondPrint('verbose', "Removing packages: %s" % (self.pkgwork['remove']))
+ self.logger.info("Removing packages: %s" % (self.pkgwork['remove']))
system("/usr/bin/emerge --quiet --nospinner unmerge %s" % " ".join(self.pkgwork['remove']))
else:
- self.CondPrint('verbose', "Need to remove packages: %s" % (self.pkgwork['remove']))
+ self.logger.info("Need to remove packages: %s" % (self.pkgwork['remove']))
if len(self.extra_services) > 0:
if self.setup['remove'] in ['all', 'services']:
- self.CondPrint('verbose', "Removing services: %s" % (self.extra_services))
+ self.logger.info("Removing services: %s" % (self.extra_services))
for service in self.extra_services:
system("/sbin/rc-update del %s" % service)
else:
- self.CondPrint('verbose', "Need to remove services: %s" % (self.extra_services))
+ self.logger.info("Need to remove services: %s" % (self.extra_services))
diff --git a/src/lib/Client/Redhat.py b/src/lib/Client/Redhat.py
index f8955318c..ee08be18e 100644
--- a/src/lib/Client/Redhat.py
+++ b/src/lib/Client/Redhat.py
@@ -61,7 +61,7 @@ class ToolsetImpl(Toolset):
def InstallService(self, entry):
'''Install Service entry'''
system("/sbin/chkconfig --add %s"%(entry.attrib['name']))
- self.CondPrint('verbose', "Installing Service %s" % (entry.get('name')))
+ self.logger.info("Installing Service %s" % (entry.get('name')))
if not entry.get('status'):
print "Can't install service %s, not enough data" % (entry.get('name'))
return False
@@ -88,18 +88,17 @@ class ToolsetImpl(Toolset):
if (self.setup['quick'] or (entry.get('verify', 'true') == 'false')):
return True
else:
- self.CondPrint('debug', "Package %s: wrong version installed. want %s have %s" %
- (entry.get('name'), entry.get('version'), self.installed[entry.get('name')]))
+ self.logger.debug("Package %s: wrong version installed. want %s have %s" %
+ (entry.get('name'), entry.get('version'), self.installed[entry.get('name')]))
return False
else:
- self.CondPrint('debug', "Package %s: not installed" % (entry.get('name')))
+ self.logger.debug("Package %s: not installed" % (entry.get('name')))
return False
(vstat, output) = self.saferun("rpm --verify -q %s-%s" % (entry.get('name'), entry.get('version')))
if vstat != 0:
if [name for name in output if name.split()[-1] not in modlist]:
- self.CondPrint('debug',
- "Package %s content verification failed" % entry.get('name'))
+ self.logger.debug("Package %s content verification failed" % entry.get('name'))
return False
return True
@@ -107,28 +106,32 @@ class ToolsetImpl(Toolset):
'''Deal with extra configuration detected'''
if len(self.pkgwork) > 0:
if self.setup['remove'] in ['all', 'packages']:
- self.CondPrint('verbose', "Removing packages: %s" % self.pkgwork['remove'])
+ self.logger.info("Removing packages: %s" % self.pkgwork['remove'])
if not system("rpm --quiet -e %s" % " ".join(self.pkgwork['remove'])):
self.pkgwork['remove'] = []
self.Refresh()
self.Inventory()
else:
- self.CondDisplayList('verbose', "Need to remove packages", self.pkgwork['remove'])
+ self.logger.info("Need to remove packages:")
+ self.logger.info(self.pkgwork['remove'])
if len(self.extra_services) > 0:
if self.setup['remove'] in ['all', 'services']:
- self.CondDisplayList('verbose', 'Removing services:', self.extra_services)
+ self.logger.info('Removing services:')
+ self.logger.info(self.extra_services)
for service in self.extra_services:
if not system("/sbin/chkconfig --level 123456 %s off" % service):
self.extra_services.remove(service)
- self.CondPrint('verbose', "Failed to remove service %s" % (service))
+ self.logger.info("Failed to remove service %s" % (service))
else:
- self.CondDisplayList('verbose', 'Need to remove services:', self.extra_services)
+ self.logger.info('Need to remove services:')
+ self.logger.info(self.extra_services)
def Inventory(self):
'''Do standard inventory plus debian extra service check'''
Toolset.Inventory(self)
allsrv = [line.split()[0] for line in popen("/sbin/chkconfig --list|grep :on").readlines()]
- self.CondDisplayList('debug', 'Found active services:', allsrv)
+ self.logger.debug('Found active services:')
+ self.logger.debug(allsrv)
csrv = self.cfg.findall(".//Service")
[allsrv.remove(svc.get('name')) for svc in csrv if
svc.get('status') == 'on' and svc.get('name') in allsrv]
diff --git a/src/lib/Client/Solaris.py b/src/lib/Client/Solaris.py
index 48f26c1f8..39e8a13c6 100644
--- a/src/lib/Client/Solaris.py
+++ b/src/lib/Client/Solaris.py
@@ -87,7 +87,7 @@ class ToolsetImpl(Toolset):
if name:
entry.set('FMRI', name[0])
else:
- self.CondPrint('verbose', 'Failed to locate FMRI for service %s' % entry.get('name'))
+ self.logger.info('Failed to locate FMRI for service %s' % entry.get('name'))
return False
if entry.get('FMRI')[:3] == 'lrc':
filename = entry.get('FMRI').split('/')[-1]
@@ -111,16 +111,16 @@ class ToolsetImpl(Toolset):
def InstallService(self, entry):
'''Install Service entry'''
if not entry.attrib.has_key('status'):
- self.CondPrint('verbose', 'Insufficient information for Service %s; cannot Install' % entry.get('name'))
+ self.logger.info('Insufficient information for Service %s; cannot Install' % entry.get('name'))
return False
if not entry.attrib.has_key('FMRI'):
name = self.saferun("/usr/bin/svcs -H -o FMRI %s 2>/dev/null" % entry.get('name'))[1]
if name:
entry.set('FMRI', name[0])
else:
- self.CondPrint('verbose', 'Failed to locate FMRI for service %s' % entry.get('name'))
+ self.logger.info('Failed to locate FMRI for service %s' % entry.get('name'))
return False
- self.CondPrint('verbose', "Installing Service %s" % (entry.get('name')))
+ self.logger.info("Installing Service %s" % (entry.get('name')))
if entry.attrib['status'] == 'off':
if self.setup['dryrun']:
print "Disabling Service %s" % (entry.get('name'))
@@ -136,8 +136,7 @@ class ToolsetImpl(Toolset):
def VerifyPackage(self, entry, modlist):
'''Verify Package status for entry'''
if not entry.get('version'):
- self.CondPrint('verbose',
- "Insufficient information of Package %s; cannot Verify" % entry.get('name'))
+ self.logger.info("Insufficient information of Package %s; cannot Verify" % entry.get('name'))
return False
if entry.get('type') in ['sysv', 'blast'] or entry.get('type')[:4] == 'sysv':
cmdrc = self.saferun("/usr/bin/pkginfo -q -v \"%s\" %s" % (entry.get('version'), entry.get('name')))[0]
@@ -145,7 +144,7 @@ class ToolsetImpl(Toolset):
cmdrc = self.saferun("/local/sbin/epkg -q -k %s-%s >/dev/null" %
(entry.get('name'), entry.get('version')))[0]
if cmdrc != 0:
- self.CondPrint('debug', "Package %s version incorrect" % entry.get('name'))
+ self.logger.debug("Package %s version incorrect" % entry.get('name'))
else:
if entry.attrib.get('verify', 'true') == 'true':
if self.setup['quick'] or entry.get('type') == 'encap':
@@ -156,7 +155,7 @@ class ToolsetImpl(Toolset):
else:
output = [line for line in odata if line[:5] == 'ERROR']
if len([name for name in output if name.split()[-1] not in modlist]):
- self.CondPrint('debug', "Package %s content verification failed" % (entry.get('name')))
+ self.logger.debug("Package %s content verification failed" % (entry.get('name')))
else:
return True
return False
@@ -174,7 +173,7 @@ class ToolsetImpl(Toolset):
if name:
srv.set('FMRI', name[0])
else:
- self.CondPrint("verbose", "failed to locate FMRI for service %s" % srv.get('name'))
+ self.logger.info("Failed to locate FMRI for service %s" % srv.get('name'))
#nsrv = [ r for r in [ popen("/usr/bin/svcs -H -o FMRI %s " % s).read().strip() for s in csrv ] if r ]
[allsrv.remove(svc.get('FMRI')) for svc in csrv if
svc.get('status') == 'on' and svc.get("FMRI") in allsrv]
@@ -184,7 +183,7 @@ class ToolsetImpl(Toolset):
'''Deal with extra configuration detected'''
if len(self.pkgwork) > 0:
if self.setup['remove'] in ['all', 'packages']:
- self.CondPrint('verbose', "Removing packages: %s" % (self.pkgwork['remove']))
+ self.logger.info("Removing packages: %s" % (self.pkgwork['remove']))
sysvrmpkgs = [pkg for pkg in self.pkgwork['remove'] if self.ptypes[pkg] == 'sysv']
enrmpkgs = [pkg for pkg in self.pkgwork['remove'] if self.ptypes[pkg] == 'encap']
if sysvrmpkgs:
@@ -194,15 +193,15 @@ class ToolsetImpl(Toolset):
if not self.saferun("/local/sbin/epkg -l -q -r %s" % " ".join(enrmpkgs))[0]:
[self.pkgwork['remove'].remove(pkg) for pkg in enrmpkgs]
else:
- self.CondPrint('verbose', "Need to remove packages: %s" % (self.pkgwork['remove']))
+ self.logger.info("Need to remove packages: %s" % (self.pkgwork['remove']))
if len(self.extra_services) > 0:
if self.setup['remove'] in ['all', 'services']:
- self.CondPrint('verbose', "Removing services: %s" % (self.extra_services))
+ self.logger.info("Removing services: %s" % (self.extra_services))
for service in self.extra_services:
if not self.saferun("/usr/sbin/svcadm disable %s" % service)[0]:
self.extra_services.remove(service)
else:
- self.CondPrint('verbose', "Need to remove services: %s" % (self.extra_services))
+ self.logger.info("Need to remove services: %s" % (self.extra_services))
def Install(self):
'''Local install method handling noaskfiles'''
diff --git a/src/lib/Client/Toolset.py b/src/lib/Client/Toolset.py
index 5334e367f..dad808981 100644
--- a/src/lib/Client/Toolset.py
+++ b/src/lib/Client/Toolset.py
@@ -5,9 +5,9 @@ from stat import S_ISVTX, S_ISGID, S_ISUID, S_IXUSR, S_IWUSR, S_IRUSR, S_IXGRP
from stat import S_IWGRP, S_IRGRP, S_IXOTH, S_IWOTH, S_IROTH, ST_MODE, S_ISDIR
from stat import S_IFREG, ST_UID, ST_GID, S_ISREG, S_IFDIR, S_ISLNK
-import binascii, copy, grp, lxml.etree, math, os, popen2, pwd, stat, sys, traceback
+import binascii, copy, grp, logging, lxml.etree, os, popen2, pwd, stat
-def calc_perms(initial, perms):
+def calcPerms(initial, perms):
'''This compares ondisk permissions with specified ones'''
pdisp = [{1:S_ISVTX, 2:S_ISGID, 4:S_ISUID}, {1:S_IXUSR, 2:S_IWUSR, 4:S_IRUSR},
{1:S_IXGRP, 2:S_IWGRP, 4:S_IRGRP}, {1:S_IXOTH, 2:S_IWOTH, 4:S_IROTH}]
@@ -36,9 +36,9 @@ class Toolset(object):
self.structures = {}
self.modified = []
self.installed = {}
+ self.logger = logging.getLogger('Toolset')
self.pkgwork = {'add':[], 'update':[], 'remove':[]}
self.extra_services = []
- (self.height, self.width) = self.get_height_width()
if self.__important__:
for cfile in [cfl for cfl in cfg.findall(".//ConfigFile") if cfl.get('name') in self.__important__]:
self.VerifyEntry(cfile)
@@ -47,103 +47,33 @@ class Toolset(object):
def saferun(self, command):
'''Run a command in a pipe dealing with stdout buffer overloads'''
- self.CondPrint('debug', '> %s' % command)
+ self.logger.debug('> %s' % command)
runpipe = popen2.Popen4(command, bufsize=16384)
output = runpipe.fromchild.read()
if len(output) > 0:
- self.CondPrint('debug', '< %s' % output)
+ self.logger.debug('< %s' % output)
cmdstat = runpipe.poll()
while cmdstat == -1:
moreOutput = runpipe.fromchild.read()
if len(moreOutput) > 0:
- self.CondPrint('debug', '< %s' % moreOutput)
+ self.logger.debug('< %s' % moreOutput)
output += moreOutput
cmdstat = runpipe.poll()
return (cmdstat, [line for line in output.split('\n') if line])
- def CondPrint(self, state, msg):
- '''Conditionally print message'''
- if self.setup[state]:
- try:
- prefix = "%s[%s]: " % (self.__name__, state)
- line_len = self.width-len(prefix)
- for line in msg.split('\n'):
- inner_lines = int(math.floor(float(len(line)) / line_len))+1
- for i in xrange(inner_lines):
- print "%s%s" % (prefix, line[i*line_len:(i+1)*line_len])
- except IOError:
- pass
-
- def get_height_width(self):
- '''Get Terminal information'''
- try:
- import termios, struct, fcntl
- height, width = struct.unpack('hhhh',
- fcntl.ioctl(0, termios.TIOCGWINSZ,
- "\000"*8))[0:2]
- if height == 0 or width == 0:
- return 25, 80
- return height, width
- except:
- return 25, 80
-
- def FormattedCondPrint(self, state, items):
- '''Formatted conditional print'''
- items.sort()
- screenWidth = self.width - len("%s[%s]:" % (self.__name__, state))
- columnWidth = 1
- for item in items:
- if len(item) > columnWidth:
- columnWidth = len(item)
- columnWidth += 1
-
- columns = int(math.floor(float(screenWidth) / columnWidth))
- lines = int(math.ceil(float(len(items)) / columns))
-
- for lineNumber in xrange(lines):
- lineItems = []
- for columnNumber in xrange(columns):
- itemNumber = int(columnNumber*lines + lineNumber)
- if itemNumber < len(items):
- lineItems.append(items[itemNumber])
- format = "%%-%ss" % columnWidth
- lineText = "".join([format % item for item in lineItems])
- self.CondPrint(state, lineText.rstrip())
-
- def CondDisplayList(self, state, title, items):
- '''Conditionally print a list of data'''
- self.CondPrint(state, title)
- self.FormattedCondPrint(state, items)
- self.CondPrint(state, '')
-
- def CondDisplayState(self, state, phase):
+ def CondDisplayState(self, phase):
'''Conditionally print tracing information'''
- self.CondPrint(state, 'Phase: %s' % phase)
- self.CondPrint(state, 'Correct entries:\t%d'
- % self.states.values().count(True))
- self.CondPrint(state, 'Incorrect entries:\t%d' %
- self.states.values().count(False))
- self.CondPrint(state, 'Total managed entries:\t%d' %
- len(self.states.values()))
- self.CondPrint(state, 'Unmanaged entries:\t%d' %
- len(self.pkgwork['remove']))
- self.CondPrint(state, '')
-
- if ((self.states.values().count(False) > 0) and
- not self.pkgwork['remove']):
- self.CondPrint('verbose', 'All entries correct.')
+ self.logger.info('Phase: %s' % phase)
+ self.logger.info('Correct entries:\t%d' % self.states.values().count(True))
+ self.logger.info('Incorrect entries:\t%d' % self.states.values().count(False))
+ self.logger.info('Total managed entries:\t%d' % len(self.states.values()))
+ self.logger.info('Unmanaged entries:\t%d' % len(self.pkgwork['remove']))
+
+ if ((self.states.values().count(False) > 0) and not self.pkgwork['remove']):
+ self.logger.info('All entries correct.')
- def LogFailure(self, area, entry):
- '''Print tracebacks in unexpected cases'''
- print "Failure in %s for entry: %s" % (area, lxml.etree.tostring(entry))
- (ttype, value, trace) = sys.exc_info()
- for line in traceback.extract_tb(trace):
- print "File %s, line %i, in %s\n %s\n" % (line)
- print "%s: %s\n" % (ttype, value)
- del ttype, value, trace
-
# These next functions form the external API
def Refresh(self):
@@ -152,7 +82,7 @@ class Toolset(object):
def Inventory(self):
'''Inventory system status'''
- self.CondPrint('verbose', "Inventorying system...")
+ self.logger.info("Inventorying system...")
self.Inventory_Entries()
all = copy.deepcopy(self.installed)
desired = {}
@@ -260,7 +190,7 @@ class Toolset(object):
else:
self.states[entry] = method(entry)
except:
- self.LogFailure("Verify", entry)
+ self.logger.error("Failure in VerifyEntry", exc_info=1)
def InstallEntry(self, entry):
'''Dispatch call to self.Install<tagname>'''
@@ -268,7 +198,7 @@ class Toolset(object):
method = getattr(self, "Install%s"%(entry.tag))
self.states[entry] = method(entry)
except:
- self.LogFailure("Install", entry)
+ self.logger.error("Failure in InstallEntry", exc_info=1)
# All remaining operations implement the mechanics of POSIX cfg elements
@@ -284,19 +214,19 @@ class Toolset(object):
def InstallSymLink(self, entry):
'''Install SymLink Entry'''
- self.CondPrint('verbose', "Installing Symlink %s" % (entry.get('name')))
+ self.logger.info("Installing Symlink %s" % (entry.get('name')))
try:
fmode = os.lstat(entry.get('name'))[ST_MODE]
if S_ISREG(fmode) or S_ISLNK(fmode):
- self.CondPrint('debug', "Non-directory entry already exists at %s" % (entry.get('name')))
+ self.logger.debug("Non-directory entry already exists at %s" % (entry.get('name')))
os.unlink(entry.get('name'))
elif S_ISDIR(fmode):
- self.CondPrint('debug', "Directory entry already exists at %s" % (entry.get('name')))
+ self.logger.debug("Directory entry already exists at %s" % (entry.get('name')))
self.saferun("mv %s/ %s.bak" % (entry.get('name'), entry.get('name')))
else:
os.unlink(entry.get('name'))
except OSError:
- print "Symlink %s cleanup failed" % (entry.get('name'))
+ self.logger.info("Symlink %s cleanup failed" % (entry.get('name')))
try:
os.symlink(entry.get('to'), entry.get('name'))
return True
@@ -310,13 +240,13 @@ class Toolset(object):
try:
ondisk = os.stat(entry.get('name'))
except OSError:
- self.CondPrint("debug", "Directory %s does not exist" % (entry.get('name')))
+ self.logger.debug("Directory %s does not exist" % (entry.get('name')))
return False
try:
owner = pwd.getpwuid(ondisk[ST_UID])[0]
group = grp.getgrgid(ondisk[ST_GID])[0]
except OSError:
- self.CondPrint('debug', 'User resolution failing')
+ self.logger.error('User resolution failing')
owner = 'root'
group = 'root'
perms = oct(os.stat(entry.get('name'))[ST_MODE])[-4:]
@@ -326,28 +256,28 @@ class Toolset(object):
return True
else:
if owner != entry.get('owner'):
- self.CondPrint("debug", "Directory %s ownership wrong" % (entry.get('name')))
+ self.logger.debug("Directory %s ownership wrong" % (entry.get('name')))
if group != entry.get('group'):
- self.CondPrint("debug", "Directory %s group wrong" % (entry.get('name')))
+ self.logger.debug("Directory %s group wrong" % (entry.get('name')))
if perms != entry.get('perms'):
- self.CondPrint("debug", "Directory %s permissions wrong: are %s should be %s" %
+ self.logger.debug("Directory %s permissions wrong: are %s should be %s" %
(entry.get('name'), perms, entry.get('perms')))
return False
def InstallDirectory(self, entry):
'''Install Directory Entry'''
- self.CondPrint('verbose', "Installing Directory %s" % (entry.get('name')))
+ self.logger.info("Installing Directory %s" % (entry.get('name')))
try:
fmode = os.lstat(entry.get('name'))
if not S_ISDIR(fmode[ST_MODE]):
- self.CondPrint("debug", "Found a non-directory entry at %s" % (entry.get('name')))
+ self.logger.debug("Found a non-directory entry at %s" % (entry.get('name')))
try:
os.unlink(entry.get('name'))
except OSError:
- self.CondPrint('verbose', "Failed to unlink %s" % (entry.get('name')))
+ self.logger.info("Failed to unlink %s" % (entry.get('name')))
return False
else:
- self.CondPrint("debug", "Found a pre-existing directory at %s" % (entry.get('name')))
+ self.logger.debug("Found a pre-existing directory at %s" % (entry.get('name')))
exists = True
except OSError:
# stat failed
@@ -357,15 +287,15 @@ class Toolset(object):
try:
os.mkdir(entry.get('name'))
except OSError:
- self.CondPrint('debug', 'Failed to create directory %s' % (entry.get('name')))
+ self.logger.error('Failed to create directory %s' % (entry.get('name')))
return False
try:
os.chown(entry.get('name'),
pwd.getpwnam(entry.get('owner'))[2], grp.getgrnam(entry.get('group'))[2])
- os.chmod(entry.get('name'), calc_perms(S_IFDIR, entry.get('perms')))
+ os.chmod(entry.get('name'), calcPerms(S_IFDIR, entry.get('perms')))
return True
except (OSError, KeyError):
- self.CondPrint('debug', 'Permission fixup failed for %s' % (entry.get('name')))
+ self.logger.error('Permission fixup failed for %s' % (entry.get('name')))
return False
def VerifyConfigFile(self, entry):
@@ -374,19 +304,19 @@ class Toolset(object):
try:
ondisk = os.stat(filename)
except OSError:
- self.CondPrint('debug', "File %s doesn't exist" % (filename))
+ self.logger.debug("File %s doesn't exist" % (filename))
return False
try:
data = open(filename).read()
except IOError:
- self.CondPrint('debug', "Failed to read %s" % (filename))
+ self.logger.debug("Failed to read %s" % (filename))
return False
try:
owner = pwd.getpwuid(ondisk[ST_UID])[0]
group = grp.getgrgid(ondisk[ST_GID])[0]
except KeyError:
- self.CondPrint('debug', "Owner/Group failure for %s: %s, %s" %
- (filename, ondisk[ST_UID], ondisk[ST_GID]))
+ self.logger.debug("Owner/Group failure for %s: %s, %s" %
+ (filename, ondisk[ST_UID], ondisk[ST_GID]))
return False
perms = os.stat(filename)[ST_MODE]
if entry.get('encoding', 'ascii') == 'base64':
@@ -395,24 +325,24 @@ class Toolset(object):
tempdata = entry.text
if ((data == tempdata) and (owner == entry.get('owner')) and
- (group == entry.get('group')) and (perms == calc_perms(S_IFREG, entry.get('perms')))):
+ (group == entry.get('group')) and (perms == calcPerms(S_IFREG, entry.get('perms')))):
return True
else:
if data != tempdata:
- self.CondPrint('debug', "File %s contents wrong" % (filename))
+ self.logger.debug("File %s contents wrong" % (filename))
elif ((owner != entry.get('owner')) or (group != entry.get('group'))):
- self.CondPrint('debug', 'File %s ownership wrong' % (filename))
- elif perms != calc_perms(S_IFREG, entry.get('perms')):
- self.CondPrint('debug', 'File %s permissions wrong' % (filename))
+ self.logger.debug('File %s ownership wrong' % (filename))
+ elif perms != calcPerms(S_IFREG, entry.get('perms')):
+ self.logger.debug('File %s permissions wrong' % (filename))
return False
def InstallConfigFile(self, entry):
'''Install ConfigFile Entry'''
if entry.text == None:
- self.CondPrint('verbose',
- "Incomplete information for ConfigFile %s. Cannot install" % (entry.get('name')))
+ self.logger.error(
+ "Incomplete information for ConfigFile %s. Cannot install" % (entry.get('name')))
return False
- self.CondPrint('verbose', "Installing ConfigFile %s" % (entry.get('name')))
+ self.logger.info("Installing ConfigFile %s" % (entry.get('name')))
if self.setup['dryrun']:
return False
@@ -421,7 +351,7 @@ class Toolset(object):
try:
os.lstat(parent)
except:
- self.CondPrint('debug', 'Creating parent path for config file %s' % (entry.get('name')))
+ self.logger.debug('Creating parent path for config file %s' % (entry.get('name')))
for idx in xrange(len(parent.split('/')[:-1])):
current = '/'+'/'.join(parent.split('/')[1:2+idx])
try:
@@ -452,14 +382,14 @@ class Toolset(object):
grp.getgrnam(entry.get('group'))[2])
except KeyError:
os.chown(newfile.name, 0, 0)
- os.chmod(newfile.name, calc_perms(S_IFREG, entry.get('perms')))
+ os.chmod(newfile.name, calcPerms(S_IFREG, entry.get('perms')))
if entry.get("paranoid", False) and self.setup.get("paranoid", False):
self.saferun("cp %s /var/cache/bcfg2/%s" % (entry.get('name')))
os.rename(newfile.name, entry.get('name'))
return True
except (OSError, IOError), err:
if err.errno == 13:
- self.CondPrint('verbose', "Failed to open %s for writing" % (entry.get('name')))
+ self.logger.info("Failed to open %s for writing" % (entry.get('name')))
else:
print err
return False
@@ -473,7 +403,7 @@ class Toolset(object):
try:
sinfo = os.stat(entry.get('name'))
except OSError:
- self.CondPrint('debug', "Entry %s doesn't exist" % entry.get('name'))
+ self.logger.debug("Entry %s doesn't exist" % entry.get('name'))
return False
# pad out perms if needed
while len(entry.get('perms', '')) < 4:
@@ -482,7 +412,7 @@ class Toolset(object):
if perms == entry.get('perms'):
return True
- self.CondPrint('debug', "Entry %s permissions incorrect" % entry.get('name'))
+ self.logger.debug("Entry %s permissions incorrect" % entry.get('name'))
return False
def InstallPermissions(self, entry):
@@ -490,13 +420,13 @@ class Toolset(object):
try:
sinfo = os.stat(entry.get('name'))
except OSError:
- self.CondPrint('debug', "Entry %s doesn't exist" % entry.get('name'))
+ self.logger.debug("Entry %s doesn't exist" % entry.get('name'))
return False
for ftype in ['DIR', 'REG', 'CHR', 'BLK']:
if getattr(stat, "S_IS%s" % ftype)(sinfo[ST_MODE]):
- os.chmod(entry.get('name'), calc_perms(getattr(stat, "S_IF%s" % ftype), entry.get('perms')))
+ os.chmod(entry.get('name'), calcPerms(getattr(stat, "S_IF%s" % ftype), entry.get('perms')))
return True
- self.CondPrint('verbose', "Entry %s has unknown file type" % entry.get('name'))
+ self.logger.info("Entry %s has unknown file type" % entry.get('name'))
return False
def VerifyPostInstall(self, entry):
@@ -509,7 +439,7 @@ class Toolset(object):
bchildren = entry.getchildren()
if [b_ent for b_ent in bchildren if b_ent in self.modified]:
# This bundle has been modified
- self.CondPrint('verbose', "%s %s needs update" % (entry.tag, entry.get('name', '???')))
+ self.logger.info("%s %s needs update" % (entry.tag, entry.get('name', '???')))
modfiles = [cfile.get('name') for cfile in bchildren if cfile.tag == 'ConfigFile']
for child in bchildren:
if child.tag == 'Package':
@@ -517,12 +447,12 @@ class Toolset(object):
else:
self.VerifyEntry(child)
if not self.states[child]:
- self.CondPrint('debug', "Reinstalling clobbered entry %s %s" % (child.tag,
- child.get('name')))
+ self.logger.debug("Reinstalling clobbered entry %s %s" % (child.tag,
+ child.get('name')))
self.InstallEntry(child)
self.VerifyEntry(child)
- self.CondPrint('debug', "Re-checked entry %s %s: %s" %
- (child.tag, child.get('name'), self.states[child]))
+ self.logger.debug("Re-checked entry %s %s: %s" %
+ (child.tag, child.get('name'), self.states[child]))
for postinst in [entry for entry in bchildren if entry.tag == 'PostInstall']:
self.saferun(postinst.get('name'))
for svc in [svc for svc in bchildren if svc.tag == 'Service' and
@@ -531,12 +461,12 @@ class Toolset(object):
# stop services in miniroot
self.saferun('/etc/init.d/%s stop' % svc.get('name'))
else:
- self.CondPrint('debug', 'Restarting service %s' % svc.get('name'))
+ self.logger.debug('Restarting service %s' % svc.get('name'))
self.saferun('/etc/init.d/%s %s' % (svc.get('name'), svc.get('reload', 'reload')))
for entry in self.structures:
if [strent for strent in entry.getchildren() if not self.states.get(strent, False)]:
- self.CondPrint('verbose', "%s %s incomplete" % (entry.tag, entry.get('name', "")))
+ self.logger.info("%s %s incomplete" % (entry.tag, entry.get('name', "")))
else:
self.structures[entry] = True
@@ -547,28 +477,29 @@ class Toolset(object):
def Install(self):
'''Correct detected misconfigurations'''
if self.setup['dryrun']:
- self.CondPrint("verbose", "Dry-run mode: no changes will be made")
+ self.logger.info("Dry-run mode: no changes will be made")
else:
- self.CondPrint("verbose", "Updating the system")
- self.CondPrint("verbose", "")
+ self.logger.info("Updating the system")
+ self.logger.info("")
self.HandleExtra()
- # use quick package ops from here on
- self.setup['quick'] = True
- self.CondDisplayList('dryrun', "Packages to update:",
- [pkg.get('name') for pkg in self.pkgwork['update']])
- self.CondDisplayList('dryrun', "Packages to add:",
- [pkg.get('name') for pkg in self.pkgwork['add']])
- self.CondDisplayList('dryrun', "Packages to remove:",
- self.pkgwork['remove'])
- self.CondDisplayList('dryrun', "Entries to update:",
- ["%s: %s" % (entry.tag, entry.get('name'))
+ if self.setup['dryrun']:
+ self.logger.info("Packages to update:")
+ self.logger.info([pkg.get('name') for pkg in self.pkgwork['update']])
+ self.logger.info("Packages to add:")
+ self.logger.info([pkg.get('name') for pkg in self.pkgwork['add']])
+ self.logger.info("Packages to remove:")
+ self.logger.info(self.pkgwork['remove'])
+ self.logger.info("Entries to update:")
+ self.logger.info(["%s: %s" % (entry.tag, entry.get('name'))
for entry in self.states if not (self.states[entry]
or entry.tag == 'Package')])
- self.CondDisplayList('dryrun', "Services to remove:", self.extra_services)
-
- if self.setup['dryrun']:
+ self.logger.info("Services to remove:")
+ self.logger.info(self.extra_services)
return
+
+ # use quick package ops from here on
+ self.setup['quick'] = True
# build up work queue
work = self.pkgwork['add'] + self.pkgwork['update']
@@ -586,9 +517,9 @@ class Toolset(object):
# Installation loop
while ((0 < left < old) and (count < 20)):
# Print pass info
- self.CondPrint('verbose', "Starting pass %s" % (count))
- self.CondPrint("verbose", "%s Entries left" % (len(work)))
- self.CondPrint('verbose', "%s new, %s update, %s remove" %
+ self.logger.info("Starting pass %s" % (count))
+ self.logger.info("%s Entries left" % (len(work)))
+ self.logger.info("%s new, %s update, %s remove" %
(len(self.pkgwork['add']), len(self.pkgwork['update']),
len(self.pkgwork['remove'])))
@@ -596,7 +527,7 @@ class Toolset(object):
count = count + 1
old = left
- self.CondPrint("verbose", "Installing non-package entries")
+ self.logger.info("Installing non-package entries")
[self.InstallEntry(ent) for ent in work if ent.tag != 'Package']
packages = [pkg for pkg in work if pkg.tag == 'Package']
@@ -607,55 +538,55 @@ class Toolset(object):
if packages:
for pkgtype in ptypes:
# try single large install
- self.CondPrint("verbose", "Trying single pass package install for pkgtype %s" % pkgtype)
+ self.logger.info("Trying single pass package install for pkgtype %s" % pkgtype)
if not self.pkgtool.has_key(pkgtype):
- self.CondPrint("verbose", "No support for pkgtype %s" % (pkgtype))
+ self.logger.info("No support for pkgtype %s" % (pkgtype))
continue
pkgtool = self.pkgtool[pkgtype]
pkglist = [pkg for pkg in packages if pkg.get('type') == pkgtype]
for field in pkgtool[1][1]:
pkglist = [pkg for pkg in pkglist if pkg.attrib.has_key(field)]
if not pkglist:
- self.CondPrint("debug", "No complete/installable packages of type %s" % pkgtype)
+ self.logger.debug("No complete/installable packages of type %s" % pkgtype)
continue
pkgargs = " ".join([pkgtool[1][0] % tuple([pkg.get(field) for field in pkgtool[1][1]])
for pkg in pkglist])
- self.CondPrint("debug", "Installing packages: :%s:" % pkgargs)
- self.CondPrint("debug", "Running command ::%s::" % (pkgtool[0] % pkgargs))
+ self.logger.debug("Installing packages: :%s:" % pkgargs)
+ self.logger.debug("Running command ::%s::" % (pkgtool[0] % pkgargs))
cmdrc = self.saferun(pkgtool[0] % pkgargs)[0]
if cmdrc == 0:
- self.CondPrint('verbose', "Single Pass Succeded")
+ self.logger.info("Single Pass Succeded")
# set all package states to true and flush workqueues
pkgnames = [pkg.get('name') for pkg in pkglist]
for entry in [entry for entry in self.states.keys()
if entry.tag == 'Package' and entry.get('type') == pkgtype
and entry.get('name') in pkgnames]:
- self.CondPrint('debug', 'Setting state to true for pkg %s' % (entry.get('name')))
+ self.logger.debug('Setting state to true for pkg %s' % (entry.get('name')))
self.states[entry] = True
[self.pkgwork[listname].remove(entry) for listname in ['add', 'update']
if self.pkgwork[listname].count(entry)]
self.Refresh()
else:
- self.CondPrint("verbose", "Single Pass Failed")
+ self.logger.error("Single Pass Failed")
# do single pass installs
self.Refresh()
for pkg in pkglist:
# handle state tracking updates
if self.VerifyPackage(pkg, []):
- self.CondPrint("verbose", "Forcing state to true for pkg %s" % (pkg.get('name')))
+ self.logger.info("Forcing state to true for pkg %s" % (pkg.get('name')))
self.states[pkg] = True
else:
- self.CondPrint("verbose", "Installing pkg %s version %s" %
- (pkg.get('name'), pkg.get('version')))
+ self.logger.info("Installing pkg %s version %s" %
+ (pkg.get('name'), pkg.get('version')))
cmdrc = self.saferun(pkgtool[0] %
(pkgtool[1][0] %
tuple([pkg.get(field) for field in pkgtool[1][1]])))
if cmdrc[0] == 0:
self.states[pkg] = True
else:
- self.CondPrint('verbose', "Failed to install package %s" % (pkg.get('name')))
+ self.logger.error("Failed to install package %s" % (pkg.get('name')))
for entry in [ent for ent in work if self.states[ent]]:
work.remove(entry)
self.modified.append(entry)