password lookup plugin, with working tests and documentation

This commit is contained in:
Javier Candeira
2013-03-08 20:08:28 +11:00
parent c4aa72f1fd
commit ca6c36e1ac
4 changed files with 138 additions and 12 deletions

View File

@@ -172,20 +172,20 @@ class TestPlaybook(unittest.TestCase):
print utils.jsonify(actual, format=True)
expected = {
"localhost": {
"changed": 9,
"changed": 16,
"failures": 0,
"ok": 14,
"ok": 21,
"skipped": 1,
"unreachable": 0
}
}
}
}
print "**EXPECTED**"
print utils.jsonify(expected, format=True)
assert utils.jsonify(expected, format=True) == utils.jsonify(actual,format=True)
print "len(EVENTS) = %d" % len(EVENTS)
assert len(EVENTS) == 60
assert len(EVENTS) == 74
def test_includes(self):
pb = os.path.join(self.test_dir, 'playbook-includer.yml')
@@ -201,14 +201,14 @@ class TestPlaybook(unittest.TestCase):
"ok": 10,
"skipped": 0,
"unreachable": 0
}
}
}
}
print "**EXPECTED**"
print utils.jsonify(expected, format=True)
assert utils.jsonify(expected, format=True) == utils.jsonify(actual,format=True)
def test_playbook_vars(self):
def test_playbook_vars(self):
test_callbacks = TestCallbacks()
playbook = ansible.playbook.PlayBook(
playbook=os.path.join(self.test_dir, 'test_playbook_vars', 'playbook.yml'),

View File

@@ -55,3 +55,25 @@
action: copy src=sample.j2 dest=/tmp/ansible-test-with_lines-data
- name: cleanup test file
action: file path=/tmp/ansible-test-with_lines-data state=absent
# password lookup plugin
- name: ensure test file doesn't exist
# command because file will return differently
action: command rm -f /tmp/ansible-test-with_password
- name: test LOOKUP and PASSWORD with non existing password file
action: command test "$LOOKUP(password, /tmp/ansible-test-with_password)" = "$PASSWORD(/tmp/ansible-test-with_password)"
- name: test LOOKUP and PASSWORD with existing password file
action: command test "$LOOKUP(password, /tmp/ansible-test-with_password)" = "$PASSWORD(/tmp/ansible-test-with_password)"
- name: now test existing password via $item and with_password
action: command test "$PASSWORD(/tmp/ansible-test-with_password)" = "$item"
with_password:
- /tmp/ansible-test-with_password
- name: cleanup test file
action: file path=/tmp/ansible-test-with_password state=absent
- name: now test a password of non-default length (default=20, but here length=8)
action: command test "$PASSWORD(/tmp/ansible-test-with_password length=8)" = "$LOOKUP(password, /tmp/ansible-test-with_password)"
# - name: did we really create a password of length=8?
# action: command test "`expr length $PASSWORD(/tmp/ansible-test-with_password)`" = "8"
- name: cleanup test file, again
action: file path=/tmp/ansible-test-with_password state=absent