1#!/usr/bin/env python3 -u
2import importlib.util
3import string as string
4
5from robot.libraries.BuiltIn import BuiltIn
6
7
8def load_source(name, module_path):
9    spec = importlib.util.spec_from_file_location(name, module_path)
10    module = importlib.util.module_from_spec(spec)
11    spec.loader.exec_module(module)
12    return module
13
14
15def get_sensor(module_name, value):
16    m = load_source("module.name", module_name)
17
18    for i in m.ID_LOOKUP["SENSOR"]:
19        if m.ID_LOOKUP["SENSOR"][i] == value:
20            return i
21
22    return 0xFF
23
24
25def get_inventory_sensor(module_name, value):
26    m = load_source("module.name", module_name)
27
28    value = string.replace(value, m.INVENTORY_ROOT, "<inventory_root>")
29
30    for i in m.ID_LOOKUP["SENSOR"]:
31        if m.ID_LOOKUP["SENSOR"][i] == value:
32            return i
33
34    return 0xFF
35
36
37def get_inventory_list(module_name):
38    inventory_list = []
39    m = load_source("module.name", module_name)
40
41    for i in m.ID_LOOKUP["FRU"]:
42        s = m.ID_LOOKUP["FRU"][i]
43        s = s.replace("<inventory_root>", m.INVENTORY_ROOT)
44        inventory_list.append(s)
45
46    return inventory_list
47
48
49def get_inventory_fru_type_list(module_name, fru_type):
50    inventory_list = []
51    m = load_source("module.name", module_name)
52
53    for i in m.FRU_INSTANCES.keys():
54        if m.FRU_INSTANCES[i]["fru_type"] == fru_type:
55            s = i.replace("<inventory_root>", m.INVENTORY_ROOT)
56            inventory_list.append(s)
57
58    return inventory_list
59
60
61def call_keyword(keyword):
62    return BuiltIn().run_keyword(keyword)
63
64
65def get_FRU_component_name_list(module_name):
66    name_list = []
67    m = load_source("module.name", module_name)
68
69    for name in m.FRU_COMPONENT_NAME:
70        name_list.append(name)
71        print(name)
72
73    return name_list
74
75
76def get_ipmi_rest_fru_field_map(module_name):
77    m = load_source("module.name", module_name)
78
79    ipmi_rest_fru_field_map = dict.copy(m.ipmi_rest_fru_field_map)
80
81    return ipmi_rest_fru_field_map
82