Small important fix for print_node_version
Change-Id: Ice1854f162d78c5f5e2ac91ef59a4cb753d3b90c
diff --git a/cvp_checks/fixtures/base.py b/cvp_checks/fixtures/base.py
index 3a440a8..8fbac37 100644
--- a/cvp_checks/fixtures/base.py
+++ b/cvp_checks/fixtures/base.py
@@ -1,4 +1,5 @@
import pytest
+import atexit
import cvp_checks.utils as utils
@@ -76,31 +77,33 @@
Prints nothing otherwise
:return None
"""
- filename_with_versions = "/etc/image_version"
- cat_image_version_file = "if [ -f '{name}' ]; then \
- cat {name}; \
- else \
- echo BUILD_TIMESTAMP='no {name}'; \
- echo BUILD_TIMESTAMP_RFC='no {name}'; \
- fi ".format(name=filename_with_versions)
+ try:
+ filename_with_versions = "/etc/image_version"
+ cat_image_version_file = "if [ -f '{name}' ]; then \
+ cat {name}; \
+ else \
+ echo BUILD_TIMESTAMP='no {name}'; \
+ echo BUILD_TIMESTAMP_RFC='no {name}'; \
+ fi ".format(name=filename_with_versions)
- list_version = local_salt_client.cmd(
- '*',
- 'cmd.run',
- 'echo "NODE_INFO=$(uname -sr)" && ' + cat_image_version_file,
- expr_form='compound')
- if list_version.__len__() == 0:
- yield
- parsed = {k: v.split('\n') for k, v in list_version.items()}
- columns = [name.split('=')[0] for name in parsed.values()[0]]
+ list_version = local_salt_client.cmd(
+ '*',
+ 'cmd.run',
+ 'echo "NODE_INFO=$(uname -sr)" && ' + cat_image_version_file,
+ expr_form='compound')
+ if list_version.__len__() == 0:
+ yield
+ parsed = {k: v.split('\n') for k, v in list_version.items()}
+ columns = [name.split('=')[0] for name in parsed.values()[0]]
- template = "{:<40} | {:<25} | {:<25} | {:<25}\n"
+ template = "{:<40} | {:<25} | {:<25} | {:<25}\n"
- report_text = template.format("NODE", *columns)
- for node, data in sorted(parsed.items()):
- report_text += template.format(node, *[item.split("=")[1] for item in data])
+ report_text = template.format("NODE", *columns)
+ for node, data in sorted(parsed.items()):
+ report_text += template.format(node, *[item.split("=")[1] for item in data])
- def write_report():
- print(report_text)
- atexit.register(write_report)
- yield
+ def write_report():
+ print(report_text)
+ atexit.register(write_report)
+ except Exception as e:
+ print("print_node_version:: some error occurred: {}".format(e))