Status encoding exception fixed 99/135099/1
authorLukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Thu, 22 Jun 2023 16:10:52 +0000 (16:10 +0000)
committerLukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Thu, 22 Jun 2023 16:11:44 +0000 (16:11 +0000)
- additional try catch introduced

Issue-ID: TEST-400
Signed-off-by: Lukasz Rajewski <lukasz.rajewski@t-mobile.pl>
Change-Id: Ifc8d2015b7f5530476c32cba27d30f8ff11b9933

src/onaptests/configuration/status_settings.py
src/onaptests/steps/cloud/check_status.py

index 686bb3c..0ad0f30 100644 (file)
@@ -92,4 +92,6 @@ GENERIC_NAMES = {
     'rabbitmq': ['ansible/awx_rabbitmq', 'rabbitmq']
 }
 
-MAX_LOG_BYTES = 512000
\ No newline at end of file
+MAX_LOG_BYTES = 512000
+
+UNLIMITED_LOG_BYTES = 10**10 # 10 GB
index 8b7ac46..40f7c72 100644 (file)
@@ -389,6 +389,26 @@ class CheckK8sPodsStep(CheckK8sResourcesUsingPodsStep):
             with open(self.res_dir + "/onap_versions.json", "w") as write_file:
                 json.dump(pod_versions, write_file)
 
+    def _get_container_logs(self, pod, container, full=True, previous=False):
+        logs = ""
+        limit_bytes = settings.MAX_LOG_BYTES
+        if full:
+            limit_bytes = settings.UNLIMITED_LOG_BYTES
+        try:
+            logs = self.core.read_namespaced_pod_log(
+                pod.name,
+                NAMESPACE,
+                container=container.name,
+                limit_bytes=limit_bytes,
+                previous=previous
+            )
+        except UnicodeDecodeError:
+            logs = "{0} has an unicode decode error...".format(pod.name)
+            self.__logger.error(
+                "{0} has an unicode decode error in the logs...", pod.name,
+            )
+        return logs
+
     def _parse_container(self, pod, k8s_container, init=False):
         """Get the logs of a container."""
         logs = ""
@@ -413,30 +433,15 @@ class CheckK8sPodsStep(CheckK8sResourcesUsingPodsStep):
         if settings.STORE_ARTIFACTS:
             try:
                 log_files = {}
-                logs = ""
-                try:
-                    logs = self.core.read_namespaced_pod_log(
-                        pod.name,
-                        NAMESPACE,
-                        container=container.name,
-                        limit_bytes=settings.MAX_LOG_BYTES,
-                    )
-                except UnicodeDecodeError:
-                    logs= "{0} has an unicode decode error...".format(pod.name)
-                    self.__logger.error(
-                        "{0} has an unicode decode error in the logs...", pod.name,
-                    )
+                logs = self._get_container_logs(pod=pod, container=container, full=False)
                 with open(
                         "{}/pod-{}-{}.log".format(self.res_dir,
                                                 pod.name, container.name),
                         'w') as log_result:
                     log_result.write(logs)
                 if (not container.ready) and container.restart_count > 0:
-                    old_logs = self.core.read_namespaced_pod_log(
-                        pod.name,
-                        NAMESPACE,
-                        container=container.name,
-                        previous=True)
+                    old_logs = self._get_container_logs(pod=pod, container=container,
+                                                        previous=True)
                     with open(
                             "{}/pod-{}-{}.old.log".format(self.res_dir,
                                                         pod.name,
@@ -444,8 +449,7 @@ class CheckK8sPodsStep(CheckK8sResourcesUsingPodsStep):
                             'w') as log_result:
                         log_result.write(old_logs)
                 if (container.name in settings.FULL_LOGS_CONTAINERS):
-                    logs = self.core.read_namespaced_pod_log(
-                        pod.name, NAMESPACE, container=container.name)
+                    logs = self._get_container_logs(pod=pod, container=container)
                     with open(
                             "{}/pod-{}-{}.log".format(self.res_dir,
                                                     pod.name, container.name),