George Keishing | e7e9171 | 2021-09-03 11:28:44 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 -u |
George Keishing | d9b3e16 | 2022-08-18 23:28:35 -0500 | [diff] [blame] | 2 | |
| 3 | r""" |
| 4 | Generic utility functions. |
| 5 | """ |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 6 | import imp |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 7 | import random |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 8 | import string |
Michael Walsh | 8b270ec | 2017-01-31 12:07:08 -0600 | [diff] [blame] | 9 | import subprocess |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 10 | |
George Keishing | d9b3e16 | 2022-08-18 23:28:35 -0500 | [diff] [blame] | 11 | from robot.libraries.BuiltIn import BuiltIn |
Michael Walsh | 8b270ec | 2017-01-31 12:07:08 -0600 | [diff] [blame] | 12 | from robot.utils import DotDict |
| 13 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 14 | |
Rahul Maheshwari | 757d80c | 2016-10-17 01:09:55 -0500 | [diff] [blame] | 15 | def random_mac(): |
| 16 | r""" |
| 17 | Return random mac address in the following format. |
| 18 | Example: 00:01:6C:80:02:78 |
| 19 | """ |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 20 | return ":".join( |
| 21 | map( |
| 22 | lambda x: "%02x" % x, |
| 23 | (random.randint(0x00, 0xFF) for _ in range(6)), |
| 24 | ) |
| 25 | ) |
Gunnar Mills | 096cd56 | 2018-03-26 10:19:12 -0500 | [diff] [blame] | 26 | |
Rahul Maheshwari | 757d80c | 2016-10-17 01:09:55 -0500 | [diff] [blame] | 27 | |
| 28 | def random_ip(): |
| 29 | r""" |
| 30 | Return random ip address in the following format. |
| 31 | Example: 9.3.128.100 |
| 32 | """ |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 33 | return ".".join(map(str, (random.randint(0, 255) for _ in range(4)))) |
Gunnar Mills | 096cd56 | 2018-03-26 10:19:12 -0500 | [diff] [blame] | 34 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 35 | |
| 36 | def get_sensor(module_name, value): |
George Keishing | d9b3e16 | 2022-08-18 23:28:35 -0500 | [diff] [blame] | 37 | r""" |
| 38 | Return sensor matched ID name. |
| 39 | """ |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 40 | m = imp.load_source("module.name", module_name) |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 41 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 42 | for i in m.ID_LOOKUP["SENSOR"]: |
| 43 | if m.ID_LOOKUP["SENSOR"][i] == value: |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 44 | return i |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 45 | |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 46 | return 0xFF |
| 47 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 48 | |
Gunnar Mills | 096cd56 | 2018-03-26 10:19:12 -0500 | [diff] [blame] | 49 | def get_inventory_sensor(module_name, value): |
George Keishing | d9b3e16 | 2022-08-18 23:28:35 -0500 | [diff] [blame] | 50 | r""" |
| 51 | Return sensor matched ID name from inventory. |
| 52 | """ |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 53 | m = imp.load_source("module.name", module_name) |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 54 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 55 | value = string.replace(value, m.INVENTORY_ROOT, "<inventory_root>") |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 56 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 57 | for i in m.ID_LOOKUP["SENSOR"]: |
| 58 | if m.ID_LOOKUP["SENSOR"][i] == value: |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 59 | return i |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 60 | |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 61 | return 0xFF |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 62 | |
| 63 | |
| 64 | ################################################################ |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 65 | # This will return the URI's of the FRU type |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 66 | # |
| 67 | # i.e. get_inventory_list('../data/Palmetto.py') |
| 68 | # |
George Keishing | d9b3e16 | 2022-08-18 23:28:35 -0500 | [diff] [blame] | 69 | # [/org/openbmc/inventory/system/chassis/motherboard/cpu0/core0, |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 70 | # /org/openbmc/inventory/system/chassis/motherboard/dimm0] |
| 71 | ################################################################ |
| 72 | def get_inventory_list(module_name): |
George Keishing | d9b3e16 | 2022-08-18 23:28:35 -0500 | [diff] [blame] | 73 | r""" |
| 74 | Return all FRU URI(s) list available from inventory. |
| 75 | """ |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 76 | |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 77 | inventory_list = [] |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 78 | m = imp.load_source("module.name", module_name) |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 79 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 80 | for i in m.ID_LOOKUP["FRU"]: |
| 81 | s = m.ID_LOOKUP["FRU"][i] |
| 82 | s = s.replace("<inventory_root>", m.INVENTORY_ROOT) |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 83 | inventory_list.append(s) |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 84 | |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 85 | return inventory_list |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 86 | |
| 87 | |
| 88 | ################################################################ |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 89 | # This will return the URI's of the FRU type |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 90 | # |
George Keishing | be3cdfd | 2018-08-28 00:00:06 -0500 | [diff] [blame] | 91 | # i.e. get_inventory_fru_type_list('../data/Witherspoon.py', 'CPU') |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 92 | # |
George Keishing | d9b3e16 | 2022-08-18 23:28:35 -0500 | [diff] [blame] | 93 | # [/org/openbmc/inventory/system/chassis/motherboard/cpu0, |
| 94 | # /org/openbmc/inventory/system/chassis/motherboard/cpu1] |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 95 | ################################################################ |
Gunnar Mills | 096cd56 | 2018-03-26 10:19:12 -0500 | [diff] [blame] | 96 | def get_inventory_fru_type_list(module_name, fru): |
George Keishing | d9b3e16 | 2022-08-18 23:28:35 -0500 | [diff] [blame] | 97 | r""" |
| 98 | Return FRU URI(s) list of a given type from inventory. |
| 99 | """ |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 100 | inventory_list = [] |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 101 | m = imp.load_source("module.name", module_name) |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 102 | |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 103 | for i in m.FRU_INSTANCES.keys(): |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 104 | if m.FRU_INSTANCES[i]["fru_type"] == fru: |
| 105 | s = i.replace("<inventory_root>", m.INVENTORY_ROOT) |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 106 | inventory_list.append(s) |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 107 | |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 108 | return inventory_list |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 109 | |
| 110 | |
| 111 | ################################################################ |
| 112 | # This will return the URI's of the FRU type that contain VPD |
| 113 | # |
| 114 | # i.e. get_vpd_inventory_list('../data/Palmetto.py', 'DIMM') |
| 115 | # |
| 116 | # [/org/openbmc/inventory/system/chassis/motherboard/dimm0, |
| 117 | # /org/openbmc/inventory/system/chassis/motherboard/dimm1] |
| 118 | ################################################################ |
Gunnar Mills | 096cd56 | 2018-03-26 10:19:12 -0500 | [diff] [blame] | 119 | def get_vpd_inventory_list(module_name, fru): |
George Keishing | d9b3e16 | 2022-08-18 23:28:35 -0500 | [diff] [blame] | 120 | r""" |
| 121 | Return VPD URI(s) list of a FRU type from inventory. |
| 122 | """ |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 123 | inventory_list = [] |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 124 | m = imp.load_source("module.name", module_name) |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 125 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 126 | for i in m.ID_LOOKUP["FRU_STR"]: |
| 127 | x = m.ID_LOOKUP["FRU_STR"][i] |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 128 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 129 | if m.FRU_INSTANCES[x]["fru_type"] == fru: |
| 130 | s = x.replace("<inventory_root>", m.INVENTORY_ROOT) |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 131 | inventory_list.append(s) |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 132 | |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 133 | return inventory_list |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 134 | |
| 135 | |
| 136 | def call_keyword(keyword): |
George Keishing | d9b3e16 | 2022-08-18 23:28:35 -0500 | [diff] [blame] | 137 | r""" |
| 138 | Return result of the execute robot keyword. |
| 139 | """ |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 140 | return BuiltIn().run_keyword(keyword) |
| 141 | |
| 142 | |
| 143 | def main(): |
George Keishing | d9b3e16 | 2022-08-18 23:28:35 -0500 | [diff] [blame] | 144 | r""" |
| 145 | Python main func call. |
| 146 | """ |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 147 | print(get_vpd_inventory_list("../data/Palmetto.py", "DIMM")) |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 148 | |
| 149 | |
| 150 | if __name__ == "__main__": |
Gunnar Mills | 096cd56 | 2018-03-26 10:19:12 -0500 | [diff] [blame] | 151 | main() |
Michael Walsh | 8b270ec | 2017-01-31 12:07:08 -0600 | [diff] [blame] | 152 | |
| 153 | |
Michael Walsh | 8b270ec | 2017-01-31 12:07:08 -0600 | [diff] [blame] | 154 | def get_mtr_report(host=""): |
Michael Walsh | 8b270ec | 2017-01-31 12:07:08 -0600 | [diff] [blame] | 155 | r""" |
| 156 | Get an mtr report and return it as a dictionary of dictionaries. |
| 157 | |
| 158 | The key for the top level dictionary will be the host DNS name. The key |
| 159 | for the next level dictionary will be the field of a given row of the |
| 160 | report. |
| 161 | |
| 162 | Example result: |
| 163 | |
| 164 | report: |
George Keishing | fb4b125 | 2017-06-15 00:05:45 -0500 | [diff] [blame] | 165 | report[host_dummy-dnsname.com]: |
| 166 | report[host_dummy-dnsname.com][row_num]: 1 |
| 167 | report[host_dummy-dnsname.com][host]: host_dummy-dnsname.com |
| 168 | report[host_dummy-dnsname.com][loss]: 0.0 |
| 169 | report[host_dummy-dnsname.com][snt]: 10 |
| 170 | report[host_dummy-dnsname.com][last]: 0.2 |
| 171 | report[host_dummy-dnsname.com][avg]: 3.5 |
| 172 | report[host_dummy-dnsname.com][best]: 0.2 |
| 173 | report[host_dummy-dnsname.com][wrst]: 32.5 |
| 174 | report[host_dummy-dnsname.com][stdev]: 10.2 |
| 175 | report[bmc-dummy-dnsname.com]: |
| 176 | report[bmc-dummy-dnsname.com][row_num]: 2 |
| 177 | report[bmc-dummy-dnsname.com][host]: bmc-dummy-dnsname.com |
| 178 | report[bmc-dummy-dnsname.com][loss]: 0.0 |
| 179 | report[bmc-dummy-dnsname.com][snt]: 10 |
| 180 | report[bmc-dummy-dnsname.com][last]: 0.5 |
| 181 | report[bmc-dummy-dnsname.com][avg]: 0.5 |
| 182 | report[bmc-dummy-dnsname.com][best]: 0.5 |
| 183 | report[bmc-dummy-dnsname.com][wrst]: 0.5 |
| 184 | report[bmc-dummy-dnsname.com][stdev]: 0.0 |
Michael Walsh | 8b270ec | 2017-01-31 12:07:08 -0600 | [diff] [blame] | 185 | |
| 186 | Description of arguments: |
| 187 | host The DNS name or IP address to be passed to the mtr command. |
| 188 | """ |
| 189 | |
Gunnar Mills | acc7c56 | 2019-08-20 13:12:46 -0500 | [diff] [blame] | 190 | # Run the mtr command. Exclude the header line. Trim leading space from |
Michael Walsh | 8b270ec | 2017-01-31 12:07:08 -0600 | [diff] [blame] | 191 | # each line. Change all multiple spaces delims to single space delims. |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 192 | cmd_buf = ( |
| 193 | "mtr --report " |
| 194 | + host |
| 195 | + " | tail -n +2 | sed -r -e 's/^[ ]+//g' -e 's/[ ]+/ /g'" |
| 196 | ) |
| 197 | sub_proc = subprocess.Popen( |
| 198 | cmd_buf, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT |
| 199 | ) |
Michael Walsh | 8b270ec | 2017-01-31 12:07:08 -0600 | [diff] [blame] | 200 | out_buf, err_buf = sub_proc.communicate() |
| 201 | shell_rc = sub_proc.returncode |
| 202 | |
| 203 | # Split the output by line. |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 204 | rows = out_buf.rstrip("\n").split("\n") |
Michael Walsh | 8b270ec | 2017-01-31 12:07:08 -0600 | [diff] [blame] | 205 | |
| 206 | # Initialize report dictionary. |
| 207 | report = DotDict() |
| 208 | for row in rows: |
| 209 | # Process each row of mtr output. |
| 210 | # Create a list of fields by splitting on space delimiter. |
| 211 | row_list = row.split(" ") |
| 212 | # Create dictionary for the row. |
| 213 | row = DotDict() |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 214 | row["row_num"] = row_list[0].rstrip(".") |
| 215 | row["host"] = row_list[1] |
| 216 | row["loss"] = row_list[2].rstrip("%") |
| 217 | row["snt"] = row_list[3] |
| 218 | row["last"] = row_list[4] |
| 219 | row["avg"] = row_list[5] |
| 220 | row["best"] = row_list[6] |
| 221 | row["wrst"] = row_list[7] |
| 222 | row["stdev"] = row_list[8] |
| 223 | report[row["host"]] = row |
Michael Walsh | 8b270ec | 2017-01-31 12:07:08 -0600 | [diff] [blame] | 224 | |
| 225 | # Return the full report as dictionary of dictionaries. |
| 226 | return report |
| 227 | |
Michael Walsh | 8b270ec | 2017-01-31 12:07:08 -0600 | [diff] [blame] | 228 | |
Michael Walsh | 8b270ec | 2017-01-31 12:07:08 -0600 | [diff] [blame] | 229 | def get_mtr_row(host=""): |
Michael Walsh | 8b270ec | 2017-01-31 12:07:08 -0600 | [diff] [blame] | 230 | r""" |
| 231 | Run an mtr report and get a specified row and return it as a dictionary. |
| 232 | |
| 233 | Example result: |
| 234 | |
| 235 | row: |
| 236 | row[row_num]: 2 |
George Keishing | fb4b125 | 2017-06-15 00:05:45 -0500 | [diff] [blame] | 237 | row[host]: bmc-dummy-dnsname.com |
Michael Walsh | 8b270ec | 2017-01-31 12:07:08 -0600 | [diff] [blame] | 238 | row[loss]: 0.0 |
| 239 | row[snt]: 10 |
| 240 | row[last]: 0.5 |
| 241 | row[avg]: 0.5 |
| 242 | row[best]: 0.4 |
| 243 | row[wrst]: 0.7 |
| 244 | row[stdev]: 0.1 |
| 245 | |
| 246 | Description of arguments: |
| 247 | host The DNS name or IP address to be passed to the mtr command as |
| 248 | well as the indicating which row of the report to return. |
| 249 | """ |
| 250 | |
| 251 | report = get_mtr_report(host) |
| 252 | |
| 253 | # The max length of host in output is 28 chars. |
| 254 | row = [value for key, value in report.items() if host[0:28] in key][0] |
| 255 | |
| 256 | return row |
| 257 | |
George Keishing | efa9735 | 2017-03-13 07:13:03 -0500 | [diff] [blame] | 258 | |
George Keishing | efa9735 | 2017-03-13 07:13:03 -0500 | [diff] [blame] | 259 | def list_to_set(fru_list=""): |
| 260 | r""" |
| 261 | Pack the list into a set tuple and return. |
| 262 | |
| 263 | It may seem that this function is rather trivial. However, it simplifies |
| 264 | the code and improves robot program readability and achieve the result |
| 265 | required. |
| 266 | |
| 267 | Example result: |
| 268 | |
| 269 | set(['Version', 'PartNumber', 'SerialNumber', 'FieldReplaceable', |
| 270 | 'BuildDate', 'Present', 'Manufacturer', 'PrettyName', 'Cached', 'Model']) |
| 271 | |
| 272 | # Description of arguments. |
| 273 | fru_list List of FRU's elements. |
| 274 | """ |
| 275 | return set(fru_list) |
| 276 | |
George Keishing | 81ae45b | 2017-09-28 14:05:04 -0500 | [diff] [blame] | 277 | |
| 278 | def min_list_value(value_list): |
| 279 | r""" |
| 280 | Returns the element from the list with minimum value. |
| 281 | """ |
| 282 | return min(value_list) |
nagarjunb22 | 87138e6 | 2022-04-19 16:49:16 +0530 | [diff] [blame] | 283 | |
| 284 | |
| 285 | def convert_lsb_to_msb(string): |
| 286 | r""" |
| 287 | Reverse given string (From LSB first to MSB first) and converts to HEX. |
| 288 | |
George Keishing | 86d85f4 | 2022-08-18 23:02:22 -0500 | [diff] [blame] | 289 | Input string 0a 00 |
nagarjunb22 | 87138e6 | 2022-04-19 16:49:16 +0530 | [diff] [blame] | 290 | Return string 0a |
| 291 | """ |
| 292 | datalist = string.split(" ") |
| 293 | new_list = datalist[::-1] |
| 294 | new_string = "".join([str(element) for element in new_list]) |
| 295 | return int(new_string, 16) |
| 296 | |
| 297 | |
| 298 | def add_prefix_to_string(string, prefix): |
| 299 | r""" |
| 300 | Add given prefix to the string and return string. |
| 301 | |
| 302 | Input string 0a 01 |
| 303 | Return string 0x0a 0x01 |
| 304 | """ |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 305 | prefix_string = "" |
nagarjunb22 | 87138e6 | 2022-04-19 16:49:16 +0530 | [diff] [blame] | 306 | data_list = string.strip().split(" ") |
| 307 | for item in data_list: |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 308 | prefix_string += prefix + item + " " |
nagarjunb22 | 87138e6 | 2022-04-19 16:49:16 +0530 | [diff] [blame] | 309 | return prefix_string.strip() |
George Keishing | 8ef9e72 | 2023-01-18 10:21:31 +0530 | [diff] [blame] | 310 | |
| 311 | |
| 312 | def get_value_from_nested_dict(key, nested_dict): |
| 313 | r""" |
| 314 | Returns the key value from the nested dictionary. |
| 315 | |
| 316 | key Key value of the dictionary to look up. |
| 317 | nested_dict Dictionary data. |
| 318 | """ |
| 319 | result = [] |
| 320 | for k, v in nested_dict.items(): |
| 321 | if k == key: |
| 322 | result.append(v) |
| 323 | elif isinstance(v, dict) and k != key: |
| 324 | result += get_value_from_nested_dict(key, v) |
| 325 | |
| 326 | return result |