blob: 80f725e2615240928231382799686ba5ea2dde0e [file] [log] [blame]
George Keishinge7e91712021-09-03 11:28:44 -05001#!/usr/bin/env python3
George Keishingae7c8202017-02-09 10:33:45 -06002r"""
3Generate an inventory variable file containing a list of properties
4fields from the YAML phosphor-dbus-interfaces repository.
5"""
Sridevi Ramesh47375aa2022-12-08 05:05:31 -06006
Patrick Williams57318182022-12-08 06:18:26 -06007from gen_print import *
George Keishingae7c8202017-02-09 10:33:45 -06008
George Keishinge635ddc2022-12-08 07:38:02 -06009import sys
10import os
11import yaml
12import json
13
George Keishingae7c8202017-02-09 10:33:45 -060014lib_path = sys.path[0] + "/../lib"
15sys.path.insert(0, lib_path)
George Keishingae7c8202017-02-09 10:33:45 -060016
17# This list will be longer when more development codes are available.
George Keishinge635ddc2022-12-08 07:38:02 -060018inventory_items = ['fru', 'core', 'fan', 'fan_wc', 'gpu']
George Keishingae7c8202017-02-09 10:33:45 -060019print_var(inventory_items)
George Keishinge635ddc2022-12-08 07:38:02 -060020fru_inventory_file_path = 'inventory.py'
George Keishingae7c8202017-02-09 10:33:45 -060021print_var(fru_inventory_file_path)
22
George Keishing1eab8832020-07-09 06:30:57 -050023# Properties inventory list
24yaml_inventory_list = []
George Keishingae7c8202017-02-09 10:33:45 -060025
26# Clone the phosphor-dbus-interfaces repository
George Keishinge635ddc2022-12-08 07:38:02 -060027cmd_buf = 'git clone https://github.com/openbmc/phosphor-dbus-interfaces'
George Keishingae7c8202017-02-09 10:33:45 -060028os.system(cmd_buf)
29
George Keishinge635ddc2022-12-08 07:38:02 -060030repo_subdir_path = '/phosphor-dbus-interfaces/xyz/openbmc_project/'
George Keishingae7c8202017-02-09 10:33:45 -060031base_dir_path = os.getcwd() + repo_subdir_path
32
George Keishing9ef1fd42017-03-10 14:52:38 -060033# yaml file paths for FRU
George Keishinge635ddc2022-12-08 07:38:02 -060034yaml_fru_list = ['Inventory/Item.interface.yaml',
35 'Inventory/Decorator/Asset.interface.yaml',
36 'Inventory/Decorator/Revision.interface.yaml',
37 'Inventory/Decorator/Replaceable.interface.yaml',
38 'Inventory/Decorator/Cacheable.interface.yaml',
39 'State/Decorator/OperationalStatus.interface.yaml', ]
George Keishingae7c8202017-02-09 10:33:45 -060040
Sweta Potthuri1da4c242018-01-09 04:42:51 -060041# yaml file paths for CORE.
George Keishinge635ddc2022-12-08 07:38:02 -060042yaml_core_list = ['Inventory/Item.interface.yaml',
43 'State/Decorator/OperationalStatus.interface.yaml', ]
George Keishingdc68eff2017-06-12 22:43:18 -050044
45# yaml file paths for fan.
George Keishinge635ddc2022-12-08 07:38:02 -060046yaml_fan_list = ['Inventory/Item.interface.yaml',
47 'Inventory/Decorator/MeetsMinimumShipLevel.interface.yaml',
48 'State/Decorator/OperationalStatus.interface.yaml', ]
Steven Sombar5c006d32018-10-08 09:35:38 -050049
50# yaml file paths for fan_wc (fans in water-cooled system).
George Keishinge635ddc2022-12-08 07:38:02 -060051yaml_fan_wc_list = ['Inventory/Item.interface.yaml',
52 'Inventory/Decorator/MeetsMinimumShipLevel.interface.yaml', ]
Steven Sombar5c006d32018-10-08 09:35:38 -050053
George Keishing19305202017-11-17 12:07:28 -060054# yaml file paths for GPU.
George Keishinge635ddc2022-12-08 07:38:02 -060055yaml_gpu_list = ['Inventory/Item.interface.yaml',
56 'Inventory/Decorator/Replaceable.interface.yaml',
57 'State/Decorator/OperationalStatus.interface.yaml', ]
Steven Sombar5c006d32018-10-08 09:35:38 -050058
George Keishing1eab8832020-07-09 06:30:57 -050059# Append to inventory list
60yaml_inventory_list.append(yaml_fru_list)
61yaml_inventory_list.append(yaml_core_list)
62yaml_inventory_list.append(yaml_fan_list)
63yaml_inventory_list.append(yaml_fan_wc_list)
64yaml_inventory_list.append(yaml_gpu_list)
George Keishingae7c8202017-02-09 10:33:45 -060065
George Keishing1eab8832020-07-09 06:30:57 -050066print_var(yaml_inventory_list)
George Keishing9ef1fd42017-03-10 14:52:38 -060067
George Keishingae7c8202017-02-09 10:33:45 -060068# Populate Inventory data
69inventory_dict = {}
70
George Keishing1eab8832020-07-09 06:30:57 -050071for inv_index in range(len(yaml_inventory_list)):
72 print_var(inv_index)
73 inventory_dict[str(inventory_items[inv_index])] = []
74 for rel_yaml_file_path in yaml_inventory_list[inv_index]:
George Keishing9ef1fd42017-03-10 14:52:38 -060075 yaml_file_path = base_dir_path + rel_yaml_file_path
George Keishingae7c8202017-02-09 10:33:45 -060076
77 # Get the yaml dictionary data
George Keishing9ef1fd42017-03-10 14:52:38 -060078 print_timen("Loading " + yaml_file_path)
79 f = open(yaml_file_path)
Yunyun Linf87cc0a2022-06-08 16:57:04 -070080 yaml_data = yaml.safe_load(f)
George Keishingae7c8202017-02-09 10:33:45 -060081 f.close()
George Keishinge635ddc2022-12-08 07:38:02 -060082 for item in range(0, len(yaml_data['properties'])):
83 tmp_data = yaml_data['properties'][item]['name']
George Keishing1eab8832020-07-09 06:30:57 -050084 inventory_dict[str(inventory_items[inv_index])].append(tmp_data)
George Keishingae7c8202017-02-09 10:33:45 -060085
86# Pretty print json formatter
George Keishinge635ddc2022-12-08 07:38:02 -060087data = json.dumps(inventory_dict,
88 indent=4,
89 sort_keys=True,
90 default=str,
91 separators=(',', ':'))
George Keishingae7c8202017-02-09 10:33:45 -060092
93# Check if there is mismatch in data vs expect list
94if len(inventory_dict) != len(inventory_items):
George Keishing178d9bf2020-07-09 08:29:29 -050095 print_error("The generated list doesn't match Inventory List.\n")
Patrick Williamsa57fef42022-12-03 07:00:14 -060096 print(data)
George Keishingae7c8202017-02-09 10:33:45 -060097 print_var(inventory_items)
98 sys.exit()
99
100# Write dictionary data to inventory file
Patrick Williamsa57fef42022-12-03 07:00:14 -0600101print("\nGenerated Inventory item json format\n")
102print(data)
George Keishinge635ddc2022-12-08 07:38:02 -0600103out = open(fru_inventory_file_path, 'w')
104out.write('inventory_dict = ')
George Keishingae7c8202017-02-09 10:33:45 -0600105out.write(data)
106
107out.close()
Patrick Williamsa57fef42022-12-03 07:00:14 -0600108print("\nGenerated Inventory File: %s " % fru_inventory_file_path)