diff --git a/anta/tests/hardware.py b/anta/tests/hardware.py index f44657a99..58f2b36dc 100644 --- a/anta/tests/hardware.py +++ b/anta/tests/hardware.py @@ -9,7 +9,7 @@ from typing import TYPE_CHECKING, ClassVar, Literal -from anta.custom_types import PowerSupplyFanStatus, PowerSupplyStatus +from anta.custom_types import PositiveInteger, PowerSupplyFanStatus, PowerSupplyStatus from anta.decorators import skip_on_platforms from anta.models import AntaCommand, AntaTest @@ -203,12 +203,13 @@ def test(self) -> None: class VerifyEnvironmentPower(AntaTest): - """Verifies the power supplies status. + """Verifies the power supplies state and input voltage. Expected Results ---------------- - * Success: The test will pass if the power supplies status are within the accepted states list. - * Failure: The test will fail if some power supplies status is not within the accepted states list. + * Success: The test will pass if all power supplies are in an accepted state and their input voltage is greater than or equal to `min_input_voltage` + (if provided). + * Failure: The test will fail if any power supply is in an unaccepted state or its input voltage is less than `min_input_voltage` (if provided). Examples -------- @@ -227,7 +228,9 @@ class Input(AntaTest.Input): """Input model for the VerifyEnvironmentPower test.""" states: list[PowerSupplyStatus] - """List of accepted states list of power supplies status.""" + """List of accepted states for power supplies.""" + min_input_voltage: PositiveInteger | None = None + """Optional minimum input voltage (Volts) to verify.""" @skip_on_platforms(["cEOSLab", "vEOS-lab", "cEOSCloudLab", "vEOS"]) @AntaTest.anta_test @@ -240,6 +243,12 @@ def test(self) -> None: if (state := value["state"]) not in self.inputs.states: self.result.is_failure(f"Power Slot: {power_supply} - Invalid power supplies state - Expected: {', '.join(self.inputs.states)} Actual: {state}") + # Verify if the power supply voltage is greater than the minimum input voltage + if self.inputs.min_input_voltage and value["inputVoltage"] < self.inputs.min_input_voltage: + self.result.is_failure( + f"Power Supply: {power_supply} - Input voltage mismatch - Expected: > {self.inputs.min_input_voltage} Actual: {value['inputVoltage']}" + ) + class VerifyAdverseDrops(AntaTest): """Verifies there are no adverse drops on DCS-7280 and DCS-7500 family switches. diff --git a/examples/tests.yaml b/examples/tests.yaml index 1efbbffe2..8e90046b7 100644 --- a/examples/tests.yaml +++ b/examples/tests.yaml @@ -224,7 +224,7 @@ anta.tests.hardware: states: - ok - VerifyEnvironmentPower: - # Verifies the power supplies status. + # Verifies the power supplies state and input voltage. states: - ok - VerifyEnvironmentSystemCooling: diff --git a/tests/units/anta_tests/test_hardware.py b/tests/units/anta_tests/test_hardware.py index 14df82ec0..11b1e88e8 100644 --- a/tests/units/anta_tests/test_hardware.py +++ b/tests/units/anta_tests/test_hardware.py @@ -778,6 +778,92 @@ "inputs": {"states": ["ok"]}, "expected": {"result": AntaTestStatus.SUCCESS}, }, + (VerifyEnvironmentPower, "success-min_power-voltage"): { + "eos_data": [ + { + "powerSupplies": { + "1": { + "modelName": "PWR-747AC-RED", + "capacity": 750.0, + "dominant": False, + "inputCurrent": 0.705078125, + "outputCurrent": 9.921875, + "inputVoltage": 206.25, + "outputVoltage": 12.025390625, + "outputPower": 119.375, + "state": "ok", + "uptime": 1730845612.5112484, + "fans": {"FanP1/1": {"status": "ok", "speed": 33}}, + "tempSensors": {"TempSensorP1/2": {"status": "ok", "temperature": 50.0}, "TempSensorP1/1": {"status": "ok", "temperature": 61.0}}, + "managed": True, + }, + "2": { + "modelName": "PWR-747AC-RED", + "capacity": 750.0, + "dominant": False, + "inputCurrent": 0.724609375, + "outputCurrent": 10.765625, + "inputVoltage": 204.75, + "outputVoltage": 12.009765625, + "outputPower": 128.0, + "state": "ok", + "uptime": 1730142355.4805274, + "fans": {"FanP2/1": {"status": "ok", "speed": 33}}, + "tempSensors": {"TempSensorP2/2": {"status": "ok", "temperature": 53.0}, "TempSensorP2/1": {"status": "ok", "temperature": 63.0}}, + "managed": True, + }, + } + } + ], + "inputs": {"states": ["ok"], "min_input_voltage": 1}, + "expected": {"result": AntaTestStatus.SUCCESS}, + }, + (VerifyEnvironmentPower, "failure-min_power-voltage"): { + "eos_data": [ + { + "powerSupplies": { + "1": { + "modelName": "PWR-747AC-RED", + "capacity": 750.0, + "dominant": False, + "inputCurrent": 0.705078125, + "outputCurrent": 9.921875, + "inputVoltage": 0.25, + "outputVoltage": 12.025390625, + "outputPower": 119.375, + "state": "ok", + "uptime": 1730845612.5112484, + "fans": {"FanP1/1": {"status": "ok", "speed": 33}}, + "tempSensors": {"TempSensorP1/2": {"status": "ok", "temperature": 50.0}, "TempSensorP1/1": {"status": "ok", "temperature": 61.0}}, + "managed": True, + }, + "2": { + "modelName": "PWR-747AC-RED", + "capacity": 750.0, + "dominant": False, + "inputCurrent": 0.724609375, + "outputCurrent": 10.765625, + "inputVoltage": 0.75, + "outputVoltage": 12.009765625, + "outputPower": 128.0, + "state": "ok", + "uptime": 1730142355.4805274, + "fans": {"FanP2/1": {"status": "ok", "speed": 33}}, + "tempSensors": {"TempSensorP2/2": {"status": "ok", "temperature": 53.0}, "TempSensorP2/1": {"status": "ok", "temperature": 63.0}}, + "managed": True, + }, + } + } + ], + "inputs": {"states": ["ok"], "min_input_voltage": 1}, + "expected": { + "result": AntaTestStatus.FAILURE, + "messages": [ + "Power Supply: 1 - Input voltage mismatch - Expected: > 1 Actual: 0.25", + "Power Supply: 2 - Input voltage mismatch - Expected: > 1 Actual: 0.75", + ], + }, + }, (VerifyEnvironmentPower, "success-additional-states"): { "eos_data": [ {