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/Options.py | 10 +++++++++- src/lib/Bcfg2/Server/Plugins/FileProbes.py | 27 +++++++++++++++++++-------- 2 files changed, 28 insertions(+), 9 deletions(-) (limited to 'src/lib') diff --git a/src/lib/Bcfg2/Options.py b/src/lib/Bcfg2/Options.py index 04233f165..b5a116ddb 100644 --- a/src/lib/Bcfg2/Options.py +++ b/src/lib/Bcfg2/Options.py @@ -723,6 +723,13 @@ CLIENT_DECISION_LIST = \ cmd='--decision-list', odesc='', long_arg=True) +CLIENT_EXIT_ON_PROBE_FAILURE = \ + Option("The client should exit if a probe fails", + default=True, + cmd='--exit-on-probe-failure', + long_arg=True, + cf=('client', 'exit_on_probe_failure'), + cook=get_bool) # bcfg2-test and bcfg2-lint options TEST_NOSEOPTS = \ @@ -1079,7 +1086,8 @@ CLIENT_COMMON_OPTIONS = \ ca=CLIENT_CA, serverCN=CLIENT_SCNS, timeout=CLIENT_TIMEOUT, - decision_list=CLIENT_DECISION_LIST) + decision_list=CLIENT_DECISION_LIST, + probe_exit=CLIENT_EXIT_ON_PROBE_FAILURE) CLIENT_COMMON_OPTIONS.update(DRIVER_OPTIONS) CLIENT_COMMON_OPTIONS.update(CLI_COMMON_OPTIONS) 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