|
1
|
|
|
import pytest |
|
2
|
|
|
|
|
3
|
|
|
import os |
|
4
|
|
|
import ssg.playbook_builder |
|
5
|
|
|
import yaml |
|
6
|
|
|
import shutil |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
DATADIR = os.path.join( |
|
10
|
|
|
os.path.dirname(__file__), |
|
11
|
|
|
"test_playbook_builder_data" |
|
12
|
|
|
) |
|
13
|
|
|
|
|
14
|
|
|
product_yaml = os.path.join(DATADIR, "product.yml") |
|
15
|
|
|
input_dir = os.path.join(DATADIR, "fixes") |
|
16
|
|
|
output_dir = os.path.join(DATADIR, "playbooks") |
|
17
|
|
|
rule = "selinux_state" |
|
18
|
|
|
profile = "ospp" |
|
19
|
|
|
|
|
20
|
|
|
real_output_filepath = os.path.join(output_dir, profile, rule + ".yml") |
|
21
|
|
|
expected_output_filepath = os.path.join(DATADIR, "selinux_state.yml") |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
def test_build_rule_playbook(): |
|
25
|
|
|
playbook_builder = ssg.playbook_builder.PlaybookBuilder( |
|
26
|
|
|
product_yaml, input_dir, output_dir |
|
27
|
|
|
) |
|
28
|
|
|
playbook_builder.build(profile, rule) |
|
29
|
|
|
|
|
30
|
|
|
assert os.path.exists(real_output_filepath) |
|
31
|
|
|
|
|
32
|
|
|
with open(real_output_filepath, "r") as real_output: |
|
33
|
|
|
real_output_yaml = yaml.load(real_output) |
|
34
|
|
|
with open(expected_output_filepath, "r") as expected_output: |
|
35
|
|
|
expected_output_yaml = yaml.load(expected_output) |
|
36
|
|
|
|
|
37
|
|
|
real_play = real_output_yaml.pop() |
|
38
|
|
|
expected_play = expected_output_yaml.pop() |
|
39
|
|
|
assert real_play["become"] == expected_play["become"] |
|
40
|
|
|
assert real_play["hosts"] == expected_play["hosts"] |
|
41
|
|
|
assert real_play["name"] == expected_play["name"] |
|
42
|
|
|
real_vars = real_play["vars"] |
|
43
|
|
|
expected_vars = expected_play["vars"] |
|
44
|
|
|
assert len(real_vars) == len(expected_vars) |
|
45
|
|
|
assert real_vars["var_selinux_state"] == expected_vars["var_selinux_state"] |
|
46
|
|
|
real_tags = real_play["tags"] |
|
47
|
|
|
expected_tags = expected_play["tags"] |
|
48
|
|
|
assert len(real_tags) == len(expected_tags) |
|
49
|
|
|
for tag in expected_tags: |
|
50
|
|
|
assert tag in real_tags |
|
51
|
|
|
for t1, t2 in zip(real_tags, expected_tags): |
|
52
|
|
|
assert t1 == t2 |
|
53
|
|
|
real_tasks = real_play["tasks"] |
|
54
|
|
|
expected_tasks = expected_play["tasks"] |
|
55
|
|
|
assert len(real_tasks) == len(expected_tasks) |
|
56
|
|
|
real_task = real_tasks.pop() |
|
57
|
|
|
expected_task = expected_tasks.pop() |
|
58
|
|
|
assert real_task["name"] == expected_task["name"] |
|
59
|
|
|
assert len(real_task.keys()) == len(expected_task.keys()) |
|
60
|
|
|
shutil.rmtree(output_dir) |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
|