-
Notifications
You must be signed in to change notification settings - Fork 0
/
read_workloads.py
201 lines (162 loc) · 6.36 KB
/
read_workloads.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import pytest
import yaml
def read_yaml_file(file_name):
with open(file_name) as cluster_file:
return cluster_file.read()
def parse_yaml_file(yaml_string):
return yaml.safe_load(yaml_string)
def dict_to_cluster(parsed_yaml):
return None
@pytest.mark.parametrize(
"input_file, expected_cluster_name",
[
("static_files/OCPCluster1.yml", "OCPCluster1"),
("static_files/OCPCluster2.yml", "OCPCluster2"),
("static_files/OCPCluster3.yml", "OCPCluster3"),
("static_files/OCPCluster4.yml", "OCPCluster4"),
("static_files/OCPCluster5.yml", "OCPCluster5"),
],
ids=["Cluster1", "Cluster2", "Cluster3", "Cluster4", "Cluster5"],
)
def test_get_cluster_name(input_file, expected_cluster_name):
read_yaml = read_yaml_file(input_file)
parsed_file = parse_yaml_file(read_yaml)
cluster = dict_to_cluster(parsed_file)
cluster_name = None
assert cluster_name == expected_cluster_name
@pytest.mark.parametrize(
"input_file, expected_cpu_count",
[
("static_files/OCPCluster1.yml", 3.0),
("static_files/OCPCluster2.yml", 5.0),
("static_files/OCPCluster3.yml", 11.0),
("static_files/OCPCluster4.yml", 14.0),
("static_files/OCPCluster5.yml", 8.0),
],
ids=["Cluster1", "Cluster2", "Cluster3", "Cluster4", "Cluster5"],
)
def test_get_cpu_count(input_file, expected_cpu_count):
read_yaml = read_yaml_file(input_file)
parsed_file = parse_yaml_file(read_yaml)
cluster = dict_to_cluster(parsed_file)
cpu_cores = None
assert cpu_cores == expected_cpu_count, "Unmatched CPU count"
@pytest.mark.parametrize(
"input_file, expected_memory_gig",
[
("static_files/OCPCluster1.yml", 12.0),
("static_files/OCPCluster2.yml", 2.0),
("static_files/OCPCluster3.yml", 20.0),
("static_files/OCPCluster4.yml", 16.0),
("static_files/OCPCluster5.yml", 2.0),
],
ids=["Cluster1", "Cluster2", "Cluster3", "Cluster4", "Cluster5"],
)
def test_get_mem_count(input_file, expected_memory_gig):
read_yaml = read_yaml_file(input_file)
parsed_file = parse_yaml_file(read_yaml)
cluster = dict_to_cluster(parsed_file["data"][0]["OCPCluster"])
memory_gig = None
assert memory_gig == expected_memory_gig, "Unmatched Memory count"
@pytest.mark.parametrize(
"input_file, expected_nodes",
[
("static_files/OCPCluster1.yml", ["node1", "node2"]),
("static_files/OCPCluster2.yml", ["node1B"]),
("static_files/OCPCluster3.yml", ["node1C", "node2C"]),
("static_files/OCPCluster4.yml", ["node1C", "node2C"]),
("static_files/OCPCluster5.yml", ["node1E", "node2E"]),
],
ids=["Cluster1", "Cluster2", "Cluster3", "Cluster4", "Cluster5"],
)
def test_get_all_nodes(input_file, expected_nodes):
read_yaml = read_yaml_file(input_file)
parsed_file = parse_yaml_file(read_yaml)
cluster = dict_to_cluster(parsed_file["data"][0]["OCPCluster"])
nodes = None
assert sorted(nodes) == sorted(expected_nodes), "Unmatched node names"
@pytest.mark.parametrize(
"input_file, expected_namespaces",
[
("static_files/OCPCluster1.yml", ["ns1", "ns2", "ns3"]),
("static_files/OCPCluster2.yml", ["ns1"]),
("static_files/OCPCluster3.yml", ["ns1", "ns2", "ns3", "ns4", "ns5"]),
("static_files/OCPCluster4.yml", ["ns1", "ns2"]),
("static_files/OCPCluster5.yml", ["ns1", "ns2", "ns3"]),
],
ids=["Cluster1", "Cluster2", "Cluster3", "Cluster4", "Cluster5"],
)
def test_get_all_namespaces(input_file, expected_namespaces):
read_yaml = read_yaml_file(input_file)
parsed_file = parse_yaml_file(read_yaml)
cluster = dict_to_cluster(parsed_file["data"][0]["OCPCluster"])
namespaces = None
assert sorted(namespaces) == sorted(expected_namespaces), "Unmatched ns names"
@pytest.mark.parametrize(
"input_file, expected_pods",
[
("static_files/OCPCluster1.yml", ["pod_1", "pod_2", "pod_3"]),
("static_files/OCPCluster2.yml", ["pod_1", "pod_2"]),
(
"static_files/OCPCluster3.yml",
[
"pod_1",
"pod_2",
"pod_3",
"pod_4",
"pod_2",
"pod_1",
"pod_2",
"pod_4",
"pod_1",
"pod_4",
"pod_2",
],
),
("static_files/OCPCluster4.yml", ["pod_1", "pod_2"]),
("static_files/OCPCluster5.yml", ["pod_1", "pod_2", "pod_3"]),
],
ids=["Cluster1", "Cluster2", "Cluster3", "Cluster4", "Cluster5"],
)
def test_get_all_pods(input_file, expected_pods):
read_yaml = read_yaml_file(input_file)
parsed_file = parse_yaml_file(read_yaml)
cluster = dict_to_cluster(parsed_file["data"][0]["OCPCluster"])
pods = None
assert sorted(pods) == sorted(expected_pods), "Unmatched pod names"
@pytest.mark.parametrize(
"input_file, nodes_regex,expected_ns",
[
("static_files/OCPCluster1.yml", "node1", ["ns1", "ns2"]),
("static_files/OCPCluster1.yml", "node2", ["ns3"]),
("static_files/OCPCluster1.yml", "node", ["ns1", "ns2", "ns3"]),
("static_files/OCPCluster1.yml", "fake:regex", []),
],
ids=["node1", "node2", "node", "fake_regex"],
)
def test_get_ns_by_node(input_file, nodes_regex, expected_ns):
read_yaml = read_yaml_file(input_file)
parsed_file = parse_yaml_file(read_yaml)
cluster = dict_to_cluster(parsed_file["data"][0]["OCPCluster"])
ns = None
assert sorted(ns) == sorted(expected_ns), "Unmatched filtered ns names"
@pytest.mark.parametrize(
"input_file,label,expected_label_values",
[
(
"static_files/OCPCluster1.yml",
"app",
("AppInClusterA", "AppInClusterA2", "AppInClusterA3"),
),
("static_files/OCPCluster1.yml", "tier", ("pod_1", "pod2", "pod_3")),
("static_files/OCPCluster1.yml", "node_name", ("node1", "node2")),
("static_files/OCPCluster1.yml", "ns_name", ("ns1", "ns2", "ns3")),
],
ids=["node1", "node1", "node1", "node1"],
)
def test_get_cluster_labels(input_file, label, expected_label_values):
read_yaml = read_yaml_file(input_file)
parsed_file = parse_yaml_file(read_yaml)
cluster = dict_to_cluster(parsed_file["data"][0]["OCPCluster"])
label_values = None
assert label_values == expected_label_values, "Unmatched label_values"