krkn-lib 5.0.2__py3-none-any.whl → 5.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- krkn_lib/aws_tests/__init__.py +1 -0
- krkn_lib/{tests → aws_tests}/test_krkn_telemetry_kubernetes.py +57 -51
- krkn_lib/k8s/krkn_kubernetes.py +219 -106
- krkn_lib/k8s/pods_monitor_pool.py +14 -3
- krkn_lib/k8s/templates/node_exec_pod.j2 +6 -1
- krkn_lib/models/elastic/models.py +37 -4
- krkn_lib/models/k8s/models.py +4 -0
- krkn_lib/models/telemetry/models.py +64 -0
- krkn_lib/prometheus/krkn_prometheus.py +1 -1
- krkn_lib/telemetry/k8s/krkn_telemetry_kubernetes.py +1 -2
- krkn_lib/tests/base_test.py +40 -0
- krkn_lib/tests/test_krkn_elastic_models.py +33 -1
- krkn_lib/tests/test_krkn_kubernetes_check.py +2 -3
- krkn_lib/tests/test_krkn_kubernetes_create.py +3 -5
- krkn_lib/tests/test_krkn_kubernetes_delete.py +2 -3
- krkn_lib/tests/test_krkn_kubernetes_exec.py +1 -1
- krkn_lib/tests/test_krkn_kubernetes_get.py +104 -5
- krkn_lib/tests/test_krkn_kubernetes_list.py +13 -0
- krkn_lib/tests/test_krkn_kubernetes_misc.py +2 -2
- krkn_lib/tests/test_krkn_kubernetes_models.py +1 -1
- krkn_lib/tests/test_krkn_kubernetes_monitor.py +168 -137
- krkn_lib/tests/test_krkn_kubernetes_pods_monitor_pool.py +7 -3
- krkn_lib/tests/test_krkn_prometheus.py +133 -128
- krkn_lib/tests/test_utils.py +21 -0
- krkn_lib/tests/test_version.py +1 -1
- krkn_lib/utils/functions.py +24 -0
- {krkn_lib-5.0.2.dist-info → krkn_lib-5.1.1.dist-info}/METADATA +1 -1
- krkn_lib-5.1.1.dist-info/RECORD +59 -0
- krkn_lib-5.0.2.dist-info/RECORD +0 -58
- /krkn_lib/{tests → aws_tests}/test_krkn_telemetry_openshift.py +0 -0
- {krkn_lib-5.0.2.dist-info → krkn_lib-5.1.1.dist-info}/LICENSE +0 -0
- {krkn_lib-5.0.2.dist-info → krkn_lib-5.1.1.dist-info}/WHEEL +0 -0
|
@@ -26,7 +26,7 @@ class PodsMonitorPool:
|
|
|
26
26
|
self.events: list[Event] = []
|
|
27
27
|
|
|
28
28
|
def select_and_monitor_by_label(
|
|
29
|
-
self, label_selector: str, max_timeout: int
|
|
29
|
+
self, label_selector: str, field_selector: str, max_timeout: int
|
|
30
30
|
):
|
|
31
31
|
"""
|
|
32
32
|
Pushes into the pool a monitoring thread for all the pods identified
|
|
@@ -47,18 +47,23 @@ class PodsMonitorPool:
|
|
|
47
47
|
event = Event()
|
|
48
48
|
self.events.append(event)
|
|
49
49
|
pods_and_namespaces = self.krkn_lib.select_pods_by_label(
|
|
50
|
-
label_selector=label_selector
|
|
50
|
+
label_selector=label_selector, field_selector=field_selector
|
|
51
51
|
)
|
|
52
52
|
pod_monitor_thread = self.krkn_lib.monitor_pods_by_label(
|
|
53
53
|
label_selector=label_selector,
|
|
54
54
|
pods_and_namespaces=pods_and_namespaces,
|
|
55
|
+
field_selector=field_selector,
|
|
55
56
|
max_timeout=max_timeout,
|
|
56
57
|
event=event,
|
|
57
58
|
)
|
|
58
59
|
self.pods_monitor_threads.append(pod_monitor_thread)
|
|
59
60
|
|
|
60
61
|
def select_and_monitor_by_name_pattern_and_namespace_pattern(
|
|
61
|
-
self,
|
|
62
|
+
self,
|
|
63
|
+
pod_name_pattern: str,
|
|
64
|
+
namespace_pattern: str,
|
|
65
|
+
field_selector: str,
|
|
66
|
+
max_timeout: int,
|
|
62
67
|
):
|
|
63
68
|
"""
|
|
64
69
|
Pushes into the pool a monitoring thread for all the pods identified
|
|
@@ -74,6 +79,7 @@ class PodsMonitorPool:
|
|
|
74
79
|
pattern used to filter the pods to be monitored
|
|
75
80
|
(must be the same used in
|
|
76
81
|
`select_pods_by_name_pattern_and_namespace_pattern`)
|
|
82
|
+
:param field_selector: Pod field selector
|
|
77
83
|
:param max_timeout: the expected time the pods should take to
|
|
78
84
|
recover. If the killed pods are replaced in this time frame,
|
|
79
85
|
but they didn't reach the Ready State, they will be marked as
|
|
@@ -90,6 +96,7 @@ class PodsMonitorPool:
|
|
|
90
96
|
self.krkn_lib.select_pods_by_name_pattern_and_namespace_pattern(
|
|
91
97
|
pod_name_pattern=pod_name_pattern,
|
|
92
98
|
namespace_pattern=namespace_pattern,
|
|
99
|
+
field_selector=field_selector,
|
|
93
100
|
)
|
|
94
101
|
)
|
|
95
102
|
|
|
@@ -98,6 +105,7 @@ class PodsMonitorPool:
|
|
|
98
105
|
pod_name_pattern=pod_name_pattern,
|
|
99
106
|
namespace_pattern=namespace_pattern,
|
|
100
107
|
pods_and_namespaces=pods_and_namespaces,
|
|
108
|
+
field_selector=field_selector,
|
|
101
109
|
max_timeout=max_timeout,
|
|
102
110
|
event=event,
|
|
103
111
|
)
|
|
@@ -109,6 +117,7 @@ class PodsMonitorPool:
|
|
|
109
117
|
self,
|
|
110
118
|
namespace_pattern: str,
|
|
111
119
|
label_selector: str,
|
|
120
|
+
field_selector: str = None,
|
|
112
121
|
max_timeout=30,
|
|
113
122
|
):
|
|
114
123
|
"""
|
|
@@ -138,6 +147,7 @@ class PodsMonitorPool:
|
|
|
138
147
|
self.krkn_lib.select_pods_by_namespace_pattern_and_label(
|
|
139
148
|
namespace_pattern=namespace_pattern,
|
|
140
149
|
label_selector=label_selector,
|
|
150
|
+
field_selector=field_selector,
|
|
141
151
|
)
|
|
142
152
|
)
|
|
143
153
|
|
|
@@ -146,6 +156,7 @@ class PodsMonitorPool:
|
|
|
146
156
|
namespace_pattern=namespace_pattern,
|
|
147
157
|
label_selector=label_selector,
|
|
148
158
|
pods_and_namespaces=pods_and_namespaces,
|
|
159
|
+
field_selector=field_selector,
|
|
149
160
|
max_timeout=max_timeout,
|
|
150
161
|
event=event,
|
|
151
162
|
)
|
|
@@ -19,7 +19,12 @@ spec:
|
|
|
19
19
|
- mountPath: /run/dbus/system_bus_socket
|
|
20
20
|
name: dbus
|
|
21
21
|
readOnly: true
|
|
22
|
+
- name: host
|
|
23
|
+
mountPath: /host
|
|
22
24
|
volumes:
|
|
23
25
|
- name: dbus
|
|
24
26
|
hostPath:
|
|
25
|
-
path: /run/dbus/system_bus_socket
|
|
27
|
+
path: /run/dbus/system_bus_socket
|
|
28
|
+
- name: host
|
|
29
|
+
hostPath:
|
|
30
|
+
path: /
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import datetime
|
|
2
2
|
|
|
3
3
|
from elasticsearch_dsl import (
|
|
4
|
-
Boolean,
|
|
5
4
|
Date,
|
|
6
5
|
Document,
|
|
7
6
|
Float,
|
|
@@ -10,6 +9,7 @@ from elasticsearch_dsl import (
|
|
|
10
9
|
Keyword,
|
|
11
10
|
Nested,
|
|
12
11
|
Text,
|
|
12
|
+
Boolean,
|
|
13
13
|
)
|
|
14
14
|
|
|
15
15
|
from krkn_lib.models.telemetry import ChaosRunTelemetry
|
|
@@ -94,7 +94,7 @@ class ElasticNodeInfo(InnerDoc):
|
|
|
94
94
|
count = Integer()
|
|
95
95
|
architecture = Text()
|
|
96
96
|
instance_type = Text()
|
|
97
|
-
|
|
97
|
+
nodes_type = Text()
|
|
98
98
|
kernel_version = Text()
|
|
99
99
|
kubelet_version = Text()
|
|
100
100
|
os_version = Text()
|
|
@@ -114,6 +114,15 @@ class ElasticHealthChecks(InnerDoc):
|
|
|
114
114
|
end_timestamp = Date()
|
|
115
115
|
duration = Float()
|
|
116
116
|
|
|
117
|
+
class ElasticVirtChecks(InnerDoc):
|
|
118
|
+
vm_name = Text()
|
|
119
|
+
ip_address = Text()
|
|
120
|
+
namespace = Text()
|
|
121
|
+
node_name = Text()
|
|
122
|
+
status = Boolean()
|
|
123
|
+
start_timestamp = Date()
|
|
124
|
+
end_timestamp = Date()
|
|
125
|
+
duration = Float()
|
|
117
126
|
|
|
118
127
|
class ElasticChaosRunTelemetry(Document):
|
|
119
128
|
scenarios = Nested(ElasticScenarioTelemetry, multi=True)
|
|
@@ -127,10 +136,11 @@ class ElasticChaosRunTelemetry(Document):
|
|
|
127
136
|
cloud_type = Text()
|
|
128
137
|
cluster_version = Text()
|
|
129
138
|
major_version = Text()
|
|
139
|
+
build_url = Text()
|
|
130
140
|
job_status = Boolean()
|
|
131
141
|
run_uuid = Text(fields={"keyword": Keyword()})
|
|
132
142
|
health_checks = Nested(ElasticHealthChecks, multi=True)
|
|
133
|
-
|
|
143
|
+
virt_checks = Nested(ElasticVirtChecks, multi=True)
|
|
134
144
|
class Index:
|
|
135
145
|
name = "chaos_run_telemetry"
|
|
136
146
|
|
|
@@ -188,6 +198,7 @@ class ElasticChaosRunTelemetry(Document):
|
|
|
188
198
|
self.node_summary_infos = [
|
|
189
199
|
ElasticNodeInfo(
|
|
190
200
|
count=info.count,
|
|
201
|
+
nodes_type=info.nodes_type,
|
|
191
202
|
architecture=info.architecture,
|
|
192
203
|
instance_type=info.instance_type,
|
|
193
204
|
kernel_version=info.kernel_version,
|
|
@@ -204,7 +215,7 @@ class ElasticChaosRunTelemetry(Document):
|
|
|
204
215
|
chaos_run_telemetry.kubernetes_objects_count
|
|
205
216
|
)
|
|
206
217
|
self.network_plugins = chaos_run_telemetry.network_plugins
|
|
207
|
-
|
|
218
|
+
|
|
208
219
|
if chaos_run_telemetry.health_checks:
|
|
209
220
|
self.health_checks = [
|
|
210
221
|
ElasticHealthChecks(
|
|
@@ -223,6 +234,27 @@ class ElasticChaosRunTelemetry(Document):
|
|
|
223
234
|
]
|
|
224
235
|
else:
|
|
225
236
|
self.health_checks = None
|
|
237
|
+
|
|
238
|
+
if chaos_run_telemetry.virt_checks:
|
|
239
|
+
self.virt_checks = [
|
|
240
|
+
ElasticVirtChecks(
|
|
241
|
+
vm_name=info.vm_name,
|
|
242
|
+
ip_address=info.ip_address,
|
|
243
|
+
namespace=info.namespace,
|
|
244
|
+
node_name=info.node_name,
|
|
245
|
+
status=info.status,
|
|
246
|
+
start_timestamp=datetime.datetime.fromisoformat(
|
|
247
|
+
str(info.start_timestamp)
|
|
248
|
+
),
|
|
249
|
+
end_timestamp=datetime.datetime.fromisoformat(
|
|
250
|
+
str(info.end_timestamp)
|
|
251
|
+
),
|
|
252
|
+
duration=info.duration,
|
|
253
|
+
)
|
|
254
|
+
for info in chaos_run_telemetry.virt_checks
|
|
255
|
+
]
|
|
256
|
+
else:
|
|
257
|
+
self.virt_checks = None
|
|
226
258
|
|
|
227
259
|
self.timestamp = chaos_run_telemetry.timestamp
|
|
228
260
|
self.total_node_count = chaos_run_telemetry.total_node_count
|
|
@@ -232,3 +264,4 @@ class ElasticChaosRunTelemetry(Document):
|
|
|
232
264
|
self.run_uuid = chaos_run_telemetry.run_uuid
|
|
233
265
|
self.job_status = chaos_run_telemetry.job_status
|
|
234
266
|
self.major_version = chaos_run_telemetry.major_version
|
|
267
|
+
self.build_url = chaos_run_telemetry.build_url
|
krkn_lib/models/k8s/models.py
CHANGED
|
@@ -421,6 +421,55 @@ class HealthCheck:
|
|
|
421
421
|
self.end_timestamp = json_dict["end_timestamp"]
|
|
422
422
|
self.duration = json_dict["duration"]
|
|
423
423
|
|
|
424
|
+
@dataclass(order=False)
|
|
425
|
+
class VirtCheck:
|
|
426
|
+
"""
|
|
427
|
+
Virt checks Response for VMI endpoints
|
|
428
|
+
"""
|
|
429
|
+
|
|
430
|
+
vm_name: str
|
|
431
|
+
"""
|
|
432
|
+
Vm name
|
|
433
|
+
"""
|
|
434
|
+
ip_address: str
|
|
435
|
+
"""
|
|
436
|
+
Vm ip address
|
|
437
|
+
"""
|
|
438
|
+
namespace: str
|
|
439
|
+
"""
|
|
440
|
+
Namespace
|
|
441
|
+
"""
|
|
442
|
+
node_name: str
|
|
443
|
+
"""
|
|
444
|
+
Node Name
|
|
445
|
+
"""
|
|
446
|
+
status: bool
|
|
447
|
+
"""
|
|
448
|
+
Status of VMI ssh connection
|
|
449
|
+
"""
|
|
450
|
+
start_timestamp: str
|
|
451
|
+
"""
|
|
452
|
+
start time stamp of virt check
|
|
453
|
+
"""
|
|
454
|
+
end_timestamp: str
|
|
455
|
+
"""
|
|
456
|
+
end time stamp of virt check
|
|
457
|
+
"""
|
|
458
|
+
duration: float
|
|
459
|
+
"""
|
|
460
|
+
Denotes the time between start time and end time
|
|
461
|
+
"""
|
|
462
|
+
|
|
463
|
+
def __init__(self, json_dict: dict = None):
|
|
464
|
+
if json_dict is not None:
|
|
465
|
+
self.node_name = json_dict["node_name"]
|
|
466
|
+
self.ip_address = json_dict["ip_address"]
|
|
467
|
+
self.namespace = json_dict["namespace"]
|
|
468
|
+
self.vm_name = json_dict["vm_name"]
|
|
469
|
+
self.status = json_dict.get("status",True)
|
|
470
|
+
self.start_timestamp = json_dict.get("start_timestamp","")
|
|
471
|
+
self.end_timestamp = json_dict.get("end_timestamp","")
|
|
472
|
+
self.duration = json_dict.get("duration","")
|
|
424
473
|
|
|
425
474
|
@dataclass(order=False)
|
|
426
475
|
class ChaosRunTelemetry:
|
|
@@ -485,10 +534,18 @@ class ChaosRunTelemetry:
|
|
|
485
534
|
"""
|
|
486
535
|
Health checks of application endpoint
|
|
487
536
|
"""
|
|
537
|
+
virt_checks: list[VirtCheck] = None
|
|
538
|
+
"""
|
|
539
|
+
Virt checks of VMIs
|
|
540
|
+
"""
|
|
488
541
|
job_status: bool = True
|
|
489
542
|
"""
|
|
490
543
|
Overall job status, will take all scenario's exit status
|
|
491
544
|
"""
|
|
545
|
+
build_url: str = "manual"
|
|
546
|
+
"""
|
|
547
|
+
Build url if run in CI
|
|
548
|
+
"""
|
|
492
549
|
|
|
493
550
|
def __init__(self, json_dict: any = None):
|
|
494
551
|
self.scenarios = list[ScenarioTelemetry]()
|
|
@@ -500,6 +557,7 @@ class ChaosRunTelemetry:
|
|
|
500
557
|
"%Y-%m-%dT%H:%M:%SZ"
|
|
501
558
|
)
|
|
502
559
|
self.health_checks = list[HealthCheck]()
|
|
560
|
+
self.virt_checks = list[VirtCheck]()
|
|
503
561
|
if json_dict is not None:
|
|
504
562
|
scenarios = json_dict.get("scenarios")
|
|
505
563
|
if scenarios is None or isinstance(scenarios, list) is False:
|
|
@@ -527,7 +585,13 @@ class ChaosRunTelemetry:
|
|
|
527
585
|
if json_dict.get("health_checks")
|
|
528
586
|
else None
|
|
529
587
|
)
|
|
588
|
+
self.virt_checks = (
|
|
589
|
+
[VirtCheck(k) for k in json_dict.get("virt_checks")]
|
|
590
|
+
if json_dict.get("virt_checks")
|
|
591
|
+
else None
|
|
592
|
+
)
|
|
530
593
|
self.job_status = json_dict.get("job_status")
|
|
594
|
+
self.build_url = json_dict.get("build_url")
|
|
531
595
|
|
|
532
596
|
def to_json(self) -> str:
|
|
533
597
|
return json.dumps(self, default=lambda o: o.__dict__, indent=4)
|
|
@@ -100,12 +100,11 @@ class KrknTelemetryKubernetes:
|
|
|
100
100
|
node_infos, taints = self.__kubecli.get_nodes_infos()
|
|
101
101
|
chaos_telemetry.node_summary_infos = node_infos
|
|
102
102
|
chaos_telemetry.cluster_version = self.__kubecli.get_version()
|
|
103
|
-
|
|
104
103
|
chaos_telemetry.major_version = chaos_telemetry.cluster_version[1:5]
|
|
105
104
|
chaos_telemetry.node_taints = taints
|
|
105
|
+
chaos_telemetry.build_url = utils.get_ci_job_url()
|
|
106
106
|
for info in node_infos:
|
|
107
107
|
chaos_telemetry.total_node_count += info.count
|
|
108
|
-
|
|
109
108
|
chaos_telemetry.job_status = True
|
|
110
109
|
for scenario in chaos_telemetry.scenarios:
|
|
111
110
|
if scenario.exit_status > 0:
|
krkn_lib/tests/base_test.py
CHANGED
|
@@ -491,6 +491,13 @@ class BaseTest(unittest.TestCase):
|
|
|
491
491
|
thread.daemon = True
|
|
492
492
|
thread.start()
|
|
493
493
|
|
|
494
|
+
def background_delete_ns(self, namespace: str):
|
|
495
|
+
thread = threading.Thread(
|
|
496
|
+
target=self.lib_k8s.delete_namespace, args=(namespace,)
|
|
497
|
+
)
|
|
498
|
+
thread.daemon = True
|
|
499
|
+
thread.start()
|
|
500
|
+
|
|
494
501
|
def get_ChaosRunTelemetry_json(self, run_uuid: str) -> dict:
|
|
495
502
|
example_data = {
|
|
496
503
|
"scenarios": [
|
|
@@ -542,6 +549,7 @@ class BaseTest(unittest.TestCase):
|
|
|
542
549
|
"kernel_version": "5.4.0-66-generic",
|
|
543
550
|
"kubelet_version": "v2.1.2",
|
|
544
551
|
"os_version": "Linux",
|
|
552
|
+
"nodes_type": "master"
|
|
545
553
|
}
|
|
546
554
|
],
|
|
547
555
|
"node_taints": [
|
|
@@ -564,6 +572,37 @@ class BaseTest(unittest.TestCase):
|
|
|
564
572
|
"duration": 259.113742,
|
|
565
573
|
}
|
|
566
574
|
],
|
|
575
|
+
"virt_checks": [
|
|
576
|
+
{
|
|
577
|
+
"node_name": "h03-r660",
|
|
578
|
+
"namespace": "benchmark-runner",
|
|
579
|
+
"ip_address": "0.0.0.0",
|
|
580
|
+
"vm_name": "windows-vm-50",
|
|
581
|
+
"status": True,
|
|
582
|
+
"start_timestamp": "2025-03-12T14:57:34.555878",
|
|
583
|
+
"end_timestamp": "2025-03-12T14:57:54.904352",
|
|
584
|
+
"duration": 20.348474
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
"node_name": "h27-r660",
|
|
588
|
+
"namespace": "benchmark-runner",
|
|
589
|
+
"vm_name": "windows-vm-51",
|
|
590
|
+
"ip_address": "0.0.0.1",
|
|
591
|
+
"status": True,
|
|
592
|
+
"start_timestamp": "2025-03-12T14:57:34.759105",
|
|
593
|
+
"end_timestamp": "2025-03-12T14:57:54.904352",
|
|
594
|
+
"duration": 20.145247
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
"node_name": "h10-r660",
|
|
598
|
+
"namespace": "benchmark-runner",
|
|
599
|
+
"vm_name": "windows-vm-52",
|
|
600
|
+
"ip_address": "0.0.0.2",
|
|
601
|
+
"status": False,
|
|
602
|
+
"start_timestamp": "2025-03-12T14:57:35.308957",
|
|
603
|
+
"end_timestamp": "2025-03-12T14:57:54.904352",
|
|
604
|
+
"duration": 19.595395
|
|
605
|
+
}],
|
|
567
606
|
"total_node_count": 3,
|
|
568
607
|
"cloud_infrastructure": "AWS",
|
|
569
608
|
"cloud_type": "EC2",
|
|
@@ -571,5 +610,6 @@ class BaseTest(unittest.TestCase):
|
|
|
571
610
|
"cluster_version": "4.18.0-0.nightly-202491014",
|
|
572
611
|
"major_verison": "4.18",
|
|
573
612
|
"job_status": True,
|
|
613
|
+
"build_url": "https://github.com/krkn-chaos/krkn-lib/actions/runs/16724993547", # NOQA
|
|
574
614
|
}
|
|
575
615
|
return example_data
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import datetime
|
|
2
1
|
import uuid
|
|
3
2
|
|
|
4
3
|
from krkn_lib.models.elastic.models import ElasticChaosRunTelemetry
|
|
5
4
|
from krkn_lib.models.telemetry import ChaosRunTelemetry
|
|
6
5
|
from krkn_lib.tests import BaseTest
|
|
6
|
+
import datetime
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class TestKrknElasticModels(BaseTest):
|
|
@@ -149,6 +149,9 @@ class TestKrknElasticModels(BaseTest):
|
|
|
149
149
|
self.assertEqual(
|
|
150
150
|
elastic_telemetry.node_summary_infos[0].instance_type, "m2i.xlarge"
|
|
151
151
|
)
|
|
152
|
+
self.assertEqual(
|
|
153
|
+
elastic_telemetry.node_summary_infos[0].nodes_type, "master"
|
|
154
|
+
)
|
|
152
155
|
self.assertEqual(
|
|
153
156
|
elastic_telemetry.node_summary_infos[0].kernel_version,
|
|
154
157
|
"5.4.0-66-generic",
|
|
@@ -211,10 +214,39 @@ class TestKrknElasticModels(BaseTest):
|
|
|
211
214
|
elastic_telemetry.health_checks[0].duration, 259.113742
|
|
212
215
|
)
|
|
213
216
|
|
|
217
|
+
# virt_checks
|
|
218
|
+
self.assertEqual(len(elastic_telemetry.virt_checks), 3)
|
|
219
|
+
self.assertEqual(
|
|
220
|
+
elastic_telemetry.virt_checks[0].vm_name, "windows-vm-50"
|
|
221
|
+
)
|
|
222
|
+
self.assertEqual(
|
|
223
|
+
elastic_telemetry.virt_checks[0].ip_address, "0.0.0.0"
|
|
224
|
+
)
|
|
225
|
+
self.assertEqual(
|
|
226
|
+
elastic_telemetry.virt_checks[0].namespace, "benchmark-runner"
|
|
227
|
+
)
|
|
228
|
+
self.assertEqual(
|
|
229
|
+
elastic_telemetry.virt_checks[0].node_name, "h03-r660"
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
self.assertEqual(elastic_telemetry.virt_checks[0].status, True)
|
|
233
|
+
self.assertEqual(
|
|
234
|
+
elastic_telemetry.virt_checks[0].start_timestamp,
|
|
235
|
+
datetime.datetime.fromisoformat("2025-03-12T14:57:34.555878"),
|
|
236
|
+
)
|
|
237
|
+
self.assertEqual(
|
|
238
|
+
elastic_telemetry.virt_checks[0].end_timestamp,
|
|
239
|
+
datetime.datetime.fromisoformat("2025-03-12T14:57:54.904352"),
|
|
240
|
+
)
|
|
241
|
+
self.assertEqual(
|
|
242
|
+
elastic_telemetry.virt_checks[0].duration, 20.348474
|
|
243
|
+
)
|
|
244
|
+
|
|
214
245
|
self.assertEqual(elastic_telemetry.total_node_count, 3)
|
|
215
246
|
self.assertEqual(elastic_telemetry.cloud_infrastructure, "AWS")
|
|
216
247
|
self.assertEqual(elastic_telemetry.cloud_type, "EC2")
|
|
217
248
|
self.assertEqual(elastic_telemetry.run_uuid, run_uuid)
|
|
249
|
+
self.assertEqual(elastic_telemetry.build_url, "https://github.com/krkn-chaos/krkn-lib/actions/runs/16724993547")
|
|
218
250
|
|
|
219
251
|
def test_ElasticChaosRunTelemetry(self):
|
|
220
252
|
run_uuid = str(uuid.uuid4())
|
|
@@ -2,10 +2,9 @@ import logging
|
|
|
2
2
|
import time
|
|
3
3
|
import unittest
|
|
4
4
|
|
|
5
|
-
from kubernetes.client import ApiException
|
|
6
|
-
|
|
7
|
-
from krkn_lib.k8s import ApiRequestException
|
|
8
5
|
from krkn_lib.tests import BaseTest
|
|
6
|
+
from krkn_lib.k8s import ApiRequestException
|
|
7
|
+
from kubernetes.client import ApiException
|
|
9
8
|
|
|
10
9
|
|
|
11
10
|
class KrknKubernetesTestsCheck(BaseTest):
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import logging
|
|
2
|
-
import tempfile
|
|
3
2
|
import unittest
|
|
4
|
-
|
|
5
3
|
import yaml
|
|
6
|
-
|
|
7
|
-
from kubernetes.client import ApiException
|
|
8
|
-
|
|
4
|
+
import tempfile
|
|
9
5
|
from krkn_lib.tests import BaseTest
|
|
6
|
+
from kubernetes.client import ApiException
|
|
7
|
+
from jinja2 import Environment, FileSystemLoader
|
|
10
8
|
|
|
11
9
|
|
|
12
10
|
class KrknKubernetesTestsCreate(BaseTest):
|
|
@@ -2,10 +2,9 @@ import logging
|
|
|
2
2
|
import time
|
|
3
3
|
import unittest
|
|
4
4
|
|
|
5
|
-
from kubernetes.client import ApiException
|
|
6
|
-
|
|
7
|
-
from krkn_lib.k8s import ApiRequestException
|
|
8
5
|
from krkn_lib.tests import BaseTest
|
|
6
|
+
from krkn_lib.k8s import ApiRequestException
|
|
7
|
+
from kubernetes.client import ApiException
|
|
9
8
|
|
|
10
9
|
|
|
11
10
|
class KrknKubernetesTestsDelete(BaseTest):
|
|
@@ -124,7 +124,7 @@ class KrknKubernetesTestsExec(BaseTest):
|
|
|
124
124
|
self.fail(f"exception on node command execution: {e}")
|
|
125
125
|
|
|
126
126
|
def test_download_folder_from_pod_as_archive(self):
|
|
127
|
-
workdir_basepath = os.getenv("TEST_WORKDIR")
|
|
127
|
+
workdir_basepath = os.getenv("TEST_WORKDIR", "/tmp")
|
|
128
128
|
workdir = self.get_random_string(10)
|
|
129
129
|
test_workdir = os.path.join(workdir_basepath, workdir)
|
|
130
130
|
os.mkdir(test_workdir)
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import logging
|
|
2
|
-
import os
|
|
3
2
|
import random
|
|
4
3
|
import re
|
|
5
4
|
import time
|
|
5
|
+
import os
|
|
6
6
|
import unittest
|
|
7
7
|
|
|
8
|
-
from kubernetes import config
|
|
9
|
-
from kubernetes.client import ApiException
|
|
10
|
-
|
|
11
|
-
from krkn_lib.k8s import ApiRequestException, KrknKubernetes
|
|
12
8
|
from krkn_lib.models.telemetry import ChaosRunTelemetry
|
|
13
9
|
from krkn_lib.tests import BaseTest
|
|
10
|
+
from kubernetes import config
|
|
11
|
+
from krkn_lib.k8s import ApiRequestException, KrknKubernetes
|
|
12
|
+
from kubernetes.client import ApiException
|
|
14
13
|
|
|
15
14
|
|
|
16
15
|
class KrknKubernetesTestsGet(BaseTest):
|
|
@@ -55,8 +54,22 @@ class KrknKubernetesTestsGet(BaseTest):
|
|
|
55
54
|
# test with label_selector filter
|
|
56
55
|
results = self.lib_k8s.get_all_pods("random=%s" % random_label)
|
|
57
56
|
self.assertTrue(len(results) == 1)
|
|
57
|
+
self.assertEqual(results[0][1], namespace)
|
|
58
58
|
self.assertEqual(results[0][0], "kraken-deployment")
|
|
59
|
+
self.wait_pod("kraken-deployment", namespace)
|
|
60
|
+
results = self.lib_k8s.get_all_pods(
|
|
61
|
+
"random=%s" % random_label, field_selector="status.phase=Running"
|
|
62
|
+
)
|
|
63
|
+
print("resuls" + str(results))
|
|
64
|
+
self.assertTrue(len(results) == 1)
|
|
59
65
|
self.assertEqual(results[0][1], namespace)
|
|
66
|
+
self.assertEqual(results[0][0], "kraken-deployment")
|
|
67
|
+
|
|
68
|
+
results = self.lib_k8s.get_all_pods(
|
|
69
|
+
field_selector="status.phase=Running"
|
|
70
|
+
)
|
|
71
|
+
self.assertTrue(len(results) >= 1)
|
|
72
|
+
|
|
60
73
|
self.pod_delete_queue.put(["kraken-deployment", namespace])
|
|
61
74
|
|
|
62
75
|
def test_get_pod_log(self):
|
|
@@ -135,6 +148,9 @@ class KrknKubernetesTestsGet(BaseTest):
|
|
|
135
148
|
self.assertIsNotNone(info.podIP)
|
|
136
149
|
self.assertIsNotNone(info.nodeName)
|
|
137
150
|
self.assertIsNotNone(info.containers)
|
|
151
|
+
|
|
152
|
+
info = self.lib_k8s.get_pod_info("test1", namespace)
|
|
153
|
+
self.assertIsNone(info)
|
|
138
154
|
except Exception as e:
|
|
139
155
|
logging.error("test raised exception {0}".format(str(e)))
|
|
140
156
|
self.assertTrue(False)
|
|
@@ -247,6 +263,89 @@ class KrknKubernetesTestsGet(BaseTest):
|
|
|
247
263
|
with self.assertRaises(Exception):
|
|
248
264
|
ip_address = self.lib_k8s.get_node_ip("not_existing")
|
|
249
265
|
|
|
266
|
+
def test_get_pod_container_id(self):
|
|
267
|
+
namespace = "test-cid-" + self.get_random_string(10)
|
|
268
|
+
name = "test-name-" + self.get_random_string(10)
|
|
269
|
+
self.deploy_namespace(namespace, [])
|
|
270
|
+
self.deploy_fedtools(namespace=namespace, name=name)
|
|
271
|
+
self.wait_pod(name, namespace)
|
|
272
|
+
container_ids = self.lib_k8s.get_container_ids(
|
|
273
|
+
pod_name=name, namespace=namespace
|
|
274
|
+
)
|
|
275
|
+
self.assertTrue(len(container_ids) > 0)
|
|
276
|
+
container_ids = self.lib_k8s.get_container_ids(
|
|
277
|
+
pod_name="do_not_exists", namespace="do_not_exists"
|
|
278
|
+
)
|
|
279
|
+
self.assertTrue(len(container_ids) == 0)
|
|
280
|
+
|
|
281
|
+
def test_get_pod_pids(self):
|
|
282
|
+
namespace = "test-cid-" + self.get_random_string(10)
|
|
283
|
+
base_pod_name = "test-name-" + self.get_random_string(10)
|
|
284
|
+
target_pod_name = "test-name-" + self.get_random_string(10)
|
|
285
|
+
|
|
286
|
+
self.deploy_namespace(namespace, [])
|
|
287
|
+
self.deploy_fedtools(namespace=namespace, name=base_pod_name)
|
|
288
|
+
self.deploy_fedtools(namespace=namespace, name=target_pod_name)
|
|
289
|
+
|
|
290
|
+
self.wait_pod(base_pod_name, namespace)
|
|
291
|
+
self.wait_pod(target_pod_name, namespace)
|
|
292
|
+
|
|
293
|
+
container_id = self.lib_k8s.get_container_ids(
|
|
294
|
+
pod_name=target_pod_name, namespace=namespace
|
|
295
|
+
)
|
|
296
|
+
pids = self.lib_k8s.get_pod_pids(
|
|
297
|
+
base_pod_name,
|
|
298
|
+
namespace,
|
|
299
|
+
base_pod_name,
|
|
300
|
+
target_pod_name,
|
|
301
|
+
namespace,
|
|
302
|
+
container_id[0],
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
self.assertIsNotNone(pids)
|
|
306
|
+
self.assertTrue(isinstance(pids, list))
|
|
307
|
+
self.assertTrue(len(pids) > 0)
|
|
308
|
+
|
|
309
|
+
pids = self.lib_k8s.get_pod_pids(
|
|
310
|
+
base_pod_name,
|
|
311
|
+
namespace,
|
|
312
|
+
base_pod_name,
|
|
313
|
+
target_pod_name,
|
|
314
|
+
namespace,
|
|
315
|
+
"does_not_exist",
|
|
316
|
+
)
|
|
317
|
+
self.assertIsNone(pids)
|
|
318
|
+
|
|
319
|
+
with self.assertRaises(Exception):
|
|
320
|
+
_ = self.lib_k8s.get_pod_pids(
|
|
321
|
+
"does_not_exist",
|
|
322
|
+
namespace,
|
|
323
|
+
base_pod_name,
|
|
324
|
+
target_pod_name,
|
|
325
|
+
namespace,
|
|
326
|
+
container_id[0],
|
|
327
|
+
)
|
|
328
|
+
|
|
329
|
+
with self.assertRaises(Exception):
|
|
330
|
+
_ = self.lib_k8s.get_pod_pids(
|
|
331
|
+
base_pod_name,
|
|
332
|
+
namespace,
|
|
333
|
+
base_pod_name,
|
|
334
|
+
"does_not_exist",
|
|
335
|
+
namespace,
|
|
336
|
+
container_id[0],
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
with self.assertRaises(Exception):
|
|
340
|
+
_ = self.lib_k8s.get_pod_pids(
|
|
341
|
+
base_pod_name,
|
|
342
|
+
namespace,
|
|
343
|
+
"does_not_exist",
|
|
344
|
+
target_pod_name,
|
|
345
|
+
namespace,
|
|
346
|
+
container_id[0],
|
|
347
|
+
)
|
|
348
|
+
|
|
250
349
|
|
|
251
350
|
if __name__ == "__main__":
|
|
252
351
|
unittest.main()
|
|
@@ -70,6 +70,19 @@ class KrknKubernetesTestsList(BaseTest):
|
|
|
70
70
|
pods = self.lib_k8s.list_pods(namespace=namespace)
|
|
71
71
|
self.assertTrue(len(pods) == 1)
|
|
72
72
|
self.assertIn("kraken-deployment", pods)
|
|
73
|
+
|
|
74
|
+
self.wait_pod(pods[0], namespace)
|
|
75
|
+
|
|
76
|
+
pods = self.lib_k8s.list_pods(
|
|
77
|
+
namespace=namespace, field_selector="status.phase=Running"
|
|
78
|
+
)
|
|
79
|
+
self.assertTrue(len(pods) == 1)
|
|
80
|
+
self.assertIn("kraken-deployment", pods)
|
|
81
|
+
|
|
82
|
+
pods = self.lib_k8s.list_pods(
|
|
83
|
+
namespace=namespace, field_selector="status.phase=Terminating"
|
|
84
|
+
)
|
|
85
|
+
self.assertTrue(len(pods) == 0)
|
|
73
86
|
self.pod_delete_queue.put(["kraken-deployment", namespace])
|
|
74
87
|
|
|
75
88
|
def test_list_ready_nodes(self):
|
|
@@ -6,11 +6,11 @@ import time
|
|
|
6
6
|
import unittest
|
|
7
7
|
|
|
8
8
|
import yaml
|
|
9
|
-
from kubernetes.client import ApiException
|
|
10
|
-
from tzlocal import get_localzone
|
|
11
9
|
|
|
12
10
|
from krkn_lib.models.krkn import HogConfig, HogType
|
|
13
11
|
from krkn_lib.tests import BaseTest
|
|
12
|
+
from tzlocal import get_localzone
|
|
13
|
+
from kubernetes.client import ApiException
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class KrknKubernetesTestsMisc(BaseTest):
|