summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-04-24 15:44:06 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-04-25 10:45:14 -0400
commit044213c789c4f1ee214da3d70f02352b1aaa8673 (patch)
treefeb62ab035d27773f20be1e052a177c0c61299aa
parent0ff6b2788de683dd89203c7ae1393ea922a62c32 (diff)
downloadbcfg2-044213c789c4f1ee214da3d70f02352b1aaa8673.tar.gz
bcfg2-044213c789c4f1ee214da3d70f02352b1aaa8673.tar.bz2
bcfg2-044213c789c4f1ee214da3d70f02352b1aaa8673.zip
Fixing unit tests
-rw-r--r--src/lib/Bcfg2/Server/Admin/Viz.py21
-rw-r--r--src/lib/Bcfg2/Server/Admin/__init__.py4
-rw-r--r--src/lib/Bcfg2/Server/Core.py13
-rw-r--r--src/lib/Bcfg2/Server/Plugin/helpers.py7
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py5
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Packages/Yum.py1
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Rules.py4
-rw-r--r--src/lib/Bcfg2/Server/Plugins/__init__.py4
-rw-r--r--src/lib/Bcfg2/Server/Statistics.py1
-rw-r--r--src/lib/Bcfg2/Server/__init__.py8
-rw-r--r--src/lib/Bcfg2/Utils.py3
-rwxr-xr-xsrc/sbin/bcfg2-crypt2
-rw-r--r--testsuite/Testsrc/Testlib/TestClient/TestTools/Test_init.py8
-rw-r--r--testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgPrivateKeyCreator.py6
14 files changed, 40 insertions, 47 deletions
diff --git a/src/lib/Bcfg2/Server/Admin/Viz.py b/src/lib/Bcfg2/Server/Admin/Viz.py
index cdd8fd0cb..a29fdaceb 100644
--- a/src/lib/Bcfg2/Server/Admin/Viz.py
+++ b/src/lib/Bcfg2/Server/Admin/Viz.py
@@ -4,6 +4,7 @@ import getopt
import Bcfg2.Server.Admin
from Bcfg2.Utils import Executor
+
class Viz(Bcfg2.Server.Admin.MetadataCore):
""" Produce graphviz diagrams of metadata structures """
__usage__ = ("[options]\n\n"
@@ -79,16 +80,16 @@ class Viz(Bcfg2.Server.Admin.MetadataCore):
self.metadata.viz(hosts, bundles,
key, only_client, self.colors)]
if key:
- idata.extend([
- "\tsubgraph cluster_key {",
- '\tstyle="filled";',
- '\tcolor="lightblue";',
- '\tBundle [ shape="septagon" ];',
- '\tGroup [shape="ellipse"];',
- '\tProfile [style="bold", shape="ellipse"];',
- '\tHblock [label="Host1|Host2|Host3",shape="record"];',
- '\tlabel="Key";',
- "\t}"])
+ idata.extend(
+ ["\tsubgraph cluster_key {",
+ '\tstyle="filled";',
+ '\tcolor="lightblue";',
+ '\tBundle [ shape="septagon" ];',
+ '\tGroup [shape="ellipse"];',
+ '\tProfile [style="bold", shape="ellipse"];',
+ '\tHblock [label="Host1|Host2|Host3",shape="record"];',
+ '\tlabel="Key";',
+ "\t}"])
idata.append("}")
try:
result = exc.run(cmd, inputdata=idata)
diff --git a/src/lib/Bcfg2/Server/Admin/__init__.py b/src/lib/Bcfg2/Server/Admin/__init__.py
index 3fbdf8fa8..d317cc03b 100644
--- a/src/lib/Bcfg2/Server/Admin/__init__.py
+++ b/src/lib/Bcfg2/Server/Admin/__init__.py
@@ -116,10 +116,10 @@ class MetadataCore(Mode):
Mode.__init__(self)
if self.__plugin_whitelist__ is not None:
self.setup['plugins'] = [p for p in self.setup['plugins']
- if p in self.__plugin_whitelist__]
+ if p in self.__plugin_whitelist__]
elif self.__plugin_blacklist__ is not None:
self.setup['plugins'] = [p for p in self.setup['plugins']
- if p not in self.__plugin_blacklist__]
+ if p not in self.__plugin_blacklist__]
# admin modes don't need to watch for changes. one shot is fine here.
self.setup['filemonitor'] = 'pseudo'
diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py
index b0cb4cc87..e356a0b4d 100644
--- a/src/lib/Bcfg2/Server/Core.py
+++ b/src/lib/Bcfg2/Server/Core.py
@@ -492,9 +492,10 @@ class BaseCore(object):
self.logger.error("%s: Error invoking hook %s: %s" %
(plugin, hook, err))
finally:
- Bcfg2.Server.Statistics.stats.add_value("%s:client_run_hook:%s" %
- (self.__class__.__name__, hook),
- time.time() - start)
+ Bcfg2.Server.Statistics.stats.add_value(
+ "%s:client_run_hook:%s" %
+ (self.__class__.__name__, hook),
+ time.time() - start)
@Bcfg2.Server.Statistics.track_statistics()
def validate_structures(self, metadata, data):
@@ -665,9 +666,9 @@ class BaseCore(object):
(entry.tag, entry.get('name')))
finally:
Bcfg2.Server.Statistics.stats.add_value("%s:Bind:%s" %
- (self.__class__.__name__,
- entry.tag),
- time.time() - start)
+ (self.__class__.__name__,
+ entry.tag),
+ time.time() - start)
def BuildConfiguration(self, client):
""" Build the complete configuration for a client.
diff --git a/src/lib/Bcfg2/Server/Plugin/helpers.py b/src/lib/Bcfg2/Server/Plugin/helpers.py
index e5ea5188a..ade14b865 100644
--- a/src/lib/Bcfg2/Server/Plugin/helpers.py
+++ b/src/lib/Bcfg2/Server/Plugin/helpers.py
@@ -6,7 +6,6 @@ import sys
import copy
import glob
import genshi
-import logging
import operator
import lxml.etree
import Bcfg2.Server
@@ -30,6 +29,7 @@ try:
except ImportError:
HAS_DJANGO = False
+
class track_statistics(object): # pylint: disable=C0103
""" Decorator that tracks execution time for the given
:class:`Plugin` method with :mod:`Bcfg2.Statistics` for reporting
@@ -1221,7 +1221,7 @@ class Specificity(CmpMixin):
return "".join(rv)
-class SpecificData(object):
+class SpecificData(Debuggable):
""" A file that is specific to certain clients, groups, or all
clients. """
@@ -1237,6 +1237,7 @@ class SpecificData(object):
:param encoding: The encoding to use for data in this file
:type encoding: string
"""
+ Debuggable.__init__(self)
self.name = name
self.specific = specific
self.data = None
@@ -1258,7 +1259,7 @@ class SpecificData(object):
except UnicodeDecodeError:
self.data = open(self.name, mode='rb').read()
except: # pylint: disable=W0201
- LOGGER.error("Failed to read file %s" % self.name)
+ self.logger.error("Failed to read file %s" % self.name)
class EntrySet(Debuggable):
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py
index 735f23a1c..862726788 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPrivateKeyCreator.py
@@ -51,7 +51,7 @@ class CfgPrivateKeyCreator(CfgCreator, StructFile):
if (HAS_CRYPTO and
self.setup.cfp.has_section("sshkeys") and
self.setup.cfp.has_option("sshkeys", "passphrase")):
- return Bcfg2.Encrypption.get_passphrases()[
+ return Bcfg2.Server.Encryption.get_passphrases()[
self.setup.cfp.get("sshkeys", "passphrase")]
return None
@@ -196,7 +196,8 @@ class CfgPrivateKeyCreator(CfgCreator, StructFile):
privkey = open(filename).read()
if HAS_CRYPTO and self.passphrase:
self.debug_log("Cfg: Encrypting key data at %s" % filename)
- privkey = ssl_encrypt(privkey, self.passphrase)
+ privkey = Bcfg2.Server.Encryption.ssl_encrypt(privkey,
+ self.passphrase)
specificity['ext'] = '.crypt'
self.write_data(privkey, **specificity)
diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py
index ab96d3f59..b544eb47e 100644
--- a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py
+++ b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py
@@ -105,6 +105,7 @@ FL = '{http://linux.duke.edu/metadata/filelists}'
PULPSERVER = None
PULPCONFIG = None
+
def _setup_pulp():
""" Connect to a Pulp server and pass authentication credentials.
This only needs to be called once, but multiple calls won't hurt
diff --git a/src/lib/Bcfg2/Server/Plugins/Rules.py b/src/lib/Bcfg2/Server/Plugins/Rules.py
index fb294972c..3d4e8671d 100644
--- a/src/lib/Bcfg2/Server/Plugins/Rules.py
+++ b/src/lib/Bcfg2/Server/Plugins/Rules.py
@@ -25,8 +25,8 @@ class Rules(Bcfg2.Server.Plugin.PrioDir):
candidate):
return True
elif (entry.tag == "Path" and
- entry.get('name').rstrip("/") == \
- candidate.get("name").rstrip("/")):
+ entry.get('name').rstrip("/") ==
+ candidate.get("name").rstrip("/")):
# special case for Path tags:
# http://trac.mcs.anl.gov/projects/bcfg2/ticket/967
return True
diff --git a/src/lib/Bcfg2/Server/Plugins/__init__.py b/src/lib/Bcfg2/Server/Plugins/__init__.py
index ad51cf368..fdb20ed0a 100644
--- a/src/lib/Bcfg2/Server/Plugins/__init__.py
+++ b/src/lib/Bcfg2/Server/Plugins/__init__.py
@@ -1,5 +1 @@
"""Imports for Bcfg2.Server.Plugins."""
-
-from Bcfg2.Compat import walk_packages
-
-__all__ = [m[1] for m in walk_packages(path=__path__)]
diff --git a/src/lib/Bcfg2/Server/Statistics.py b/src/lib/Bcfg2/Server/Statistics.py
index dfb698b61..e34135d4b 100644
--- a/src/lib/Bcfg2/Server/Statistics.py
+++ b/src/lib/Bcfg2/Server/Statistics.py
@@ -5,6 +5,7 @@ server core. This data is exposed by
import time
from Bcfg2.Compat import wraps
+
class Statistic(object):
""" A single named statistic, tracking minimum, maximum, and
average execution time, and number of invocations. """
diff --git a/src/lib/Bcfg2/Server/__init__.py b/src/lib/Bcfg2/Server/__init__.py
index 6bd0ff9eb..bf8d0191d 100644
--- a/src/lib/Bcfg2/Server/__init__.py
+++ b/src/lib/Bcfg2/Server/__init__.py
@@ -1,14 +1,6 @@
"""This is the set of modules for Bcfg2.Server."""
import lxml.etree
-from Bcfg2.Compat import walk_packages
-
-<<<<<<< HEAD
-__all__ = ["Admin", "Core", "FileMonitor", "Plugin", "Plugins",
- "Reports", "XMLParser", "XI", "XI_NAMESPACE"]
-=======
-__all__ = [m[1] for m in walk_packages(path=__path__)]
->>>>>>> maint
XI = 'http://www.w3.org/2001/XInclude'
XI_NAMESPACE = '{%s}' % XI
diff --git a/src/lib/Bcfg2/Utils.py b/src/lib/Bcfg2/Utils.py
index ef88a1a36..68282331e 100644
--- a/src/lib/Bcfg2/Utils.py
+++ b/src/lib/Bcfg2/Utils.py
@@ -246,7 +246,8 @@ class Executor(object):
self.logger.debug('< %s' % line)
for line in stderr.splitlines(): # pylint: disable=E1103
self.logger.info(line)
- return ExecutorResult(stdout, stderr, proc.wait())
+ return ExecutorResult(stdout, stderr,
+ proc.wait()) # pylint: disable=E1101
finally:
if timeout is not None:
timer.cancel()
diff --git a/src/sbin/bcfg2-crypt b/src/sbin/bcfg2-crypt
index c4d5f0747..a75c0da9d 100755
--- a/src/sbin/bcfg2-crypt
+++ b/src/sbin/bcfg2-crypt
@@ -160,7 +160,7 @@ class Encryptor(object):
except TypeError:
pchunk = None
for pname, passphrase in \
- Bcfg2.Server.Encryption.get_passphrases().items():
+ Bcfg2.Server.Encryption.get_passphrases().items():
self.logger.debug("Trying passphrase %s" % pname)
try:
pchunk = self._decrypt(chunk, passphrase)
diff --git a/testsuite/Testsrc/Testlib/TestClient/TestTools/Test_init.py b/testsuite/Testsrc/Testlib/TestClient/TestTools/Test_init.py
index 2dc763730..df7b7c217 100644
--- a/testsuite/Testsrc/Testlib/TestClient/TestTools/Test_init.py
+++ b/testsuite/Testsrc/Testlib/TestClient/TestTools/Test_init.py
@@ -520,14 +520,14 @@ class TestSvcTool(TestTool):
st.get_svc_command.reset_mock()
st.cmd.reset_mock()
- self.assertEqual(st.check_service(service),
- st.cmd.run.return_value)
+ st.cmd.run.return_value = True
+ self.assertEqual(st.check_service(service), True)
st.get_svc_command.assert_called_with(service, "status")
st.cmd.run.assert_called_with(st.get_svc_command.return_value)
reset()
- self.assertEqual(st.check_service(service),
- st.cmd.run.return_value)
+ st.cmd.run.return_value = False
+ self.assertEqual(st.check_service(service), False)
st.get_svc_command.assert_called_with(service, "status")
st.cmd.run.assert_called_with(st.get_svc_command.return_value)
diff --git a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgPrivateKeyCreator.py b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgPrivateKeyCreator.py
index 6cfd2f666..48d5cdbfe 100644
--- a/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgPrivateKeyCreator.py
+++ b/testsuite/Testsrc/Testlib/TestServer/TestPlugins/TestCfg/TestCfgPrivateKeyCreator.py
@@ -66,8 +66,7 @@ class TestCfgPrivateKeyCreator(TestCfgCreator, TestStructFile):
pkc.setup.cfp.get.assert_called_with("sshkeys", "category")
@skipUnless(HAS_CRYPTO, "No crypto libraries found, skipping")
- @patchIf(HAS_CRYPTO,
- "Bcfg2.Server.Plugins.Cfg.CfgPrivateKeyCreator.get_passphrases")
+ @patchIf(HAS_CRYPTO, "Bcfg2.Server.Encryption.get_passphrases")
def test_passphrase(self, mock_get_passphrases):
pkc = self.get_obj()
pkc.setup = Mock()
@@ -279,7 +278,7 @@ class TestCfgPrivateKeyCreator(TestCfgCreator, TestStructFile):
if HAS_CRYPTO:
@patch(passphrase, "foo")
- @patch("Bcfg2.Server.Plugins.Cfg.CfgPrivateKeyCreator.ssl_encrypt")
+ @patch("Bcfg2.Server.Encryption.ssl_encrypt")
def inner2(mock_ssl_encrypt):
reset()
mock_ssl_encrypt.return_value = "encryptedprivatekey"
@@ -303,4 +302,3 @@ class TestCfgPrivateKeyCreator(TestCfgCreator, TestStructFile):
mock_rmtree.assert_called_with(datastore)
inner2()
-