Prevent parsing error due to format change for onap-helm 77/112477/1
authormrichomme <morgan.richomme@orange.com>
Thu, 10 Sep 2020 12:18:12 +0000 (14:18 +0200)
committermrichomme <morgan.richomme@orange.com>
Thu, 10 Sep 2020 12:18:12 +0000 (14:18 +0200)
Note the success criteria part shall be refactored
For the moment I keep as it is but it is too complex
As we plan to refactor onap-helm to include more detail
I do not do it here

Issue-ID: INT-1718

Signed-off-by: mrichomme <morgan.richomme@orange.com>
Change-Id: Ib93e0afca6b31571607bc0bd548b71a194f44c44

infra-healthcheck/infra_healthcheck/k8stest.py

index 1ea2aca..deab627 100644 (file)
@@ -50,8 +50,7 @@ class K8sTesting(testcase.TestCase):
         # create a log file
         result_folder = "/var/lib/xtesting/results/" + self.case_name + "/"
         file_name = result_folder + self.case_name + ".log"
-        if not os.path.exists(result_folder):
-            os.makedirs(result_folder)
+        os.makedirs(result_folder, exist_ok=True)
         log_file = open(file_name, "w")
         log_file.write(output)
         log_file.close()
@@ -74,14 +73,21 @@ class K8sTesting(testcase.TestCase):
                     # 2 possible Results
                     # * numeric nb pods, failed, duration
                     # * list of pods, charts,...
-                    if '[' in remark:
+                    # split and replace can be hazardous, depending
+                    # on result format change..
+                    try:
+                        if '[' in remark:
                         # it is a list
-                        str1 = remark.split(":", 1)[1].strip().replace(
-                            ']', '').replace('[', '')
-                        details[remark.split(":", 1)[0].strip()] = str1.split(",")
-                    else:
-                        details[remark.split(":", 1)[0].strip()] = int(
-                            remark.split(":", 1)[1].strip())
+                            str1 = remark.split(
+                                ":", 1)[1].strip().replace(
+                                    ']', '').replace('[', '')
+                            details[remark.split(
+                                ":", 1)[0].strip()] = str1.split(",")
+                        else:
+                            details[remark.split(":", 1)[0].strip()] = int(
+                                remark.split(":", 1)[1].strip())
+                    except:
+                        pass
 
             # if 1 pod/helm chart if Failed, the testcase is failed
             if int(details[self.criteria_string]) < 1: