-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest_ansbak.py
118 lines (98 loc) · 3.34 KB
/
test_ansbak.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from ansbak import main
from textwrap import dedent
def test_main_groups_hosts(capsys):
ansible_output = dedent("""\
red01 | CHANGED | rc=0 >>
foo
red02 | CHANGED | rc=0 >>
foo
""").splitlines(keepends=True)
main(ansible_output)
captured = capsys.readouterr()
expected_output = dedent("""\
red01,red02 | CHANGED | rc=0 >>
foo
""")
assert captured.out == expected_output
def test_main_groups_hosts_with_different_output(capsys):
ansible_output = dedent("""\
red01 | CHANGED | rc=0 >>
foo
red02 | CHANGED | rc=0 >>
bar
red03 | CHANGED | rc=0 >>
foo
""").splitlines(keepends=True)
main(ansible_output)
captured = capsys.readouterr()
expected_output = dedent("""\
red01,red03 | CHANGED | rc=0 >>
foo
--------------------
red02 | CHANGED | rc=0 >>
bar
""")
assert captured.out == expected_output
def test_main_shows_unreachables_condensed_at_start(capsys):
ansible_output = dedent("""\
red01 | CHANGED | rc=0 >>
foo
unreachable03 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: connect to host unreachable03 port 22: No route to host",
"unreachable": true
}
red02 | CHANGED | rc=0 >>
foo
unreachable04 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: connect to host unreachable04 port 22: Operation timed out",
"unreachable": true
}
""").splitlines(keepends=True)
main(ansible_output)
captured = capsys.readouterr()
expected_output = dedent("""\
unreachable03 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: connect to host unreachable03 port 22: No route to host",
"unreachable": true
}
unreachable04 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: connect to host unreachable04 port 22: Operation timed out",
"unreachable": true
}
--------------------
red01,red02 | CHANGED | rc=0 >>
foo
""")
assert captured.out == expected_output
def test_main_shows_changed_after_failed_after_unreachable(capsys):
ansible_output = dedent("""\
red01 | CHANGED | rc=0 >>
succeeding
red02 | FAILED | rc=1 >>
failing
unreachable03 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: connect to host unreachable03 port 22: Connection refused",
"unreachable": true
}
""").splitlines(keepends=True)
main(ansible_output)
captured = capsys.readouterr()
expected_output = dedent("""\
unreachable03 | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: connect to host unreachable03 port 22: Connection refused",
"unreachable": true
}
--------------------
red02 | FAILED | rc=1 >>
failing
--------------------
red01 | CHANGED | rc=0 >>
succeeding
""")
assert captured.out == expected_output