294
314
env_vars = ["env"] + ["=".join((k, v)) for k, v in env.items()]
295
315
command = env_vars + [script]
296
output = subprocess.check_output(command, stderr=subprocess.STDOUT)
317
output = subprocess.check_output(command, stderr=subprocess.STDOUT)
318
except subprocess.CalledProcessError as e:
319
dl = mojo.juju.debuglogs.DebugLogs(
320
workspace, stage, self.options.get('debug-logs'), self.options.get('debug-logs-stages-to-exclude'))
322
exception_output = "{}\n{}".format(e.output, dl.get_log_output())
324
exception_output = e.output
325
raise ScriptPhaseException(e.returncode, exception_output)
297
326
if output.strip():
298
327
logging.info(output)
545
584
cmd += ('-d', deploy_name, '-W', '-u')
546
if str2bool(self.options.get('optional')):
547
with chdir(workspace.repo_dir):
550
logging.info("Running: {}".format(" ".join(cmd)))
551
with chdir(workspace.repo_dir):
552
status, output = bicommand(" ".join(cmd), showoutput=True, env=env)
553
logging.getLogger('file').info(output)
555
timeout_fail = re.search("Reached deployment timeout.. exiting",
558
logging.error("Deployment timed out. It was set to {} "
559
"seconds".format(timeout[1]))
560
hook_fail = re.search(".*unit: (?P<unit>[^:]+):.*hook failed",
563
failed_unit = hook_fail.group("unit")
564
logging.error("Deployment failed, grabbing the last 200 lines of "
565
"output from the juju logs on {}".format(failed_unit))
566
cmd = ["juju", "ssh", failed_unit, "sudo", "tail", "-200",
567
"/var/log/juju/unit-%s.log" % (
568
failed_unit.replace("/", "-"),)]
569
with chdir(workspace.repo_dir):
570
failure = subprocess.check_output(cmd)
571
logging.error(failure)
573
juju_status = mojo.juju.status.Status(environment=juju_env)
574
logging.error("Juju Status: {}".format(juju_status.status()))
575
if not timeout_fail and not hook_fail:
576
logging.error("There was an unrecognised problem with "
577
"running a deploy phase")
586
logging.info("Running: {}".format(" ".join(cmd)))
589
logging.info("NOTE: This phase is marked optional; "
590
"failure will not terminate the run.")
592
with chdir(workspace.repo_dir):
593
status, output = bicommand(cmd, showoutput=True, env=env)
594
logging.getLogger('file').info(output)
597
timeout_fail = re.search("Reached deployment timeout.. exiting",
600
logging.error("Deployment timed out. It was set to {} "
601
"seconds".format(timeout[1]))
602
hook_fail = re.search(".*unit: (?P<unit>[^:]+):.*hook failed",
605
failed_unit = hook_fail.group("unit")
606
logging.error("Deployment failed, grabbing the last 200 lines of "
607
"output from the juju logs on {}".format(failed_unit))
608
cmd = ["juju", "ssh", failed_unit, "sudo", "tail", "-200",
609
"/var/log/juju/unit-%s.log" % (
610
failed_unit.replace("/", "-"),)]
611
with chdir(workspace.repo_dir):
612
failure = subprocess.check_output(cmd)
613
logging.error(failure)
615
juju_status = mojo.juju.status.Status(environment=juju_env)
616
logging.error("Juju Status: {}".format(juju_status.status()))
617
if not timeout_fail and not hook_fail:
618
logging.error("There was an unrecognised problem with "
619
"running a deploy phase")
622
logging.info("Error found during optional deployment phase: continuing as directed.")
578
624
raise JujuDeployerException("Error found during deployment phase")
580
logging.info("Checking Juju status")
581
juju_status = mojo.juju.status.Status(environment=juju_env)
582
juju_status.check_and_wait(timeout=status_timeout)
584
logging.info("Waiting for environment to reach steady state")
587
except JujuWaitException:
589
logging.error("Juju Status: {}".format(print_juju_status(environment=juju_env)))
591
logging.info("Environment has reached steady state")
626
logging.info("Checking Juju status")
627
juju_status = mojo.juju.status.Status(environment=juju_env)
628
juju_status.check_and_wait(timeout=status_timeout)
630
logging.info("Waiting for environment to reach steady state")
633
except JujuWaitException:
635
logging.error("Juju Status: {}".format(print_juju_status(environment=juju_env)))
637
logging.info("Environment has reached steady state")
593
639
def render_config(self, src, dest, tmpl_vars=None):
594
640
if not tmpl_vars: