Skip to content

Commit d853396

Browse files
committed
dividing 404
Signed-off-by: Katharina Trentau <[email protected]>
1 parent a335677 commit d853396

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ def create_pvc_pod(
9191
"""
9292
# 1. Create PersistantVolumeClaim
9393
logger.debug(f"create pvc: {pvc_name}")
94+
9495
creationflag = 2
96+
9597
pvc_meta = client.V1ObjectMeta(name=pvc_name)
9698
pvc_resources = client.V1ResourceRequirements(
9799
requests={"storage": "1Gi"},
@@ -108,9 +110,16 @@ def create_pvc_pod(
108110
api_response = k8s_api_instance.create_namespaced_persistent_volume_claim(
109111
namespace, body_pvc
110112
)
111-
if k8s_api_instance.read_namespaced_persistent_volume_claim(name=pvc_name, namespace=namespace):
112-
creationflag -=1
113+
try k8s_api_instance.read_namespaced_persistent_volume_claim(name=pvc_name, namespace=namespace):
113114
logger.debug(f"created pvc successfully {creationflag}")
115+
except ApiException as api_exception:
116+
logger.info(f"code {api_exception.status}")
117+
if api_exception.status == 404:
118+
logger.info(
119+
"pod not found, "
120+
"failed to build resources correctly"
121+
)
122+
return 43
114123

115124
# 2. Create a pod which makes use of the PersistantVolumeClaim
116125
logger.debug(f"create pod: {pod_name}")
@@ -138,9 +147,17 @@ def create_pvc_pod(
138147
api_response = k8s_api_instance.create_namespaced_pod(
139148
namespace, pod_body, _preload_content=False,
140149
)
141-
if k8s_api_instance.read_namespaced_pod(name=pod_name, namespace=namespace):
142-
creationflag-=1
143-
logger.debug(f"created pod successfully {creationflag}")
150+
try:
151+
k8s_api_instance.read_namespaced_pod(name=pod_name, namespace=namespace):
152+
logger.debug(f"created pod successfully")
153+
except ApiException as api_exception:
154+
logger.info(f"code {api_exception.status}")
155+
if api_exception.status == 404:
156+
logger.info(
157+
"pod not found, "
158+
"failed to build resources correctly"
159+
)
160+
return 44
144161
pod_info = json.loads(api_response.read().decode("utf-8"))
145162
pod_status = pod_info["status"]["phase"]
146163

0 commit comments

Comments
 (0)