summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-10-17 15:17:03 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-10-17 15:17:08 -0400
commit3cf1f738c0a474e21ce56604ad874241584d59e9 (patch)
tree50aafe6501d1c48ef8bf91140808adef8b912da0 /src/lib/Bcfg2
parent63ca36cc3569bc5b31ffd9203d8f9d591eb9c21c (diff)
downloadbcfg2-3cf1f738c0a474e21ce56604ad874241584d59e9.tar.gz
bcfg2-3cf1f738c0a474e21ce56604ad874241584d59e9.tar.bz2
bcfg2-3cf1f738c0a474e21ce56604ad874241584d59e9.zip
assigned Cfg handlers explicit priorities to avoid over-zealous regex matches
Diffstat (limited to 'src/lib/Bcfg2')
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgCheetahGenerator.py4
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedCheetahGenerator.py3
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py4
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenshiGenerator.py3
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py4
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/CfgPlaintextGenerator.py5
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py16
7 files changed, 36 insertions, 3 deletions
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgCheetahGenerator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgCheetahGenerator.py
index 7f02d4a05..73c70901b 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgCheetahGenerator.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgCheetahGenerator.py
@@ -23,6 +23,10 @@ class CfgCheetahGenerator(CfgGenerator):
#: Handle .cheetah files
__extensions__ = ['cheetah']
+ #: Low priority to avoid matching host- or group-specific
+ #: .crypt.cheetah files
+ __priority__ = 50
+
#: :class:`Cheetah.Template.Template` compiler settings
settings = dict(useStackFrames=False)
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedCheetahGenerator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedCheetahGenerator.py
index 9eed633c4..9e2b75537 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedCheetahGenerator.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedCheetahGenerator.py
@@ -13,6 +13,9 @@ class CfgEncryptedCheetahGenerator(CfgCheetahGenerator, CfgEncryptedGenerator):
#: handle .crypt.cheetah or .cheetah.crypt files
__extensions__ = ['cheetah.crypt', 'crypt.cheetah']
+ #: Override low priority from parent class
+ __priority__ = 0
+
def handle_event(self, event):
CfgEncryptedGenerator.handle_event(self, event)
handle_event.__doc__ = CfgEncryptedGenerator.handle_event.__doc__
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py
index dc4bab9f6..98a807602 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenerator.py
@@ -21,6 +21,10 @@ class CfgEncryptedGenerator(CfgGenerator):
#: Handle .crypt files
__extensions__ = ["crypt"]
+ #: Low priority to avoid matching host- or group-specific
+ #: .genshi.crypt and .cheetah.crypt files
+ __priority__ = 50
+
def __init__(self, fname, spec, encoding):
CfgGenerator.__init__(self, fname, spec, encoding)
if not HAS_CRYPTO:
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenshiGenerator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenshiGenerator.py
index 01f590b06..feedbdb1b 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenshiGenerator.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgEncryptedGenshiGenerator.py
@@ -43,6 +43,9 @@ class CfgEncryptedGenshiGenerator(CfgGenshiGenerator):
#: handle .crypt.genshi or .genshi.crypt files
__extensions__ = ['genshi.crypt', 'crypt.genshi']
+ #: Override low priority from parent class
+ __priority__ = 0
+
#: Use a TemplateLoader class that decrypts the data on the fly
#: when it's read in
__loader_cls__ = EncryptedTemplateLoader
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py
index 5cec33489..ce77717da 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgGenshiGenerator.py
@@ -53,6 +53,10 @@ class CfgGenshiGenerator(CfgGenerator):
#: Genshi ``{% include ... %}`` directive without raising warnings.
__ignore__ = ["genshi_include"]
+ #: Low priority to avoid matching host- or group-specific
+ #: .crypt.genshi files
+ __priority__ = 50
+
#: Error-handling in Genshi is pretty obtuse. This regex is used
#: to extract the first line of the code block that raised an
#: exception in a Genshi template so we can provide a decent error
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPlaintextGenerator.py b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPlaintextGenerator.py
index 92fb06ee9..42e1fd7c3 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPlaintextGenerator.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/CfgPlaintextGenerator.py
@@ -12,4 +12,7 @@ class CfgPlaintextGenerator(CfgGenerator):
files. The base Generator class already implements this
functionality, so CfgPlaintextGenerator doesn't need to do
anything itself."""
- pass
+
+ #: Very low priority to avoid matching host- or group-specific
+ #: files with other extensions -- e.g., .genshi, .crypt, etc.
+ __priority__ = 100
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py b/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py
index 114cdab70..fe53ea809 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py
@@ -5,6 +5,7 @@ import os
import sys
import stat
import logging
+import operator
import lxml.etree
import Bcfg2.Options
import Bcfg2.Server.Plugin
@@ -56,6 +57,16 @@ class CfgBaseFileMatcher(Bcfg2.Server.Plugin.SpecificData):
#: ``.H_client.example.com`` or ``.G10_foogroup``.
__specific__ = True
+ #: Cfg handlers are checked in ascending order of priority to see
+ #: if they handle a given event. If this explicit priority is not
+ #: set, then
+ #: :class:`Bcfg2.Server.Plugins.Cfg.CfgPlaintextGenerator` would
+ #: match against nearly every other sort of generator file if it
+ #: comes first. It's not necessary to set ``__priority`` on
+ #: handlers where :attr:`__specific__` is False, since they don't
+ #: have a potentially open-ended regex
+ __priority__ = 0
+
#: Flag to indicate a deprecated handler.
deprecated = False
@@ -63,14 +74,14 @@ class CfgBaseFileMatcher(Bcfg2.Server.Plugin.SpecificData):
Bcfg2.Server.Plugin.SpecificData.__init__(self, name, specific,
encoding)
self.encoding = encoding
- self.regex = self.__class__.get_regex([name])
__init__.__doc__ = Bcfg2.Server.Plugin.SpecificData.__init__.__doc__ + \
"""
.. -----
.. autoattribute:: Bcfg2.Server.Plugins.Cfg.CfgBaseFileMatcher.__basenames__
.. autoattribute:: Bcfg2.Server.Plugins.Cfg.CfgBaseFileMatcher.__extensions__
.. autoattribute:: Bcfg2.Server.Plugins.Cfg.CfgBaseFileMatcher.__ignore__
-.. autoattribute:: Bcfg2.Server.Plugins.Cfg.CfgBaseFileMatcher.__specific__"""
+.. autoattribute:: Bcfg2.Server.Plugins.Cfg.CfgBaseFileMatcher.__specific__
+.. autoattribute:: Bcfg2.Server.Plugins.Cfg.CfgBaseFileMatcher.__priority__ """
@classmethod
def get_regex(cls, basenames):
@@ -339,6 +350,7 @@ class CfgEntrySet(Bcfg2.Server.Plugin.EntrySet):
if set(hdlr.__mro__).intersection([CfgInfo, CfgFilter,
CfgGenerator, CfgVerifier]):
self._handlers.append(hdlr)
+ self._handlers.sort(key=operator.attrgetter("__priority__"))
return self._handlers
def handle_event(self, event):