88
9931: Default storage class has no provisioner
101032: 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
121441: Not able to bind PersitantVolume to PersitantVolumeClaim
131542: ReadWriteOnce is not a supported access mode
4547PVC_NAME = "test-k-pvc"
4648PV_NAME = "test-k-pv"
4749POD_NAME = "test-k-pod"
50+ ALLOWED_CSI_PROV = ["cinder" , "rookCeph" , "longhorn" ]
4851
4952
5053def 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
156160def 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+
189213class 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