From e224ae0359840d54b9bd995a5231e4774321755a Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Fri, 28 Sep 2012 12:04:49 -0400 Subject: made client runs abort on probe failure, added option to disable that --- src/lib/Bcfg2/Server/Plugins/FileProbes.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'src/lib/Bcfg2/Server/Plugins/FileProbes.py') diff --git a/src/lib/Bcfg2/Server/Plugins/FileProbes.py b/src/lib/Bcfg2/Server/Plugins/FileProbes.py index 59ac9f85e..b1930e203 100644 --- a/src/lib/Bcfg2/Server/Plugins/FileProbes.py +++ b/src/lib/Bcfg2/Server/Plugins/FileProbes.py @@ -13,9 +13,14 @@ import Bcfg2.Server import Bcfg2.Server.Plugin from Bcfg2.Compat import b64decode +#: The probe we send to clients to get the file data. Returns an XML +#: document describing the file and its metadata. We avoid returning +#: a non-0 error code on most errors, since that could halt client +#: execution. PROBECODE = """#!/usr/bin/env python import os +import sys import pwd import grp import Bcfg2.Client.XML @@ -24,16 +29,24 @@ from Bcfg2.Compat import b64encode path = "%s" if not os.path.exists(path): - print("%%s does not exist" %% path) - raise SystemExit(1) - -stat = os.stat(path) + sys.stderr.write("%%s does not exist" %% path) + raise SystemExit(0) + +try: + stat = os.stat(path) +except: + sys.stderr.write("Could not stat %%s: %%s" % (path, sys.exc_info()[1])) + raise SystemExit(0) data = Bcfg2.Client.XML.Element("ProbedFileData", name=path, owner=pwd.getpwuid(stat[4])[0], group=grp.getgrgid(stat[5])[0], - perms=oct(stat[0] & 07777)) -data.text = b64encode(open(path).read()) + perms=oct(stat[0] & 4095)) +try: + data.text = b64encode(open(path).read()) +except: + sys.stderr.write("Could not read %%s: %%s" % (path, sys.exc_info()[1])) + raise SystemExit(0) print(Bcfg2.Client.XML.tostring(data, xml_declaration=False).decode('UTF-8')) """ @@ -45,8 +58,6 @@ class FileProbes(Bcfg2.Server.Plugin.Plugin, replaced on the client if it is missing; if it has changed on the client, it can either be updated in the specification or replaced on the client """ - - name = 'FileProbes' __author__ = 'chris.a.st.pierre@gmail.com' def __init__(self, core, datastore): -- cgit v1.2.3-1-g7c22