Skip to content

Commit

Permalink
Merge branch 'paull/ippower' of https://github.com/paulli2017/lisa in…
Browse files Browse the repository at this point in the history
…to paull/ippower
  • Loading branch information
paull committed Dec 10, 2024
2 parents 07ba11e + 5e73428 commit 344ad7e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
24 changes: 16 additions & 8 deletions lisa/sut_orchestrator/baremetal/ip_power.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
import requests

from lisa import schema
from lisa.util import ContextMixin, InitializableMixin, subclasses
from lisa.util import ContextMixin, InitializableMixin, LisaException, subclasses
from lisa.util.logger import get_logger

from .schema import IPPowerSchema

REQUEST_TIMEOUT = 3


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

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

def off(self, port: int) -> None:
def off(self, port: str) -> 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"
)
Expand All @@ -45,10 +47,16 @@ def type_name(cls) -> str:
def type_schema(cls) -> Type[schema.TypedSchema]:
return IPPowerSchema

def on(self, port: int) -> None:
def on(self, port: str) -> None:
request_on = f"{self._request_cmd}{port}=1"
requests.get(request_on)
try:
requests.get(request_on, timeout=REQUEST_TIMEOUT)
except requests.Timeout:
raise LisaException(f"Failed to turn off port {port}")

def off(self, port: int) -> None:
def off(self, port: str) -> None:
request_off = f"{self._request_cmd}{port}=0"
requests.get(request_off)
try:
requests.get(request_off, timeout=REQUEST_TIMEOUT)
except requests.Timeout:
raise LisaException(f"Failed to turn off port {port}")
14 changes: 7 additions & 7 deletions lisa/sut_orchestrator/baremetal/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,24 @@ 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 = field(default="Ip9285", metadata=field_metadata(required=True))
hostname: str = ""
host: str = ""
username: str = ""
password: str = ""

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


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


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

0 comments on commit 344ad7e

Please sign in to comment.