def main(environment, platform, timeout, dirty, fast, consistency_only, predict_only, reset): output.backend = TerminalBackend() output.line(self_id()) if consistency_only: ACTION = 'CONSISTENCY CHECK' elif predict_only: ACTION = 'DEPLOYMENT PREDICTION' else: ACTION = 'DEPLOYMENT' with locked('.batou-lock'): try: deployment = Deployment(environment, platform, timeout, dirty, fast, predict_only, reset=reset) deployment.load() deployment.connect() deployment.configure() if not consistency_only: deployment.deploy() deployment.disconnect() except MissingEnvironment as e: e.report() output.section("{} FAILED".format(ACTION), red=True) notify( '{} FAILED'.format(ACTION), 'Configuration for {} encountered an error.'.format( environment)) sys.exit(1) except ConfigurationError: output.section("{} FAILED".format(ACTION), red=True) notify( '{} FAILED'.format(ACTION), 'Configuration for {} encountered an error.'.format( environment)) sys.exit(1) except DeploymentError as e: e.report() output.section("{} FAILED".format(ACTION), red=True) notify('{} FAILED'.format(ACTION), '{} encountered an error.'.format(environment)) sys.exit(1) except Exception: # An unexpected exception happened. Bad. output.error("Unexpected exception", exc_info=sys.exc_info()) output.section("{} FAILED".format(ACTION), red=True) notify('{} FAILED'.format(ACTION), 'Encountered an unexpected exception.') sys.exit(1) else: output.section('{} FINISHED'.format(ACTION), green=True) notify('{} SUCCEEDED'.format(ACTION), environment)
def main(environment, platform, timeout, dirty, consistency_only, predict_only, jobs): output.backend = TerminalBackend() output.line(self_id()) STEPS = ['load', 'connect', 'configure', 'deploy'] if consistency_only: ACTION = "CONSISTENCY CHECK" STEPS.remove('deploy') elif predict_only: ACTION = "DEPLOYMENT PREDICTION" else: ACTION = "DEPLOYMENT" with locked(".batou-lock"): deployment = Deployment(environment, platform, timeout, dirty, jobs, predict_only) environment = deployment.environment try: for step in STEPS: try: getattr(deployment, step)() except Exception as e: environment.exceptions.append(e) if not environment.exceptions: continue # Note: There is a similar sorting / output routine in # remote_core __channelexec__. This is a bit of copy/paste # due to the way bootstrapping works environment.exceptions = list( filter( lambda e: not isinstance(e, SilentConfigurationError), environment.exceptions)) environment.exceptions.sort( key=lambda x: getattr(x, 'sort_key', (-99,))) exception = '' for exception in environment.exceptions: if isinstance(exception, ReportingException): output.line('') exception.report() else: output.line('') output.error("Unexpected exception") tb = traceback.TracebackException.from_exception( exception) for line in tb.format(): output.line('\t' + line.strip(), red=True) summary = "{} FAILED (during {})".format(ACTION, step) output.section(summary, red=True) notify(summary, str(exception)) sys.exit(1) finally: deployment.disconnect() output.section("{} FINISHED".format(ACTION), green=True) notify("{} SUCCEEDED".format(ACTION), environment.name)
DummyException) ReportingException = getattr(batou, "ReportingException", DummyException) environment = deployment.environment if exception not in environment.exceptions: environment.exceptions.append(e) environment.exceptions = list( filter(lambda e: not isinstance(e, SilentConfigurationError), environment.exceptions)) deployment.environment.exceptions.sort(key=lambda x: x.sort_key) for exception in deployment.environment.exceptions: if isinstance(exception, ReportingException): output.line('') exception.report() else: output.line('') output.error("Unexpected exception") tb = traceback.TracebackException.from_exception(exception) for line in tb.format(): output.line('\t' + line.strip(), red=True) batou.output.section("{} ERRORS - CONFIGURATION FAILED".format( len(deployment.environment.exceptions)), red=True) channel.send(("batou-configuration-error", None)) except getattr(batou, "DeploymentError", DummyException) as e: e.report() channel.send(("batou-deployment-error", None))
def main( environment, platform, timeout, dirty, consistency_only, predict_only, jobs ): output.backend = TerminalBackend() output.line(self_id()) if consistency_only: ACTION = "CONSISTENCY CHECK" elif predict_only: ACTION = "DEPLOYMENT PREDICTION" else: ACTION = "DEPLOYMENT" with locked(".batou-lock"): try: deployment = Deployment( environment, platform, timeout, dirty, jobs, predict_only ) deployment.load() deployment.connect() deployment.configure() if not consistency_only: deployment.deploy() deployment.disconnect() except FileLockedError as e: output.error("File already locked: {}".format(e.filename)) output.section("{} FAILED".format(ACTION), red=True) notify( "{} FAILED".format(ACTION), "File already locked: {}".format(e.filename), ) except MissingEnvironment as e: e.report() output.section("{} FAILED".format(ACTION), red=True) notify( "{} FAILED".format(ACTION), "Configuration for {} encountered an error.".format( environment ), ) sys.exit(1) except ConfigurationError: output.section("{} FAILED".format(ACTION), red=True) notify( "{} FAILED".format(ACTION), "Configuration for {} encountered an error.".format( environment ), ) sys.exit(1) except DeploymentError as e: e.report() output.section("{} FAILED".format(ACTION), red=True) notify( "{} FAILED".format(ACTION), "{} encountered an error.".format(environment), ) sys.exit(1) except Exception: # An unexpected exception happened. Bad. output.error("Unexpected exception", exc_info=sys.exc_info()) output.section("{} FAILED".format(ACTION), red=True) notify( "{} FAILED".format(ACTION), "Encountered an unexpected exception.", ) sys.exit(1) else: output.section("{} FINISHED".format(ACTION), green=True) notify("{} SUCCEEDED".format(ACTION), environment)
def output_migration_step(title: str, text: str) -> None: """Print the information of migration step in a formatted way.""" output.section(title, red=True) output.line(textwrap.dedent(text).replace('\n', ' ')) output.line('')