From ae3dc099f25c067ea414e675e24b97848f3bd81a Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Tue, 31 Jul 2007 14:50:10 +0000 Subject: Improve statistics location routines for bcfg2-admin pull git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@3586 ce84e21b-d406-0410-9b95-82705330c041 --- src/sbin/bcfg2-admin | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/sbin/bcfg2-admin b/src/sbin/bcfg2-admin index e4a2ccfb3..5264bacf4 100755 --- a/src/sbin/bcfg2-admin +++ b/src/sbin/bcfg2-admin @@ -3,7 +3,7 @@ import getopt, difflib, logging, lxml.etree, os, popen2, re, socket, sys, ConfigParser import Bcfg2.Server.Core, Bcfg2.Logging, Bcfg2.tlslite.api -import xml.sax.saxutils, binascii +import xml.sax.saxutils, binascii, time log = logging.getLogger('bcfg-admin') @@ -308,15 +308,22 @@ def do_pull(cfile, repopath, client, etype, ename): else: state = 'clean' # need to pull entry out of statistics - entry = sdata.xpath('.//Statistics[@state="%s"]/Bad/%s[@name="%s"]' % \ - (state, etype, ename)) + sxpath = ".//Statistics[@state='%s']/Bad/ConfigFile[@name='%s']/../.." % (state, ename) + sentries = sdata.xpath(sxpath) + print "Found %d entries for %s:%s:%s" % \ + (len(sentries), client, etype, ename) + 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 \ + if time.strptime(stat.get('time')) == maxtime] + entry = statblock[0].xpath('.//Bad/ConfigFile[@name="%s"]' % ename) if not entry: err_exit("Could not find state data for entry; rerun bcfg2 on client system") if 'current_bdiff' in entry[0].attrib: - diff = binascii.a2b_base64(entry[0].get('current_bdiff')) + diff = binascii.a2b_base64(entry[-1].get('current_bdiff')) else: - diff = entry[0].get('current_diff') + diff = entry[-1].get('current_diff') try: bcore = Bcfg2.Server.Core.Core({}, cfile) @@ -335,7 +342,7 @@ def do_pull(cfile, repopath, client, etype, ename): + "%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(entry[0])) + err_exit("Failed to locate diff\nStatistics entry was:\n%s" % lxml.etree.tostring(entry[-1])) try: plugin.AcceptEntry(m, 'ConfigFile', ename, diff) except Bcfg2.Server.Plugin.PluginExecutionError: -- cgit v1.2.3-1-g7c22