#2887 - Fixed Node unit test failures
This commit is contained in:
@@ -269,7 +269,8 @@ class PrimaiteGame:
|
||||
|
||||
new_node = None
|
||||
if n_type in Node._registry:
|
||||
# simplify down Node creation:
|
||||
if n_type == "wireless_router":
|
||||
node_cfg["airspace"] = net.airspace
|
||||
new_node = Node._registry[n_type].from_config(config=node_cfg)
|
||||
else:
|
||||
msg = f"invalid node type {n_type} in config"
|
||||
|
||||
@@ -178,7 +178,7 @@ class AirSpace(BaseModel):
|
||||
status = "Enabled" if interface.enabled else "Disabled"
|
||||
table.add_row(
|
||||
[
|
||||
interface._connected_node.hostname, # noqa
|
||||
interface._connected_node.config.hostname, # noqa
|
||||
interface.mac_address,
|
||||
interface.ip_address if hasattr(interface, "ip_address") else None,
|
||||
interface.subnet_mask if hasattr(interface, "subnet_mask") else None,
|
||||
|
||||
@@ -7,7 +7,7 @@ from ipaddress import IPv4Address, IPv4Network
|
||||
from typing import Any, ClassVar, Dict, List, Optional, Tuple, Union
|
||||
|
||||
from prettytable import MARKDOWN, PrettyTable
|
||||
from pydantic import Field, validate_call
|
||||
from pydantic import validate_call
|
||||
|
||||
from primaite.interface.request import RequestResponse
|
||||
from primaite.simulator.core import RequestManager, RequestType, SimComponent
|
||||
@@ -1217,16 +1217,18 @@ class Router(NetworkNode, identifier="router"):
|
||||
config: "Router.ConfigSchema"
|
||||
|
||||
class ConfigSchema(NetworkNode.ConfigSchema):
|
||||
|
||||
hostname: str = "router"
|
||||
num_ports: int
|
||||
"""Configuration Schema for Routers."""
|
||||
|
||||
hostname: str = "router"
|
||||
num_ports: int = 5
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
if not kwargs.get("sys_log"):
|
||||
kwargs["sys_log"] = SysLog(kwargs["config"].hostname)
|
||||
if not kwargs.get("acl"):
|
||||
kwargs["acl"] = AccessControlList(sys_log=kwargs["sys_log"], implicit_action=ACLAction.DENY, name=kwargs["config"].hostname)
|
||||
kwargs["acl"] = AccessControlList(
|
||||
sys_log=kwargs["sys_log"], implicit_action=ACLAction.DENY, name=kwargs["config"].hostname
|
||||
)
|
||||
if not kwargs.get("route_table"):
|
||||
kwargs["route_table"] = RouteTable(sys_log=kwargs["sys_log"])
|
||||
super().__init__(**kwargs)
|
||||
@@ -1656,5 +1658,7 @@ class Router(NetworkNode, identifier="router"):
|
||||
next_hop_ip_address = config["default_route"].get("next_hop_ip_address", None)
|
||||
if next_hop_ip_address:
|
||||
router.route_table.set_default_route_next_hop_ip_address(next_hop_ip_address)
|
||||
router.operating_state = NodeOperatingState.ON if not (p := config.get("operating_state")) else NodeOperatingState[p.upper()]
|
||||
router.operating_state = (
|
||||
NodeOperatingState.ON if not (p := config.get("operating_state")) else NodeOperatingState[p.upper()]
|
||||
)
|
||||
return router
|
||||
|
||||
@@ -129,7 +129,7 @@ class WirelessRouter(Router, identifier="wireless_router"):
|
||||
"""Configuration Schema for WirelessRouter nodes within PrimAITE."""
|
||||
|
||||
hostname: str = "WirelessRouter"
|
||||
airspace: Optional[AirSpace] = None
|
||||
airspace: AirSpace
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
@@ -262,9 +262,6 @@ class WirelessRouter(Router, identifier="wireless_router"):
|
||||
:return: WirelessRouter instance.
|
||||
:rtype: WirelessRouter
|
||||
"""
|
||||
operating_state = (
|
||||
NodeOperatingState.ON if not (p := config.get("operating_state")) else NodeOperatingState[p.upper()]
|
||||
)
|
||||
router = cls(config=cls.ConfigSchema(**config))
|
||||
if "router_interface" in config:
|
||||
ip_address = config["router_interface"]["ip_address"]
|
||||
@@ -297,4 +294,7 @@ class WirelessRouter(Router, identifier="wireless_router"):
|
||||
next_hop_ip_address=IPv4Address(route.get("next_hop_ip_address")),
|
||||
metric=float(route.get("metric", 0)),
|
||||
)
|
||||
router.operating_state = (
|
||||
NodeOperatingState.ON if not (p := config.get("operating_state")) else NodeOperatingState[p.upper()]
|
||||
)
|
||||
return router
|
||||
|
||||
@@ -208,7 +208,7 @@ class NMAP(Application, identifier="NMAP"):
|
||||
if show:
|
||||
table = PrettyTable(["IP Address", "Can Ping"])
|
||||
table.align = "l"
|
||||
table.title = f"{self.software_manager.node.hostname} NMAP Ping Scan"
|
||||
table.title = f"{self.software_manager.node.config.hostname} NMAP Ping Scan"
|
||||
|
||||
ip_addresses = self._explode_ip_address_network_array(target_ip_address)
|
||||
|
||||
@@ -367,7 +367,7 @@ class NMAP(Application, identifier="NMAP"):
|
||||
if show:
|
||||
table = PrettyTable(["IP Address", "Port", "Protocol"])
|
||||
table.align = "l"
|
||||
table.title = f"{self.software_manager.node.hostname} NMAP Port Scan ({scan_type})"
|
||||
table.title = f"{self.software_manager.node.config.hostname} NMAP Port Scan ({scan_type})"
|
||||
self.sys_log.info(f"{self.name}: Starting port scan")
|
||||
for ip_address in ip_addresses:
|
||||
# Prevent port scan on this node
|
||||
|
||||
Reference in New Issue
Block a user