summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-28 12:04:49 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-28 12:04:49 -0400
commite224ae0359840d54b9bd995a5231e4774321755a (patch)
tree30c47babc201d52397dc12cfa7df64c97d50aa69 /src/lib
parent1bdb14055dd1b2395047793ee28c17bbae65c845 (diff)
downloadbcfg2-e224ae0359840d54b9bd995a5231e4774321755a.tar.gz
bcfg2-e224ae0359840d54b9bd995a5231e4774321755a.tar.bz2
bcfg2-e224ae0359840d54b9bd995a5231e4774321755a.zip
made client runs abort on probe failure, added option to disable that
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Bcfg2/Options.py10
-rw-r--r--src/lib/Bcfg2/Server/Plugins/FileProbes.py27
2 files changed, 28 insertions, 9 deletions
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='<file>',
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):