From e4601724cc1fcbcd9e243078269338a11680a85d Mon Sep 17 00:00:00 2001 From: Fabio Erculiani Date: Fri, 23 Jul 2010 11:11:56 +0200 Subject: [PATCH] [molecule.specs.plugins.tar_plugin] add "pre_tar_script" and "post_tar_script" parameters support (see example) --- molecule/specs/plugins/tar_plugin.py | 55 +++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/molecule/specs/plugins/tar_plugin.py b/molecule/specs/plugins/tar_plugin.py index e542dde..5470a6d 100644 --- a/molecule/specs/plugins/tar_plugin.py +++ b/molecule/specs/plugins/tar_plugin.py @@ -17,7 +17,6 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. import os -import tempfile import shutil from molecule.i18n import _ @@ -62,6 +61,29 @@ class TarHandler(GenericExecutionStep, BuiltinHandlerMixin): ) ) + # run pre tar script + exec_script = self.metadata.get('pre_tar_script') + if exec_script: + os.environ['CHROOT_DIR'] = self.chroot_path + os.environ['TAR_PATH'] = self.dest_path + os.environ['TAR_CHECKSUM_PATH'] = self.dest_path + \ + TarHandler.MD5_EXT + self._output.output("[%s|%s] %s: %s" % ( + blue("TarHandler"), darkred(self.spec_name), + _("spawning"), exec_script, + ) + ) + rc = molecule.utils.exec_cmd(exec_script) + if rc != 0: + self._output.output("[%s|%s] %s: %s" % ( + blue("TarHandler"), darkred(self.spec_name), + _("pre tar hook failed"), rc, + ) + ) + return rc + + return 0 + def run(self): self._output.output("[%s|%s] %s => %s" % ( blue("TarHandler"), darkred(self.spec_name), @@ -109,6 +131,29 @@ class TarHandler(GenericExecutionStep, BuiltinHandlerMixin): ) ) + # run post tar script + exec_script = self.metadata.get('post_tar_script') + if exec_script: + os.environ['CHROOT_DIR'] = self.chroot_path + os.environ['TAR_PATH'] = self.dest_path + os.environ['TAR_CHECKSUM_PATH'] = self.dest_path + \ + TarHandler.MD5_EXT + self._output.output("[%s|%s] %s: %s" % ( + blue("TarHandler"), darkred(self.spec_name), + _("spawning"), exec_script, + ) + ) + rc = molecule.utils.exec_cmd(exec_script) + if rc != 0: + self._output.output("[%s|%s] %s: %s" % ( + blue("TarHandler"), darkred(self.spec_name), + _("post tar hook failed"), rc, + ) + ) + return rc + + return 0 + def kill(self, success = True): if not success: self._run_error_script(None, self.chroot_path, None) @@ -193,6 +238,14 @@ class IsoToTarSpec(GenericSpec): 'cb': self.valid_dir, 've': self.ve_string_stripper, }, + 'pre_tar_script': { + 'cb': self.valid_exec_first_list_item, + 've': self.ve_string_splitter, + }, + 'post_tar_script': { + 'cb': self.valid_exec_first_list_item, + 've': self.ve_string_splitter, + }, 'iso_mounter': { 'cb': self.ne_list, 've': self.ve_string_splitter,