#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:
@@ -117,7 +117,9 @@ def test_firewall_observation():
|
||||
assert all(observation["PORTS"][i]["operating_status"] == 2 for i in range(1, 4))
|
||||
|
||||
# connect a switch to the firewall and check that only the correct port is updated
|
||||
switch: Switch = Switch.from_config(config={"type": "switch", "hostname":"switch", "num_ports":1, "operating_state":NodeOperatingState.ON})
|
||||
switch: Switch = Switch.from_config(
|
||||
config={"type": "switch", "hostname": "switch", "num_ports": 1, "operating_state": NodeOperatingState.ON}
|
||||
)
|
||||
link = net.connect(firewall.network_interface[1], switch.network_interface[1])
|
||||
assert firewall.network_interface[1].enabled
|
||||
observation = firewall_observation.observe(firewall.describe_state())
|
||||
|
||||
@@ -56,12 +56,26 @@ def test_link_observation():
|
||||
"""Check the shape and contents of the link observation."""
|
||||
net = Network()
|
||||
sim = Simulation(network=net)
|
||||
switch: Switch = Switch.from_config(config={"type":"switch", "hostname":"switch", "num_ports":5, "operating_state":NodeOperatingState.ON})
|
||||
computer_1: Computer = Computer.from_config(config={"type": "computer",
|
||||
"hostname":"computer_1", "ip_address":"10.0.0.1", "subnet_mask":"255.255.255.0", "start_up_duration":0}
|
||||
switch: Switch = Switch.from_config(
|
||||
config={"type": "switch", "hostname": "switch", "num_ports": 5, "operating_state": NodeOperatingState.ON}
|
||||
)
|
||||
computer_2: Computer = Computer.from_config(config={"type":"computer",
|
||||
"hostname":"computer_2", "ip_address":"10.0.0.2", "subnet_mask":"255.255.255.0", "start_up_duration":0}
|
||||
computer_1: Computer = Computer.from_config(
|
||||
config={
|
||||
"type": "computer",
|
||||
"hostname": "computer_1",
|
||||
"ip_address": "10.0.0.1",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
)
|
||||
computer_2: Computer = Computer.from_config(
|
||||
config={
|
||||
"type": "computer",
|
||||
"hostname": "computer_2",
|
||||
"ip_address": "10.0.0.2",
|
||||
"subnet_mask": "255.255.255.0",
|
||||
"start_up_duration": 0,
|
||||
}
|
||||
)
|
||||
computer_1.power_on()
|
||||
computer_2.power_on()
|
||||
|
||||
@@ -163,7 +163,9 @@ def test_nic_monitored_traffic(simulation):
|
||||
pc2: Computer = simulation.network.get_node_by_hostname("client_2")
|
||||
|
||||
nic_obs = NICObservation(
|
||||
where=["network", "nodes", pc.config.hostname, "NICs", 1], include_nmne=False, monitored_traffic=monitored_traffic
|
||||
where=["network", "nodes", pc.config.hostname, "NICs", 1],
|
||||
include_nmne=False,
|
||||
monitored_traffic=monitored_traffic,
|
||||
)
|
||||
|
||||
simulation.pre_timestep(0) # apply timestep to whole sim
|
||||
|
||||
@@ -16,7 +16,9 @@ from primaite.utils.validation.port import PORT_LOOKUP
|
||||
def test_router_observation():
|
||||
"""Test adding/removing acl rules and enabling/disabling ports."""
|
||||
net = Network()
|
||||
router = Router.from_config(config={"type": "router", "hostname":"router", "num_ports":5, "operating_state":NodeOperatingState.ON})
|
||||
router = Router.from_config(
|
||||
config={"type": "router", "hostname": "router", "num_ports": 5, "operating_state": NodeOperatingState.ON}
|
||||
)
|
||||
|
||||
ports = [PortObservation(where=["NICs", i]) for i in range(1, 6)]
|
||||
acl = ACLObservation(
|
||||
@@ -89,7 +91,9 @@ def test_router_observation():
|
||||
assert all(observed_output["PORTS"][i]["operating_status"] == 2 for i in range(1, 6))
|
||||
|
||||
# connect a switch to the router and check that only the correct port is updated
|
||||
switch: Switch = Switch.from_config(config={"type": "switch", "hostname":"switch", "num_ports":1, "operating_state":NodeOperatingState.ON})
|
||||
switch: Switch = Switch.from_config(
|
||||
config={"type": "switch", "hostname": "switch", "num_ports": 1, "operating_state": NodeOperatingState.ON}
|
||||
)
|
||||
link = net.connect(router.network_interface[1], switch.network_interface[1])
|
||||
assert router.network_interface[1].enabled
|
||||
observed_output = router_observation.observe(router.describe_state())
|
||||
|
||||
Reference in New Issue
Block a user