George Keishing | e7e9171 | 2021-09-03 11:28:44 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 2 | r""" |
| 3 | Generate an inventory variable file containing a list of properties |
| 4 | fields from the YAML phosphor-dbus-interfaces repository. |
| 5 | """ |
Sridevi Ramesh | 47375aa | 2022-12-08 05:05:31 -0600 | [diff] [blame] | 6 | |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 7 | import json |
Patrick Williams | 5731818 | 2022-12-08 06:18:26 -0600 | [diff] [blame^] | 8 | import os |
| 9 | import sys |
| 10 | |
| 11 | import yaml |
| 12 | from gen_print import * |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 13 | |
| 14 | lib_path = sys.path[0] + "/../lib" |
| 15 | sys.path.insert(0, lib_path) |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 16 | |
| 17 | # This list will be longer when more development codes are available. |
Patrick Williams | 5731818 | 2022-12-08 06:18:26 -0600 | [diff] [blame^] | 18 | inventory_items = ["fru", "core", "fan", "fan_wc", "gpu"] |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 19 | print_var(inventory_items) |
Patrick Williams | 5731818 | 2022-12-08 06:18:26 -0600 | [diff] [blame^] | 20 | fru_inventory_file_path = "inventory.py" |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 21 | print_var(fru_inventory_file_path) |
| 22 | |
George Keishing | 1eab883 | 2020-07-09 06:30:57 -0500 | [diff] [blame] | 23 | # Properties inventory list |
| 24 | yaml_inventory_list = [] |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 25 | |
| 26 | # Clone the phosphor-dbus-interfaces repository |
Patrick Williams | 5731818 | 2022-12-08 06:18:26 -0600 | [diff] [blame^] | 27 | cmd_buf = "git clone https://github.com/openbmc/phosphor-dbus-interfaces" |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 28 | os.system(cmd_buf) |
| 29 | |
Patrick Williams | 5731818 | 2022-12-08 06:18:26 -0600 | [diff] [blame^] | 30 | repo_subdir_path = "/phosphor-dbus-interfaces/xyz/openbmc_project/" |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 31 | base_dir_path = os.getcwd() + repo_subdir_path |
| 32 | |
George Keishing | 9ef1fd4 | 2017-03-10 14:52:38 -0600 | [diff] [blame] | 33 | # yaml file paths for FRU |
Patrick Williams | 5731818 | 2022-12-08 06:18:26 -0600 | [diff] [blame^] | 34 | yaml_fru_list = [ |
| 35 | "Inventory/Item.interface.yaml", |
| 36 | "Inventory/Decorator/Asset.interface.yaml", |
| 37 | "Inventory/Decorator/Revision.interface.yaml", |
| 38 | "Inventory/Decorator/Replaceable.interface.yaml", |
| 39 | "Inventory/Decorator/Cacheable.interface.yaml", |
| 40 | "State/Decorator/OperationalStatus.interface.yaml", |
| 41 | ] |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 42 | |
Sweta Potthuri | 1da4c24 | 2018-01-09 04:42:51 -0600 | [diff] [blame] | 43 | # yaml file paths for CORE. |
Patrick Williams | 5731818 | 2022-12-08 06:18:26 -0600 | [diff] [blame^] | 44 | yaml_core_list = [ |
| 45 | "Inventory/Item.interface.yaml", |
| 46 | "State/Decorator/OperationalStatus.interface.yaml", |
| 47 | ] |
George Keishing | dc68eff | 2017-06-12 22:43:18 -0500 | [diff] [blame] | 48 | |
| 49 | # yaml file paths for fan. |
Patrick Williams | 5731818 | 2022-12-08 06:18:26 -0600 | [diff] [blame^] | 50 | yaml_fan_list = [ |
| 51 | "Inventory/Item.interface.yaml", |
| 52 | "Inventory/Decorator/MeetsMinimumShipLevel.interface.yaml", |
| 53 | "State/Decorator/OperationalStatus.interface.yaml", |
| 54 | ] |
Steven Sombar | 5c006d3 | 2018-10-08 09:35:38 -0500 | [diff] [blame] | 55 | |
| 56 | # yaml file paths for fan_wc (fans in water-cooled system). |
Patrick Williams | 5731818 | 2022-12-08 06:18:26 -0600 | [diff] [blame^] | 57 | yaml_fan_wc_list = [ |
| 58 | "Inventory/Item.interface.yaml", |
| 59 | "Inventory/Decorator/MeetsMinimumShipLevel.interface.yaml", |
| 60 | ] |
Steven Sombar | 5c006d3 | 2018-10-08 09:35:38 -0500 | [diff] [blame] | 61 | |
George Keishing | 1930520 | 2017-11-17 12:07:28 -0600 | [diff] [blame] | 62 | # yaml file paths for GPU. |
Patrick Williams | 5731818 | 2022-12-08 06:18:26 -0600 | [diff] [blame^] | 63 | yaml_gpu_list = [ |
| 64 | "Inventory/Item.interface.yaml", |
| 65 | "Inventory/Decorator/Replaceable.interface.yaml", |
| 66 | "State/Decorator/OperationalStatus.interface.yaml", |
| 67 | ] |
Steven Sombar | 5c006d3 | 2018-10-08 09:35:38 -0500 | [diff] [blame] | 68 | |
George Keishing | 1eab883 | 2020-07-09 06:30:57 -0500 | [diff] [blame] | 69 | # Append to inventory list |
| 70 | yaml_inventory_list.append(yaml_fru_list) |
| 71 | yaml_inventory_list.append(yaml_core_list) |
| 72 | yaml_inventory_list.append(yaml_fan_list) |
| 73 | yaml_inventory_list.append(yaml_fan_wc_list) |
| 74 | yaml_inventory_list.append(yaml_gpu_list) |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 75 | |
George Keishing | 1eab883 | 2020-07-09 06:30:57 -0500 | [diff] [blame] | 76 | print_var(yaml_inventory_list) |
George Keishing | 9ef1fd4 | 2017-03-10 14:52:38 -0600 | [diff] [blame] | 77 | |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 78 | # Populate Inventory data |
| 79 | inventory_dict = {} |
| 80 | |
George Keishing | 1eab883 | 2020-07-09 06:30:57 -0500 | [diff] [blame] | 81 | for inv_index in range(len(yaml_inventory_list)): |
| 82 | print_var(inv_index) |
| 83 | inventory_dict[str(inventory_items[inv_index])] = [] |
| 84 | for rel_yaml_file_path in yaml_inventory_list[inv_index]: |
George Keishing | 9ef1fd4 | 2017-03-10 14:52:38 -0600 | [diff] [blame] | 85 | yaml_file_path = base_dir_path + rel_yaml_file_path |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 86 | |
| 87 | # Get the yaml dictionary data |
George Keishing | 9ef1fd4 | 2017-03-10 14:52:38 -0600 | [diff] [blame] | 88 | print_timen("Loading " + yaml_file_path) |
| 89 | f = open(yaml_file_path) |
Yunyun Lin | f87cc0a | 2022-06-08 16:57:04 -0700 | [diff] [blame] | 90 | yaml_data = yaml.safe_load(f) |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 91 | f.close() |
Patrick Williams | 5731818 | 2022-12-08 06:18:26 -0600 | [diff] [blame^] | 92 | for item in range(0, len(yaml_data["properties"])): |
| 93 | tmp_data = yaml_data["properties"][item]["name"] |
George Keishing | 1eab883 | 2020-07-09 06:30:57 -0500 | [diff] [blame] | 94 | inventory_dict[str(inventory_items[inv_index])].append(tmp_data) |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 95 | |
| 96 | # Pretty print json formatter |
Patrick Williams | 5731818 | 2022-12-08 06:18:26 -0600 | [diff] [blame^] | 97 | data = json.dumps( |
| 98 | inventory_dict, |
| 99 | indent=4, |
| 100 | sort_keys=True, |
| 101 | default=str, |
| 102 | separators=(",", ":"), |
| 103 | ) |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 104 | |
| 105 | # Check if there is mismatch in data vs expect list |
| 106 | if len(inventory_dict) != len(inventory_items): |
George Keishing | 178d9bf | 2020-07-09 08:29:29 -0500 | [diff] [blame] | 107 | print_error("The generated list doesn't match Inventory List.\n") |
Patrick Williams | a57fef4 | 2022-12-03 07:00:14 -0600 | [diff] [blame] | 108 | print(data) |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 109 | print_var(inventory_items) |
| 110 | sys.exit() |
| 111 | |
| 112 | # Write dictionary data to inventory file |
Patrick Williams | a57fef4 | 2022-12-03 07:00:14 -0600 | [diff] [blame] | 113 | print("\nGenerated Inventory item json format\n") |
| 114 | print(data) |
Patrick Williams | 5731818 | 2022-12-08 06:18:26 -0600 | [diff] [blame^] | 115 | out = open(fru_inventory_file_path, "w") |
| 116 | out.write("inventory_dict = ") |
George Keishing | ae7c820 | 2017-02-09 10:33:45 -0600 | [diff] [blame] | 117 | out.write(data) |
| 118 | |
| 119 | out.close() |
Patrick Williams | a57fef4 | 2022-12-03 07:00:14 -0600 | [diff] [blame] | 120 | print("\nGenerated Inventory File: %s " % fru_inventory_file_path) |