def execute_cmdline_scenarios(scenario_name, args, command_args, ansible_args=()): """ Execute scenario sequences based on parsed command-line arguments. This is useful for subcommands that run scenario sequences, which excludes subcommands such as ``list``, ``login``, and ``matrix``. ``args`` and ``command_args`` are combined using :func:`get_configs` to generate the scenario(s) configuration. :param scenario_name: Name of scenario to run, or ``None`` to run all. :param args: ``args`` dict from ``click`` command context :param command_args: dict of command arguments, including the target subcommand to execute :returns: None """ glob_str = MOLECULE_GLOB if scenario_name: glob_str = glob_str.replace("*", scenario_name) scenarios = molecule.scenarios.Scenarios( get_configs(args, command_args, ansible_args, glob_str), scenario_name) scenarios.print_matrix() for scenario in scenarios: if command_args.get("subcommand") == "reset": LOG.info("Removing %s" % scenario.ephemeral_directory) shutil.rmtree(scenario.ephemeral_directory) return try: execute_scenario(scenario) except SystemExit: # if the command has a 'destroy' arg, like test does, # handle that behavior here. if command_args.get("destroy") == "always": msg = ("An error occurred during the {} sequence action: " "'{}'. Cleaning up.").format(scenario.config.subcommand, scenario.config.action) LOG.warning(msg) execute_subcommand(scenario.config, "cleanup") execute_subcommand(scenario.config, "destroy") # always prune ephemeral dir if destroying on failure scenario.prune() if scenario.config.is_parallel: scenario._remove_scenario_state_directory() util.sysexit() else: raise
def execute_cmdline_scenarios(scenario_name, args, command_args, ansible_args=()): """ Execute scenario sequences based on parsed command-line arguments. This is useful for subcommands that run scenario sequences, which excludes subcommands such as ``list``, ``login``, and ``matrix``. ``args`` and ``command_args`` are combined using :func:`get_configs` to generate the scenario(s) configuration. :param scenario_name: Name of scenario to run, or ``None`` to run all. :param args: ``args`` dict from ``click`` command context :param command_args: dict of command argumentss, including the target subcommand to execute :returns: None """ scenarios = molecule.scenarios.Scenarios( get_configs(args, command_args, ansible_args), scenario_name) scenarios.print_matrix() for scenario in scenarios: try: execute_scenario(scenario) except SystemExit: # if the command has a 'destroy' arg, like test does, # handle that behavior here. if command_args.get('destroy') == 'always': msg = ('An error occurred during the {} sequence action: ' "'{}'. Cleaning up.").format(scenario.config.subcommand, scenario.config.action) LOG.warning(msg) execute_subcommand(scenario.config, 'cleanup') execute_subcommand(scenario.config, 'destroy') # always prune ephemeral dir if destroying on failure scenario.prune() util.sysexit() else: raise