summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Plugins
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-03-26 22:12:20 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-03-26 22:12:20 -0400
commitbc35aa70ab8794b73019d90a41eb252fbb80ff52 (patch)
tree3cce934901374c67c1f56d5841643028dc058ae6 /src/lib/Bcfg2/Server/Plugins
parent0fae9849fd7047c299468fd6728db56d6861ee12 (diff)
downloadbcfg2-bc35aa70ab8794b73019d90a41eb252fbb80ff52.tar.gz
bcfg2-bc35aa70ab8794b73019d90a41eb252fbb80ff52.tar.bz2
bcfg2-bc35aa70ab8794b73019d90a41eb252fbb80ff52.zip
testsuite: fixed more unit test stuff
Diffstat (limited to 'src/lib/Bcfg2/Server/Plugins')
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Fossil.py4
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Metadata.py2
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Ohai.py23
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py1
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Probes.py5
-rw-r--r--src/lib/Bcfg2/Server/Plugins/SSHbase.py2
-rw-r--r--src/lib/Bcfg2/Server/Plugins/TemplateHelper.py2
7 files changed, 29 insertions, 10 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/Fossil.py b/src/lib/Bcfg2/Server/Plugins/Fossil.py
index d0c328b36..6165ac651 100644
--- a/src/lib/Bcfg2/Server/Plugins/Fossil.py
+++ b/src/lib/Bcfg2/Server/Plugins/Fossil.py
@@ -23,8 +23,8 @@ class Fossil(Bcfg2.Server.Plugin.Version):
shell=True,
cwd=self.vcs_root,
stdout=PIPE).stdout.readlines()
- revline = [line.split(': ')[1].strip() for line in data if \
- line.split(': ')[0].strip() == 'checkout'][-1]
+ revline = [line.split(': ')[1].strip() for line in data
+ if line.split(': ')[0].strip() == 'checkout'][-1]
return revline.split(' ')[0]
except IndexError:
msg = "Failed to read fossil info"
diff --git a/src/lib/Bcfg2/Server/Plugins/Metadata.py b/src/lib/Bcfg2/Server/Plugins/Metadata.py
index 3611f2c6e..b181c2237 100644
--- a/src/lib/Bcfg2/Server/Plugins/Metadata.py
+++ b/src/lib/Bcfg2/Server/Plugins/Metadata.py
@@ -446,7 +446,7 @@ class MetadataQuery(object):
return [self.by_name(name) for name in self.all_clients()]
-class MetadataGroup(tuple):
+class MetadataGroup(tuple): # pylint: disable=E0012,R0924
""" representation of a metadata group. basically just a named tuple """
# pylint: disable=R0913,W0613
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)])
diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py b/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py
index ff57d57e8..332f0bbab 100644
--- a/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py
+++ b/src/lib/Bcfg2/Server/Plugins/Packages/PackagesSources.py
@@ -7,6 +7,7 @@ import Bcfg2.Server.Plugin
from Bcfg2.Server.Plugins.Packages.Source import SourceInitError
+# pylint: disable=E0012,R0924
class PackagesSources(Bcfg2.Server.Plugin.StructFile,
Bcfg2.Server.Plugin.Debuggable):
""" PackagesSources handles parsing of the
diff --git a/src/lib/Bcfg2/Server/Plugins/Probes.py b/src/lib/Bcfg2/Server/Plugins/Probes.py
index fa56564fa..a8001d9af 100644
--- a/src/lib/Bcfg2/Server/Plugins/Probes.py
+++ b/src/lib/Bcfg2/Server/Plugins/Probes.py
@@ -58,7 +58,7 @@ class ClientProbeDataSet(dict):
dict.__init__(self, *args, **kwargs)
-class ProbeData(str):
+class ProbeData(str): # pylint: disable=E0012,R0924
""" a ProbeData object emulates a str object, but also has .xdata,
.json, and .yaml properties to provide convenient ways to use
ProbeData objects as XML, JSON, or YAML data """
@@ -231,9 +231,10 @@ class Probes(Bcfg2.Server.Plugin.Probing,
if pdata.data != data:
pdata.data = data
pdata.save()
+
ProbesDataModel.objects.filter(
hostname=client.hostname).exclude(
- probe__in=self.probedata[client.hostname]).delete()
+ probe__in=self.probedata[client.hostname]).delete()
for group in self.cgroups[client.hostname]:
try:
diff --git a/src/lib/Bcfg2/Server/Plugins/SSHbase.py b/src/lib/Bcfg2/Server/Plugins/SSHbase.py
index 0c5644395..fc07a90e9 100644
--- a/src/lib/Bcfg2/Server/Plugins/SSHbase.py
+++ b/src/lib/Bcfg2/Server/Plugins/SSHbase.py
@@ -205,7 +205,7 @@ class SSHbase(Bcfg2.Server.Plugin.Plugin,
chain(
*[names[cmeta.hostname]
for cmeta in
- mquery.by_groups([specific.group])]))
+ mquery.by_groups([specific.group])]))
elif specific.all:
# a generic key for all hosts? really?
hostnames = list(chain(*list(names.values())))
diff --git a/src/lib/Bcfg2/Server/Plugins/TemplateHelper.py b/src/lib/Bcfg2/Server/Plugins/TemplateHelper.py
index ea7454e11..7dd15f7b5 100644
--- a/src/lib/Bcfg2/Server/Plugins/TemplateHelper.py
+++ b/src/lib/Bcfg2/Server/Plugins/TemplateHelper.py
@@ -82,7 +82,7 @@ class TemplateHelper(Bcfg2.Server.Plugin.Plugin,
Bcfg2.Server.Plugin.DirectoryBacked):
""" A plugin to provide helper classes and functions to templates """
__author__ = 'chris.a.st.pierre@gmail.com'
- ignore = re.compile("^(\.#.*|.*~|\\..*\\.(sw[px])|.*\.py[co])$")
+ ignore = re.compile(r'^(\.#.*|.*~|\..*\.(sw[px])|.*\.py[co])$')
patterns = MODULE_RE
__child__ = HelperModule