Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 1 | #!/usr/bin/python -u |
| 2 | import sys |
| 3 | from robot.libraries.BuiltIn import BuiltIn |
| 4 | import imp |
| 5 | import string |
Rahul Maheshwari | 757d80c | 2016-10-17 01:09:55 -0500 | [diff] [blame] | 6 | import random |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 7 | |
Rahul Maheshwari | 757d80c | 2016-10-17 01:09:55 -0500 | [diff] [blame] | 8 | def 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 | |
| 16 | def 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 Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 23 | |
| 24 | def get_sensor(module_name, value): |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 25 | m = imp.load_source('module.name', module_name) |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 26 | |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 27 | for i in m.ID_LOOKUP['SENSOR']: |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 28 | |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 29 | if m.ID_LOOKUP['SENSOR'][i] == value: |
| 30 | return i |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 31 | |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 32 | return 0xFF |
| 33 | |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 34 | |
| 35 | def get_inventory_sensor (module_name, value): |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 36 | m = imp.load_source('module.name', module_name) |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 37 | |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 38 | value = string.replace(value, m.INVENTORY_ROOT, '<inventory_root>') |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 39 | |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 40 | for i in m.ID_LOOKUP['SENSOR']: |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 41 | |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 42 | if m.ID_LOOKUP['SENSOR'][i] == value: |
| 43 | return i |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 44 | |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 45 | return 0xFF |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 46 | |
| 47 | |
| 48 | ################################################################ |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 49 | # This will return the URI's of the FRU type |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 50 | # |
| 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 | ################################################################ |
| 56 | def get_inventory_list(module_name): |
| 57 | |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 58 | l = [] |
| 59 | m = imp.load_source('module.name', module_name) |
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 | |
| 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 Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 68 | |
| 69 | |
| 70 | ################################################################ |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 71 | # This will return the URI's of the FRU type |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 72 | # |
| 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 | ################################################################ |
| 78 | def get_inventory_fru_type_list(module_name, fru): |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 79 | l = [] |
| 80 | m = imp.load_source('module.name', module_name) |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 81 | |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 82 | 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 Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 88 | |
| 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 | ################################################################ |
| 98 | def get_vpd_inventory_list(module_name, fru): |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 99 | l = [] |
| 100 | m = imp.load_source('module.name', module_name) |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 101 | |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 102 | for i in m.ID_LOOKUP['FRU_STR']: |
| 103 | x = m.ID_LOOKUP['FRU_STR'][i] |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 104 | |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 105 | 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 Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 110 | |
| 111 | |
| 112 | def call_keyword(keyword): |
| 113 | return BuiltIn().run_keyword(keyword) |
| 114 | |
| 115 | |
| 116 | def main(): |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 117 | print get_vpd_inventory_list('../data/Palmetto.py', 'DIMM') |
Chris Austen | b29d2e8 | 2016-06-07 12:25:35 -0500 | [diff] [blame] | 118 | |
| 119 | |
| 120 | if __name__ == "__main__": |
Gunnar Mills | bb398ac | 2016-11-14 11:50:22 -0600 | [diff] [blame] | 121 | main() |