blob: f316b3b299da984f167342cdcc91913196950922 [file] [log] [blame]
Chris Austenb29d2e82016-06-07 12:25:35 -05001#!/usr/bin/python -u
2import sys
3from robot.libraries.BuiltIn import BuiltIn
4import imp
5import string
Rahul Maheshwari757d80c2016-10-17 01:09:55 -05006import random
Chris Austenb29d2e82016-06-07 12:25:35 -05007
Rahul Maheshwari757d80c2016-10-17 01:09:55 -05008def random_mac():
9 r"""
10 Return random mac address in the following format.
11 Example: 00:01:6C:80:02:78
12 """
13 return ":".join(map(lambda x: "%02x" % x, (random.randint(0x00, 0xff)
14 for _ in range(6))))
15
16def random_ip():
17 r"""
18 Return random ip address in the following format.
19 Example: 9.3.128.100
20 """
21 return ".".join(map(str, (random.randint(0, 255)
22 for _ in range(4))))
Chris Austenb29d2e82016-06-07 12:25:35 -050023
24def get_sensor(module_name, value):
Gunnar Millsbb398ac2016-11-14 11:50:22 -060025 m = imp.load_source('module.name', module_name)
Chris Austenb29d2e82016-06-07 12:25:35 -050026
Gunnar Millsbb398ac2016-11-14 11:50:22 -060027 for i in m.ID_LOOKUP['SENSOR']:
Chris Austenb29d2e82016-06-07 12:25:35 -050028
Gunnar Millsbb398ac2016-11-14 11:50:22 -060029 if m.ID_LOOKUP['SENSOR'][i] == value:
30 return i
Chris Austenb29d2e82016-06-07 12:25:35 -050031
Gunnar Millsbb398ac2016-11-14 11:50:22 -060032 return 0xFF
33
Chris Austenb29d2e82016-06-07 12:25:35 -050034
35def get_inventory_sensor (module_name, value):
Gunnar Millsbb398ac2016-11-14 11:50:22 -060036 m = imp.load_source('module.name', module_name)
Chris Austenb29d2e82016-06-07 12:25:35 -050037
Gunnar Millsbb398ac2016-11-14 11:50:22 -060038 value = string.replace(value, m.INVENTORY_ROOT, '<inventory_root>')
Chris Austenb29d2e82016-06-07 12:25:35 -050039
Gunnar Millsbb398ac2016-11-14 11:50:22 -060040 for i in m.ID_LOOKUP['SENSOR']:
Chris Austenb29d2e82016-06-07 12:25:35 -050041
Gunnar Millsbb398ac2016-11-14 11:50:22 -060042 if m.ID_LOOKUP['SENSOR'][i] == value:
43 return i
Chris Austenb29d2e82016-06-07 12:25:35 -050044
Gunnar Millsbb398ac2016-11-14 11:50:22 -060045 return 0xFF
Chris Austenb29d2e82016-06-07 12:25:35 -050046
47
48################################################################
Gunnar Millsbb398ac2016-11-14 11:50:22 -060049# This will return the URI's of the FRU type
Chris Austenb29d2e82016-06-07 12:25:35 -050050#
51# i.e. get_inventory_list('../data/Palmetto.py')
52#
53# [/org/openbmc/inventory//system/chassis/motherboard/cpu0/core0,
54# /org/openbmc/inventory/system/chassis/motherboard/dimm0]
55################################################################
56def get_inventory_list(module_name):
57
Gunnar Millsbb398ac2016-11-14 11:50:22 -060058 l = []
59 m = imp.load_source('module.name', module_name)
Chris Austenb29d2e82016-06-07 12:25:35 -050060
Gunnar Millsbb398ac2016-11-14 11:50:22 -060061
62 for i in m.ID_LOOKUP['FRU']:
63 s = m.ID_LOOKUP['FRU'][i]
64 s = s.replace('<inventory_root>',m.INVENTORY_ROOT)
65 l.append(s)
66
67 return l
Chris Austenb29d2e82016-06-07 12:25:35 -050068
69
70################################################################
Gunnar Millsbb398ac2016-11-14 11:50:22 -060071# This will return the URI's of the FRU type
Chris Austenb29d2e82016-06-07 12:25:35 -050072#
73# i.e. get_inventory_fru_type_list('../data/Barreleye.py', 'CPU')
74#
75# [/org/openbmc/inventory//system/chassis/motherboard/cpu0,
76# /org/openbmc/inventory//system/chassis/motherboard/cpu1]
77################################################################
78def get_inventory_fru_type_list(module_name, fru):
Gunnar Millsbb398ac2016-11-14 11:50:22 -060079 l = []
80 m = imp.load_source('module.name', module_name)
Chris Austenb29d2e82016-06-07 12:25:35 -050081
Gunnar Millsbb398ac2016-11-14 11:50:22 -060082 for i in m.FRU_INSTANCES.keys():
83 if m.FRU_INSTANCES[i]['fru_type'] == fru:
84 s = i.replace('<inventory_root>',m.INVENTORY_ROOT)
85 l.append(s)
86
87 return l
Chris Austenb29d2e82016-06-07 12:25:35 -050088
89
90################################################################
91# This will return the URI's of the FRU type that contain VPD
92#
93# i.e. get_vpd_inventory_list('../data/Palmetto.py', 'DIMM')
94#
95# [/org/openbmc/inventory/system/chassis/motherboard/dimm0,
96# /org/openbmc/inventory/system/chassis/motherboard/dimm1]
97################################################################
98def get_vpd_inventory_list(module_name, fru):
Gunnar Millsbb398ac2016-11-14 11:50:22 -060099 l = []
100 m = imp.load_source('module.name', module_name)
Chris Austenb29d2e82016-06-07 12:25:35 -0500101
Gunnar Millsbb398ac2016-11-14 11:50:22 -0600102 for i in m.ID_LOOKUP['FRU_STR']:
103 x = m.ID_LOOKUP['FRU_STR'][i]
Chris Austenb29d2e82016-06-07 12:25:35 -0500104
Gunnar Millsbb398ac2016-11-14 11:50:22 -0600105 if m.FRU_INSTANCES[x]['fru_type'] == fru:
106 s = x.replace('<inventory_root>',m.INVENTORY_ROOT)
107 l.append(s)
108
109 return l
Chris Austenb29d2e82016-06-07 12:25:35 -0500110
111
112def call_keyword(keyword):
113 return BuiltIn().run_keyword(keyword)
114
115
116def main():
Gunnar Millsbb398ac2016-11-14 11:50:22 -0600117 print get_vpd_inventory_list('../data/Palmetto.py', 'DIMM')
Chris Austenb29d2e82016-06-07 12:25:35 -0500118
119
120if __name__ == "__main__":
Gunnar Millsbb398ac2016-11-14 11:50:22 -0600121 main()