summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2007-08-01 14:22:32 +0000
committerNarayan Desai <desai@mcs.anl.gov>2007-08-01 14:22:32 +0000
commit867b093e26069de43268e424dc673d1242f6380d (patch)
treea34227e283b174485738151dc543324286597b9f
parent27f130ee295c6469c74d172fe08ac310046c5d2c (diff)
downloadbcfg2-867b093e26069de43268e424dc673d1242f6380d.tar.gz
bcfg2-867b093e26069de43268e424dc673d1242f6380d.tar.bz2
bcfg2-867b093e26069de43268e424dc673d1242f6380d.zip
Fix binary config file stats upload
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@3589 ce84e21b-d406-0410-9b95-82705330c041
-rw-r--r--src/lib/Client/Tools/POSIX.py5
-rw-r--r--src/lib/Server/Plugins/Cfg.py15
-rw-r--r--src/lib/Server/Plugins/SSHbase.py10
-rwxr-xr-xsrc/sbin/bcfg2-admin17
4 files changed, 27 insertions, 20 deletions
diff --git a/src/lib/Client/Tools/POSIX.py b/src/lib/Client/Tools/POSIX.py
index f4e3063a6..a98ae24fd 100644
--- a/src/lib/Client/Tools/POSIX.py
+++ b/src/lib/Client/Tools/POSIX.py
@@ -5,7 +5,7 @@ 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, ST_MTIME
-import binascii, difflib, grp, os, pwd, xml.sax.saxutils
+import binascii, difflib, grp, os, pwd, string
import Bcfg2.Client.Tools
def calcPerms(initial, perms):
@@ -268,7 +268,6 @@ class POSIX(Bcfg2.Client.Tools.Tool):
entry.set('current_bfile', binascii.b2a_base64(content))
nqtext = entry.get('qtext', '')
nqtext += '\nBinary file, no printable diff'
- entry.set('qtext', nqtest)
else:
diff = '\n'.join([x for x in difflib.ndiff(content.split('\n'),
tempdata.split('\n'))])
@@ -284,7 +283,7 @@ class POSIX(Bcfg2.Client.Tools.Tool):
if nqtext:
nqtext += '\n'
nqtext += eudiff
- entry.set('qtext', nqtext)
+ entry.set('qtext', nqtext)
qtxt = entry.get('qtext', '')
qtxt += "\nInstall ConfigFile %s: (y/N): " % (entry.get('name'))
entry.set('qtext', qtxt)
diff --git a/src/lib/Server/Plugins/Cfg.py b/src/lib/Server/Plugins/Cfg.py
index ad1711d01..207f4465f 100644
--- a/src/lib/Server/Plugins/Cfg.py
+++ b/src/lib/Server/Plugins/Cfg.py
@@ -10,12 +10,6 @@ specific = re.compile('(.*/)(?P<filename>[\S\-.]+)\.((H_(?P<hostname>\S+))|' +
'(G(?P<prio>\d+)_(?P<group>\S+)))$')
probeData = {}
-def update_file(path, diff):
- '''Update file at path using diff'''
- newdata = '\n'.join(difflib.restore(xml.sax.saxutils.unescape(diff).split('\n'), 1))
- print "writing file, %s" % path
- open(path, 'w').write(newdata)
-
class SpecificityError(Exception):
'''Thrown in case of filename parse failure'''
pass
@@ -362,7 +356,7 @@ class Cfg(Bcfg2.Server.Plugin.Plugin):
logger.error("Got unknown event %s %s:%s" % (action, event.requestID, event.filename))
self.interpolate = len([entry for entry in self.entries.values() if entry.interpolate ]) > 0
- def AcceptEntry(self, meta, _, entry_name, diff):
+ def AcceptEntry(self, meta, _, entry_name, diff, fulldata):
'''per-plugin bcfg2-admin pull support'''
hsq = "Found host-specific file %s; Should it be updated (n/Y): "
repo_vers = lxml.etree.Element('ConfigFile', name=entry_name)
@@ -392,4 +386,9 @@ class Cfg(Bcfg2.Server.Plugin.Plugin):
newname = basefile.name + ".H_%s" % (meta.hostname)
print "This file will be installed as file %s" % newname
if raw_input("Should it be installed? (N/y): ") in 'Yy':
- update_file(newname, diff)
+ print "writing file, %s" % newname
+ if fulldata:
+ newdata = fulldata
+ else:
+ newdata = '\n'.join(difflib.restore(diff.split('\n'), 1))
+ open(newname, 'w').write(newdata)
diff --git a/src/lib/Server/Plugins/SSHbase.py b/src/lib/Server/Plugins/SSHbase.py
index 3e468d91f..bc5375da6 100644
--- a/src/lib/Server/Plugins/SSHbase.py
+++ b/src/lib/Server/Plugins/SSHbase.py
@@ -181,11 +181,17 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin, Bcfg2.Server.Plugin.DirectoryBacked):
except OSError:
self.logger.error("Failed to unlink temporary ssh keys")
- def AcceptEntry(self, meta, _, entry_name, diff):
+ def AcceptEntry(self, meta, _, entry_name, diff, fulldata):
'''per-plugin bcfg2-admin pull support'''
filename = "%s/%s.H_%s" % (self.data, entry_name.split('/')[-1],
meta.hostname)
print "This file will be installed as file %s" % filename
if raw_input("Should it be installed? (N/y): ") in 'Yy':
- update_file(filename, diff)
+ print "writing file, %s" % filename
+ if fulldata:
+ newdata = fulldata
+ else:
+ newdata = '\n'.join(difflib.restore(diff.split('\n'), 1))
+ open(filename, 'w').write(newdata)
+
diff --git a/src/sbin/bcfg2-admin b/src/sbin/bcfg2-admin
index 95aa2b68a..b913db6f8 100755
--- a/src/sbin/bcfg2-admin
+++ b/src/sbin/bcfg2-admin
@@ -306,6 +306,8 @@ def do_pull(cfile, repopath, client, etype, ename):
sentries = sdata.xpath(sxpath)
print "Found %d entries for %s:%s:%s" % \
(len(sentries), client, etype, ename)
+ if not len(sentries):
+ raise SystemExit, 1
maxtime = max([time.strptime(stat.get('time')) for stat in sentries])
print "Found entry from", time.strftime("%c", maxtime)
statblock = [stat for stat in sentries \
@@ -315,19 +317,20 @@ def do_pull(cfile, repopath, client, etype, ename):
err_exit("Could not find state data for entry; rerun bcfg2 on client system")
cfentry = entry[-1]
- mode = 'diff'
if 'current_bdiff' in cfentry.attrib:
+ data = False
diff = binascii.a2b_base64(cfentry.get('current_bdiff'))
elif 'current_diff' in cfentry.attrib:
+ data = False
diff = cfentry.get('current_diff')
elif 'current_bfile' in cfentry.attrib:
- mode = 'full'
data = binascii.a2b_base64(cfentry.get('current_bfile'))
+ diff = False
- if mode == 'diff':
+ if diff:
print "Located diff:\n %s" % diff
else:
- print "Found full file data:\n", data
+ print "Found full (binary) file data"
try:
bcore = Bcfg2.Server.Core.Core({}, cfile)
@@ -345,10 +348,10 @@ def do_pull(cfile, repopath, client, etype, ename):
err_exit("Got wrong numbers of matching generators for entry:" \
+ "%s" % ([g.__name__ for g in glist]))
plugin = glist[0]
- if diff == None:
- err_exit("Failed to locate diff\nStatistics entry was:\n%s" % lxml.etree.tostring(cfentry))
+ if not diff and not data:
+ err_exit("Failed to locate diff or full data\nStatistics entry was:\n%s" % lxml.etree.tostring(cfentry))
try:
- plugin.AcceptEntry(m, 'ConfigFile', ename, diff)
+ plugin.AcceptEntry(m, 'ConfigFile', ename, diff, data)
except Bcfg2.Server.Plugin.PluginExecutionError:
err_exit("Configuration upload not supported by plugin %s" \
% (plugin.__name__))