Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
paull committed Jan 14, 2025
1 parent 9b7f226 commit b50a704
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 69 deletions.
66 changes: 65 additions & 1 deletion lisa/sut_orchestrator/baremetal/cluster/pxe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
from pathlib import Path
from typing import Any, Optional, Type, cast

import requests

from lisa import features
from lisa.environment import Environment
from lisa.features.serial_console import SerialConsole
from lisa.features import SerialConsole, StartStop
from lisa.node import Node, RemoteNode, quick_connect
from lisa.platform_ import Platform
from lisa.schema import FeatureSettings
Expand All @@ -17,6 +19,8 @@
from ..context import get_node_context
from .cluster import Cluster

REQUEST_TIMEOUT = 3


class RemoteComSerialConsole(features.SerialConsole):
def __init__(
Expand Down Expand Up @@ -103,6 +107,56 @@ def _connect(self) -> None:
self._log.debug("connected to serial console: {serial_port}")


class Ip9285StartStop(features.StartStop):
def __init__(
self, settings: FeatureSettings, node: Node, platform: Platform
) -> None:
super().__init__(settings, node, platform)

def _initialize(self, *args: Any, **kwargs: Any) -> None:
super()._initialize(*args, **kwargs)

context = get_node_context(self._node)
pxe_cluster = cast(schema.PxeCluster, context.cluster)
assert pxe_cluster.start_stop, "start_stop is not defined"

ip_power_runbook = pxe_cluster.start_stop.get_extended_runbook(schema.Ip9285)

self._request_cmd = (
f"http://{ip_power_runbook.host}/set.cmd?"
f"user={ip_power_runbook.username}+pass="
f"{ip_power_runbook.password}+cmd="
f"setpower+P6{ip_power_runbook.ctl_port}"
)

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} occurred in set_ip_power")
except Exception as err:
raise LisaException(f"Other Error: {err} occurred in set_ip_power")
else:
self._log.debug(f"Command {power_cmd} done in set_ip_power")

def _stop(
self,
wait: bool = True,
state: features.StopState = features.StopState.Shutdown,
) -> None:
request_off = f"{self._request_cmd}=0"
self._set_ip_power(request_off)

def _start(self, wait: bool = True) -> None:
request_on = f"{self._request_cmd}=1"
self._set_ip_power(request_on)

def _restart(self, wait: bool = True) -> None:
self._stop()
self._start()


class Pxe(Cluster):
def __init__(self, runbook: schema.ClusterSchema, **kwargs: Any) -> None:
super().__init__(runbook, **kwargs)
Expand All @@ -126,11 +180,21 @@ def get_serial_console(self) -> Type[SerialConsole]:
f"is not supported."
)

def get_start_stop(self) -> Type[StartStop]:
assert self.runbook.start_stop, "start_stop is not defined"
if self.runbook.start_stop.type == "Ip9285":
return Ip9285StartStop
else:
raise NotImplementedError(
f"start_stop type {self.runbook.start_stop.type} " f"is not supported."
)

def deploy(self, environment: Environment) -> Any:
# connect to serial console
for node in environment.nodes.list():
# start serial console to save all log
_ = node.features[features.SerialConsole]
_ = node.features[features.StartStop]

def delete(self, environment: Environment, log: Logger) -> None:
for node in environment.nodes.list():
Expand Down
68 changes: 0 additions & 68 deletions lisa/sut_orchestrator/baremetal/ip_power.py

This file was deleted.

25 changes: 25 additions & 0 deletions lisa/sut_orchestrator/baremetal/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,30 @@ 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):
host: str = ""
username: str = ""
password: str = ""

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


@dataclass_json()
@dataclass
class Ip9285(IPPowerSchema):
type: str = "Ip9285"
ctl_port: str = ""


@dataclass_json()
@dataclass
class ClusterSchema(schema.TypedSchema, schema.ExtendableSchemaMixin):
Expand Down Expand Up @@ -207,6 +231,7 @@ class PxeClient(ClientSchema):
class PxeCluster(ClusterSchema):
type: str = "pxe"
serial_console: Optional[SerialConsoleServer] = field(default=None)
start_stop: Optional[IPPowerSchema] = field(default=None)
client: List[PxeClient] = field(default_factory=list)


Expand Down

0 comments on commit b50a704

Please sign in to comment.