#2887 - Node class changes to address some test failures. Addressed some inconsistencies around operating_state, amended instantiation of some Nodes in test environments
This commit is contained in:
@@ -34,54 +34,64 @@ def basic_network() -> Network:
|
||||
|
||||
# Creating two generic nodes for the C2 Server and the C2 Beacon.
|
||||
|
||||
node_a_cfg = {"type": "computer",
|
||||
"hostname": "node_a",
|
||||
"ip_address": "192.168.0.2",
|
||||
"subnet_mask": "255.255.255.252",
|
||||
"default_gateway": "192.168.0.1",
|
||||
"start_up_duration": 0}
|
||||
|
||||
node_a_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "node_a",
|
||||
"ip_address": "192.168.0.2",
|
||||
"subnet_mask": "255.255.255.252",
|
||||
"default_gateway": "192.168.0.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
node_a: Computer = Computer.from_config(config=node_a_cfg)
|
||||
node_a.power_on()
|
||||
node_a.software_manager.get_open_ports()
|
||||
node_a.software_manager.install(software_class=C2Server)
|
||||
|
||||
node_b_cfg = {"type": "computer",
|
||||
"hostname": "node_b",
|
||||
"ip_address": "192.168.255.2",
|
||||
"subnet_mask": "255.255.255.248",
|
||||
"default_gateway": "192.168.255.1",
|
||||
"start_up_duration": 0}
|
||||
|
||||
node_b_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "node_b",
|
||||
"ip_address": "192.168.255.2",
|
||||
"subnet_mask": "255.255.255.248",
|
||||
"default_gateway": "192.168.255.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
node_b: Computer = Computer.from_config(config=node_b_cfg)
|
||||
node_b.power_on()
|
||||
node_b.software_manager.install(software_class=C2Beacon)
|
||||
|
||||
# Creating a generic computer for testing remote terminal connections.
|
||||
node_c_cfg = {"type": "computer",
|
||||
"hostname": "node_c",
|
||||
"ip_address": "192.168.255.3",
|
||||
"subnet_mask": "255.255.255.248",
|
||||
"default_gateway": "192.168.255.1",
|
||||
"start_up_duration": 0}
|
||||
|
||||
node_c_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "node_c",
|
||||
"ip_address": "192.168.255.3",
|
||||
"subnet_mask": "255.255.255.248",
|
||||
"default_gateway": "192.168.255.1",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
|
||||
node_c: Computer = Computer.from_config(config=node_c_cfg)
|
||||
node_c.power_on()
|
||||
|
||||
# Creating a router to sit between node 1 and node 2.
|
||||
router = Router.from_config(config={"type":"router", "hostname":"router", "num_ports":3, "start_up_duration":0})
|
||||
router = Router.from_config(config={"type": "router", "hostname": "router", "num_ports": 3, "start_up_duration": 0})
|
||||
# Default allow all.
|
||||
router.acl.add_rule(action=ACLAction.PERMIT)
|
||||
router.power_on()
|
||||
# Creating switches for each client.
|
||||
switch_1 = Switch.from_config(config={"type":"switch", "hostname":"switch_1", "num_ports":6, "start_up_duration":0})
|
||||
switch_1 = Switch.from_config(
|
||||
config={"type": "switch", "hostname": "switch_1", "num_ports": 6, "start_up_duration": 0}
|
||||
)
|
||||
switch_1.power_on()
|
||||
|
||||
# Connecting the switches to the router.
|
||||
router.configure_port(port=1, ip_address="192.168.0.1", subnet_mask="255.255.255.252")
|
||||
network.connect(endpoint_a=router.network_interface[1], endpoint_b=switch_1.network_interface[6])
|
||||
|
||||
switch_2 = Switch.from_config(config={"type":"switch", "hostname":"switch_2", "num_ports":6, "start_up_duration":0})
|
||||
switch_2 = Switch.from_config(
|
||||
config={"type": "switch", "hostname": "switch_2", "num_ports": 6, "start_up_duration": 0}
|
||||
)
|
||||
switch_2.power_on()
|
||||
|
||||
network.connect(endpoint_a=router.network_interface[2], endpoint_b=switch_2.network_interface[6])
|
||||
|
||||
@@ -72,7 +72,7 @@ def test_dns_client_requests_offline_dns_server(dns_client_and_dns_server):
|
||||
|
||||
server.power_off()
|
||||
|
||||
for i in range(server.shut_down_duration + 1):
|
||||
for i in range(server.config.shut_down_duration + 1):
|
||||
server.apply_timestep(timestep=i)
|
||||
|
||||
assert server.operating_state == NodeOperatingState.OFF
|
||||
|
||||
@@ -13,13 +13,15 @@ from primaite.simulator.system.services.service import Service, ServiceOperating
|
||||
def populated_node(
|
||||
service_class,
|
||||
) -> Tuple[Server, Service]:
|
||||
server = Server(
|
||||
hostname="server",
|
||||
ip_address="192.168.0.1",
|
||||
subnet_mask="255.255.255.0",
|
||||
start_up_duration=0,
|
||||
shut_down_duration=0,
|
||||
)
|
||||
server_cfg = {
|
||||
"type": "server",
|
||||
"hostname": "server",
|
||||
"ip_address": "192.168.0.1",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"start_up_duration": 0,
|
||||
"shut_down_duration": 0,
|
||||
}
|
||||
server: Server = Server.from_config(config=server_cfg)
|
||||
server.power_on()
|
||||
server.software_manager.install(service_class)
|
||||
|
||||
@@ -31,14 +33,16 @@ def populated_node(
|
||||
|
||||
def test_service_on_offline_node(service_class):
|
||||
"""Test to check that the service cannot be interacted with when node it is on is off."""
|
||||
computer: Computer = Computer(
|
||||
hostname="test_computer",
|
||||
ip_address="192.168.1.2",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway="192.168.1.1",
|
||||
start_up_duration=0,
|
||||
shut_down_duration=0,
|
||||
)
|
||||
computer_cfg = {
|
||||
"type": "computer",
|
||||
"hostname": "test_computer",
|
||||
"ip_address": "192.168.1.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"default_gateway": "192.168.1.1",
|
||||
"start_up_duration": 0,
|
||||
"shut_down_duration": 0,
|
||||
}
|
||||
computer: Computer = Computer.from_config(config=computer_cfg)
|
||||
computer.power_on()
|
||||
computer.software_manager.install(service_class)
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ def test_web_page_request_from_shut_down_server(web_client_and_web_server):
|
||||
|
||||
server.power_off()
|
||||
|
||||
for i in range(server.shut_down_duration + 1):
|
||||
for i in range(server.config.shut_down_duration + 1):
|
||||
server.apply_timestep(timestep=i)
|
||||
|
||||
# node should be off
|
||||
|
||||
Reference in New Issue
Block a user