Beispiel #1
0
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)
Beispiel #2
0
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
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
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)
Beispiel #6
0
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)
Beispiel #7
0
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)
Beispiel #8
0
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)
Beispiel #9
0
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)
Beispiel #10
0
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)
Beispiel #11
0
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)
Beispiel #12
0
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)
Beispiel #13
0
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()
Beispiel #14
0
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)
Beispiel #15
0
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)
Beispiel #16
0
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
Beispiel #17
0
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)
Beispiel #18
0
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
Beispiel #19
0
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)
Beispiel #20
0
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
Beispiel #21
0
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)
Beispiel #22
0
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)
Beispiel #23
0
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)
Beispiel #24
0
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