diff --git a/lisa/sut_orchestrator/baremetal/ip_power.py b/lisa/sut_orchestrator/baremetal/ip_power.py index 4c8c8f888c..96faa27998 100644 --- a/lisa/sut_orchestrator/baremetal/ip_power.py +++ b/lisa/sut_orchestrator/baremetal/ip_power.py @@ -12,6 +12,7 @@ from .schema import IPPowerSchema REQUEST_TIMEOUT = 3 +REQUEST_SUCCESS_CODE = 200 class IPPower(subclasses.BaseClassWithRunbookMixin, ContextMixin, InitializableMixin): @@ -49,14 +50,19 @@ def type_schema(cls) -> Type[schema.TypedSchema]: def on(self, port: str) -> None: request_on = f"{self._request_cmd}{port}=1" - try: - requests.get(request_on, timeout=REQUEST_TIMEOUT) - except requests.Timeout: - raise LisaException(f"Failed to turn off port {port}") + self._set_ip_power(request_on) def off(self, port: str) -> None: request_off = f"{self._request_cmd}{port}=0" + self._set_ip_power(request_off) + + def _set_ip_power(self, power_cmd: str) -> None: try: - requests.get(request_off, timeout=REQUEST_TIMEOUT) - except requests.Timeout: - raise LisaException(f"Failed to turn off port {port}") + response = requests.get(power_cmd, timeout=REQUEST_TIMEOUT) + response.raise_for_status() + except requests.HTTPError as http_err: + raise LisaException(f"HTTP error: {http_err} in set_ip_power occurred") + except Exception as err: + raise LisaException(f"Other Error: {err} in set_ip_power occurred") + else: + self._log.debug(f"Command {power_cmd} in set_ip_power done") diff --git a/lisa/sut_orchestrator/baremetal/schema.py b/lisa/sut_orchestrator/baremetal/schema.py index 74acfe23d5..0772190344 100644 --- a/lisa/sut_orchestrator/baremetal/schema.py +++ b/lisa/sut_orchestrator/baremetal/schema.py @@ -74,7 +74,7 @@ class KeyLoaderSchema(schema.TypedSchema, schema.ExtendableSchemaMixin): @dataclass_json() -@dataclass +@dataclass class BootConfigSchema(schema.TypedSchema, schema.ExtendableSchemaMixin): type: str = field(default="boot_config", metadata=field_metadata(required=True))