Skip to content

Commit 1bd8a81

Browse files
committed
csi provider check
Signed-off-by: Katharina Trentau <[email protected]>
1 parent 3d3802c commit 1bd8a81

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

Tests/kaas/k8s-default-storage-class/k8s-default-storage-class-check.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
99
31: Default storage class has no provisioner
1010
32: None or more then one default Storage Class is defined
11+
33: CSI provider does not belong to the recommended providers
12+
(34: No CSI provider found)
1113
1214
41: Not able to bind PersitantVolume to PersitantVolumeClaim
1315
42: ReadWriteOnce is not a supported access mode
@@ -45,6 +47,7 @@
4547
PVC_NAME = "test-k-pvc"
4648
PV_NAME = "test-k-pv"
4749
POD_NAME = "test-k-pod"
50+
ALLOWED_CSI_PROV = ["cinder", "rookCeph", "longhorn"]
4851

4952

5053
def check_default_storageclass(k8s_client_storage):
@@ -151,6 +154,7 @@ def create_pvc_pod(k8s_api_instance, storage_class):
151154
"pod is not Running not able to setup test Environment",
152155
return_code=13,
153156
)
157+
return 0
154158

155159

156160
def check_default_persistentvolumeclaim_readwriteonce(k8s_api_instance):
@@ -185,7 +189,27 @@ def check_default_persistentvolumeclaim_readwriteonce(k8s_api_instance):
185189
return 0
186190

187191

188-
# with TestEnvironment(k8s_core_api, return_code, return_message) as env:
192+
def check_csi_provider(k8s_core_api):
193+
pods = k8s_core_api.list_namespaced_pod(namespace="kube-system")
194+
csi_list = []
195+
for pod in pods.items:
196+
if "csi" in pod.metadata.name:
197+
if pod.metadata.name in ALLOWED_CSI_PROV:
198+
csi_list.append(pod.metadata.name)
199+
logger.info(f"CSI-Provider: {pod.metadata.name}")
200+
else:
201+
raise SCSTestException(
202+
f"CSI-Provider: {pod.metadata.name} not recommended",
203+
return_code=33,
204+
)
205+
else:
206+
raise SCSTestException(
207+
f"CSI-Provider: No CSI Provider found.",
208+
return_code=34,
209+
)
210+
return 0
211+
212+
189213
class TestEnvironment:
190214
def __init__(self, kubeconfig):
191215
self.namespace = NAMESPACE
@@ -279,7 +303,7 @@ def __exit__(self, exc_type, exc_value, traceback):
279303
else:
280304
# No specific exception, handle normally
281305
logger.debug(f"Exiting the context with return_code: {self.return_code}")
282-
logger.debug(f"return_code:{self.return_code} {self.return_message}")
306+
logger.debug(f"{self.return_message}")
283307

284308
gen_sonobuoy_result_file(
285309
self.return_code, self.return_message, os.path.basename(__file__)
@@ -353,6 +377,7 @@ def main(argv):
353377
env.return_code = check_default_persistentvolumeclaim_readwriteonce(
354378
k8s_core_api
355379
)
380+
# this might be to much
356381
except SCSTestException as test_exception:
357382
logger.error(f"L{inspect.currentframe().f_lineno} {test_exception}")
358383
env.return_message = f"{test_exception}"
@@ -361,6 +386,8 @@ def main(argv):
361386
logger.info(f"{exception_message}")
362387
env.return_message = f"{exception_message}"
363388
env.return_code = 1
389+
env.return_code = check_csi_provider(env.k8s_core_api)
390+
logger.debug(f"CSI Provider check: {env.return_code}")
364391
return env.return_code
365392

366393

0 commit comments

Comments
 (0)