#2887 - Unit test fixes ahead of raising PR.
This commit is contained in:
@@ -36,7 +36,6 @@ class NodeAbstractAction(AbstractAction, identifier="node_abstract"):
|
||||
@classmethod
|
||||
def form_request(cls, config: ConfigSchema) -> RequestFormat:
|
||||
"""Return the action formatted as a request which can be ingested by the PrimAITE simulation."""
|
||||
print(config)
|
||||
return ["network", "node", config.node_name, config.verb]
|
||||
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ class OfficeLANAdder(NetworkNodeAdder, identifier="office_lan"):
|
||||
|
||||
# Create a core switch if more than one edge switch is needed
|
||||
if num_of_switches > 1:
|
||||
core_switch = Switch(hostname=f"switch_core_{config.lan_name}", start_up_duration=0)
|
||||
core_switch = Switch.from_config(config = {"type":"switch","hostname":f"switch_core_{config.lan_name}", "start_up_duration": 0 })
|
||||
core_switch.power_on()
|
||||
network.add_node(core_switch)
|
||||
core_switch_port = 1
|
||||
@@ -164,7 +164,8 @@ class OfficeLANAdder(NetworkNodeAdder, identifier="office_lan"):
|
||||
# Optionally include a router in the LAN
|
||||
if config.include_router:
|
||||
default_gateway = IPv4Address(f"192.168.{config.subnet_base}.1")
|
||||
router = Router(hostname=f"router_{config.lan_name}", start_up_duration=0)
|
||||
# router = Router(hostname=f"router_{config.lan_name}", start_up_duration=0)
|
||||
router = Router.from_config(config={"hostname":f"router_{config.lan_name}", "type": "router", "start_up_duration": 0})
|
||||
router.power_on()
|
||||
router.acl.add_rule(
|
||||
action=ACLAction.PERMIT, src_port=PORT_LOOKUP["ARP"], dst_port=PORT_LOOKUP["ARP"], position=22
|
||||
@@ -177,7 +178,7 @@ class OfficeLANAdder(NetworkNodeAdder, identifier="office_lan"):
|
||||
# Initialise the first edge switch and connect to the router or core switch
|
||||
switch_port = 0
|
||||
switch_n = 1
|
||||
switch = Switch(hostname=f"switch_edge_{switch_n}_{config.lan_name}", start_up_duration=0)
|
||||
switch = Switch.from_config(config={"type": "switch","hostname":f"switch_edge_{switch_n}_{config.lan_name}", "start_up_duration":0})
|
||||
switch.power_on()
|
||||
network.add_node(switch)
|
||||
if num_of_switches > 1:
|
||||
@@ -195,7 +196,7 @@ class OfficeLANAdder(NetworkNodeAdder, identifier="office_lan"):
|
||||
if switch_port == effective_network_interface:
|
||||
switch_n += 1
|
||||
switch_port = 0
|
||||
switch = Switch(hostname=f"switch_edge_{switch_n}_{config.lan_name}", start_up_duration=0)
|
||||
switch = Switch.from_config(config={"type": "switch","hostname":f"switch_edge_{switch_n}_{config.lan_name}", "start_up_duration":0})
|
||||
switch.power_on()
|
||||
network.add_node(switch)
|
||||
# Connect the new switch to the router or core switch
|
||||
@@ -212,13 +213,13 @@ class OfficeLANAdder(NetworkNodeAdder, identifier="office_lan"):
|
||||
)
|
||||
|
||||
# Create and add a PC to the network
|
||||
pc = Computer(
|
||||
hostname=f"pc_{i}_{config.lan_name}",
|
||||
ip_address=f"192.168.{config.subnet_base}.{i+config.pcs_ip_block_start-1}",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway=default_gateway,
|
||||
start_up_duration=0,
|
||||
)
|
||||
pc_cfg = {"type": "computer",
|
||||
"hostname": f"pc_{i}_{config.lan_name}",
|
||||
"ip_address": f"192.168.{config.subnet_base}.{i+config.pcs_ip_block_start-1}",
|
||||
"default_gateway": "192.168.10.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
pc = Computer.from_config(config = pc_cfg)
|
||||
pc.power_on()
|
||||
network.add_node(pc)
|
||||
|
||||
|
||||
@@ -1979,7 +1979,7 @@ class Node(SimComponent, ABC):
|
||||
else:
|
||||
if self.operating_state == NodeOperatingState.SHUTTING_DOWN:
|
||||
self.operating_state = NodeOperatingState.OFF
|
||||
self.sys_log.info(f"{self.hostname}: Turned off")
|
||||
self.sys_log.info(f"{self.config.hostname}: Turned off")
|
||||
self._shut_down_actions()
|
||||
|
||||
# if resetting turn back on
|
||||
|
||||
@@ -129,7 +129,7 @@ class Switch(NetworkNode, identifier="switch"):
|
||||
if markdown:
|
||||
table.set_style(MARKDOWN)
|
||||
table.align = "l"
|
||||
table.title = f"{self.hostname} Switch Ports"
|
||||
table.title = f"{self.config.hostname} Switch Ports"
|
||||
for port_num, port in self.network_interface.items():
|
||||
table.add_row([port_num, port.mac_address, port.speed, "Enabled" if port.enabled else "Disabled"])
|
||||
print(table)
|
||||
|
||||
@@ -128,32 +128,34 @@ def arcd_uc2_network() -> Network:
|
||||
network = Network()
|
||||
|
||||
# Router 1
|
||||
router_1 = Router(hostname="router_1", num_ports=5, start_up_duration=0)
|
||||
router_1 = Router.from_config(config={"type":"router", "hostname":"router_1", "num_ports":5, "start_up_duration":0})
|
||||
router_1.power_on()
|
||||
router_1.configure_port(port=1, ip_address="192.168.1.1", subnet_mask="255.255.255.0")
|
||||
router_1.configure_port(port=2, ip_address="192.168.10.1", subnet_mask="255.255.255.0")
|
||||
|
||||
# Switch 1
|
||||
switch_1 = Switch(hostname="switch_1", num_ports=8, start_up_duration=0)
|
||||
switch_1 = Switch.from_config(config={"type":"switch", "hostname":"switch_1", "num_ports":8, "start_up_duration":0})
|
||||
switch_1.power_on()
|
||||
network.connect(endpoint_a=router_1.network_interface[1], endpoint_b=switch_1.network_interface[8])
|
||||
router_1.enable_port(1)
|
||||
|
||||
# Switch 2
|
||||
switch_2 = Switch(hostname="switch_2", num_ports=8, start_up_duration=0)
|
||||
switch_2 = Switch.from_config(config={"type":"switch", "hostname":"switch_2", "num_ports":8, "start_up_duration":0})
|
||||
switch_2.power_on()
|
||||
network.connect(endpoint_a=router_1.network_interface[2], endpoint_b=switch_2.network_interface[8])
|
||||
router_1.enable_port(2)
|
||||
|
||||
# Client 1
|
||||
client_1 = Computer(
|
||||
hostname="client_1",
|
||||
ip_address="192.168.10.21",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway="192.168.10.1",
|
||||
dns_server=IPv4Address("192.168.1.10"),
|
||||
start_up_duration=0,
|
||||
)
|
||||
client_1_cfg = {"type": "computer",
|
||||
"hostname": "client_1",
|
||||
"ip_address": "192.168.10.21",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.10.1",
|
||||
"dns_server": IPv4Address("192.168.1.10"),
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
client_1: Computer = Computer.from_config(config = client_1_cfg)
|
||||
|
||||
client_1.power_on()
|
||||
network.connect(endpoint_b=client_1.network_interface[1], endpoint_a=switch_2.network_interface[1])
|
||||
client_1.software_manager.install(DatabaseClient)
|
||||
@@ -172,14 +174,17 @@ def arcd_uc2_network() -> Network:
|
||||
)
|
||||
|
||||
# Client 2
|
||||
client_2 = Computer(
|
||||
hostname="client_2",
|
||||
ip_address="192.168.10.22",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway="192.168.10.1",
|
||||
dns_server=IPv4Address("192.168.1.10"),
|
||||
start_up_duration=0,
|
||||
)
|
||||
|
||||
client_2_cfg = {"type": "computer",
|
||||
"hostname": "client_2",
|
||||
"ip_address": "192.168.10.22",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.10.1",
|
||||
"dns_server": IPv4Address("192.168.1.10"),
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
client_2: Computer = Computer.from_config(config = client_2_cfg)
|
||||
|
||||
client_2.power_on()
|
||||
client_2.software_manager.install(DatabaseClient)
|
||||
db_client_2 = client_2.software_manager.software.get("DatabaseClient")
|
||||
@@ -193,27 +198,34 @@ def arcd_uc2_network() -> Network:
|
||||
)
|
||||
|
||||
# Domain Controller
|
||||
domain_controller = Server(
|
||||
hostname="domain_controller",
|
||||
ip_address="192.168.1.10",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway="192.168.1.1",
|
||||
start_up_duration=0,
|
||||
)
|
||||
|
||||
domain_controller_cfg = {"type": "server",
|
||||
"hostname": "domain_controller",
|
||||
"ip_address": "192.168.1.10",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration": 0
|
||||
}
|
||||
|
||||
domain_controller = Server.from_config(config=domain_controller_cfg)
|
||||
domain_controller.power_on()
|
||||
domain_controller.software_manager.install(DNSServer)
|
||||
|
||||
network.connect(endpoint_b=domain_controller.network_interface[1], endpoint_a=switch_1.network_interface[1])
|
||||
|
||||
# Database Server
|
||||
database_server = Server(
|
||||
hostname="database_server",
|
||||
ip_address="192.168.1.14",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway="192.168.1.1",
|
||||
dns_server=IPv4Address("192.168.1.10"),
|
||||
start_up_duration=0,
|
||||
)
|
||||
|
||||
database_server_cfg = {"type": "server",
|
||||
"hostname": "database_server",
|
||||
"ip_address": "192.168.1.14",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"dns_server": IPv4Address("192.168.1.10"),
|
||||
"start_up_duration": 0
|
||||
}
|
||||
|
||||
database_server = Server.from_config(config=database_server_cfg)
|
||||
|
||||
database_server.power_on()
|
||||
network.connect(endpoint_b=database_server.network_interface[1], endpoint_a=switch_1.network_interface[3])
|
||||
|
||||
@@ -223,14 +235,18 @@ def arcd_uc2_network() -> Network:
|
||||
database_service.configure_backup(backup_server=IPv4Address("192.168.1.16"))
|
||||
|
||||
# Web Server
|
||||
web_server = Server(
|
||||
hostname="web_server",
|
||||
ip_address="192.168.1.12",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway="192.168.1.1",
|
||||
dns_server=IPv4Address("192.168.1.10"),
|
||||
start_up_duration=0,
|
||||
)
|
||||
|
||||
|
||||
web_server_cfg = {"type": "server",
|
||||
"hostname": "web_server",
|
||||
"ip_address": "192.168.1.11",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"dns_server": IPv4Address("192.168.1.10"),
|
||||
"start_up_duration": 0
|
||||
}
|
||||
web_server = Server.from_config(config=web_server_cfg)
|
||||
|
||||
web_server.power_on()
|
||||
web_server.software_manager.install(DatabaseClient)
|
||||
|
||||
@@ -247,27 +263,30 @@ def arcd_uc2_network() -> Network:
|
||||
dns_server_service.dns_register("arcd.com", web_server.network_interface[1].ip_address)
|
||||
|
||||
# Backup Server
|
||||
backup_server = Server(
|
||||
hostname="backup_server",
|
||||
ip_address="192.168.1.16",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway="192.168.1.1",
|
||||
dns_server=IPv4Address("192.168.1.10"),
|
||||
start_up_duration=0,
|
||||
)
|
||||
backup_server_cfg = {"type": "server",
|
||||
"hostname": "backup_server",
|
||||
"ip_address": "192.168.1.16",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"dns_server": IPv4Address("192.168.1.10"),
|
||||
"start_up_duration": 0
|
||||
}
|
||||
backup_server: Server = Server.from_config(config=backup_server_cfg)
|
||||
|
||||
backup_server.power_on()
|
||||
backup_server.software_manager.install(FTPServer)
|
||||
network.connect(endpoint_b=backup_server.network_interface[1], endpoint_a=switch_1.network_interface[4])
|
||||
|
||||
# Security Suite
|
||||
security_suite = Server(
|
||||
hostname="security_suite",
|
||||
ip_address="192.168.1.110",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway="192.168.1.1",
|
||||
dns_server=IPv4Address("192.168.1.10"),
|
||||
start_up_duration=0,
|
||||
)
|
||||
security_suite_cfg = {"type": "server",
|
||||
"hostname": "backup_server",
|
||||
"ip_address": "192.168.1.110",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"dns_server": IPv4Address("192.168.1.10"),
|
||||
"start_up_duration": 0
|
||||
}
|
||||
security_suite: Server = Server.from_config(config=security_suite_cfg)
|
||||
security_suite.power_on()
|
||||
network.connect(endpoint_b=security_suite.network_interface[1], endpoint_a=switch_1.network_interface[7])
|
||||
security_suite.connect_nic(NIC(ip_address="192.168.10.110", subnet_mask="255.255.255.0"))
|
||||
|
||||
Reference in New Issue
Block a user