aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLukasz Rajewski <lukasz.rajewski@t-mobile.pl>2023-06-22 16:10:52 +0000
committerLukasz Rajewski <lukasz.rajewski@t-mobile.pl>2023-06-22 16:11:44 +0000
commitfb6c5a2ae003b2b8769df6134346b7eb00edd1fe (patch)
treee5bfb3b12e42a17009d0b61fea3c3a6012439575 /src
parent4d8370108b05cbfba419b7b4cc0342a35a38fa14 (diff)
Status encoding exception fixed
- additional try catch introduced Issue-ID: TEST-400 Signed-off-by: Lukasz Rajewski <lukasz.rajewski@t-mobile.pl> Change-Id: Ifc8d2015b7f5530476c32cba27d30f8ff11b9933
Diffstat (limited to 'src')
-rw-r--r--src/onaptests/configuration/status_settings.py4
-rw-r--r--src/onaptests/steps/cloud/check_status.py44
2 files changed, 27 insertions, 21 deletions
diff --git a/src/onaptests/configuration/status_settings.py b/src/onaptests/configuration/status_settings.py
index 686bb3c..0ad0f30 100644
--- a/src/onaptests/configuration/status_settings.py
+++ b/src/onaptests/configuration/status_settings.py
@@ -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
diff --git a/src/onaptests/steps/cloud/check_status.py b/src/onaptests/steps/cloud/check_status.py
index 8b7ac46..40f7c72 100644
--- a/src/onaptests/steps/cloud/check_status.py
+++ b/src/onaptests/steps/cloud/check_status.py
@@ -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),