summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Client/Frame.py
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2013-04-23 14:50:09 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2013-04-23 14:50:09 -0400
commit46a47b4120b3d892b8149a5e181e4d976ad87f99 (patch)
treef2697f233fc7f5ad5022864222a5ca87715a651b /src/lib/Bcfg2/Client/Frame.py
parente1f99d1d5045e0511db42debb30aa97da2018796 (diff)
parent3d06f311274d6b942ee89d8cdb13b2ecc99af1b0 (diff)
downloadbcfg2-46a47b4120b3d892b8149a5e181e4d976ad87f99.tar.gz
bcfg2-46a47b4120b3d892b8149a5e181e4d976ad87f99.tar.bz2
bcfg2-46a47b4120b3d892b8149a5e181e4d976ad87f99.zip
Merge branch '1.4.x'
Conflicts: debian/bcfg2-server.install doc/server/plugins/grouping/metadata.txt src/lib/Bcfg2/Client/Client.py src/lib/Bcfg2/Client/Tools/Portage.py src/lib/Bcfg2/Client/Tools/RcUpdate.py src/lib/Bcfg2/Client/Tools/YUM24.py src/lib/Bcfg2/Client/Tools/__init__.py src/lib/Bcfg2/Client/Tools/launchd.py src/lib/Bcfg2/Options.py src/lib/Bcfg2/Server/Core.py src/lib/Bcfg2/Server/Plugin/helpers.py src/lib/Bcfg2/Server/Plugins/Metadata.py src/lib/Bcfg2/Server/models.py src/lib/Bcfg2/Utils.py src/sbin/bcfg2-info src/sbin/bcfg2-test testsuite/Testsrc/Testlib/TestClient/TestTools/Test_init.py testsuite/Testsrc/test_code_checks.py
Diffstat (limited to 'src/lib/Bcfg2/Client/Frame.py')
-rw-r--r--src/lib/Bcfg2/Client/Frame.py84
1 files changed, 52 insertions, 32 deletions
diff --git a/src/lib/Bcfg2/Client/Frame.py b/src/lib/Bcfg2/Client/Frame.py
index bc6bd4d4c..6ef686c10 100644
--- a/src/lib/Bcfg2/Client/Frame.py
+++ b/src/lib/Bcfg2/Client/Frame.py
@@ -7,6 +7,7 @@ import logging
import Bcfg2.Client.Tools
from Bcfg2.Client import prompt
from Bcfg2.Compat import any, all # pylint: disable=W0622
+from Bcfg2.Options import get_option_parser
def cmpent(ent1, ent2):
@@ -48,20 +49,25 @@ def passes_black_list(entry, blacklist):
class Frame(object):
"""Frame is the container for all Tool objects and state information."""
- def __init__(self, config, setup, times, drivers, dryrun):
+ def __init__(self, config, times):
+ self.setup = get_option_parser()
self.config = config
self.times = times
- self.dryrun = dryrun
+ self.dryrun = self.setup['dryrun']
self.times['initialization'] = time.time()
- self.setup = setup
self.tools = []
+
+ #: A dict of the state of each entry. Keys are the entries.
+ #: Values are boolean: True means that the entry is good,
+ #: False means that the entry is bad.
self.states = {}
self.whitelist = []
self.blacklist = []
self.removal = []
self.logger = logging.getLogger(__name__)
+ drivers = self.setup['drivers']
for driver in drivers[:]:
- if driver not in Bcfg2.Client.Tools.drivers and \
+ if driver not in Bcfg2.Client.Tools.__all__ and \
isinstance(driver, str):
self.logger.error("Tool driver %s is not available" % driver)
drivers.remove(driver)
@@ -83,7 +89,7 @@ class Frame(object):
for tool in list(tclass.values()):
try:
- self.tools.append(tool(self.logger, setup, config))
+ self.tools.append(tool(config))
except Bcfg2.Client.Tools.ToolInstantiationError:
continue
except:
@@ -261,7 +267,7 @@ class Frame(object):
self.states[entry] = False
for tool in self.tools:
try:
- tool.Inventory(self.states)
+ self.states.update(tool.Inventory())
except:
self.logger.error("%s.Inventory() call failed:" % tool.name,
exc_info=1)
@@ -310,10 +316,10 @@ class Frame(object):
for bundle in self.setup['bundle']:
if bundle not in all_bundle_names:
self.logger.info("Warning: Bundle %s not found" % bundle)
- bundles = filter(lambda b: b.get('name') in self.setup['bundle'],
- bundles)
+ bundles = [b for b in bundles
+ if b.get('name') in self.setup['bundle']]
elif self.setup['indep']:
- bundles = filter(lambda b: b.tag != 'Bundle', bundles)
+ bundles = [b for b in bundles if b.tag != 'Bundle']
if self.setup['skipbundle']:
# warn if non-existent bundle given
if not self.setup['bundle_quick']:
@@ -321,39 +327,41 @@ class Frame(object):
if bundle not in all_bundle_names:
self.logger.info("Warning: Bundle %s not found" %
bundle)
- bundles = filter(lambda b:
- b.get('name') not in self.setup['skipbundle'],
- bundles)
+ bundles = [b for b in bundles
+ if b.get('name') not in self.setup['skipbundle']]
if self.setup['skipindep']:
- bundles = filter(lambda b: b.tag == 'Bundle', bundles)
+ bundles = [b for b in bundles if b.tag == 'Bundle']
self.whitelist = [e for e in self.whitelist
- if True in [e in b for b in bundles]]
+ if any(e in b for b in bundles)]
# first process prereq actions
for bundle in bundles[:]:
- if bundle.tag != 'Bundle':
- continue
- bmodified = len([item for item in bundle
- if item in self.whitelist])
+ if bundle.tag == 'Bundle':
+ bmodified = any(item in self.whitelist for item in bundle)
+ else:
+ bmodified = False
actions = [a for a in bundle.findall('./Action')
- if (a.get('timing') != 'post' and
+ if (a.get('timing') in ['pre', 'both'] and
(bmodified or a.get('when') == 'always'))]
# now we process all "always actions"
if self.setup['interactive']:
self.promptFilter(iprompt, actions)
self.DispatchInstallCalls(actions)
+ if bundle.tag != 'Bundle':
+ continue
+
# need to test to fail entries in whitelist
- if False in [self.states[a] for a in actions]:
+ if not all(self.states[a] for a in actions):
# then display bundles forced off with entries
- self.logger.info("Bundle %s failed prerequisite action" %
- (bundle.get('name')))
+ self.logger.info("%s %s failed prerequisite action" %
+ (bundle.tag, bundle.get('name')))
bundles.remove(bundle)
b_to_remv = [ent for ent in self.whitelist if ent in bundle]
if b_to_remv:
- self.logger.info("Not installing entries from Bundle %s" %
- (bundle.get('name')))
+ self.logger.info("Not installing entries from %s %s" %
+ (bundle.tag, bundle.get('name')))
self.logger.info(["%s:%s" % (e.tag, e.get('name'))
for e in b_to_remv])
for ent in b_to_remv:
@@ -378,7 +386,7 @@ class Frame(object):
if not handled:
continue
try:
- tool.Install(handled, self.states)
+ self.states.update(tool.Install(handled))
except:
self.logger.error("%s.Install() call failed:" % tool.name,
exc_info=1)
@@ -398,7 +406,7 @@ class Frame(object):
tbm = [(t, b) for t in self.tools for b in mbundles]
for tool, bundle in tbm:
try:
- tool.Inventory(self.states, [bundle])
+ self.states.update(tool.Inventory(structures=[bundle]))
except:
self.logger.error("%s.Inventory() call failed:" %
tool.name,
@@ -419,14 +427,26 @@ class Frame(object):
# prune out unspecified bundles when running with -b
continue
for tool in self.tools:
+ if bundle in mbundles:
+ func = tool.BundleUpdated
+ else:
+ func = tool.BundleNotUpdated
try:
- if bundle in mbundles:
- tool.BundleUpdated(bundle, self.states)
- else:
- tool.BundleNotUpdated(bundle, self.states)
+ self.states.update(func(bundle))
+ except:
+ self.logger.error("%s.%s(%s:%s) call failed:" %
+ (tool.name, func.im_func.func_name,
+ bundle.tag, bundle.get("name")),
+ exc_info=1)
+
+ for indep in self.config.findall('.//Independent'):
+ for tool in self.tools:
+ try:
+ self.states.update(tool.BundleNotUpdated(indep))
except:
- self.logger.error("%s.BundleNotUpdated() call failed:" %
- tool.name, exc_info=1)
+ self.logger.error("%s.BundleNotUpdated(%s:%s) call failed:"
+ % (tool.name, indep.tag,
+ indep.get("name")), exc_info=1)
def Remove(self):
"""Remove extra entries."""