forked from OSS-MLOPS-PLATFORM/oss-mlops-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cluster_ready.py
More file actions
53 lines (37 loc) · 1.5 KB
/
Copy pathtest_cluster_ready.py
File metadata and controls
53 lines (37 loc) · 1.5 KB
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
import subprocess
import logging
import pytest
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
CHECK_NAMESPACES = [
# 'ingress-nginx',
'mlflow',
'kube-node-lease',
'kube-public',
'kube-system',
'kubeflow',
'local-path-storage'
]
def all_pods_ready(namespace: str):
output = subprocess.check_output(["kubectl", "get", "pods", "-n", namespace])
logger.info("\n" + output.decode())
for line in output.decode().strip().split('\n')[1:]:
name, ready, status, restarts = line.split()[:4]
if status != 'Completed' and (ready[0] == '0' or status != 'Running'):
logger.error(f"ERROR: Resources not ready (namespace={namespace}).")
return False
logger.info(f"All resources are ready (namespace={namespace}).")
return True
def get_all_namespaces():
out = subprocess.check_output(["kubectl", "get", "namespaces"]).decode()
all_namespaces = [n.split()[0] for n in out.strip().split('\n')[1:]]
return all_namespaces
@pytest.mark.order(2)
@pytest.mark.parametrize(argnames="namespace", argvalues=CHECK_NAMESPACES)
def test_namespaces_exists(namespace):
all_namespaces = get_all_namespaces()
assert namespace in all_namespaces, f"Namespace {namespace} doesn't exists."
@pytest.mark.order(1)
@pytest.mark.parametrize(argnames="namespace", argvalues=get_all_namespaces())
def test_resources_ready(namespace: str):
assert all_pods_ready(namespace=namespace), "Some resources are not ready yet."