summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Plugins/FileProbes.py
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/Bcfg2/Server/Plugins/FileProbes.py
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/Bcfg2/Server/Plugins/FileProbes.py')
-rw-r--r--src/lib/Bcfg2/Server/Plugins/FileProbes.py27
1 files changed, 19 insertions, 8 deletions
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):