Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
paull committed Jan 13, 2025
1 parent 9b7f226 commit a0ba5ba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lisa/sut_orchestrator/baremetal/ip_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from .schema import IPPowerSchema

REQUEST_TIMEOUT = 3
REQUEST_SUCCESS_CODE = 200


class IPPower(subclasses.BaseClassWithRunbookMixin, ContextMixin, InitializableMixin):
Expand All @@ -24,20 +23,20 @@ def __init__(self, runbook: IPPowerSchema) -> None:
def type_schema(cls) -> Type[schema.TypedSchema]:
return IPPowerSchema

def on(self, port: str) -> None:
def on(self) -> None:
raise NotImplementedError()

def off(self, port: str) -> None:
def off(self) -> None:
raise NotImplementedError()


class Ip9285(IPPower):
def __init__(self, runbook: IPPowerSchema) -> None:
super().__init__(runbook)
self._request_cmd = (
f"http://{runbook.hostname}/set.cmd?"
f"http://{runbook.host}/set.cmd?"
f"user={runbook.username}+pass="
f"{runbook.password}+cmd=setpower+P6"
f"{runbook.password}+cmd=setpower+P6{runbook.ctrl_port}"
)

@classmethod
Expand All @@ -48,21 +47,21 @@ def type_name(cls) -> str:
def type_schema(cls) -> Type[schema.TypedSchema]:
return IPPowerSchema

def on(self, port: str) -> None:
request_on = f"{self._request_cmd}{port}=1"
def on(self) -> None:
request_on = f"{self._request_cmd}=1"
self._set_ip_power(request_on)

def off(self, port: str) -> None:
request_off = f"{self._request_cmd}{port}=0"
def off(self) -> None:
request_off = f"{self._request_cmd}=0"
self._set_ip_power(request_off)

def _set_ip_power(self, power_cmd: str) -> None:
try:
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")
raise LisaException(f"HTTP error: {http_err} occurred in set_ip_power")
except Exception as err:
raise LisaException(f"Other Error: {err} in set_ip_power occurred")
raise LisaException(f"Other Error: {err} occurred in set_ip_power")
else:
self._log.debug(f"Command {power_cmd} in set_ip_power done")
self._log.debug(f"Command {power_cmd} done in set_ip_power")
19 changes: 19 additions & 0 deletions lisa/sut_orchestrator/baremetal/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ class KeyLoaderSchema(schema.TypedSchema, schema.ExtendableSchemaMixin):
type: str = field(default="build", metadata=field_metadata(required=True))


@dataclass_json()
@dataclass
class BootConfigSchema(schema.TypedSchema, schema.ExtendableSchemaMixin):
type: str = field(default="boot_config", metadata=field_metadata(required=True))


@dataclass_json()
@dataclass
class IPPowerSchema(schema.TypedSchema, schema.ExtendableSchemaMixin):
type: str = "Ip9285"
host: str = ""
username: str = ""
password: str = ""
ctrl_port: str = ""

def __post_init__(self, *args: Any, **kwargs: Any) -> None:
add_secret(self.password)


@dataclass_json()
@dataclass
class ClusterSchema(schema.TypedSchema, schema.ExtendableSchemaMixin):
Expand Down

0 comments on commit a0ba5ba

Please sign in to comment.