George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | r""" |
| 4 | BMC redfish utility functions. |
| 5 | """ |
| 6 | |
| 7 | import json |
George Keishing | 3a6f073 | 2020-07-13 14:21:23 -0500 | [diff] [blame] | 8 | import re |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 9 | from robot.libraries.BuiltIn import BuiltIn |
Michael Walsh | c86a2f7 | 2019-03-19 13:24:37 -0500 | [diff] [blame] | 10 | import gen_print as gp |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 11 | |
| 12 | |
| 13 | class bmc_redfish_utils(object): |
| 14 | |
George Keishing | eb1fe35 | 2020-06-19 03:02:22 -0500 | [diff] [blame] | 15 | ROBOT_LIBRARY_SCOPE = 'TEST SUITE' |
| 16 | |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 17 | def __init__(self): |
| 18 | r""" |
| 19 | Initialize the bmc_redfish_utils object. |
| 20 | """ |
| 21 | # Obtain a reference to the global redfish object. |
George Keishing | eb1fe35 | 2020-06-19 03:02:22 -0500 | [diff] [blame] | 22 | self.__inited__ = False |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 23 | self._redfish_ = BuiltIn().get_library_instance('redfish') |
| 24 | |
George Keishing | eb1fe35 | 2020-06-19 03:02:22 -0500 | [diff] [blame] | 25 | # There is a possibility that a given driver support both redfish and |
| 26 | # legacy REST. |
| 27 | self._redfish_.login() |
| 28 | self._rest_response_ = \ |
| 29 | self._redfish_.get("/xyz/openbmc_project/", valid_status_codes=[200, 404]) |
| 30 | |
| 31 | # If REST URL /xyz/openbmc_project/ is supported. |
| 32 | if self._rest_response_.status == 200: |
| 33 | self.__inited__ = True |
| 34 | |
| 35 | BuiltIn().set_global_variable("${REDFISH_REST_SUPPORTED}", self.__inited__) |
| 36 | |
George Keishing | 374e684 | 2019-02-20 08:57:18 -0600 | [diff] [blame] | 37 | def get_redfish_session_info(self): |
| 38 | r""" |
| 39 | Returns redfish sessions info dictionary. |
| 40 | |
| 41 | { |
| 42 | 'key': 'yLXotJnrh5nDhXj5lLiH' , |
| 43 | 'location': '/redfish/v1/SessionService/Sessions/nblYY4wlz0' |
| 44 | } |
| 45 | """ |
| 46 | session_dict = { |
George Keishing | 97c9394 | 2019-03-04 12:45:07 -0600 | [diff] [blame] | 47 | "key": self._redfish_.get_session_key(), |
| 48 | "location": self._redfish_.get_session_location() |
George Keishing | 374e684 | 2019-02-20 08:57:18 -0600 | [diff] [blame] | 49 | } |
| 50 | return session_dict |
| 51 | |
Sandhya Somashekar | 37122b6 | 2019-06-18 06:02:02 -0500 | [diff] [blame] | 52 | def get_attribute(self, resource_path, attribute, verify=None): |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 53 | r""" |
| 54 | Get resource attribute. |
| 55 | |
| 56 | Description of argument(s): |
Michael Walsh | c86a2f7 | 2019-03-19 13:24:37 -0500 | [diff] [blame] | 57 | resource_path URI resource absolute path (e.g. |
| 58 | "/redfish/v1/Systems/1"). |
| 59 | attribute Name of the attribute (e.g. 'PowerState'). |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 60 | """ |
| 61 | |
| 62 | resp = self._redfish_.get(resource_path) |
Sandhya Somashekar | 37122b6 | 2019-06-18 06:02:02 -0500 | [diff] [blame] | 63 | |
| 64 | if verify: |
| 65 | if resp.dict[attribute] == verify: |
| 66 | return resp.dict[attribute] |
| 67 | else: |
| 68 | raise ValueError("Attribute value is not equal") |
| 69 | elif attribute in resp.dict: |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 70 | return resp.dict[attribute] |
| 71 | |
| 72 | return None |
| 73 | |
George Keishing | c3c05c2 | 2019-02-19 01:04:54 -0600 | [diff] [blame] | 74 | def get_properties(self, resource_path): |
| 75 | r""" |
| 76 | Returns dictionary of attributes for the resource. |
| 77 | |
| 78 | Description of argument(s): |
Michael Walsh | c86a2f7 | 2019-03-19 13:24:37 -0500 | [diff] [blame] | 79 | resource_path URI resource absolute path (e.g. |
Sandhya Somashekar | 37122b6 | 2019-06-18 06:02:02 -0500 | [diff] [blame] | 80 | /redfish/v1/Systems/1"). |
George Keishing | c3c05c2 | 2019-02-19 01:04:54 -0600 | [diff] [blame] | 81 | """ |
| 82 | |
| 83 | resp = self._redfish_.get(resource_path) |
| 84 | return resp.dict |
| 85 | |
George Keishing | 789c3b4 | 2020-07-14 08:44:47 -0500 | [diff] [blame^] | 86 | def get_members_uri(self, resource_path, attribute): |
| 87 | r""" |
| 88 | Returns the list of valid path which has a given attribute. |
| 89 | |
| 90 | Description of argument(s): |
| 91 | resource_path URI resource base path (e.g. |
| 92 | '/redfish/v1/Systems/', |
| 93 | '/redfish/v1/Chassis/'). |
| 94 | attribute Name of the attribute (e.g. 'PowerSupplies'). |
| 95 | """ |
| 96 | |
| 97 | # Get the member id list. |
| 98 | # e.g. ['/redfish/v1/Chassis/foo', '/redfish/v1/Chassis/bar'] |
| 99 | resource_path_list = self.get_member_list(resource_path) |
| 100 | BuiltIn().log_to_console(resource_path_list) |
| 101 | |
| 102 | valid_path_list = [] |
| 103 | |
| 104 | for path_idx in resource_path_list: |
| 105 | # Get all the child object path under the member id e.g. |
| 106 | # ['/redfish/v1/Chassis/foo/Power','/redfish/v1/Chassis/bar/Power'] |
| 107 | child_path_list = self.list_request(path_idx) |
| 108 | BuiltIn().log_to_console(child_path_list) |
| 109 | |
| 110 | # Iterate and check if path object has the attribute. |
| 111 | for child_path_idx in child_path_list: |
| 112 | if self.get_attribute(child_path_idx, attribute): |
| 113 | valid_path_list.append(child_path_idx) |
| 114 | |
| 115 | return valid_path_list |
| 116 | |
George Keishing | 3a6f073 | 2020-07-13 14:21:23 -0500 | [diff] [blame] | 117 | def get_endpoint_path_list(self, resource_path, end_point_prefix): |
| 118 | r""" |
| 119 | Returns list with entries ending in "/endpoint". |
| 120 | |
| 121 | Description of argument(s): |
| 122 | resource_path URI resource base path (e.g. "/redfish/v1/Chassis/"). |
| 123 | end_point_prefix Name of the enpoint (e.g. 'Power'). |
| 124 | |
| 125 | Find all list entries ending in "/endpoint" combination such as |
| 126 | /redfish/v1/Chassis/<foo>/Power |
| 127 | /redfish/v1/Chassis/<bar>/Power |
| 128 | """ |
| 129 | |
| 130 | end_point_list = self.list_request(resource_path) |
| 131 | |
| 132 | # Regex to match entries ending in "/prefix" with optional underscore. |
| 133 | regex = ".*/" + end_point_prefix + "[_]?[0-9]*?" |
| 134 | return [x for x in end_point_list if re.match(regex, x, re.IGNORECASE)] |
| 135 | |
George Keishing | 7ec4593 | 2019-02-27 14:02:16 -0600 | [diff] [blame] | 136 | def get_target_actions(self, resource_path, target_attribute): |
| 137 | r""" |
| 138 | Returns resource target entry of the searched target attribute. |
| 139 | |
| 140 | Description of argument(s): |
| 141 | resource_path URI resource absolute path |
George Keishing | f8acde9 | 2019-04-19 19:46:48 +0000 | [diff] [blame] | 142 | (e.g. "/redfish/v1/Systems/system"). |
George Keishing | 7ec4593 | 2019-02-27 14:02:16 -0600 | [diff] [blame] | 143 | target_attribute Name of the attribute (e.g. 'ComputerSystem.Reset'). |
| 144 | |
| 145 | Example: |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 146 | "Actions": { |
| 147 | "#ComputerSystem.Reset": { |
| 148 | "ResetType@Redfish.AllowableValues": [ |
George Keishing | 7ec4593 | 2019-02-27 14:02:16 -0600 | [diff] [blame] | 149 | "On", |
| 150 | "ForceOff", |
| 151 | "GracefulRestart", |
| 152 | "GracefulShutdown" |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 153 | ], |
| 154 | "target": "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset" |
| 155 | } |
| 156 | } |
George Keishing | 7ec4593 | 2019-02-27 14:02:16 -0600 | [diff] [blame] | 157 | """ |
| 158 | |
| 159 | global target_list |
| 160 | target_list = [] |
| 161 | |
| 162 | resp_dict = self.get_attribute(resource_path, "Actions") |
| 163 | if resp_dict is None: |
| 164 | return None |
| 165 | |
| 166 | # Recursively search the "target" key in the nested dictionary. |
| 167 | # Populate the target_list of target entries. |
| 168 | self.get_key_value_nested_dict(resp_dict, "target") |
George Keishing | 7ec4593 | 2019-02-27 14:02:16 -0600 | [diff] [blame] | 169 | # Return the matching target URL entry. |
| 170 | for target in target_list: |
| 171 | # target "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset" |
| 172 | if target_attribute in target: |
| 173 | return target |
| 174 | |
| 175 | return None |
| 176 | |
George Keishing | dabf38f | 2019-03-10 09:52:40 -0500 | [diff] [blame] | 177 | def get_member_list(self, resource_path): |
| 178 | r""" |
| 179 | Perform a GET list request and return available members entries. |
| 180 | |
| 181 | Description of argument(s): |
| 182 | resource_path URI resource absolute path |
George Keishing | f8acde9 | 2019-04-19 19:46:48 +0000 | [diff] [blame] | 183 | (e.g. "/redfish/v1/SessionService/Sessions"). |
George Keishing | dabf38f | 2019-03-10 09:52:40 -0500 | [diff] [blame] | 184 | |
| 185 | "Members": [ |
| 186 | { |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 187 | "@odata.id": "/redfish/v1/SessionService/Sessions/Z5HummWPZ7" |
George Keishing | dabf38f | 2019-03-10 09:52:40 -0500 | [diff] [blame] | 188 | } |
| 189 | { |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 190 | "@odata.id": "/redfish/v1/SessionService/Sessions/46CmQmEL7H" |
George Keishing | dabf38f | 2019-03-10 09:52:40 -0500 | [diff] [blame] | 191 | } |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 192 | ], |
George Keishing | dabf38f | 2019-03-10 09:52:40 -0500 | [diff] [blame] | 193 | """ |
| 194 | |
| 195 | member_list = [] |
| 196 | resp_list_dict = self.get_attribute(resource_path, "Members") |
| 197 | if resp_list_dict is None: |
| 198 | return member_list |
| 199 | |
| 200 | for member_id in range(0, len(resp_list_dict)): |
| 201 | member_list.append(resp_list_dict[member_id]["@odata.id"]) |
| 202 | |
| 203 | return member_list |
| 204 | |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 205 | def list_request(self, resource_path): |
| 206 | r""" |
| 207 | Perform a GET list request and return available resource paths. |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 208 | Description of argument(s): |
| 209 | resource_path URI resource absolute path |
George Keishing | f8acde9 | 2019-04-19 19:46:48 +0000 | [diff] [blame] | 210 | (e.g. "/redfish/v1/SessionService/Sessions"). |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 211 | """ |
Michael Walsh | c86a2f7 | 2019-03-19 13:24:37 -0500 | [diff] [blame] | 212 | gp.qprint_executing(style=gp.func_line_style_short) |
Michael Walsh | c86a2f7 | 2019-03-19 13:24:37 -0500 | [diff] [blame] | 213 | # Set quiet variable to keep subordinate get() calls quiet. |
| 214 | quiet = 1 |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 215 | self.__pending_enumeration = set() |
Michael Walsh | c86a2f7 | 2019-03-19 13:24:37 -0500 | [diff] [blame] | 216 | self._rest_response_ = \ |
George Keishing | f8acde9 | 2019-04-19 19:46:48 +0000 | [diff] [blame] | 217 | self._redfish_.get(resource_path, |
| 218 | valid_status_codes=[200, 404, 500]) |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 219 | |
| 220 | # Return empty list. |
| 221 | if self._rest_response_.status != 200: |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 222 | return self.__pending_enumeration |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 223 | self.walk_nested_dict(self._rest_response_.dict) |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 224 | if not self.__pending_enumeration: |
| 225 | return resource_path |
| 226 | for resource in self.__pending_enumeration.copy(): |
Michael Walsh | c86a2f7 | 2019-03-19 13:24:37 -0500 | [diff] [blame] | 227 | self._rest_response_ = \ |
George Keishing | f8acde9 | 2019-04-19 19:46:48 +0000 | [diff] [blame] | 228 | self._redfish_.get(resource, |
| 229 | valid_status_codes=[200, 404, 500]) |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 230 | |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 231 | if self._rest_response_.status != 200: |
| 232 | continue |
| 233 | self.walk_nested_dict(self._rest_response_.dict) |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 234 | return list(sorted(self.__pending_enumeration)) |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 235 | |
Anusha Dathatri | 3e7930d | 2019-11-06 03:55:35 -0600 | [diff] [blame] | 236 | def enumerate_request(self, resource_path, return_json=1, |
| 237 | include_dead_resources=False): |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 238 | r""" |
| 239 | Perform a GET enumerate request and return available resource paths. |
| 240 | |
| 241 | Description of argument(s): |
Michael Walsh | 37e028f | 2019-05-22 16:16:32 -0500 | [diff] [blame] | 242 | resource_path URI resource absolute path (e.g. |
| 243 | "/redfish/v1/SessionService/Sessions"). |
| 244 | return_json Indicates whether the result should be |
| 245 | returned as a json string or as a |
| 246 | dictionary. |
Anusha Dathatri | 3e7930d | 2019-11-06 03:55:35 -0600 | [diff] [blame] | 247 | include_dead_resources Check and return a list of dead/broken URI |
| 248 | resources. |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 249 | """ |
| 250 | |
Michael Walsh | c86a2f7 | 2019-03-19 13:24:37 -0500 | [diff] [blame] | 251 | gp.qprint_executing(style=gp.func_line_style_short) |
| 252 | |
Michael Walsh | 37e028f | 2019-05-22 16:16:32 -0500 | [diff] [blame] | 253 | return_json = int(return_json) |
| 254 | |
Michael Walsh | c86a2f7 | 2019-03-19 13:24:37 -0500 | [diff] [blame] | 255 | # Set quiet variable to keep subordinate get() calls quiet. |
| 256 | quiet = 1 |
| 257 | |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 258 | # Variable to hold enumerated data. |
| 259 | self.__result = {} |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 260 | |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 261 | # Variable to hold the pending list of resources for which enumeration. |
| 262 | # is yet to be obtained. |
| 263 | self.__pending_enumeration = set() |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 264 | |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 265 | self.__pending_enumeration.add(resource_path) |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 266 | |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 267 | # Variable having resources for which enumeration is completed. |
| 268 | enumerated_resources = set() |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 269 | |
Anusha Dathatri | 3e7930d | 2019-11-06 03:55:35 -0600 | [diff] [blame] | 270 | if include_dead_resources: |
| 271 | dead_resources = {} |
| 272 | |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 273 | resources_to_be_enumerated = (resource_path,) |
| 274 | |
| 275 | while resources_to_be_enumerated: |
| 276 | for resource in resources_to_be_enumerated: |
Anusha Dathatri | 6d2d42f | 2019-11-20 06:17:51 -0600 | [diff] [blame] | 277 | # JsonSchemas, SessionService or URLs containing # are not |
| 278 | # required in enumeration. |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 279 | # Example: '/redfish/v1/JsonSchemas/' and sub resources. |
Anusha Dathatri | cdb77db | 2019-09-10 08:10:29 -0500 | [diff] [blame] | 280 | # '/redfish/v1/SessionService' |
Anusha Dathatri | 6d2d42f | 2019-11-20 06:17:51 -0600 | [diff] [blame] | 281 | # '/redfish/v1/Managers/bmc#/Oem' |
| 282 | if ('JsonSchemas' in resource) or ('SessionService' in resource)\ |
| 283 | or ('#' in resource): |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 284 | continue |
| 285 | |
| 286 | self._rest_response_ = \ |
| 287 | self._redfish_.get(resource, valid_status_codes=[200, 404, 500]) |
| 288 | # Enumeration is done for available resources ignoring the |
| 289 | # ones for which response is not obtained. |
| 290 | if self._rest_response_.status != 200: |
Anusha Dathatri | 3e7930d | 2019-11-06 03:55:35 -0600 | [diff] [blame] | 291 | if include_dead_resources: |
| 292 | try: |
| 293 | dead_resources[self._rest_response_.status].append( |
| 294 | resource) |
| 295 | except KeyError: |
| 296 | dead_resources[self._rest_response_.status] = \ |
| 297 | [resource] |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 298 | continue |
| 299 | |
| 300 | self.walk_nested_dict(self._rest_response_.dict, url=resource) |
| 301 | |
| 302 | enumerated_resources.update(set(resources_to_be_enumerated)) |
| 303 | resources_to_be_enumerated = \ |
| 304 | tuple(self.__pending_enumeration - enumerated_resources) |
| 305 | |
Michael Walsh | 37e028f | 2019-05-22 16:16:32 -0500 | [diff] [blame] | 306 | if return_json: |
Anusha Dathatri | 3e7930d | 2019-11-06 03:55:35 -0600 | [diff] [blame] | 307 | if include_dead_resources: |
| 308 | return json.dumps(self.__result, sort_keys=True, |
| 309 | indent=4, separators=(',', ': ')), dead_resources |
| 310 | else: |
| 311 | return json.dumps(self.__result, sort_keys=True, |
| 312 | indent=4, separators=(',', ': ')) |
Michael Walsh | 37e028f | 2019-05-22 16:16:32 -0500 | [diff] [blame] | 313 | else: |
Anusha Dathatri | 3e7930d | 2019-11-06 03:55:35 -0600 | [diff] [blame] | 314 | if include_dead_resources: |
| 315 | return self.__result, dead_resources |
| 316 | else: |
| 317 | return self.__result |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 318 | |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 319 | def walk_nested_dict(self, data, url=''): |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 320 | r""" |
| 321 | Parse through the nested dictionary and get the resource id paths. |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 322 | Description of argument(s): |
| 323 | data Nested dictionary data from response message. |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 324 | url Resource for which the response is obtained in data. |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 325 | """ |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 326 | url = url.rstrip('/') |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 327 | |
| 328 | for key, value in data.items(): |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 329 | |
| 330 | # Recursion if nested dictionary found. |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 331 | if isinstance(value, dict): |
| 332 | self.walk_nested_dict(value) |
| 333 | else: |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 334 | # Value contains a list of dictionaries having member data. |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 335 | if 'Members' == key: |
| 336 | if isinstance(value, list): |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 337 | for memberDict in value: |
| 338 | self.__pending_enumeration.add(memberDict['@odata.id']) |
George Keishing | f2613b7 | 2019-02-13 12:45:59 -0600 | [diff] [blame] | 339 | if '@odata.id' == key: |
Anusha Dathatri | 62dfb86 | 2019-04-23 06:52:16 -0500 | [diff] [blame] | 340 | value = value.rstrip('/') |
| 341 | # Data for the given url. |
| 342 | if value == url: |
| 343 | self.__result[url] = data |
| 344 | # Data still needs to be looked up, |
| 345 | else: |
| 346 | self.__pending_enumeration.add(value) |
George Keishing | 7ec4593 | 2019-02-27 14:02:16 -0600 | [diff] [blame] | 347 | |
| 348 | def get_key_value_nested_dict(self, data, key): |
| 349 | r""" |
| 350 | Parse through the nested dictionary and get the searched key value. |
| 351 | |
| 352 | Description of argument(s): |
| 353 | data Nested dictionary data from response message. |
| 354 | key Search dictionary key element. |
| 355 | """ |
| 356 | |
| 357 | for k, v in data.items(): |
| 358 | if isinstance(v, dict): |
| 359 | self.get_key_value_nested_dict(v, key) |
| 360 | |
| 361 | if k == key: |
| 362 | target_list.append(v) |