Add re-try for redfish GET request for targets
Changes:
- This retries is added to improve the success rate
for the GET request in case returns JSON errors
for the following URI during operation
/redfish/v1/Systems/ and /redfish/v1/Managers/
- Added other places in code to handle exceptions.
- Fix IPMI import paths in test suite
Tested:
- Ran from sandbox.
Change-Id: Ie37dbdd9c7572e0003a56e65a7b5f0a4c3b26a1a
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/lib/bmc_redfish_utils.py b/lib/bmc_redfish_utils.py
index e240d94..8299abd 100644
--- a/lib/bmc_redfish_utils.py
+++ b/lib/bmc_redfish_utils.py
@@ -6,6 +6,7 @@
import json
import re
+from json.decoder import JSONDecodeError
import gen_print as gp
from robot.libraries.BuiltIn import BuiltIn
@@ -66,8 +67,13 @@
"/redfish/v1/Systems/1").
attribute Name of the attribute (e.g. 'PowerState').
"""
-
- resp = self._redfish_.get(resource_path)
+ try:
+ resp = self._redfish_.get(resource_path)
+ except JSONDecodeError as e:
+ BuiltIn().log_to_console(
+ "get_attribute: JSONDecodeError, re-trying"
+ )
+ resp = self._redfish_.get(resource_path)
if verify:
if resp.dict[attribute] == verify:
@@ -308,9 +314,18 @@
):
continue
- self._rest_response_ = self._redfish_.get(
- resource, valid_status_codes=[200, 404, 405, 500]
- )
+ try:
+ self._rest_response_ = self._redfish_.get(
+ resource, valid_status_codes=[200, 404, 405, 500]
+ )
+ except JSONDecodeError as e:
+ BuiltIn().log_to_console(
+ "enumerate_request: JSONDecodeError, re-trying"
+ )
+ self._rest_response_ = self._redfish_.get(
+ resource, valid_status_codes=[200, 404, 405, 500]
+ )
+
# Enumeration is done for available resources ignoring the
# ones for which response is not obtained.
if self._rest_response_.status != 200: