#2887 - Corrected failures seen when generating services from config & syntax issues. Wireless Router tests currently fail due to port 1 being disabled on startup

This commit is contained in:
Charlie Crane
2025-01-29 16:57:25 +00:00
parent 51f1c91e15
commit 4b42a74ac8
7 changed files with 26 additions and 21 deletions

View File

@@ -263,6 +263,9 @@ class WirelessRouter(Router, identifier="wireless_router"):
:rtype: WirelessRouter :rtype: WirelessRouter
""" """
router = cls(config=cls.ConfigSchema(**config)) router = cls(config=cls.ConfigSchema(**config))
router.operating_state = (
NodeOperatingState.ON if not (p := config.get("operating_state")) else NodeOperatingState[p.upper()]
)
if "router_interface" in config: if "router_interface" in config:
ip_address = config["router_interface"]["ip_address"] ip_address = config["router_interface"]["ip_address"]
subnet_mask = config["router_interface"]["subnet_mask"] subnet_mask = config["router_interface"]["subnet_mask"]
@@ -294,7 +297,4 @@ class WirelessRouter(Router, identifier="wireless_router"):
next_hop_ip_address=IPv4Address(route.get("next_hop_ip_address")), next_hop_ip_address=IPv4Address(route.get("next_hop_ip_address")),
metric=float(route.get("metric", 0)), metric=float(route.get("metric", 0)),
) )
router.operating_state = (
NodeOperatingState.ON if not (p := config.get("operating_state")) else NodeOperatingState[p.upper()]
)
return router return router

View File

@@ -31,12 +31,11 @@ class DatabaseService(Service, identifier="DatabaseService"):
type: str = "DatabaseService" type: str = "DatabaseService"
backup_server_ip: Optional[IPv4Address] = None backup_server_ip: Optional[IPv4Address] = None
db_password: Optional[str] = None
"""Password that needs to be provided by clients if they want to connect to the DatabaseService."""
config: "DatabaseService.ConfigSchema" = Field(default_factory=lambda: DatabaseService.ConfigSchema()) config: "DatabaseService.ConfigSchema" = Field(default_factory=lambda: DatabaseService.ConfigSchema())
password: Optional[str] = None
"""Password that needs to be provided by clients if they want to connect to the DatabaseService."""
backup_server_ip: IPv4Address = None backup_server_ip: IPv4Address = None
"""IP address of the backup server.""" """IP address of the backup server."""
@@ -217,7 +216,7 @@ class DatabaseService(Service, identifier="DatabaseService"):
SoftwareHealthState.FIXING, SoftwareHealthState.FIXING,
SoftwareHealthState.COMPROMISED, SoftwareHealthState.COMPROMISED,
]: ]:
if self.password == password: if self.config.db_password == password:
status_code = 200 # ok status_code = 200 # ok
connection_id = self._generate_connection_id() connection_id = self._generate_connection_id()
# try to create connection # try to create connection

View File

@@ -22,11 +22,13 @@ class DNSClient(Service, identifier="DNSClient"):
type: str = "DNSClient" type: str = "DNSClient"
dns_server: Optional[IPv4Address] = None
"The DNS Server the client sends requests to."
config: "DNSClient.ConfigSchema" = Field(default_factory=lambda: DNSClient.ConfigSchema()) config: "DNSClient.ConfigSchema" = Field(default_factory=lambda: DNSClient.ConfigSchema())
dns_cache: Dict[str, IPv4Address] = {} dns_cache: Dict[str, IPv4Address] = {}
"A dict of known mappings between domain/URLs names and IPv4 addresses." "A dict of known mappings between domain/URLs names and IPv4 addresses."
dns_server: Optional[IPv4Address] = None
"The DNS Server the client sends requests to."
def __init__(self, **kwargs): def __init__(self, **kwargs):
kwargs["name"] = "DNSClient" kwargs["name"] = "DNSClient"

View File

@@ -23,14 +23,17 @@ class FTPServer(FTPServiceABC, identifier="FTPServer"):
config: "FTPServer.ConfigSchema" = Field(default_factory=lambda: FTPServer.ConfigSchema()) config: "FTPServer.ConfigSchema" = Field(default_factory=lambda: FTPServer.ConfigSchema())
server_password: Optional[str] = None
"""Password needed to connect to FTP server. Default is None."""
class ConfigSchema(Service.ConfigSchema): class ConfigSchema(Service.ConfigSchema):
"""ConfigSchema for FTPServer.""" """ConfigSchema for FTPServer."""
type: str = "FTPServer" type: str = "FTPServer"
server_password: Optional[str] = None
"""Password needed to connect to FTP server. Default is None."""
def __init__(self, **kwargs): def __init__(self, **kwargs):
kwargs["name"] = "FTPServer" kwargs["name"] = "FTPServer"
kwargs["port"] = PORT_LOOKUP["FTP"] kwargs["port"] = PORT_LOOKUP["FTP"]

View File

@@ -22,10 +22,12 @@ class NTPClient(Service, identifier="NTPClient"):
type: str = "NTPClient" type: str = "NTPClient"
ntp_server_ip: Optional[IPv4Address] = None
"The NTP server the client sends requests to."
config: "NTPClient.ConfigSchema" = Field(default_factory=lambda: NTPClient.ConfigSchema()) config: "NTPClient.ConfigSchema" = Field(default_factory=lambda: NTPClient.ConfigSchema())
ntp_server: Optional[IPv4Address] = None
"The NTP server the client sends requests to."
time: Optional[datetime] = None time: Optional[datetime] = None
def __init__(self, **kwargs): def __init__(self, **kwargs):
@@ -42,8 +44,8 @@ class NTPClient(Service, identifier="NTPClient"):
:param ntp_server_ip_address: IPv4 address of NTP server. :param ntp_server_ip_address: IPv4 address of NTP server.
:param ntp_client_ip_Address: IPv4 address of NTP client. :param ntp_client_ip_Address: IPv4 address of NTP client.
""" """
self.ntp_server = ntp_server_ip_address self.config.ntp_server_ip = ntp_server_ip_address
self.sys_log.info(f"{self.name}: ntp_server: {self.ntp_server}") self.sys_log.info(f"{self.name}: ntp_server: {self.config.ntp_server_ip}")
def describe_state(self) -> Dict: def describe_state(self) -> Dict:
""" """
@@ -105,10 +107,10 @@ class NTPClient(Service, identifier="NTPClient"):
def request_time(self) -> None: def request_time(self) -> None:
"""Send request to ntp_server.""" """Send request to ntp_server."""
if self.ntp_server: if self.config.ntp_server_ip:
self.software_manager.session_manager.receive_payload_from_software_manager( self.software_manager.session_manager.receive_payload_from_software_manager(
payload=NTPPacket(), payload=NTPPacket(),
dst_ip_address=self.ntp_server, dst_ip_address=self.config.ntp_server_ip,
src_port=self.port, src_port=self.port,
dst_port=self.port, dst_port=self.port,
ip_protocol=self.protocol, ip_protocol=self.protocol,

View File

@@ -387,7 +387,6 @@ def install_stuff_to_sim(sim: Simulation):
"ip_address": "10.0.1.2", "ip_address": "10.0.1.2",
"subnet_mask": "255.255.255.0", "subnet_mask": "255.255.255.0",
"default_gateway": "10.0.1.1", "default_gateway": "10.0.1.1",
"start_up_duration": 0,
} }
client_1: Computer = Computer.from_config(config=client_1_cfg) client_1: Computer = Computer.from_config(config=client_1_cfg)
client_1.power_on() client_1.power_on()

View File

@@ -31,14 +31,14 @@ class ExtendedService(Service, identifier="ExtendedService"):
type: str = "ExtendedService" type: str = "ExtendedService"
backup_server_ip: IPv4Address = None
"""IP address of the backup server."""
config: "ExtendedService.ConfigSchema" = Field(default_factory=lambda: ExtendedService.ConfigSchema()) config: "ExtendedService.ConfigSchema" = Field(default_factory=lambda: ExtendedService.ConfigSchema())
password: Optional[str] = None password: Optional[str] = None
"""Password that needs to be provided by clients if they want to connect to the DatabaseService.""" """Password that needs to be provided by clients if they want to connect to the DatabaseService."""
backup_server_ip: IPv4Address = None
"""IP address of the backup server."""
latest_backup_directory: str = None latest_backup_directory: str = None
"""Directory of latest backup.""" """Directory of latest backup."""