summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/lib/Client/Frame.py30
-rwxr-xr-xsrc/sbin/bcfg23
-rw-r--r--testsuite/TestFrame.py25
3 files changed, 41 insertions, 17 deletions
diff --git a/src/lib/Client/Frame.py b/src/lib/Client/Frame.py
index d0477f752..3b3174d9d 100644
--- a/src/lib/Client/Frame.py
+++ b/src/lib/Client/Frame.py
@@ -1,7 +1,7 @@
'''Frame is the Client Framework that verifies and installs entries, and generates statistics'''
__revision__ = '$Revision$'
-import logging, time
+import logging, time, types
import Bcfg2.Client.Tools
def cmpent(ent1, ent2):
@@ -36,9 +36,10 @@ toolset_defs = {'rh': {'Service':'chkconfig', 'Package':'rpm'},
class Frame:
'''Frame is the container for all Tool objects and state information'''
- def __init__(self, config, setup, times):
+ def __init__(self, config, setup, times, drivers, dryrun):
self.config = config
self.times = times
+ self.dryrun = dryrun
self.times['initialization'] = time.time()
self.setup = setup
self.tools = []
@@ -47,18 +48,15 @@ class Frame:
self.blacklist = []
self.removal = []
self.logger = logging.getLogger("Bcfg2.Client.Frame")
- if self.setup['drivers']:
- tools = []
- for tcandidate in self.setup['drivers'].split(','):
- if tcandidate not in Bcfg2.Client.Tools.drivers:
- self.logger.error("Tool driver %s is not available"\
- % (tcandidate))
- else:
- tools.append(tcandidate)
- else:
- tools = Bcfg2.Client.Tools.default[:]
+ for driver in drivers[:]:
+ if driver not in Bcfg2.Client.Tools.drivers:
+ self.logger.error("Tool driver %s is not available" % driver)
+ drivers.remove(driver)
+
tclass = {}
- for tool in tools:
+ for tool in drivers:
+ if not isinstance(tool, types.StringType):
+ tclass[time.time()] = tool
tool_class = "Bcfg2.Client.Tools.%s" % tool
try:
tclass[tool] = getattr(__import__(tool_class, globals(),
@@ -86,7 +84,7 @@ class Frame:
self.logger.info("Loaded tool drivers:")
self.logger.info([tool.__name__ for tool in self.tools])
- if not self.setup['dryrun']:
+ if not self.dryrun:
for cfile in [cfl for cfl in config.findall(".//ConfigFile") \
if cfl.get('name') in self.__important__]:
tool = [t for t in self.tools if t.handlesEntry(cfile)][0]
@@ -154,7 +152,7 @@ class Frame:
candidates = [entry for entry in self.states if not self.states[entry]]
self.whitelist = [entry for entry in self.states if not self.states[entry]]
- if self.setup['dryrun']:
+ if self.dryrun:
if self.whitelist:
self.logger.info("In dryrun mode: suppressing entry installation for:")
self.logger.info(["%s:%s" % (entry.tag, entry.get('name')) for entry \
@@ -289,7 +287,7 @@ class Frame:
def ReInventory(self):
'''Recheck everything'''
- if not self.setup['dryrun'] and self.setup['kevlar']:
+ if not self.dryrun and self.setup['kevlar']:
self.logger.info("Rechecking system inventory")
self.Inventory()
diff --git a/src/sbin/bcfg2 b/src/sbin/bcfg2
index d78f6f9a2..50e5c616a 100755
--- a/src/sbin/bcfg2
+++ b/src/sbin/bcfg2
@@ -235,7 +235,8 @@ class Client:
self.tools = Bcfg2.Client.Frame.Frame(self.config,
self.setup,
- times)
+ times, self.setup['drivers'],
+ self.setup['dryrun'])
self.tools.Execute()
diff --git a/testsuite/TestFrame.py b/testsuite/TestFrame.py
new file mode 100644
index 000000000..933298f06
--- /dev/null
+++ b/testsuite/TestFrame.py
@@ -0,0 +1,25 @@
+import lxml.etree
+
+import Bcfg2.Client.Frame, Bcfg2.Client.Tools
+
+c1 = lxml.etree.XML("<Configuration><Bundle name='foo'><Configfile name='/tmp/test12' owner='root' group='root' empty='true' perms='644'/></Bundle></Configuration>")
+
+c2 = lxml.etree.XML("<Configuration><Bundle name='foo'><Configfile name='/tmp/test12' owner='root' group='root' empty='true' perms='644'/><Configfile name='/tmp/test12' owner='root' group='root' empty='true' perms='644'/></Bundle></Configuration>")
+
+class DriverInitFail(object):
+ def __init__(self, *args):
+ raise Bcfg2.Client.Tools.toolInstantiationError
+
+class TestFrame(object):
+ def test__init(self):
+ config = lxml.etree.Element('Configuration')
+ setup = {}
+ times = {}
+ drivers = []
+ frame = Bcfg2.Client.Frame.Frame(config, setup, times, drivers, False)
+ assert frame.tools == []
+ frame2 = Bcfg2.Client.Frame.Frame(c1, setup, times, ['POSIX'], False)
+ assert len(frame2.tools) == 1
+ frame3 = Bcfg2.Client.Frame.Frame(c2, setup, times, ['foo'], False)
+ assert len(frame3.tools) == 0
+ frame4 = Bcfg2.Client.Frame.Frame(c2, setup, times, [DriverInitFail], False)