George Keishing | e7e9171 | 2021-09-03 11:28:44 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 -u |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 2 | import imp |
| 3 | import string |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 4 | import sys |
| 5 | |
| 6 | from robot.libraries.BuiltIn import BuiltIn |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 7 | |
| 8 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 9 | def get_sensor(module_name, value): |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 10 | m = imp.load_source("module.name", module_name) |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 11 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 12 | for i in m.ID_LOOKUP["SENSOR"]: |
| 13 | if m.ID_LOOKUP["SENSOR"][i] == value: |
Gunnar Mills | dca3579 | 2018-03-26 10:05:38 -0500 | [diff] [blame] | 14 | return i |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 15 | |
Gunnar Mills | dca3579 | 2018-03-26 10:05:38 -0500 | [diff] [blame] | 16 | return 0xFF |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 17 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 18 | |
Gunnar Mills | dca3579 | 2018-03-26 10:05:38 -0500 | [diff] [blame] | 19 | def get_inventory_sensor(module_name, value): |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 20 | m = imp.load_source("module.name", module_name) |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 21 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 22 | value = string.replace(value, m.INVENTORY_ROOT, "<inventory_root>") |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 23 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 24 | for i in m.ID_LOOKUP["SENSOR"]: |
| 25 | if m.ID_LOOKUP["SENSOR"][i] == value: |
Gunnar Mills | dca3579 | 2018-03-26 10:05:38 -0500 | [diff] [blame] | 26 | return i |
| 27 | |
| 28 | return 0xFF |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 29 | |
| 30 | |
| 31 | def get_inventory_list(module_name): |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 32 | inventory_list = [] |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 33 | m = imp.load_source("module.name", module_name) |
George Keishing | e635ddc | 2022-12-08 07:38:02 -0600 | [diff] [blame] | 34 | |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 35 | for i in m.ID_LOOKUP["FRU"]: |
| 36 | s = m.ID_LOOKUP["FRU"][i] |
| 37 | s = s.replace("<inventory_root>", m.INVENTORY_ROOT) |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 38 | inventory_list.append(s) |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 39 | |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 40 | return inventory_list |
Gunnar Mills | dca3579 | 2018-03-26 10:05:38 -0500 | [diff] [blame] | 41 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 42 | |
| 43 | def get_inventory_fru_type_list(module_name, fru_type): |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 44 | inventory_list = [] |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 45 | m = imp.load_source("module.name", module_name) |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 46 | |
Gunnar Mills | dca3579 | 2018-03-26 10:05:38 -0500 | [diff] [blame] | 47 | for i in m.FRU_INSTANCES.keys(): |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 48 | if m.FRU_INSTANCES[i]["fru_type"] == fru_type: |
| 49 | s = i.replace("<inventory_root>", m.INVENTORY_ROOT) |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 50 | inventory_list.append(s) |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 51 | |
Joy Onyerikwu | 004ad3c | 2018-06-11 16:29:56 -0500 | [diff] [blame] | 52 | return inventory_list |
Gunnar Mills | dca3579 | 2018-03-26 10:05:38 -0500 | [diff] [blame] | 53 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 54 | |
| 55 | def call_keyword(keyword): |
Gunnar Mills | dca3579 | 2018-03-26 10:05:38 -0500 | [diff] [blame] | 56 | return BuiltIn().run_keyword(keyword) |
Tony Lee | 1e303ca | 2020-02-27 10:53:47 +0800 | [diff] [blame] | 57 | |
| 58 | |
| 59 | def get_FRU_component_name_list(module_name): |
| 60 | name_list = [] |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 61 | m = imp.load_source("module.name", module_name) |
Tony Lee | 1e303ca | 2020-02-27 10:53:47 +0800 | [diff] [blame] | 62 | |
| 63 | for name in m.FRU_COMPONENT_NAME: |
| 64 | name_list.append(name) |
| 65 | print(name) |
| 66 | |
| 67 | return name_list |
| 68 | |
| 69 | |
| 70 | def get_ipmi_rest_fru_field_map(module_name): |
Patrick Williams | 20f3871 | 2022-12-08 06:18:26 -0600 | [diff] [blame] | 71 | m = imp.load_source("module.name", module_name) |
Tony Lee | 1e303ca | 2020-02-27 10:53:47 +0800 | [diff] [blame] | 72 | |
| 73 | ipmi_rest_fru_field_map = dict.copy(m.ipmi_rest_fru_field_map) |
| 74 | |
| 75 | return ipmi_rest_fru_field_map |