blob: 0d90343ea4fcf493779efb0e5cc232c8bbe64cff [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"""
George Keishinge635ddc2022-12-08 07:38:02 -06006import sys
7import os
8import yaml
9import json
10
George Keishingae7c8202017-02-09 10:33:45 -060011lib_path = sys.path[0] + "/../lib"
12sys.path.insert(0, lib_path)
George Keishing09679892022-12-08 08:21:52 -060013from gen_print import * # NOQA
George Keishingae7c8202017-02-09 10:33:45 -060014
15# This list will be longer when more development codes are available.
George Keishinge635ddc2022-12-08 07:38:02 -060016inventory_items = ['fru', 'core', 'fan', 'fan_wc', 'gpu']
George Keishingae7c8202017-02-09 10:33:45 -060017print_var(inventory_items)
George Keishinge635ddc2022-12-08 07:38:02 -060018fru_inventory_file_path = 'inventory.py'
George Keishingae7c8202017-02-09 10:33:45 -060019print_var(fru_inventory_file_path)
20
George Keishing1eab8832020-07-09 06:30:57 -050021# Properties inventory list
22yaml_inventory_list = []
George Keishingae7c8202017-02-09 10:33:45 -060023
24# Clone the phosphor-dbus-interfaces repository
George Keishinge635ddc2022-12-08 07:38:02 -060025cmd_buf = 'git clone https://github.com/openbmc/phosphor-dbus-interfaces'
George Keishingae7c8202017-02-09 10:33:45 -060026os.system(cmd_buf)
27
George Keishinge635ddc2022-12-08 07:38:02 -060028repo_subdir_path = '/phosphor-dbus-interfaces/xyz/openbmc_project/'
George Keishingae7c8202017-02-09 10:33:45 -060029base_dir_path = os.getcwd() + repo_subdir_path
30
George Keishing9ef1fd42017-03-10 14:52:38 -060031# yaml file paths for FRU
George Keishinge635ddc2022-12-08 07:38:02 -060032yaml_fru_list = ['Inventory/Item.interface.yaml',
33 'Inventory/Decorator/Asset.interface.yaml',
34 'Inventory/Decorator/Revision.interface.yaml',
35 'Inventory/Decorator/Replaceable.interface.yaml',
36 'Inventory/Decorator/Cacheable.interface.yaml',
37 'State/Decorator/OperationalStatus.interface.yaml', ]
George Keishingae7c8202017-02-09 10:33:45 -060038
Sweta Potthuri1da4c242018-01-09 04:42:51 -060039# yaml file paths for CORE.
George Keishinge635ddc2022-12-08 07:38:02 -060040yaml_core_list = ['Inventory/Item.interface.yaml',
41 'State/Decorator/OperationalStatus.interface.yaml', ]
George Keishingdc68eff2017-06-12 22:43:18 -050042
43# yaml file paths for fan.
George Keishinge635ddc2022-12-08 07:38:02 -060044yaml_fan_list = ['Inventory/Item.interface.yaml',
45 'Inventory/Decorator/MeetsMinimumShipLevel.interface.yaml',
46 'State/Decorator/OperationalStatus.interface.yaml', ]
Steven Sombar5c006d32018-10-08 09:35:38 -050047
48# yaml file paths for fan_wc (fans in water-cooled system).
George Keishinge635ddc2022-12-08 07:38:02 -060049yaml_fan_wc_list = ['Inventory/Item.interface.yaml',
50 'Inventory/Decorator/MeetsMinimumShipLevel.interface.yaml', ]
Steven Sombar5c006d32018-10-08 09:35:38 -050051
George Keishing19305202017-11-17 12:07:28 -060052# yaml file paths for GPU.
George Keishinge635ddc2022-12-08 07:38:02 -060053yaml_gpu_list = ['Inventory/Item.interface.yaml',
54 'Inventory/Decorator/Replaceable.interface.yaml',
55 'State/Decorator/OperationalStatus.interface.yaml', ]
Steven Sombar5c006d32018-10-08 09:35:38 -050056
George Keishing1eab8832020-07-09 06:30:57 -050057# Append to inventory list
58yaml_inventory_list.append(yaml_fru_list)
59yaml_inventory_list.append(yaml_core_list)
60yaml_inventory_list.append(yaml_fan_list)
61yaml_inventory_list.append(yaml_fan_wc_list)
62yaml_inventory_list.append(yaml_gpu_list)
George Keishingae7c8202017-02-09 10:33:45 -060063
George Keishing1eab8832020-07-09 06:30:57 -050064print_var(yaml_inventory_list)
George Keishing9ef1fd42017-03-10 14:52:38 -060065
George Keishingae7c8202017-02-09 10:33:45 -060066# Populate Inventory data
67inventory_dict = {}
68
George Keishing1eab8832020-07-09 06:30:57 -050069for inv_index in range(len(yaml_inventory_list)):
70 print_var(inv_index)
71 inventory_dict[str(inventory_items[inv_index])] = []
72 for rel_yaml_file_path in yaml_inventory_list[inv_index]:
George Keishing9ef1fd42017-03-10 14:52:38 -060073 yaml_file_path = base_dir_path + rel_yaml_file_path
George Keishingae7c8202017-02-09 10:33:45 -060074
75 # Get the yaml dictionary data
George Keishing9ef1fd42017-03-10 14:52:38 -060076 print_timen("Loading " + yaml_file_path)
77 f = open(yaml_file_path)
Yunyun Linf87cc0a2022-06-08 16:57:04 -070078 yaml_data = yaml.safe_load(f)
George Keishingae7c8202017-02-09 10:33:45 -060079 f.close()
George Keishinge635ddc2022-12-08 07:38:02 -060080 for item in range(0, len(yaml_data['properties'])):
81 tmp_data = yaml_data['properties'][item]['name']
George Keishing1eab8832020-07-09 06:30:57 -050082 inventory_dict[str(inventory_items[inv_index])].append(tmp_data)
George Keishingae7c8202017-02-09 10:33:45 -060083
84# Pretty print json formatter
George Keishinge635ddc2022-12-08 07:38:02 -060085data = json.dumps(inventory_dict,
86 indent=4,
87 sort_keys=True,
88 default=str,
89 separators=(',', ':'))
George Keishingae7c8202017-02-09 10:33:45 -060090
91# Check if there is mismatch in data vs expect list
92if len(inventory_dict) != len(inventory_items):
George Keishing178d9bf2020-07-09 08:29:29 -050093 print_error("The generated list doesn't match Inventory List.\n")
Patrick Williamsa57fef42022-12-03 07:00:14 -060094 print(data)
George Keishingae7c8202017-02-09 10:33:45 -060095 print_var(inventory_items)
96 sys.exit()
97
98# Write dictionary data to inventory file
Patrick Williamsa57fef42022-12-03 07:00:14 -060099print("\nGenerated Inventory item json format\n")
100print(data)
George Keishinge635ddc2022-12-08 07:38:02 -0600101out = open(fru_inventory_file_path, 'w')
102out.write('inventory_dict = ')
George Keishingae7c8202017-02-09 10:33:45 -0600103out.write(data)
104
105out.close()
Patrick Williamsa57fef42022-12-03 07:00:14 -0600106print("\nGenerated Inventory File: %s " % fru_inventory_file_path)