|
9 | 9 | MISSING_PSU = "N/A" |
10 | 10 | PSU_NUM_SENSOR_PATTERN = r'PSU-(\d+)(?:\([A-Z]\))?' |
11 | 11 | SKIPPED_CHECK_TYPES = ["psu_skips", "sensor_skip_per_version"] |
| 12 | +PSU_FAN_DIR_PATTERN = r'-(PSF|PSR)-' |
| 13 | +# PSUs in this dictionary are only supported with the specified manufacturers |
| 14 | +PSU_MANUFACTURER_SUPPORT = {'MTEF-AC-G': ['ACBEL']} |
| 15 | +VPD_DATA_PATH_FORMAT = "/var/run/hw-management/eeprom/psu{PSU_INDEX}_vpd" |
| 16 | +PSU_VPD_MANUFACTURER_FIELD = 'MFR_NAME' |
12 | 17 | logger = logging.getLogger() |
13 | 18 |
|
14 | 19 |
|
@@ -106,6 +111,20 @@ def update_sensor_data(alarm_data, psu_platform_data, psu_numbers): |
106 | 111 | return updated_alarm_data |
107 | 112 |
|
108 | 113 |
|
| 114 | +def parse_psu_manufacturer(duthost, psu_index): |
| 115 | + """ |
| 116 | + The function parses the psu manufacturer of the psu installed at the given index from the vpd_data |
| 117 | + :param duthost: duthost fixture |
| 118 | + :param psu_index: Index of the psu |
| 119 | + :return: The psu manufacturer name as it appears in the psu vpd_data |
| 120 | + """ |
| 121 | + vpd_data_path = VPD_DATA_PATH_FORMAT.format(PSU_INDEX=psu_index) |
| 122 | + manufacturer_cmd = f"cat {vpd_data_path} | grep {PSU_VPD_MANUFACTURER_FIELD}" |
| 123 | + psu_manufacturer_line = duthost.shell(manufacturer_cmd)["stdout"] |
| 124 | + manufacturer_name_ind = 1 |
| 125 | + return psu_manufacturer_line.split(':')[manufacturer_name_ind].strip() |
| 126 | + |
| 127 | + |
109 | 128 | class SensorHelper: |
110 | 129 | """ |
111 | 130 | Helper class to the test_sensors tests |
@@ -159,16 +178,17 @@ def read_psus_from_dut(self): |
159 | 178 | self.missing_psus = set() |
160 | 179 | if self.supports_dynamic_psus: |
161 | 180 | psu_data = json.loads(self.duthost.shell('show platform psu --json')['stdout']) |
162 | | - covered_psus = set(self.psu_sensors_checks.keys()) |
163 | 181 | for psu in psu_data: |
164 | 182 | psu_index, psu_model = psu["index"], psu["model"] |
165 | | - if psu_model in covered_psus: |
166 | | - self.psu_dict[psu_index] = psu_model |
| 183 | + # Ignore PSR/PSF part, as we don't care if the fan is reversed (PSR) or not (PSF) |
| 184 | + psu_model_no_fan_dir = re.sub(PSU_FAN_DIR_PATTERN, '-', psu_model) |
| 185 | + if self.is_supported_psu_model(psu_index, psu_model_no_fan_dir): |
| 186 | + self.psu_dict[psu_index] = psu_model_no_fan_dir |
167 | 187 | elif psu["model"] == MISSING_PSU: |
168 | 188 | self.missing_psus.add(psu_index) |
169 | 189 | logger.warning(f"Slot {psu_index} is missing a PSU.") |
170 | 190 | else: |
171 | | - self.uncovered_psus.add(psu_model) |
| 191 | + self.uncovered_psus.add(psu_model_no_fan_dir) |
172 | 192 |
|
173 | 193 | def platform_supports_dynamic_psu(self): |
174 | 194 | """ |
@@ -277,3 +297,28 @@ def parse_psu_json_mapping(self, psu_nums_to_replace, hardware_version): |
277 | 297 | bus_number = bus_data[0].split('-')[1] |
278 | 298 | psu_json_data[psu_num] = (bus_number, bus_address, psu_side) |
279 | 299 | return psu_json_data |
| 300 | + |
| 301 | + def is_supported_psu_model(self, psu_index, psu_model): |
| 302 | + """ |
| 303 | + This function returns whether the given psu_model should be supported or not |
| 304 | + :param psu_index: The index the psu is installed in |
| 305 | + :param psu_model: A psu model (without fan direction) |
| 306 | + :returns: A boolean stating whether the psu dynamic feature is supported with this psu model |
| 307 | + """ |
| 308 | + covered_psus = set(self.psu_sensors_checks.keys()) |
| 309 | + |
| 310 | + return psu_model in covered_psus and self.is_psu_manufacturer_supported(psu_index, psu_model) |
| 311 | + |
| 312 | + def is_psu_manufacturer_supported(self, psu_index, psu_model): |
| 313 | + """ |
| 314 | + This function returns whether the given psu_model is installed with supported manufacturers |
| 315 | + :param psu_index: The index the psu is installed in |
| 316 | + :param psu_model: A psu model (without fan direction) |
| 317 | + :returns: A boolean stating whether the psu dynamic feature is supported with this psu model its manufacturer |
| 318 | + """ |
| 319 | + manufacturer_supported = True |
| 320 | + if psu_model in PSU_MANUFACTURER_SUPPORT: |
| 321 | + supported_psu_manufacturers = PSU_MANUFACTURER_SUPPORT[psu_model] |
| 322 | + psu_manufacturer = parse_psu_manufacturer(self.duthost, psu_index) |
| 323 | + manufacturer_supported &= psu_manufacturer in supported_psu_manufacturers |
| 324 | + return manufacturer_supported |
0 commit comments