# Copyright (c) 2023-2024 Arista Networks, Inc. # Use of this source code is governed by the Apache License 2.0 # that can be found in the LICENSE file. """Test inputs for anta.tests.hardware.""" from __future__ import annotations from typing import Any from anta.tests.hardware import ( VerifyAdverseDrops, VerifyEnvironmentCooling, VerifyEnvironmentPower, VerifyEnvironmentSystemCooling, VerifyTemperature, VerifyTransceiversManufacturers, VerifyTransceiversTemperature, ) from tests.units.anta_tests import test DATA: list[dict[str, Any]] = [ { "name": "success", "test": VerifyTransceiversManufacturers, "eos_data": [ { "xcvrSlots": { "1": {"mfgName": "Arista Networks", "modelName": "QSFP-100G-DR", "serialNum": "XKT203501340", "hardwareRev": "21"}, "2": {"mfgName": "Arista Networks", "modelName": "QSFP-100G-DR", "serialNum": "XKT203501337", "hardwareRev": "21"}, }, }, ], "inputs": {"manufacturers": ["Arista Networks"]}, "expected": {"result": "success"}, }, { "name": "failure", "test": VerifyTransceiversManufacturers, "eos_data": [ { "xcvrSlots": { "1": {"mfgName": "Arista Networks", "modelName": "QSFP-100G-DR", "serialNum": "XKT203501340", "hardwareRev": "21"}, "2": {"mfgName": "Arista Networks", "modelName": "QSFP-100G-DR", "serialNum": "XKT203501337", "hardwareRev": "21"}, }, }, ], "inputs": {"manufacturers": ["Arista"]}, "expected": {"result": "failure", "messages": ["Some transceivers are from unapproved manufacturers: {'1': 'Arista Networks', '2': 'Arista Networks'}"]}, }, { "name": "success", "test": VerifyTemperature, "eos_data": [ { "powercycleOnOverheat": "False", "ambientThreshold": 45, "cardSlots": [], "shutdownOnOverheat": "True", "systemStatus": "temperatureOk", "recoveryModeOnOverheat": "recoveryModeNA", }, ], "inputs": None, "expected": {"result": "success"}, }, { "name": "failure", "test": VerifyTemperature, "eos_data": [ { "powercycleOnOverheat": "False", "ambientThreshold": 45, "cardSlots": [], "shutdownOnOverheat": "True", "systemStatus": "temperatureKO", "recoveryModeOnOverheat": "recoveryModeNA", }, ], "inputs": None, "expected": {"result": "failure", "messages": ["Device temperature exceeds acceptable limits. Current system status: 'temperatureKO'"]}, }, { "name": "success", "test": VerifyTransceiversTemperature, "eos_data": [ { "tempSensors": [ { "maxTemperature": 25.03125, "maxTemperatureLastChange": 1682509618.2227979, "hwStatus": "ok", "alertCount": 0, "description": "Xcvr54 temp sensor", "overheatThreshold": 70.0, "criticalThreshold": 70.0, "inAlertState": False, "targetTemperature": 62.0, "relPos": "54", "currentTemperature": 24.171875, "setPointTemperature": 61.8, "pidDriverCount": 0, "isPidDriver": False, "name": "DomTemperatureSensor54", }, ], "cardSlots": [], }, ], "inputs": None, "expected": {"result": "success"}, }, { "name": "failure-hwStatus", "test": VerifyTransceiversTemperature, "eos_data": [ { "tempSensors": [ { "maxTemperature": 25.03125, "maxTemperatureLastChange": 1682509618.2227979, "hwStatus": "ko", "alertCount": 0, "description": "Xcvr54 temp sensor", "overheatThreshold": 70.0, "criticalThreshold": 70.0, "inAlertState": False, "targetTemperature": 62.0, "relPos": "54", "currentTemperature": 24.171875, "setPointTemperature": 61.8, "pidDriverCount": 0, "isPidDriver": False, "name": "DomTemperatureSensor54", }, ], "cardSlots": [], }, ], "inputs": None, "expected": { "result": "failure", "messages": [ "The following sensors are operating outside the acceptable temperature range or have raised alerts: " "{'DomTemperatureSensor54': " "{'hwStatus': 'ko', 'alertCount': 0}}", ], }, }, { "name": "failure-alertCount", "test": VerifyTransceiversTemperature, "eos_data": [ { "tempSensors": [ { "maxTemperature": 25.03125, "maxTemperatureLastChange": 1682509618.2227979, "hwStatus": "ok", "alertCount": 1, "description": "Xcvr54 temp sensor", "overheatThreshold": 70.0, "criticalThreshold": 70.0, "inAlertState": False, "targetTemperature": 62.0, "relPos": "54", "currentTemperature": 24.171875, "setPointTemperature": 61.8, "pidDriverCount": 0, "isPidDriver": False, "name": "DomTemperatureSensor54", }, ], "cardSlots": [], }, ], "inputs": None, "expected": { "result": "failure", "messages": [ "The following sensors are operating outside the acceptable temperature range or have raised alerts: " "{'DomTemperatureSensor54': " "{'hwStatus': 'ok', 'alertCount': 1}}", ], }, }, { "name": "success", "test": VerifyEnvironmentSystemCooling, "eos_data": [ { "defaultZones": False, "numCoolingZones": [], "coolingMode": "automatic", "ambientTemperature": 24.5, "shutdownOnInsufficientFans": True, "airflowDirection": "frontToBackAirflow", "overrideFanSpeed": 0, "powerSupplySlots": [], "fanTraySlots": [], "minFanSpeed": 0, "currentZones": 1, "configuredZones": 0, "systemStatus": "coolingOk", }, ], "inputs": None, "expected": {"result": "success"}, }, { "name": "failure", "test": VerifyEnvironmentSystemCooling, "eos_data": [ { "defaultZones": False, "numCoolingZones": [], "coolingMode": "automatic", "ambientTemperature": 24.5, "shutdownOnInsufficientFans": True, "airflowDirection": "frontToBackAirflow", "overrideFanSpeed": 0, "powerSupplySlots": [], "fanTraySlots": [], "minFanSpeed": 0, "currentZones": 1, "configuredZones": 0, "systemStatus": "coolingKo", }, ], "inputs": None, "expected": {"result": "failure", "messages": ["Device system cooling is not OK: 'coolingKo'"]}, }, { "name": "success", "test": VerifyEnvironmentCooling, "eos_data": [ { "defaultZones": False, "numCoolingZones": [], "coolingMode": "automatic", "ambientTemperature": 24.5, "shutdownOnInsufficientFans": True, "airflowDirection": "frontToBackAirflow", "overrideFanSpeed": 0, "powerSupplySlots": [ { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498937.0240965, "maxSpeed": 23000, "lastSpeedStableChangeTime": 1682499033.0403435, "configuredSpeed": 30, "actualSpeed": 33, "speedHwOverride": True, "speedStable": True, "label": "PowerSupply1/1", }, ], "speed": 30, "label": "PowerSupply1", }, { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498935.9121106, "maxSpeed": 23000, "lastSpeedStableChangeTime": 1682499092.4665174, "configuredSpeed": 30, "actualSpeed": 33, "speedHwOverride": True, "speedStable": True, "label": "PowerSupply2/1", }, ], "speed": 30, "label": "PowerSupply2", }, ], "fanTraySlots": [ { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498923.9303148, "maxSpeed": 17500, "lastSpeedStableChangeTime": 1682498975.0139885, "configuredSpeed": 30, "actualSpeed": 29, "speedHwOverride": False, "speedStable": True, "label": "1/1", }, ], "speed": 30, "label": "1", }, { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498923.9304729, "maxSpeed": 17500, "lastSpeedStableChangeTime": 1682498939.9329433, "configuredSpeed": 30, "actualSpeed": 30, "speedHwOverride": False, "speedStable": True, "label": "2/1", }, ], "speed": 30, "label": "2", }, { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498923.9383528, "maxSpeed": 17500, "lastSpeedStableChangeTime": 1682498975.0140095, "configuredSpeed": 30, "actualSpeed": 30, "speedHwOverride": False, "speedStable": True, "label": "3/1", }, ], "speed": 30, "label": "3", }, { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498923.9303904, "maxSpeed": 17500, "lastSpeedStableChangeTime": 1682498975.0140295, "configuredSpeed": 30, "actualSpeed": 30, "speedHwOverride": False, "speedStable": True, "label": "4/1", }, ], "speed": 30, "label": "4", }, ], "minFanSpeed": 0, "currentZones": 1, "configuredZones": 0, "systemStatus": "coolingOk", }, ], "inputs": {"states": ["ok"]}, "expected": {"result": "success"}, }, { "name": "success-additional-states", "test": VerifyEnvironmentCooling, "eos_data": [ { "defaultZones": False, "numCoolingZones": [], "coolingMode": "automatic", "ambientTemperature": 24.5, "shutdownOnInsufficientFans": True, "airflowDirection": "frontToBackAirflow", "overrideFanSpeed": 0, "powerSupplySlots": [ { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498937.0240965, "maxSpeed": 23000, "lastSpeedStableChangeTime": 1682499033.0403435, "configuredSpeed": 30, "actualSpeed": 33, "speedHwOverride": True, "speedStable": True, "label": "PowerSupply1/1", }, ], "speed": 30, "label": "PowerSupply1", }, { "status": "ok", "fans": [ { "status": "Not Inserted", "uptime": 1682498935.9121106, "maxSpeed": 23000, "lastSpeedStableChangeTime": 1682499092.4665174, "configuredSpeed": 30, "actualSpeed": 33, "speedHwOverride": True, "speedStable": True, "label": "PowerSupply2/1", }, ], "speed": 30, "label": "PowerSupply2", }, ], "fanTraySlots": [ { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498923.9303148, "maxSpeed": 17500, "lastSpeedStableChangeTime": 1682498975.0139885, "configuredSpeed": 30, "actualSpeed": 29, "speedHwOverride": False, "speedStable": True, "label": "1/1", }, ], "speed": 30, "label": "1", }, { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498923.9304729, "maxSpeed": 17500, "lastSpeedStableChangeTime": 1682498939.9329433, "configuredSpeed": 30, "actualSpeed": 30, "speedHwOverride": False, "speedStable": True, "label": "2/1", }, ], "speed": 30, "label": "2", }, { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498923.9383528, "maxSpeed": 17500, "lastSpeedStableChangeTime": 1682498975.0140095, "configuredSpeed": 30, "actualSpeed": 30, "speedHwOverride": False, "speedStable": True, "label": "3/1", }, ], "speed": 30, "label": "3", }, { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498923.9303904, "maxSpeed": 17500, "lastSpeedStableChangeTime": 1682498975.0140295, "configuredSpeed": 30, "actualSpeed": 30, "speedHwOverride": False, "speedStable": True, "label": "4/1", }, ], "speed": 30, "label": "4", }, ], "minFanSpeed": 0, "currentZones": 1, "configuredZones": 0, "systemStatus": "coolingOk", }, ], "inputs": {"states": ["ok", "Not Inserted"]}, "expected": {"result": "success"}, }, { "name": "failure-fan-tray", "test": VerifyEnvironmentCooling, "eos_data": [ { "defaultZones": False, "numCoolingZones": [], "coolingMode": "automatic", "ambientTemperature": 24.5, "shutdownOnInsufficientFans": True, "airflowDirection": "frontToBackAirflow", "overrideFanSpeed": 0, "powerSupplySlots": [ { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498937.0240965, "maxSpeed": 23000, "lastSpeedStableChangeTime": 1682499033.0403435, "configuredSpeed": 30, "actualSpeed": 33, "speedHwOverride": True, "speedStable": True, "label": "PowerSupply1/1", }, ], "speed": 30, "label": "PowerSupply1", }, { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498935.9121106, "maxSpeed": 23000, "lastSpeedStableChangeTime": 1682499092.4665174, "configuredSpeed": 30, "actualSpeed": 33, "speedHwOverride": True, "speedStable": True, "label": "PowerSupply2/1", }, ], "speed": 30, "label": "PowerSupply2", }, ], "fanTraySlots": [ { "status": "ok", "fans": [ { "status": "down", "uptime": 1682498923.9303148, "maxSpeed": 17500, "lastSpeedStableChangeTime": 1682498975.0139885, "configuredSpeed": 30, "actualSpeed": 29, "speedHwOverride": False, "speedStable": True, "label": "1/1", }, ], "speed": 30, "label": "1", }, { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498923.9304729, "maxSpeed": 17500, "lastSpeedStableChangeTime": 1682498939.9329433, "configuredSpeed": 30, "actualSpeed": 30, "speedHwOverride": False, "speedStable": True, "label": "2/1", }, ], "speed": 30, "label": "2", }, { "status": "ok", "fans": [ { "status": "Not Inserted", "uptime": 1682498923.9383528, "maxSpeed": 17500, "lastSpeedStableChangeTime": 1682498975.0140095, "configuredSpeed": 30, "actualSpeed": 30, "speedHwOverride": False, "speedStable": True, "label": "3/1", }, ], "speed": 30, "label": "3", }, { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498923.9303904, "maxSpeed": 17500, "lastSpeedStableChangeTime": 1682498975.0140295, "configuredSpeed": 30, "actualSpeed": 30, "speedHwOverride": False, "speedStable": True, "label": "4/1", }, ], "speed": 30, "label": "4", }, ], "minFanSpeed": 0, "currentZones": 1, "configuredZones": 0, "systemStatus": "CoolingKo", }, ], "inputs": {"states": ["ok", "Not Inserted"]}, "expected": {"result": "failure", "messages": ["Fan 1/1 on Fan Tray 1 is: 'down'"]}, }, { "name": "failure-power-supply", "test": VerifyEnvironmentCooling, "eos_data": [ { "defaultZones": False, "numCoolingZones": [], "coolingMode": "automatic", "ambientTemperature": 24.5, "shutdownOnInsufficientFans": True, "airflowDirection": "frontToBackAirflow", "overrideFanSpeed": 0, "powerSupplySlots": [ { "status": "ok", "fans": [ { "status": "down", "uptime": 1682498937.0240965, "maxSpeed": 23000, "lastSpeedStableChangeTime": 1682499033.0403435, "configuredSpeed": 30, "actualSpeed": 33, "speedHwOverride": True, "speedStable": True, "label": "PowerSupply1/1", }, ], "speed": 30, "label": "PowerSupply1", }, { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498935.9121106, "maxSpeed": 23000, "lastSpeedStableChangeTime": 1682499092.4665174, "configuredSpeed": 30, "actualSpeed": 33, "speedHwOverride": True, "speedStable": True, "label": "PowerSupply2/1", }, ], "speed": 30, "label": "PowerSupply2", }, ], "fanTraySlots": [ { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498923.9303148, "maxSpeed": 17500, "lastSpeedStableChangeTime": 1682498975.0139885, "configuredSpeed": 30, "actualSpeed": 29, "speedHwOverride": False, "speedStable": True, "label": "1/1", }, ], "speed": 30, "label": "1", }, { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498923.9304729, "maxSpeed": 17500, "lastSpeedStableChangeTime": 1682498939.9329433, "configuredSpeed": 30, "actualSpeed": 30, "speedHwOverride": False, "speedStable": True, "label": "2/1", }, ], "speed": 30, "label": "2", }, { "status": "ok", "fans": [ { "status": "Not Inserted", "uptime": 1682498923.9383528, "maxSpeed": 17500, "lastSpeedStableChangeTime": 1682498975.0140095, "configuredSpeed": 30, "actualSpeed": 30, "speedHwOverride": False, "speedStable": True, "label": "3/1", }, ], "speed": 30, "label": "3", }, { "status": "ok", "fans": [ { "status": "ok", "uptime": 1682498923.9303904, "maxSpeed": 17500, "lastSpeedStableChangeTime": 1682498975.0140295, "configuredSpeed": 30, "actualSpeed": 30, "speedHwOverride": False, "speedStable": True, "label": "4/1", }, ], "speed": 30, "label": "4", }, ], "minFanSpeed": 0, "currentZones": 1, "configuredZones": 0, "systemStatus": "CoolingKo", }, ], "inputs": {"states": ["ok", "Not Inserted"]}, "expected": {"result": "failure", "messages": ["Fan PowerSupply1/1 on PowerSupply PowerSupply1 is: 'down'"]}, }, { "name": "success", "test": VerifyEnvironmentPower, "eos_data": [ { "powerSupplies": { "1": { "outputPower": 0.0, "modelName": "PWR-500AC-F", "capacity": 500.0, "tempSensors": { "TempSensorP1/2": {"status": "ok", "temperature": 0.0}, "TempSensorP1/3": {"status": "ok", "temperature": 0.0}, "TempSensorP1/1": {"status": "ok", "temperature": 0.0}, }, "fans": {"FanP1/1": {"status": "ok", "speed": 33}}, "state": "ok", "inputCurrent": 0.0, "dominant": False, "inputVoltage": 0.0, "outputCurrent": 0.0, "managed": True, }, "2": { "outputPower": 117.375, "uptime": 1682498935.9121966, "modelName": "PWR-500AC-F", "capacity": 500.0, "tempSensors": { "TempSensorP2/1": {"status": "ok", "temperature": 39.0}, "TempSensorP2/3": {"status": "ok", "temperature": 43.0}, "TempSensorP2/2": {"status": "ok", "temperature": 31.0}, }, "fans": {"FanP2/1": {"status": "ok", "speed": 33}}, "state": "ok", "inputCurrent": 0.572265625, "dominant": False, "inputVoltage": 232.5, "outputCurrent": 9.828125, "managed": True, }, }, }, ], "inputs": {"states": ["ok"]}, "expected": {"result": "success"}, }, { "name": "success-additional-states", "test": VerifyEnvironmentPower, "eos_data": [ { "powerSupplies": { "1": { "outputPower": 0.0, "modelName": "PWR-500AC-F", "capacity": 500.0, "tempSensors": { "TempSensorP1/2": {"status": "ok", "temperature": 0.0}, "TempSensorP1/3": {"status": "ok", "temperature": 0.0}, "TempSensorP1/1": {"status": "ok", "temperature": 0.0}, }, "fans": {"FanP1/1": {"status": "ok", "speed": 33}}, "state": "Not Inserted", "inputCurrent": 0.0, "dominant": False, "inputVoltage": 0.0, "outputCurrent": 0.0, "managed": True, }, "2": { "outputPower": 117.375, "uptime": 1682498935.9121966, "modelName": "PWR-500AC-F", "capacity": 500.0, "tempSensors": { "TempSensorP2/1": {"status": "ok", "temperature": 39.0}, "TempSensorP2/3": {"status": "ok", "temperature": 43.0}, "TempSensorP2/2": {"status": "ok", "temperature": 31.0}, }, "fans": {"FanP2/1": {"status": "ok", "speed": 33}}, "state": "ok", "inputCurrent": 0.572265625, "dominant": False, "inputVoltage": 232.5, "outputCurrent": 9.828125, "managed": True, }, }, }, ], "inputs": {"states": ["ok", "Not Inserted"]}, "expected": {"result": "success"}, }, { "name": "failure", "test": VerifyEnvironmentPower, "eos_data": [ { "powerSupplies": { "1": { "outputPower": 0.0, "modelName": "PWR-500AC-F", "capacity": 500.0, "tempSensors": { "TempSensorP1/2": {"status": "ok", "temperature": 0.0}, "TempSensorP1/3": {"status": "ok", "temperature": 0.0}, "TempSensorP1/1": {"status": "ok", "temperature": 0.0}, }, "fans": {"FanP1/1": {"status": "ok", "speed": 33}}, "state": "powerLoss", "inputCurrent": 0.0, "dominant": False, "inputVoltage": 0.0, "outputCurrent": 0.0, "managed": True, }, "2": { "outputPower": 117.375, "uptime": 1682498935.9121966, "modelName": "PWR-500AC-F", "capacity": 500.0, "tempSensors": { "TempSensorP2/1": {"status": "ok", "temperature": 39.0}, "TempSensorP2/3": {"status": "ok", "temperature": 43.0}, "TempSensorP2/2": {"status": "ok", "temperature": 31.0}, }, "fans": {"FanP2/1": {"status": "ok", "speed": 33}}, "state": "ok", "inputCurrent": 0.572265625, "dominant": False, "inputVoltage": 232.5, "outputCurrent": 9.828125, "managed": True, }, }, }, ], "inputs": {"states": ["ok"]}, "expected": {"result": "failure", "messages": ["The following power supplies status are not in the accepted states list: {'1': {'state': 'powerLoss'}}"]}, }, { "name": "success", "test": VerifyAdverseDrops, "eos_data": [{"totalAdverseDrops": 0}], "inputs": None, "expected": {"result": "success"}, }, { "name": "failure", "test": VerifyAdverseDrops, "eos_data": [{"totalAdverseDrops": 10}], "inputs": None, "expected": {"result": "failure", "messages": ["Device totalAdverseDrops counter is: '10'"]}, }, ]