generated from arcalot/arcaflow-plugin-template-python
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkubeburner_plugin.py
253 lines (225 loc) · 8.04 KB
/
kubeburner_plugin.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/usr/bin/env python3
import sys
import os
import typing
from arcaflow_plugin_sdk import plugin
import subprocess
import time
from kubeburner_schema import (
KubeBurnerInputParams,
WebBurnerInputParams,
SuccessOutput,
ErrorOutput,
kube_burner_input_schema,
node_density_params,
cluster_density_params,
node_density_cni_params,
node_density_heavy_params,
)
from helper_functions import (
get_prometheus_creds,
readkubeconfig,
calculate_normal_limit_count,
create_kubeconfig_secret,
)
@plugin.step(
id="kube-burner",
name="Kube-Burner Workload",
description="""Kube-burner Workloads: node-density, node-density-cni,
node-density-heavy, cluster-density, cluster-density-v2,
cluster-density-ms """,
outputs={"success": SuccessOutput, "error": ErrorOutput},
)
def RunKubeBurner(
params: KubeBurnerInputParams,
) -> typing.Tuple[str, typing.Union[SuccessOutput, ErrorOutput]]:
print("==>> Running Kube Burner {} Workload ...".format(params.workload))
readkubeconfig(params.kubeconfig)
os.environ["KUBECONFIG"] = "./kubeconfig"
serialized_params = kube_burner_input_schema.serialize(params)
if params.workload == "node-density":
param_list = node_density_params
elif params.workload == "node-density-cni":
param_list = node_density_cni_params
elif params.workload == "node-density-heavy":
param_list = node_density_heavy_params
elif "cluster-density" in params.workload:
param_list = cluster_density_params
else:
param_list = ["--help"]
flags = []
for param, value in serialized_params.items():
if param in param_list:
if "_" in param:
param = param.replace("_", "-")
flags.append(f"--{param}={value}")
try:
cmd = ["./kube-burner", "ocp", str(params.workload)] + flags
process_out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as error:
return "error", ErrorOutput(
error.returncode,
"{} failed with return code {}:\n{}".format(
error.cmd[0], error.returncode, error.output
),
)
output = process_out.decode("utf-8")
print("==>> Kube Burner {} Workload complete!".format(params.workload))
return "success", SuccessOutput(params.uuid, output)
@plugin.step(
id="run-web-burner",
name="Web-Burner Workload",
description="Plugin to run the Web-burner workload",
outputs={"success": SuccessOutput, "error": ErrorOutput},
)
def RunWebBurner(
params: WebBurnerInputParams,
) -> typing.Tuple[str, typing.Union[SuccessOutput, ErrorOutput]]:
print("==>> Running Web Burner {} Workload ...".format(params.workload_template))
readkubeconfig(params.kubeconfig)
os.environ["KUBECONFIG"] = "./kubeconfig"
create_kubeconfig_secret()
# exporting these vars as they are read by the kube-burner templates
os.environ["SCALE"] = str(params.scale_factor)
os.environ["BFD"] = params.bfd_enabled
os.environ["QPS"] = str(params.qps)
os.environ["BURST"] = str(params.burst)
os.environ["INDEXING"] = params.indexing
os.environ["LIMITCOUNT"] = str(calculate_normal_limit_count(params.number_of_nodes))
os.environ["ES_SERVER"] = str(params.es_server)
os.environ["ES_INDEX"] = str(params.es_index)
os.environ["SRIOV"] = str(params.sriov)
os.environ["BRIDGE"] = str(params.bridge)
prom_url, prom_token = get_prometheus_creds()
try:
print("Creating the SPK pods..")
cmd = [
"./kube-burner-wb",
"init",
"-c",
"workload/cfg_icni2_serving_resource_init.yml",
"-t",
str(prom_token),
"--uuid",
"1234",
]
process_out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as error:
return "error", ErrorOutput(
error.returncode,
"{} failed with return code {}:\n{}".format(
error.cmd[0], error.returncode, error.output
),
)
print("Pausing for a minute..")
time.sleep(60)
try:
print("Creating the ICNI2 workload..", params.uuid)
cmd = [
"./kube-burner-wb",
"init",
"-c",
"workload/" + params.workload_template,
"-t",
str(prom_token),
"--uuid",
str(params.uuid),
"--prometheus-url",
str(prom_url),
"-m",
"workload/metrics_full.yml",
]
process_out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as error:
return "error", ErrorOutput(
error.returncode,
"{} failed with return code {}:\n{}".format(
error.cmd[0], error.returncode, error.output
),
)
output = process_out.decode("utf-8")
print("==>> Web Burner {} Workload complete!".format(params.workload_template))
return "success", SuccessOutput(params.uuid, output)
@plugin.step(
id="delete-web-burner",
name="Web-Burner Workload",
description="Plugin to delete resources created by the web-burner workload",
outputs={"success": SuccessOutput, "error": ErrorOutput},
)
def DeleteWebBurner(
params: WebBurnerInputParams,
) -> typing.Tuple[str, typing.Union[SuccessOutput, ErrorOutput]]:
print("==>> Running Web Burner {} Workload ...".format(params.workload_template))
readkubeconfig(params.kubeconfig)
os.environ["KUBECONFIG"] = "./kubeconfig"
# exporting these vars as they are read by the kube-burner templates
os.environ["SCALE"] = str(params.scale_factor)
os.environ["BFD"] = params.bfd_enabled
os.environ["QPS"] = str(params.qps)
os.environ["BURST"] = str(params.burst)
os.environ["ES_SERVER"] = str(params.es_server)
os.environ["ES_INDEX"] = str(params.es_index)
os.environ["LIMITCOUNT"] = str(calculate_normal_limit_count(params.number_of_nodes))
os.environ["SRIOV"] = str(params.sriov)
os.environ["BRIDGE"] = str(params.bridge)
prom_url, prom_token = get_prometheus_creds()
try:
print("Deleting the ICNI2 workload..")
cmd = [
"./kube-burner-wb",
"init",
"-c",
"workload/" + params.workload_template,
"-t",
str(prom_token),
"--uuid",
str(params.uuid),
"--prometheus-url",
str(prom_url),
"-m",
"workload/metrics_full.yml",
]
process_out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as error:
return "error", ErrorOutput(
error.returncode,
"{} failed with return code {}:\n{}".format(
error.cmd[0], error.returncode, error.output
),
)
print("Pausing for a minute..")
time.sleep(60)
try:
print("Deleting the SPK pods..", params.uuid)
cmd = [
"./kube-burner-wb",
"init",
"-c",
"workload/cfg_delete_icni2_serving_resource.yml",
"-t",
str(prom_token),
"--uuid",
"1234",
]
process_out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as error:
return "error", ErrorOutput(
error.returncode,
"{} failed with return code {}:\n{}".format(
error.cmd[0], error.returncode, error.output
),
)
output = process_out.decode("utf-8")
print("==>> Web Burner {} Workload complete!".format(params.workload_template))
return "success", SuccessOutput(params.uuid, output)
if __name__ == "__main__":
sys.exit(
plugin.run(
plugin.build_schema(
# List your step functions here:
RunKubeBurner,
RunWebBurner,
DeleteWebBurner,
)
)
)