Exemplo n.º 1
0
def test_cli_no_playbook():
    """
    Test with no playbook provided
    :return:
    """
    args = [__prog__]

    cli = PlaybookGrapherCLI(args)

    with pytest.raises(AnsibleOptionsError) as exception_info:
        cli.parse()

    assert "You must specify a playbook file to graph." in exception_info.value.message
Exemplo n.º 2
0
def test_cli_multiple_playbooks():
    """
    Test with multiple playbooks provided
    :return:
    """
    args = [__prog__, 'playbook1.yml', 'playbook2.yml']

    cli = PlaybookGrapherCLI(args)

    with pytest.raises(AnsibleOptionsError) as exception_info:
        cli.parse()

    assert "You must specify only one playbook file to graph" in exception_info.value.message
Exemplo n.º 3
0
def test_cli_output_filename(output_filename_option, expected):
    """
    Test for the output filename option: -o, --ouput-file-name
    :param output_filename_option:
    :param expected:
    :return:
    """
    args = [__prog__] + output_filename_option + ['playbook.yml']

    cli = PlaybookGrapherCLI(args)

    cli.parse()

    assert cli.options.output_filename == expected
Exemplo n.º 4
0
def test_cli_save_dot_file(save_dot_file_option, expected):
    """
    Test for the save dot file option: -s, --save-dot-file
    :param save_dot_file_option:
    :param expected:
    :return:
    """
    args = [__prog__] + save_dot_file_option + ['playbook.yml']

    cli = PlaybookGrapherCLI(args)

    cli.parse()

    assert cli.options.save_dot_file == expected
Exemplo n.º 5
0
def test_cli_include_role_tasks(include_role_tasks_option, expected):
    """
    Test for the include role tasks option: --include-role-tasks
    :param include_role_tasks_option:
    :param expected:
    :return:
    """

    args = [__prog__] + include_role_tasks_option + ['playboook.yml']

    cli = PlaybookGrapherCLI(args)

    cli.parse()

    assert cli.options.include_role_tasks == expected
Exemplo n.º 6
0
def grapher_cli(request) -> PlaybookGrapherCLI:
    """
    Because Ansible is not designed to be used as a library, we need the CLI everywhere. The CLI is the main entrypoint
    of Ansible and it sets some global variables that are needed by some classes and methods.
    See this commit: https://github.com/ansible/ansible/commit/afdbb0d9d5bebb91f632f0d4a1364de5393ba17a
    As such, this fixture is just used to init this global context
    :return:
    """
    # The request param should be the path to the playbook
    args_params = request.param.copy()
    # The last item of the args should be the name of the playbook file in the fixtures.
    args_params[-1] = os.path.join(FIXTURES_DIR, args_params[-1])
    cli = PlaybookGrapherCLI([__prog__] + args_params)
    cli.parse()
    return cli
Exemplo n.º 7
0
def test_skip_tags(skip_tags_option, expected):
    """

    :param tags_option:
    :param expected:
    :return:
    """
    args = [__prog__] + skip_tags_option + ['playbook.yml']

    cli = PlaybookGrapherCLI(args)

    cli.parse()

    # Ansible uses a set to construct the tags list. It may happen that the order of tags changes between two runs. As
    # the order of tags doesn't matter, I sorted them to avoid the test to fail
    assert sorted(cli.options.skip_tags) == sorted(expected)
Exemplo n.º 8
0
def test_cli_help(help_option, capfd):
    """
    Test for the help option : -h, --help
    :param help_option:
    :param capfd:
    :return:
    """
    args = [__prog__, help_option]

    cli = PlaybookGrapherCLI(args)

    with pytest.raises(SystemExit) as exception_info:
        cli.parse()

    out, err = capfd.readouterr()

    assert "Make graph from your Playbook." in out
Exemplo n.º 9
0
def run_grapher(args):
    cli = PlaybookGrapherCLI(args)

    cli.parse()

    return cli.run()