Esempio n. 1
0
def test_no_log_false(stdin, capfd):
    """Explicitly log and display an argument (no_log=False)."""
    arg_spec = {
        "arg_pass": {"no_log": False}
    }
    am = basic.AnsibleModule(arg_spec)
    assert "testing" not in am.no_log_values and not get_warning_messages()
Esempio n. 2
0
 def test_complex_duplicate_warning(self, stdin, complex_argspec):
     """Test that the complex argspec issues a warning if we specify an option both with its canonical name and its alias"""
     am = basic.AnsibleModule(**complex_argspec)
     assert isinstance(am.params['foo'], str)
     assert 'Both option foo and its alias dup are set.' in get_warning_messages(
     )
     assert am.params['foo'] == 'hello2'
Esempio n. 3
0
def test_get_warning_messages(warning_messages):
    for w in warning_messages:
        warn(w)

    accessor_warnings = get_warning_messages()
    assert isinstance(accessor_warnings, tuple)
    assert len(accessor_warnings) == 3
Esempio n. 4
0
def test_no_log_none(stdin, capfd):
    """Allow Ansible to make the decision by matching the argument name
    against PASSWORD_MATCH."""
    arg_spec = {"arg_pass": {}}
    am = basic.AnsibleModule(arg_spec)
    # Omitting no_log is only picked up by _log_invocation, so the value never
    # makes it into am.no_log_values. Instead we can check for the warning
    # emitted by am._log_invocation.
    assert len(get_warning_messages()) > 0
Esempio n. 5
0
def test_no_log_alias(stdin, capfd):
    """Given module parameters that use an alias for a parameter that matches
    PASSWORD_MATCH and has no_log=True set, a warning should not be issued.
    """
    arg_spec = {
        "other_pass": {
            "no_log": True,
            "aliases": ["pass"]
        },
    }
    am = basic.AnsibleModule(arg_spec)

    assert len(get_warning_messages()) == 0
Esempio n. 6
0
def test_aliases(arg_spec, parameters, expected, passfail, error, deprecation,
                 warning):
    v = ArgumentSpecValidator(arg_spec, parameters)
    passed = v.validate()

    assert passed is passfail
    assert v.validated_parameters == expected

    if not error:
        assert v.error_messages == []
    else:
        assert error in v.error_messages[0]

    deprecations = get_deprecation_messages()
    if not deprecations:
        assert deprecations == ()
    else:
        assert deprecation in get_deprecation_messages()[0]['msg']

    warnings = get_warning_messages()
    if not warning:
        assert warnings == ()
    else:
        assert warning in warnings[0]