summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-10-31 11:46:51 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-01-17 10:45:07 -0500
commitcebd0d7ad54995c37f68586a14540ad64d99d762 (patch)
treeac4de894cd8ed43d33890180cfc09cf3a0f90249 /src
parent45c7bbf24ae3c6530f33ebb33c062818ad44816d (diff)
downloadbcfg2-cebd0d7ad54995c37f68586a14540ad64d99d762.tar.gz
bcfg2-cebd0d7ad54995c37f68586a14540ad64d99d762.tar.bz2
bcfg2-cebd0d7ad54995c37f68586a14540ad64d99d762.zip
fixed unit tests
Diffstat (limited to 'src')
-rw-r--r--src/lib/Bcfg2/Server/Plugin/helpers.py12
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Bundler.py34
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Packages/Yum.py2
-rw-r--r--src/lib/Bcfg2/Server/Plugins/__init__.py1
-rw-r--r--src/lib/Bcfg2/Server/models.py14
5 files changed, 37 insertions, 26 deletions
diff --git a/src/lib/Bcfg2/Server/Plugin/helpers.py b/src/lib/Bcfg2/Server/Plugin/helpers.py
index 674aa5ffd..6ad18fa43 100644
--- a/src/lib/Bcfg2/Server/Plugin/helpers.py
+++ b/src/lib/Bcfg2/Server/Plugin/helpers.py
@@ -11,8 +11,8 @@ import lxml.etree
import Bcfg2.Server
import Bcfg2.Options
import Bcfg2.Statistics
+import Bcfg2.Server.FileMonitor
from Bcfg2.Compat import CmpMixin, wraps
-from Bcfg2.Server.FileMonitor import get_fam
from Bcfg2.Server.Plugin.base import Debuggable, Plugin
from Bcfg2.Server.Plugin.interfaces import Generator
from Bcfg2.Server.Plugin.exceptions import SpecificityError, \
@@ -208,7 +208,7 @@ class FileBacked(object):
self.name = name
#: The FAM object used to receive notifications of changes
- self.fam = get_fam()
+ self.fam = Bcfg2.Server.FileMonitor.get_fam()
def HandleEvent(self, event=None):
""" HandleEvent is called whenever the FAM registers an event.
@@ -273,7 +273,7 @@ class DirectoryBacked(object):
object.__init__(self)
self.data = os.path.normpath(data)
- self.fam = get_fam()
+ self.fam = Bcfg2.Server.FileMonitor.get_fam()
#: self.entries contains information about the files monitored
#: by this object. The keys of the dict are the relative
@@ -809,8 +809,8 @@ class XMLSrc(XMLFileBacked):
__cacheobj__ = dict
__priority_required__ = True
- def __init__(self, filename, fam=None, should_monitor=False):
- XMLFileBacked.__init__(self, filename, fam, should_monitor)
+ def __init__(self, filename, should_monitor=False):
+ XMLFileBacked.__init__(self, filename, should_monitor)
self.items = {}
self.cache = None
self.pnode = None
@@ -1469,7 +1469,7 @@ class GroupSpool(Plugin, Generator):
if self.data[-1] == '/':
self.data = self.data[:-1]
- self.fam = get_fam()
+ self.fam = Bcfg2.Server.FileMonitor.get_fam()
#: See :class:`Bcfg2.Server.Plugins.interfaces.Generator` for
#: details on the Entries attribute.
diff --git a/src/lib/Bcfg2/Server/Plugins/Bundler.py b/src/lib/Bcfg2/Server/Plugins/Bundler.py
index 9c6c7946d..fa993cd85 100644
--- a/src/lib/Bcfg2/Server/Plugins/Bundler.py
+++ b/src/lib/Bcfg2/Server/Plugins/Bundler.py
@@ -14,8 +14,7 @@ from Bcfg2.Options import get_option_parser
try:
import genshi.core
import genshi.input
- from genshi.template import TemplateLoader, \
- TextTemplate, MarkupTemplate, TemplateError
+ from genshi.template import TemplateLoader, MarkupTemplate, TemplateError
HAS_GENSHI = True
except ImportError:
HAS_GENSHI = False
@@ -55,6 +54,7 @@ if HAS_GENSHI:
Bcfg2.Server.Plugin.StructFile.__init__(self, name)
self.encoding = encoding
self.logger = logging.getLogger(name)
+ self.template = None
def HandleEvent(self, event=None):
"""Handle all fs events for this template."""
@@ -62,22 +62,20 @@ if HAS_GENSHI:
return
try:
loader = TemplateLoader()
- try:
- self.template = loader.load(self.name,
- cls=MarkupTemplate,
- encoding=self.encoding)
- except LookupError:
- err = sys.exc_info()[1]
- self.logger.error('Genshi lookup error in %s: %s' %
- (self.name, err))
- except TemplateError:
- err = sys.exc_info()[1]
- self.logger.error('Genshi template error in %s: %s' %
- (self.name, err))
- except genshi.input.ParseError:
- err = sys.exc_info()[1]
- self.logger.error('Genshi parse error in %s: %s' %
- (self.name, err))
+ self.template = loader.load(self.name, cls=MarkupTemplate,
+ encoding=self.encoding)
+ except LookupError:
+ err = sys.exc_info()[1]
+ self.logger.error('Genshi lookup error in %s: %s' %
+ (self.name, err))
+ except TemplateError:
+ err = sys.exc_info()[1]
+ self.logger.error('Genshi template error in %s: %s' %
+ (self.name, err))
+ except genshi.input.ParseError:
+ err = sys.exc_info()[1]
+ self.logger.error('Genshi parse error in %s: %s' %
+ (self.name, err))
def get_xml_value(self, metadata):
""" get the rendered XML data that applies to the given
diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py
index 17aff900b..859a0657f 100644
--- a/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py
+++ b/src/lib/Bcfg2/Server/Plugins/Packages/Yum.py
@@ -193,7 +193,7 @@ class PulpCertificateSet(Bcfg2.Server.Plugin.EntrySet):
important='true',
sensitive='true',
paranoid=self.metadata['paranoid'])
- self.fam = Bcfg2.Server.FileMonitor.get_fam().
+ self.fam = Bcfg2.Server.FileMonitor.get_fam()
self.fam.AddMonitor(path, self)
def HandleEvent(self, event):
diff --git a/src/lib/Bcfg2/Server/Plugins/__init__.py b/src/lib/Bcfg2/Server/Plugins/__init__.py
index e69de29bb..1f85702f0 100644
--- a/src/lib/Bcfg2/Server/Plugins/__init__.py
+++ b/src/lib/Bcfg2/Server/Plugins/__init__.py
@@ -0,0 +1 @@
+""" Bcfg2 Plugins """
diff --git a/src/lib/Bcfg2/Server/models.py b/src/lib/Bcfg2/Server/models.py
index 4ac2be43b..11d85c248 100644
--- a/src/lib/Bcfg2/Server/models.py
+++ b/src/lib/Bcfg2/Server/models.py
@@ -5,6 +5,7 @@ import copy
import logging
import Bcfg2.Options
import Bcfg2.Server.Plugins
+from Bcfg2.Compat import walk_packages
from django.db import models
LOGGER = logging.getLogger('Bcfg2.Server.models')
@@ -21,7 +22,18 @@ def load_models(plugins=None, cfile='/etc/bcfg2.conf', quiet=True):
# namely, _all_ plugins, so that the database is guaranteed to
# work, even if /etc/bcfg2.conf isn't set up properly
plugin_opt = copy.deepcopy(Bcfg2.Options.SERVER_PLUGINS)
- plugin_opt.default = Bcfg2.Server.Plugins.__all__
+ all_plugins = []
+ for submodule in walk_packages(path=Bcfg2.Server.Plugins.__path__,
+ prefix="Bcfg2.Server.Plugins."):
+ module = submodule[1].rsplit('.', 1)[-1]
+ if submodule[1] == "Bcfg2.Server.Plugins.%s" % module:
+ # we only include direct children of
+ # Bcfg2.Server.Plugins -- e.g., all_plugins should
+ # include Bcfg2.Server.Plugins.Cfg, but not
+ # Bcfg2.Server.Plugins.Cfg.CfgInfoXML
+ all_plugins.append(module)
+ plugin_opt.default = all_plugins
+
setup = Bcfg2.Options.get_option_parser()
setup.add_option("plugins", plugin_opt)
setup.add_option("configfile", Bcfg2.Options.CFILE)