def dependency(ctx, scenario_name): # pragma: no cover """Manage the role's dependencies.""" args = ctx.obj.get("args") subcommand = base._get_subcommand(__name__) command_args = {"subcommand": subcommand} base.execute_cmdline_scenarios(scenario_name, args, command_args)
def test_execute_cmdline_scenarios_destroy( config_instance, _patched_execute_scenario, _patched_prune, _patched_execute_subcommand, _patched_sysexit): # Ensure execute_cmdline_scenarios handles errors correctly when 'destroy' # is 'always': # - cleanup and destroy subcommands are run when execute_scenario # raises SystemExit # - scenario is pruned scenario_name = 'default' args = {} command_args = { 'destroy': 'always', 'subcommand': 'test', } _patched_execute_scenario.side_effect = SystemExit() base.execute_cmdline_scenarios(scenario_name, args, command_args) assert _patched_execute_subcommand.call_count == 2 # pull out the second positional call argument for each call, # which is the called subcommand. 'cleanup' and 'destroy' should be called. assert _patched_execute_subcommand.call_args_list[0][0][1] == 'cleanup' assert _patched_execute_subcommand.call_args_list[1][0][1] == 'destroy' assert _patched_prune.called assert _patched_sysexit.called
def reset(ctx, scenario_name): # pragma: no cover """Reset molecule temporary folders.""" args = ctx.obj.get('args') subcommand = base._get_subcommand(__name__) command_args = {'subcommand': subcommand} base.execute_cmdline_scenarios(scenario_name, args, command_args)
def create(ctx, scenario_name, driver_name): # pragma: no cover """Use the provisioner to start the instances.""" args = ctx.obj.get('args') subcommand = base._get_subcommand(__name__) command_args = {'subcommand': subcommand, 'driver_name': driver_name} base.execute_cmdline_scenarios(scenario_name, args, command_args)
def lint(ctx, scenario_name): # pragma: no cover """ Lint the role. """ args = ctx.obj.get('args') subcommand = base._get_subcommand(__name__) command_args = {'subcommand': subcommand} base.execute_cmdline_scenarios(scenario_name, args, command_args)
def verify(ctx, scenario_name): # pragma: no cover """Run automated tests against instances.""" args = ctx.obj.get("args") subcommand = base._get_subcommand(__name__) command_args = {"subcommand": subcommand} base.execute_cmdline_scenarios(scenario_name, args, command_args)
def lint(ctx, scenario_name): # pragma: no cover """Lint the role (dependency, lint).""" args = ctx.obj.get("args") subcommand = base._get_subcommand(__name__) command_args = {"subcommand": subcommand} base.execute_cmdline_scenarios(scenario_name, args, command_args)
def side_effect(ctx, scenario_name): # pragma: no cover """Use the provisioner to perform side-effects to the instances.""" args = ctx.obj.get('args') subcommand = base._get_subcommand(__name__) command_args = {'subcommand': subcommand} base.execute_cmdline_scenarios(scenario_name, args, command_args)
def syntax(ctx, scenario_name): # pragma: no cover """Use the provisioner to syntax check the role.""" args = ctx.obj.get('args') subcommand = base._get_subcommand(__name__) command_args = {'subcommand': subcommand} base.execute_cmdline_scenarios(scenario_name, args, command_args)
def converge(ctx, scenario_name, ansible_args): # pragma: no cover """Use the provisioner to configure instances (dependency, create, prepare converge).""" args = ctx.obj.get("args") subcommand = base._get_subcommand(__name__) command_args = {"subcommand": subcommand} base.execute_cmdline_scenarios(scenario_name, args, command_args, ansible_args)
def cleanup(ctx, scenario_name): # pragma: no cover """Use the provisioner to cleanup any changes made to external systems during \ the stages of testing.""" args = ctx.obj.get("args") subcommand = base._get_subcommand(__name__) command_args = {"subcommand": subcommand} base.execute_cmdline_scenarios(scenario_name, args, command_args)
def idempotence(ctx, scenario_name): # pragma: no cover """Use the provisioner to configure the instances and parse the output to \ determine idempotence.""" args = ctx.obj.get('args') subcommand = base._get_subcommand(__name__) command_args = {'subcommand': subcommand} base.execute_cmdline_scenarios(scenario_name, args, command_args)
def reset(ctx, scenario_name): # pragma: no cover """Reset molecule temporary folders.""" args = ctx.obj.get("args") subcommand = base._get_subcommand(__name__) command_args = {"subcommand": subcommand} base.execute_cmdline_scenarios(scenario_name, args, command_args) for driver in drivers(): driver.reset()
def prepare(ctx, scenario_name, driver_name, force): # pragma: no cover """Use the provisioner to prepare the instances into a particular starting state.""" args = ctx.obj.get('args') subcommand = base._get_subcommand(__name__) command_args = { 'subcommand': subcommand, 'driver_name': driver_name, 'force': force, } base.execute_cmdline_scenarios(scenario_name, args, command_args)
def check(ctx, scenario_name, parallel): # pragma: no cover """Use the provisioner to perform a Dry-Run (destroy, dependency, create, \ prepare, converge).""" args = ctx.obj.get('args') subcommand = base._get_subcommand(__name__) command_args = {'parallel': parallel, 'subcommand': subcommand} if parallel: util.validate_parallel_cmd_args(command_args) base.execute_cmdline_scenarios(scenario_name, args, command_args)
def test_execute_cmdline_scenarios_no_prune(config_instance, _patched_prune, _patched_execute_subcommand): # Subcommands should be executed but prune *should not* run when # destroy is 'never' scenario_name = "default" args = {} command_args = {"destroy": "never", "subcommand": "test"} base.execute_cmdline_scenarios(scenario_name, args, command_args) assert _patched_execute_subcommand.called assert not _patched_prune.called
def check(ctx, scenario_name): # pragma: no cover """ Use the provisioner to perform a Dry-Run (destroy, dependency, create, prepare, converge). """ args = ctx.obj.get('args') subcommand = base._get_subcommand(__name__) command_args = { 'subcommand': subcommand, } base.execute_cmdline_scenarios(scenario_name, args, command_args)
def test_execute_cmdline_scenarios_no_prune(config_instance, _patched_prune, _patched_execute_subcommand): # Subcommands should be executed but prune *should not* run when # destroy is 'never' scenario_name = 'default' args = {} command_args = {'destroy': 'never', 'subcommand': 'test'} base.execute_cmdline_scenarios(scenario_name, args, command_args) assert _patched_execute_subcommand.called assert not _patched_prune.called
def destroy(ctx, scenario_name, driver_name, __all): # pragma: no cover """ Use the provisioner to destroy the instances. """ args = ctx.obj.get('args') subcommand = base._get_subcommand(__name__) command_args = { 'subcommand': subcommand, 'driver_name': driver_name, } if __all: scenario_name = None base.execute_cmdline_scenarios(scenario_name, args, command_args)
def test_execute_cmdline_scenarios(config_instance, _patched_print_matrix, _patched_execute_scenario): # Ensure execute_cmdline_scenarios runs normally: # - scenarios.print_matrix is called, which also indicates Scenarios # was instantiated correctly # - execute_scenario is called once, indicating the function correctly # loops over Scenarios. scenario_name = None args = {} command_args = {'destroy': 'always', 'subcommand': 'test'} base.execute_cmdline_scenarios(scenario_name, args, command_args) assert _patched_print_matrix.called_once_with() assert _patched_execute_scenario.call_count == 1
def test(ctx, scenario_name, driver_name, __all, destroy): # pragma: no cover """ Test (lint, cleanup, destroy, dependency, syntax, create, prepare, converge, idempotence, side_effect, verify, cleanup, destroy). """ args = ctx.obj.get('args') subcommand = base._get_subcommand(__name__) command_args = { 'destroy': destroy, 'subcommand': subcommand, 'driver_name': driver_name, } if __all: scenario_name = None base.execute_cmdline_scenarios(scenario_name, args, command_args)
def destroy(ctx, scenario_name, driver_name, __all, parallel): # pragma: no cover """Use the provisioner to destroy the instances.""" args = ctx.obj.get("args") subcommand = base._get_subcommand(__name__) command_args = { "parallel": parallel, "subcommand": subcommand, "driver_name": driver_name, } if __all: scenario_name = None if parallel: util.validate_parallel_cmd_args(command_args) base.execute_cmdline_scenarios(scenario_name, args, command_args)
def test(ctx, scenario_name, driver_name, __all, destroy, parallel): # pragma: no cover """Test (dependency, lint, cleanup, destroy, syntax, create, prepare, converge, idempotence, side_effect, verify, cleanup, destroy).""" args = ctx.obj.get("args") subcommand = base._get_subcommand(__name__) command_args = { "parallel": parallel, "destroy": destroy, "subcommand": subcommand, "driver_name": driver_name, } if __all: scenario_name = None if parallel: util.validate_parallel_cmd_args(command_args) base.execute_cmdline_scenarios(scenario_name, args, command_args)
def test_execute_cmdline_scenarios_exit_nodestroy( config_instance, _patched_execute_scenario, _patched_prune, _patched_sysexit ): # Ensure execute_cmdline_scenarios handles errors correctly when 'destroy' # is 'always': # - destroy subcommand is not run when execute_scenario raises SystemExit # - scenario is not pruned # - caught SystemExit is reraised scenario_name = "default" args = {} command_args = {"destroy": "never", "subcommand": "test"} _patched_execute_scenario.side_effect = SystemExit() # Catch the expected SystemExit reraise with pytest.raises(SystemExit): base.execute_cmdline_scenarios(scenario_name, args, command_args) assert _patched_execute_scenario.called assert not _patched_prune.called assert not _patched_sysexit.called