-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathasb_save_test_result.py
executable file
·75 lines (61 loc) · 1.92 KB
/
asb_save_test_result.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python
from ansible.module_utils.basic import AnsibleModule
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: asb_save_test_result
short_description: Encodes the test results for testing action.
description:
- Takes a test result object and makes it available during the testing
action.
notes: []
requirements: []
author:
- "Red Hat, Inc."
options:
fail:
description:
- 'Will signify whether the test result has passed or failed.'
default: false
type: bool
msg:
description:
- 'The message that will be printed with the failure or success'
type: string
'''
EXAMPLES = '''
- name: save test results
asb_save_test_result:
fail: true
msg: "Test failed"
- name: test passed
asb_save_test_result:
msg: "Test passed!"
'''
RETURN = '''
'''
TEST_RESULT_PATH = "/var/tmp/test-result"
def main():
"""Ansible module that will Append test result to test result file."""
argument_spec = dict(
fail=dict(default=False, type='bool'),
msg=dict(default=None, type='str')
)
ansible_module = AnsibleModule(argument_spec=argument_spec)
try:
with open(TEST_RESULT_PATH, "a") as test_result_file:
# If failure is true then print the 1 code the test file.
if ansible_module.params['fail']:
test_result_file.write("1\n")
else:
# If failue is false, then 0 code signals success.
test_result_file.write("0\n")
if ansible_module.params['msg'] is not None:
test_result_file.write("%s\n" % ansible_module.params['msg'])
except Exception as error:
ansible_module.fail_json(msg="Error attempting to write test result: {}".format(error))
ansible_module.exit_json(changed=True)
if __name__ == '__main__':
main()