Handle exceptions in vpd-tool function
Changes:
Add exception handler in vpd-tool function
Exception:
Created unit testcase and verified changes in BMC environment
Change-Id: Ib6e0d748f75bc726d98e343af600adb7f5a0be7e
Signed-off-by: Sridevi Ramesh <sridevra@in.ibm.com>
diff --git a/lib/vpd_utils.py b/lib/vpd_utils.py
index 754d255..fdcb191 100644
--- a/lib/vpd_utils.py
+++ b/lib/vpd_utils.py
@@ -10,6 +10,16 @@
import func_args as fa
+class VpdtoolException(Exception):
+ r"""
+ Base class for vpdtool related exceptions.
+ """
+
+ def __init__(self, message):
+ self.message = message
+ super().__init__(self.message)
+
+
def vpdtool(option_string, **bsu_options):
r"""
Run vpdtool on the BMC with the caller's option string and return the result.
@@ -50,9 +60,14 @@
)
# Only return output if its not a VPD write command.
- if "-w" not in option_string:
- out_buf = json.loads(out_buf)
- if "-r" in option_string:
- return out_buf
- else:
- return out_buf[0]
+ try:
+ if "-w" not in option_string:
+ out_buf = json.loads(out_buf)
+ if "-r" in option_string:
+ return out_buf
+ else:
+ return out_buf[0]
+ except Exception as exception:
+ raise VpdtoolException(
+ "Failed to get VPD data from BMC : " + str(exception)
+ ) from exception