diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-12-10 20:58:55 -0500 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2013-12-11 10:51:54 -0500 |
commit | 94ba31279869d7052ba001e38927f9eecd0a636f (patch) | |
tree | d54894a50fbe4850996a3aa5fb254d6956cb92af /src/lib | |
parent | 13fbef668878239dc5116f899a0c9791df81081e (diff) | |
download | bcfg2-94ba31279869d7052ba001e38927f9eecd0a636f.tar.gz bcfg2-94ba31279869d7052ba001e38927f9eecd0a636f.tar.bz2 bcfg2-94ba31279869d7052ba001e38927f9eecd0a636f.zip |
Augeas improvements:
* Added ability to specify initial content for a file that doesn't
exist, to avoid a messy situation where you'd have to probe for file
existence and either use a Path type="file" or Path type="augeas"
depending, and run Bcfg2 twice.
* All commands in an Augeas path are run if *any* of them fail to
verify. Previously, only commands that hadn't been run would be
installed, but that had issues, particularly with the Clear command,
which could pass verification but then be required during the
installation phase anyway.
* Miscellaneous bug fixes.
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Bcfg2/Client/Tools/POSIX/Augeas.py | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/lib/Bcfg2/Client/Tools/POSIX/Augeas.py b/src/lib/Bcfg2/Client/Tools/POSIX/Augeas.py index 81c948d0d..187b4d77c 100644 --- a/src/lib/Bcfg2/Client/Tools/POSIX/Augeas.py +++ b/src/lib/Bcfg2/Client/Tools/POSIX/Augeas.py @@ -4,6 +4,7 @@ import sys import Bcfg2.Client.XML from augeas import Augeas from Bcfg2.Client.Tools.POSIX.base import POSIXTool +from Bcfg2.Client.Tools.POSIX.File import POSIXFile class AugeasCommand(object): @@ -187,13 +188,14 @@ class Insert(AugeasCommand): class POSIXAugeas(POSIXTool): """ Handle <Path type='augeas'...> entries. See :ref:`client-tools-augeas`. """ - - __handles__ = [('Path', 'augeas')] - __req__ = {'Path': ['type', 'name', 'setting', 'value']} + __req__ = ['name', 'mode', 'owner', 'group'] def __init__(self, logger, setup, config): POSIXTool.__init__(self, logger, setup, config) self._augeas = dict() + # file tool for setting initial values of files that don't + # exist + self.filetool = POSIXFile(logger, setup, config) def get_augeas(self, entry): """ Get an augeas object for the given entry. """ @@ -214,9 +216,9 @@ class POSIXAugeas(POSIXTool): return self._augeas[entry.get("name")] def fully_specified(self, entry): - return entry.text is not None + return len(entry.getchildren()) != 0 - def get_commands(self, entry, unverified=False): + def get_commands(self, entry): """ Get a list of commands to verify or install. @param entry: The entry to get commands from. @@ -229,7 +231,7 @@ class POSIXAugeas(POSIXTool): """ rv = [] for cmd in entry.iterchildren(): - if unverified and cmd.get("verified", "false") != "false": + if cmd.tag == "Initial": continue if cmd.tag in globals(): rv.append(globals()[cmd.tag](cmd, self.get_augeas(entry), @@ -266,7 +268,17 @@ class POSIXAugeas(POSIXTool): def install(self, entry): rv = True - for cmd in self.get_commands(entry, unverified=True): + if entry.get("current_exists", "true") == "false": + initial = entry.find("Initial") + if initial is not None: + self.logger.debug("Augeas: Setting initial data for %s" % + entry.get("name")) + file_entry = Bcfg2.Client.XML.Element("Path", **entry.attrib) + file_entry.text = initial.text + self.filetool.install(file_entry) + # re-parse the file + self.get_augeas(entry).load() + for cmd in self.get_commands(entry): try: cmd.install() except: # pylint: disable=W0702 @@ -277,8 +289,7 @@ class POSIXAugeas(POSIXTool): try: self.get_augeas(entry).save() except: # pylint: disable=W0702 - self.logger.error( - "Failure saving Augeas changes to %s: %s" % - (entry.get("name"), sys.exc_info()[1])) + self.logger.error("Failure saving Augeas changes to %s: %s" % + (entry.get("name"), sys.exc_info()[1])) rv = False return POSIXTool.install(self, entry) and rv |