summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2007-11-03 23:41:12 +0000
committerNarayan Desai <desai@mcs.anl.gov>2007-11-03 23:41:12 +0000
commita6a57ac9af207b8128e3cc575a18cbe506232d3a (patch)
tree8404dd36e03d69b3417c0545feb3dd1ff90987b6 /src
parentb675fc60be84b2300a37a62752347b5a233e1e1f (diff)
downloadbcfg2-a6a57ac9af207b8128e3cc575a18cbe506232d3a.tar.gz
bcfg2-a6a57ac9af207b8128e3cc575a18cbe506232d3a.tar.bz2
bcfg2-a6a57ac9af207b8128e3cc575a18cbe506232d3a.zip
Implement data collection on incomplete entry path for POSIX
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@3911 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src')
-rw-r--r--src/lib/Client/Tools/POSIX.py23
-rw-r--r--src/lib/Client/Tools/__init__.py8
2 files changed, 30 insertions, 1 deletions
diff --git a/src/lib/Client/Tools/POSIX.py b/src/lib/Client/Tools/POSIX.py
index 7b0544a25..aea5e7f3c 100644
--- a/src/lib/Client/Tools/POSIX.py
+++ b/src/lib/Client/Tools/POSIX.py
@@ -47,7 +47,7 @@ def normGid(entry):
log.error('GID normalization failed for %s' % (entry.get('name')))
return False
-text_chars = "".join(map(chr, range(32, 127)) + list("\n\r\t\b"))
+text_chars = "".join([chr(y) for y in range(32, 127)] + list("\n\r\t\b"))
notrans = string.maketrans("", "")
def isString(strng):
@@ -278,6 +278,27 @@ class POSIX(Bcfg2.Client.Tools.Tool):
self.logger.error('Permission fixup failed for %s' % (entry.get('name')))
return False
+ def gatherCurrentData(self, entry):
+ if entry.tag == 'ConfigFile':
+ try:
+ ondisk = os.stat(entry.get('name'))
+ except OSError:
+ entry.set('current_exists', 'false')
+ self.logger.debug("%s %s does not exist" %
+ (entry.tag, entry.get('name')))
+ return False
+ try:
+ entry.set('current_owner', str(ondisk[ST_UID]))
+ entry.set('current_group', str(ondisk[ST_GID]))
+ except (OSError, KeyError):
+ pass
+ entry.set('perms', str(oct(ondisk[ST_MODE])[-4:]))
+ try:
+ content = open(entry.get('name')).read()
+ entry.set('current_bfile', binascii.b2a_base64(content))
+ except IOError, error:
+ self.logger.error("Failed to read %s: %s" % (error.filename, error.strerror))
+
def VerifyConfigFile(self, entry, _):
'''Install ConfigFile Entry'''
# configfile verify is permissions check + content check
diff --git a/src/lib/Client/Tools/__init__.py b/src/lib/Client/Tools/__init__.py
index ed8649082..663fa3433 100644
--- a/src/lib/Client/Tools/__init__.py
+++ b/src/lib/Client/Tools/__init__.py
@@ -152,6 +152,10 @@ class Tool:
return [sentry.get('name') for sentry in struct if sentry.tag in \
['ConfigFile', 'SymLink', 'Directory', 'Permissions']]
+ def gatherCurrentData(self, entry):
+ '''Default implementation of the information gathering routines'''
+ pass
+
def canVerify(self, entry):
'''test if entry has enough information to be verified'''
if not self.handlesEntry(entry):
@@ -164,6 +168,10 @@ class Tool:
% (entry.tag, entry.get('name')))
self.logger.error("\t... due to absense of %s attribute(s)" % \
(":".join(missing)))
+ try:
+ self.gatherCurrentData(entry)
+ except:
+ self.logger.error("Unexpected error in gatherCurrentData", exc_info=1)
return False
return True