Modified enumerate_request method to print broken URI resources on demand

Signed-off-by: Anusha Dathatri <adathatr@in.ibm.com>
Change-Id: I2cb044d011696e6c6d548c70f55b97ebbde6c3a7
diff --git a/lib/bmc_redfish_utils.py b/lib/bmc_redfish_utils.py
index 872a998..f492312 100644
--- a/lib/bmc_redfish_utils.py
+++ b/lib/bmc_redfish_utils.py
@@ -167,7 +167,8 @@
             self.walk_nested_dict(self._rest_response_.dict)
         return list(sorted(self.__pending_enumeration))
 
-    def enumerate_request(self, resource_path, return_json=1):
+    def enumerate_request(self, resource_path, return_json=1,
+                          include_dead_resources=False):
         r"""
         Perform a GET enumerate request and return available resource paths.
 
@@ -177,6 +178,8 @@
         return_json                 Indicates whether the result should be
                                     returned as a json string or as a
                                     dictionary.
+        include_dead_resources      Check and return a list of dead/broken URI
+                                    resources.
         """
 
         gp.qprint_executing(style=gp.func_line_style_short)
@@ -198,6 +201,9 @@
         # Variable having resources for which enumeration is completed.
         enumerated_resources = set()
 
+        if include_dead_resources:
+            dead_resources = {}
+
         resources_to_be_enumerated = (resource_path,)
 
         while resources_to_be_enumerated:
@@ -213,6 +219,13 @@
                 # Enumeration is done for available resources ignoring the
                 # ones for which response is not obtained.
                 if self._rest_response_.status != 200:
+                    if include_dead_resources:
+                        try:
+                            dead_resources[self._rest_response_.status].append(
+                                resource)
+                        except KeyError:
+                            dead_resources[self._rest_response_.status] = \
+                                [resource]
                     continue
 
                 self.walk_nested_dict(self._rest_response_.dict, url=resource)
@@ -222,10 +235,17 @@
                 tuple(self.__pending_enumeration - enumerated_resources)
 
         if return_json:
-            return json.dumps(self.__result, sort_keys=True,
-                              indent=4, separators=(',', ': '))
+            if include_dead_resources:
+                return json.dumps(self.__result, sort_keys=True,
+                                  indent=4, separators=(',', ': ')), dead_resources
+            else:
+                return json.dumps(self.__result, sort_keys=True,
+                                  indent=4, separators=(',', ': '))
         else:
-            return self.__result
+            if include_dead_resources:
+                return self.__result, dead_resources
+            else:
+                return self.__result
 
     def walk_nested_dict(self, data, url=''):
         r"""