From 9c603d8267c0a511968a8a553d7fa0b2d5bf9b73 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Mon, 25 Mar 2013 13:31:21 -0400 Subject: Handle FAM monitor failures more gracefully: * Where possible, create the file or directory that is about to be monitored. This ensures that content can be added later without need to restart Bcfg2. (Otherwise, adding the monitor would fail, and so when you did create the file in question, bcfg2-server would never be notified of it.) * When not possible, give better error messages. --- src/lib/Bcfg2/Server/Plugins/Ohai.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/lib/Bcfg2/Server/Plugins/Ohai.py') diff --git a/src/lib/Bcfg2/Server/Plugins/Ohai.py b/src/lib/Bcfg2/Server/Plugins/Ohai.py index ebc03197e..07b04f3f0 100644 --- a/src/lib/Bcfg2/Server/Plugins/Ohai.py +++ b/src/lib/Bcfg2/Server/Plugins/Ohai.py @@ -69,10 +69,6 @@ class Ohai(Bcfg2.Server.Plugin.Plugin, self.probe = lxml.etree.Element('probe', name='Ohai', source='Ohai', interpreter='/bin/sh') self.probe.text = PROBECODE - try: - os.stat(self.data) - except OSError: - os.makedirs(self.data) self.cache = OhaiCache(self.data) def GetProbes(self, _): -- cgit v1.2.3-1-g7c22 From 64eec5fe6a9b640bb77dd65f10f3fac5a586347c Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 26 Mar 2013 12:47:14 -0400 Subject: testsuite: fixed issues found by latest version of pep8 --- src/lib/Bcfg2/Server/Plugins/Ohai.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib/Bcfg2/Server/Plugins/Ohai.py') diff --git a/src/lib/Bcfg2/Server/Plugins/Ohai.py b/src/lib/Bcfg2/Server/Plugins/Ohai.py index 07b04f3f0..a88c245bd 100644 --- a/src/lib/Bcfg2/Server/Plugins/Ohai.py +++ b/src/lib/Bcfg2/Server/Plugins/Ohai.py @@ -32,7 +32,7 @@ class OhaiCache(object): self.cache = dict() def __setitem__(self, item, value): - if value == None: + if value is None: # simply return if the client returned nothing return self.cache[item] = json.loads(value) -- cgit v1.2.3-1-g7c22 From bc35aa70ab8794b73019d90a41eb252fbb80ff52 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 26 Mar 2013 22:12:20 -0400 Subject: testsuite: fixed more unit test stuff --- src/lib/Bcfg2/Server/Plugins/Ohai.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/lib/Bcfg2/Server/Plugins/Ohai.py') diff --git a/src/lib/Bcfg2/Server/Plugins/Ohai.py b/src/lib/Bcfg2/Server/Plugins/Ohai.py index a88c245bd..8a1b07ac8 100644 --- a/src/lib/Bcfg2/Server/Plugins/Ohai.py +++ b/src/lib/Bcfg2/Server/Plugins/Ohai.py @@ -2,8 +2,10 @@ operating system using ohai (http://wiki.opscode.com/display/chef/Ohai) """ -import lxml.etree import os +import sys +import glob +import lxml.etree import Bcfg2.Server.Plugin try: @@ -31,22 +33,37 @@ class OhaiCache(object): self.dirname = dirname self.cache = dict() + def itempath(self, item): + return os.path.join(self.dirname, "%s.json" % item) + def __setitem__(self, item, value): if value is None: # simply return if the client returned nothing return self.cache[item] = json.loads(value) - open("%s/%s.json" % (self.dirname, item), 'w').write(value) + open(self.itempath(item), 'w').write(value) def __getitem__(self, item): if item not in self.cache: try: - data = open("%s/%s.json" % (self.dirname, item)).read() + data = open(self.itempath(item)).read() except: raise KeyError(item) self.cache[item] = json.loads(data) return self.cache[item] + def __delitem__(self, item): + if item in self.cache: + del self.cache[item] + try: + os.unlink(self.itempath(item)) + except: + raise IndexError("Could not unlink %s: %s" % (self.itempath(item), + sys.exc_info()[1])) + + def __len__(self): + return len(glob.glob(self.itempath('*'))) + def __iter__(self): data = list(self.cache.keys()) data.extend([x[:-5] for x in os.listdir(self.dirname)]) -- cgit v1.2.3-1-g7c22 From 4a364848c6d0e64a38d5d481ff978c519389814c Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Tue, 26 Mar 2013 23:12:51 -0400 Subject: testsuite: more text fixes --- src/lib/Bcfg2/Server/Plugins/Ohai.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/lib/Bcfg2/Server/Plugins/Ohai.py') diff --git a/src/lib/Bcfg2/Server/Plugins/Ohai.py b/src/lib/Bcfg2/Server/Plugins/Ohai.py index 8a1b07ac8..1ec3cbd60 100644 --- a/src/lib/Bcfg2/Server/Plugins/Ohai.py +++ b/src/lib/Bcfg2/Server/Plugins/Ohai.py @@ -33,20 +33,22 @@ class OhaiCache(object): self.dirname = dirname self.cache = dict() - def itempath(self, item): - return os.path.join(self.dirname, "%s.json" % item) + def hostpath(self, host): + """ Get the path to the file that contains Ohai data for the + given host """ + return os.path.join(self.dirname, "%s.json" % host) def __setitem__(self, item, value): if value is None: # simply return if the client returned nothing return self.cache[item] = json.loads(value) - open(self.itempath(item), 'w').write(value) + open(self.hostpath(item), 'w').write(value) def __getitem__(self, item): if item not in self.cache: try: - data = open(self.itempath(item)).read() + data = open(self.hostpath(item)).read() except: raise KeyError(item) self.cache[item] = json.loads(data) @@ -56,13 +58,13 @@ class OhaiCache(object): if item in self.cache: del self.cache[item] try: - os.unlink(self.itempath(item)) + os.unlink(self.hostpath(item)) except: - raise IndexError("Could not unlink %s: %s" % (self.itempath(item), + raise IndexError("Could not unlink %s: %s" % (self.hostpath(item), sys.exc_info()[1])) def __len__(self): - return len(glob.glob(self.itempath('*'))) + return len(glob.glob(self.hostpath('*'))) def __iter__(self): data = list(self.cache.keys()) -- cgit v1.2.3-1-g7c22