From 9533e579b390c171f8147211d63866935b2d683b Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Thu, 8 Sep 2011 14:04:30 +0200 Subject: [PATCH] finish run of initial manifest, finish shell_run_or_debug_fail() Signed-off-by: Nico Schottelius --- bin/cdist | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/bin/cdist b/bin/cdist index 766a2acf..594b5eea 100755 --- a/bin/cdist +++ b/bin/cdist @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# -*- coding: utf-8 -*- # # 2010-2011 Nico Schottelius (nico-cdist at schottelius.org) # @@ -96,11 +97,23 @@ class Cdist: log.error(args) sys.exit(1) - def run_or_fail(self,*args, **kargs): + def shell_run_or_debug_fail(self, script, *args, **kargs): + kargs['shell'] = True + log.debug("Shell exec: " + " ".join(*args)) + + try: + subprocess.check_call(*args, **kargs) + except subprocess.CalledProcessError: + # FIXME: print out shell script! + script_fd = open(script) + log.error("Code that raised the error:\n" + script_fd.read()) + script_fd.close() + self.exit_error("Non-Zero exit code exit of " + " ".join(*args)) + + def run_or_fail(self, *args, **kargs): # newargs = ["echo"] newargs = [] newargs.extend(*args) - print(newargs) try: subprocess.check_call(newargs, **kargs) @@ -165,15 +178,18 @@ class Cdist: # # Link configuraion source directory - consistent with remote # run_or_fail(["ln -sf", "$__cdist_conf_dir", "$__cdist_local_base_dir/$__cdist_name_conf_dir"]) - def initial_manifes(self): + def run_initial_manifest(self): """Run the initial manifest""" + log.info("Running the initial manifest") + self.shell_run_or_debug_fail(self.initial_manifest, [self.initial_manifest]) + def deploy_to(self): """Mimic the old deploy to: Deploy to one host""" log.info("Deploying to host " + self.hostname) self.init_deploy() self.global_explore() - self.initial_manifest() + self.run_initial_manifest() if __name__ == "__main__":