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