Update IPMI test case

Changes:
    - Add code to dynamically load the PowerControl redfish URI.
    - Adjust debug log and logging request in library.

Resolves openbmc/openbmc-test-automation#2091

Change-Id: I79315d615d39fdd5dda02ccb9b66bf27c0e8f06f
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/ipmi/test_ipmi_sensor.robot b/ipmi/test_ipmi_sensor.robot
index 941d643..fef1c81 100644
--- a/ipmi/test_ipmi_sensor.robot
+++ b/ipmi/test_ipmi_sensor.robot
@@ -315,14 +315,35 @@
 
     ${ipmi_reading}=  Get IPMI Power Reading
 
-    ${power}=  Redfish.Get Properties  /redfish/v1/Chassis/chassis/Power
-    ${redfish_reading}=  Set Variable  ${power['PowerControl'][0]['PowerConsumedWatts']}
+    ${power_uri_list}=  redfish_utils.Get Members URI  /redfish/v1/Chassis/  PowerControl
+    Log List  ${power_uri_list}
 
-    ${ipmi_redfish_power_diff}=
-    ...  Evaluate  abs(${redfish_reading} - ${ipmi_reading['instantaneous_power_reading']})
+    # Power entries could be seen across different redfish path, remove the URI
+    # where the attribute is non-existent.
+    # Example:
+    #     ['/redfish/v1/Chassis/chassis/Power',
+    #      '/redfish/v1/Chassis/motherboard/Power']
+    FOR  ${idx}  IN  @{power_uri_list}
+        ${power}=  redfish_utils.Get Attribute  ${idx}  PowerControl
+        Log Dictionary  ${power[0]}
 
-    Should Be True  ${ipmi_redfish_power_diff} <= ${allowed_power_diff}
-    ...  msg=Power reading above allowed threshold ${allowed_power_diff}.
+        # Ensure the path does have the attribute else set to EMPTY as default to skip.
+        ${value}=  Get Variable Value  ${power[0]['PowerConsumedWatts']}  ${EMPTY}
+        Run Keyword If  "${value}" == "${EMPTY}"
+        ...  Remove Values From List  ${power_uri_list}  ${idx}
+
+        # Check the next available element in the list.
+        Continue For Loop If  "${value}" == "${EMPTY}"
+
+        ${ipmi_redfish_power_diff}=
+        ...  Evaluate  abs(${${power[0]['PowerConsumedWatts']}} - ${ipmi_reading['instantaneous_power_reading']})
+        Should Be True  ${ipmi_redfish_power_diff} <= ${allowed_power_diff}
+        ...  msg=Power reading above allowed threshold ${allowed_power_diff}.
+    END
+
+    # Double check, the validation has atleast one valid path.
+    Should Not Be Empty  ${power_uri_list}
+    ...  msg=Should contain atleast one element in the list.
 
 
 Verify Power Reading Via Raw Command
diff --git a/lib/bmc_redfish_utils.py b/lib/bmc_redfish_utils.py
index 6da4af3..4510b5b 100644
--- a/lib/bmc_redfish_utils.py
+++ b/lib/bmc_redfish_utils.py
@@ -94,10 +94,12 @@
         attribute                Name of the attribute (e.g. 'PowerSupplies').
         """
 
+        # Set quiet variable to keep subordinate get() calls quiet.
+        quiet = 1
+
         # Get the member id list.
         # e.g. ['/redfish/v1/Chassis/foo', '/redfish/v1/Chassis/bar']
         resource_path_list = self.get_member_list(resource_path)
-        BuiltIn().log_to_console(resource_path_list)
 
         valid_path_list = []
 
@@ -105,13 +107,13 @@
             # Get all the child object path under the member id e.g.
             # ['/redfish/v1/Chassis/foo/Power','/redfish/v1/Chassis/bar/Power']
             child_path_list = self.list_request(path_idx)
-            BuiltIn().log_to_console(child_path_list)
 
             # Iterate and check if path object has the attribute.
             for child_path_idx in child_path_list:
                 if self.get_attribute(child_path_idx, attribute):
                     valid_path_list.append(child_path_idx)
 
+        BuiltIn().log_to_console(valid_path_list)
         return valid_path_list
 
     def get_endpoint_path_list(self, resource_path, end_point_prefix):