diff options
author | Narayan Desai <desai@mcs.anl.gov> | 2004-10-21 19:26:15 +0000 |
---|---|---|
committer | Narayan Desai <desai@mcs.anl.gov> | 2004-10-21 19:26:15 +0000 |
commit | b411cbfbc74dd7d0cb8e633532d76341503c3e7b (patch) | |
tree | 24348af8aa2f4fcf22d4562ea8680affc0c5b815 /src/lib/Client/Redhat.py | |
parent | 9389e6be1f22c9a820f3e2f08228164a542a8279 (diff) | |
download | bcfg2-b411cbfbc74dd7d0cb8e633532d76341503c3e7b.tar.gz bcfg2-b411cbfbc74dd7d0cb8e633532d76341503c3e7b.tar.bz2 bcfg2-b411cbfbc74dd7d0cb8e633532d76341503c3e7b.zip |
pylint fixes
(Logical change 1.104)
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@475 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Client/Redhat.py')
-rw-r--r-- | src/lib/Client/Redhat.py | 94 |
1 files changed, 43 insertions, 51 deletions
diff --git a/src/lib/Client/Redhat.py b/src/lib/Client/Redhat.py index 1d1ae62bb..c3c0da4ac 100644 --- a/src/lib/Client/Redhat.py +++ b/src/lib/Client/Redhat.py @@ -1,12 +1,13 @@ # This is the bcfg2 support for redhat # $Id: $ +__revision__ = '$Revision$' +'''This is redhat client support''' + from os import popen, system from popen2 import Popen4 -from re import compile -from string import join -from Toolset import Toolset +from Bcfg2.Client.Toolset import Toolset def Detect(): # until the code works @@ -14,10 +15,6 @@ def Detect(): class Redhat(Toolset): '''This class implelements support for rpm packages and standard chkconfig services''' - chkre=compile("(?P<name>\S+)\s+(?P<status>0:(?P<level0>\S+)\s+1:(?P<level1>\S+)\s+2:(?P<level2>\S+)\s+3:(?P<level3>\S+)\s+4:(?P<level4>\S+)\s+5:(?P<level5>\S+)\s+6:(?P<level6>\S+))") - onre=compile(".*on.*") - offre=compile(".*off.*") - xre=compile("(?P<name>\S+)\s+(?P<status>\S+)") rpmcmd = "rpm --oldpackage --replacepkgs --quiet -U %s" def __init__(self, cfg, setup): @@ -25,63 +22,58 @@ class Redhat(Toolset): self.pkgtodo = [] def VerifyService(self, entry): - ckline = popen("/sbin/chkconfig --list %s"%entry.attrib['name']).readlines() - if len(ckline) > 1: - print "got too many lines from for service %s"%(entry.attrib['name']) - return False + srvdata = popen("/sbin/chkconfig --list %s"%entry.attrib['name']).readlines()[0].split() + if entry.attrib['type'] == 'xinetd': + if entry.attrib['status'] == srvdata[1]: + return True + else: + return False else: - if entry.attrib['type'] == 'chkconfig': - cstatus = chkre.match(ckline[0]).group('status') - if entry.attrib['status'] == 'off': - if onre.match(cstatus) == None: - return True - else: - return False - else: # status == on - if not onre.match(cstatus): + # chkconfig/init.d service + if entry.attrib['status'] == 'off': + for level in srvdata[1:]: + if level.split(':')[1] != 'off': return False + return True + else: + # services should be on for 2345 + for level in srvdata[1:]: + [num, status] = level.split(':') + if num in '2345': + if status == 'off': + return False else: - levels = popen("grep chkconfig /etc/init.d/%s | awk '{print $3}' "%(name)).readlines()[0] - if levels[0] == '-' : levels = '345' - for i in range(7): - if str(i) in levels: - if cdata[i] == 'off': - return False - else: - if cdata[i] == 'on': - return False - if i == 6: - return True - elif entry.attrib['type'] == 'xinetd': - if xre.match(ckline[0]).group("status") == entry.attrib['status']: - return True - return False + if status == 'on': + return False + return True def InstallService(self, entry): system("/sbin/chkconfig --add %s"%(entry.attrib['name'])) - if status == 'off': - rc = system("/sbin/chkconfig --level 0123456 %s %s"%(entry.attrib['name'],entry.attrib['status'])) + if entry.attrib['status'] == 'off': + rc = system("/sbin/chkconfig --level 0123456 %s %s" % (entry.attrib['name'], entry.attrib['status'])) else: - rc = system("/sbin/chkconfig %s %s"%(entry.attrib['name'],entry.attrib['status'])) + rc = system("/sbin/chkconfig %s %s" % + (entry.attrib['name'], entry.attrib['status'])) if rc == 0: return True else: return False def VerifyPackage(self, entry, modlist = []): - instp=Popen4("rpm -qi %s-%s"%(entry.attrib['name'],entry.attrib['version'])) - istat=instp.wait()/256 + instp = Popen4("rpm -qi %s-%s" % (entry.attrib['name'], entry.attrib['version'])) + istat = instp.wait()/256 if istat == 0: if entry.attrib.get('verify', 'true') == 'true': if self.setup['quick']: return True - verp=Popen4("rpm --verify --nomd5 -q %s-%s"%(entry.attrib['name'],entry.attrib['version']), bufsize=16384) - odata='' - vstat=verp.poll() + verp = Popen4("rpm --verify --nomd5 -q %s-%s" % + (entry.attrib['name'],entry.attrib['version']), bufsize=16384) + odata = '' + vstat = verp.poll() while vstat == -1: - odata+=verp.fromchild.read() - vstat=verp.poll() >> 8 - output=filter(lambda x:x,odata.split('\n')) + odata += verp.fromchild.read() + vstat = verp.poll() >> 8 + output = [x for x in odata.split("\n") if x] if vstat == 0: return True else: @@ -93,13 +85,13 @@ class Redhat(Toolset): self.pkgtodo.append(entry) return False - def Commit(self, entrystate): + def Install(self): # try single install - rc = system(self.rpmcmd%(join(map(lambda x:x.attrib['url'], self.pkgtodo)))) + rc = system(self.rpmcmd % (" ".join([x.attrib['url'] for x in self.pkgtodo]))) if rc == 0: # set state == True for all just-installed packages for pkg in self.pkgtodo: - entrystate[x] = True + self.states[pkg] = True self.pkgtodo = [] else: # fall back to single package installs @@ -109,10 +101,10 @@ class Redhat(Toolset): for entry in self.pkgtodo: rc = system(self.rpmcmd%(entry.attrib['url'])) if rc == 0: - entrystate[entry] = True + self.states[entry] = True self.pkgtodo.remove(entry) else: if self.setup['verbose']: - print "package %s-%s failed to install"%(entry.attrib['name'], entry.attrib['version']) + print "package %s-%s failed to install" % (entry.attrib['name'], entry.attrib['version']) |