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/Metadata.py | 1 + src/lib/Bcfg2/Server/Plugins/Ohai.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'src/lib/Bcfg2/Server/Plugins') diff --git a/src/lib/Bcfg2/Server/Plugins/Metadata.py b/src/lib/Bcfg2/Server/Plugins/Metadata.py index b181c2237..7561aec1e 100644 --- a/src/lib/Bcfg2/Server/Plugins/Metadata.py +++ b/src/lib/Bcfg2/Server/Plugins/Metadata.py @@ -75,6 +75,7 @@ if HAS_DJANGO: yield client.hostname def keys(self): + """ Get keys for the mapping """ return [c.hostname for c in MetadataClientModel.objects.all()] def __contains__(self, key): 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