#2248 - All tests (bar the one config file test) now working. Still need to tidy up docstrings and some docs. Almost there
This commit is contained in:
@@ -25,9 +25,9 @@ def test_passing_actions_down(monkeypatch) -> None:
|
||||
downloads_folder = pc1.file_system.create_folder("downloads")
|
||||
pc1.file_system.create_file("bermuda_triangle.png", folder_name="downloads")
|
||||
|
||||
sim.network.connect(pc1.network_interface[1], s1.switch_ports[1])
|
||||
sim.network.connect(pc2.network_interface[1], s1.switch_ports[2])
|
||||
sim.network.connect(s1.switch_ports[3], srv.network_interface[1])
|
||||
sim.network.connect(pc1.network_interface[1], s1.network_interface[1])
|
||||
sim.network.connect(pc2.network_interface[1], s1.network_interface[2])
|
||||
sim.network.connect(s1.network_interface[3], srv.network_interface[1])
|
||||
|
||||
# call this method to make sure no errors occur.
|
||||
sim._request_manager.get_request_types_recursively()
|
||||
|
||||
@@ -111,9 +111,9 @@ def broadcast_network() -> Network:
|
||||
switch_1 = Switch(hostname="switch_1", num_ports=6, start_up_duration=0)
|
||||
switch_1.power_on()
|
||||
|
||||
network.connect(endpoint_a=client_1.network_interface[1], endpoint_b=switch_1.switch_ports[1])
|
||||
network.connect(endpoint_a=client_2.network_interface[1], endpoint_b=switch_1.switch_ports[2])
|
||||
network.connect(endpoint_a=server_1.network_interface[1], endpoint_b=switch_1.switch_ports[3])
|
||||
network.connect(endpoint_a=client_1.network_interface[1], endpoint_b=switch_1.network_interface[1])
|
||||
network.connect(endpoint_a=client_2.network_interface[1], endpoint_b=switch_1.network_interface[2])
|
||||
network.connect(endpoint_a=server_1.network_interface[1], endpoint_b=switch_1.network_interface[3])
|
||||
|
||||
return network
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from primaite.simulator.network.container import Network
|
||||
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||
from primaite.simulator.network.hardware.nodes.host.host_node import NIC
|
||||
from primaite.simulator.network.hardware.nodes.host.server import Server
|
||||
from primaite.simulator.network.hardware.nodes.network.switch import Switch
|
||||
|
||||
@@ -30,32 +31,33 @@ def test_node_to_node_ping():
|
||||
switch_1 = Switch(hostname="switch_1", start_up_duration=0)
|
||||
switch_1.power_on()
|
||||
|
||||
network.connect(endpoint_a=client_1.network_interface[1], endpoint_b=switch_1.switch_ports[1])
|
||||
network.connect(endpoint_a=server_1.network_interface[1], endpoint_b=switch_1.switch_ports[2])
|
||||
network.connect(endpoint_a=client_1.network_interface[1], endpoint_b=switch_1.network_interface[1])
|
||||
network.connect(endpoint_a=server_1.network_interface[1], endpoint_b=switch_1.network_interface[2])
|
||||
|
||||
assert client_1.ping("192.168.1.11")
|
||||
|
||||
|
||||
def test_multi_nic():
|
||||
"""Tests that Computers with multiple NICs can ping each other and the data go across the correct links."""
|
||||
node_a = Computer(hostname="node_a", operating_state=ComputerOperatingState.ON)
|
||||
nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0")
|
||||
node_a.connect_nic(nic_a)
|
||||
network = Network()
|
||||
|
||||
node_b = Computer(hostname="node_b", operating_state=ComputerOperatingState.ON)
|
||||
nic_b1 = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0")
|
||||
nic_b2 = NIC(ip_address="10.0.0.12", subnet_mask="255.0.0.0")
|
||||
node_b.connect_nic(nic_b1)
|
||||
node_b.connect_nic(nic_b2)
|
||||
node_a = Computer(hostname="node_a", ip_address="192.168.0.10", subnet_mask="255.255.255.0", start_up_duration=0)
|
||||
node_a.power_on()
|
||||
|
||||
node_c = Computer(hostname="node_c", operating_state=ComputerOperatingState.ON)
|
||||
nic_c = NIC(ip_address="10.0.0.13", subnet_mask="255.0.0.0")
|
||||
node_c.connect_nic(nic_c)
|
||||
node_b = Computer(hostname="node_b", ip_address="192.168.0.11", subnet_mask="255.255.255.0", start_up_duration=0)
|
||||
node_b.power_on()
|
||||
node_b.connect_nic(NIC(ip_address="10.0.0.12", subnet_mask="255.0.0.0"))
|
||||
|
||||
Link(endpoint_a=nic_a, endpoint_b=nic_b1)
|
||||
node_c = Computer(hostname="node_c", ip_address="10.0.0.13", subnet_mask="255.0.0.0", start_up_duration=0)
|
||||
node_c.power_on()
|
||||
|
||||
Link(endpoint_a=nic_b2, endpoint_b=nic_c)
|
||||
network.connect(node_a.network_interface[1], node_b.network_interface[1])
|
||||
network.connect(node_b.network_interface[2], node_c.network_interface[1])
|
||||
|
||||
node_a.ping("192.168.0.11")
|
||||
assert node_a.ping(node_b.network_interface[1].ip_address)
|
||||
|
||||
assert node_c.ping("10.0.0.12")
|
||||
assert node_c.ping(node_b.network_interface[2].ip_address)
|
||||
|
||||
assert not node_a.ping(node_b.network_interface[2].ip_address)
|
||||
|
||||
assert not node_a.ping(node_c.network_interface[1].ip_address)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from primaite.simulator.network.container import Network
|
||||
from primaite.simulator.network.hardware.base import Node
|
||||
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||
from primaite.simulator.network.hardware.nodes.host.host_node import NIC
|
||||
from primaite.simulator.network.hardware.nodes.host.server import Server
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ def test_network(example_network):
|
||||
def test_adding_removing_nodes():
|
||||
"""Check that we can create and add a node to a network."""
|
||||
net = Network()
|
||||
n1 = Node(hostname="computer")
|
||||
n1 = Computer(hostname="computer", ip_address="192.168.1.2", subnet_mask="255.255.255.0", start_up_duration=0)
|
||||
net.add_node(n1)
|
||||
assert n1.parent is net
|
||||
assert n1 in net
|
||||
@@ -39,7 +39,7 @@ def test_adding_removing_nodes():
|
||||
def test_readding_node():
|
||||
"""Check that warning is raised when readding a node."""
|
||||
net = Network()
|
||||
n1 = Node(hostname="computer")
|
||||
n1 = Computer(hostname="computer", ip_address="192.168.1.2", subnet_mask="255.255.255.0", start_up_duration=0)
|
||||
net.add_node(n1)
|
||||
net.add_node(n1)
|
||||
assert n1.parent is net
|
||||
@@ -49,7 +49,7 @@ def test_readding_node():
|
||||
def test_removing_nonexistent_node():
|
||||
"""Check that warning is raised when trying to remove a node that is not in the network."""
|
||||
net = Network()
|
||||
n1 = Node(hostname="computer")
|
||||
n1 = Computer(hostname="computer1", ip_address="192.168.1.1", subnet_mask="255.255.255.0", start_up_duration=0)
|
||||
net.remove_node(n1)
|
||||
assert n1.parent is None
|
||||
assert n1 not in net
|
||||
@@ -58,17 +58,13 @@ def test_removing_nonexistent_node():
|
||||
def test_connecting_nodes():
|
||||
"""Check that two nodes on the network can be connected."""
|
||||
net = Network()
|
||||
n1 = Node(hostname="computer")
|
||||
n1_nic = NIC(ip_address="120.30.0.1", gateway="192.168.0.1", subnet_mask="255.255.255.0")
|
||||
n1.connect_nic(n1_nic)
|
||||
n2 = Node(hostname="server")
|
||||
n2_nic = NIC(ip_address="120.30.0.2", gateway="192.168.0.1", subnet_mask="255.255.255.0")
|
||||
n2.connect_nic(n2_nic)
|
||||
n1 = Computer(hostname="computer1", ip_address="192.168.1.1", subnet_mask="255.255.255.0", start_up_duration=0)
|
||||
n2 = Computer(hostname="computer2", ip_address="192.168.1.2", subnet_mask="255.255.255.0", start_up_duration=0)
|
||||
|
||||
net.add_node(n1)
|
||||
net.add_node(n2)
|
||||
|
||||
net.connect(n1.network_interfaces[n1_nic.uuid], n2.network_interfaces[n2_nic.uuid], bandwidth=30)
|
||||
net.connect(n1.network_interface[1], n2.network_interface[1])
|
||||
|
||||
assert len(net.links) == 1
|
||||
link = list(net.links.values())[0]
|
||||
@@ -76,40 +72,32 @@ def test_connecting_nodes():
|
||||
assert link.parent is net
|
||||
|
||||
|
||||
def test_connecting_node_to_itself():
|
||||
def test_connecting_node_to_itself_fails():
|
||||
net = Network()
|
||||
node = Node(hostname="computer")
|
||||
nic1 = NIC(ip_address="120.30.0.1", gateway="192.168.0.1", subnet_mask="255.255.255.0")
|
||||
node.connect_nic(nic1)
|
||||
nic2 = NIC(ip_address="120.30.0.2", gateway="192.168.0.1", subnet_mask="255.255.255.0")
|
||||
node.connect_nic(nic2)
|
||||
node = Computer(hostname="node_b", ip_address="192.168.0.11", subnet_mask="255.255.255.0", start_up_duration=0)
|
||||
node.power_on()
|
||||
node.connect_nic(NIC(ip_address="10.0.0.12", subnet_mask="255.0.0.0"))
|
||||
|
||||
net.add_node(node)
|
||||
|
||||
net.connect(node.network_interfaces[nic1.uuid], node.network_interfaces[nic2.uuid], bandwidth=30)
|
||||
net.connect(node.network_interface[1], node.network_interface[2])
|
||||
|
||||
assert node in net
|
||||
assert nic1._connected_link is None
|
||||
assert nic2._connected_link is None
|
||||
assert node.network_interface[1]._connected_link is None
|
||||
assert node.network_interface[2]._connected_link is None
|
||||
assert len(net.links) == 0
|
||||
|
||||
|
||||
def test_disconnecting_nodes():
|
||||
net = Network()
|
||||
|
||||
n1 = Node(hostname="computer")
|
||||
n1_nic = NIC(ip_address="120.30.0.1", gateway="192.168.0.1", subnet_mask="255.255.255.0")
|
||||
n1.connect_nic(n1_nic)
|
||||
net.add_node(n1)
|
||||
n1 = Computer(hostname="computer1", ip_address="192.168.1.1", subnet_mask="255.255.255.0", start_up_duration=0)
|
||||
n2 = Computer(hostname="computer2", ip_address="192.168.1.2", subnet_mask="255.255.255.0", start_up_duration=0)
|
||||
|
||||
n2 = Node(hostname="server")
|
||||
n2_nic = NIC(ip_address="120.30.0.2", gateway="192.168.0.1", subnet_mask="255.255.255.0")
|
||||
n2.connect_nic(n2_nic)
|
||||
net.add_node(n2)
|
||||
|
||||
net.connect(n1.network_interfaces[n1_nic.uuid], n2.network_interfaces[n2_nic.uuid], bandwidth=30)
|
||||
net.connect(n1.network_interface[1], n2.network_interface[1])
|
||||
assert len(net.links) == 1
|
||||
|
||||
|
||||
link = list(net.links.values())[0]
|
||||
net.remove_link(link)
|
||||
assert link not in net
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from primaite.simulator.network.hardware.base import Link, NIC
|
||||
from primaite.simulator.network.hardware.base import Link
|
||||
from primaite.simulator.network.hardware.nodes.host.host_node import NIC
|
||||
|
||||
|
||||
def test_link_fails_with_same_nic():
|
||||
|
||||
@@ -3,7 +3,9 @@ from typing import Tuple
|
||||
|
||||
import pytest
|
||||
|
||||
from primaite.simulator.network.hardware.base import Link, NIC, Node, NodeOperatingState
|
||||
from primaite.simulator.network.container import Network
|
||||
from primaite.simulator.network.hardware.node_operating_state import NodeOperatingState
|
||||
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||
from primaite.simulator.network.hardware.nodes.host.server import Server
|
||||
from primaite.simulator.system.applications.database_client import DatabaseClient
|
||||
from primaite.simulator.system.services.database.database_service import DatabaseService
|
||||
@@ -12,17 +14,25 @@ from primaite.simulator.system.services.service import ServiceOperatingState
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def peer_to_peer() -> Tuple[Node, Node]:
|
||||
node_a = Node(hostname="node_a", operating_state=NodeOperatingState.ON)
|
||||
nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", operating_state=NodeOperatingState.ON)
|
||||
node_a.connect_nic(nic_a)
|
||||
def peer_to_peer() -> Tuple[Computer, Computer]:
|
||||
network = Network()
|
||||
node_a = Computer(
|
||||
hostname="node_a",
|
||||
ip_address="192.168.0.10",
|
||||
subnet_mask="255.255.255.0",
|
||||
start_up_duration=0
|
||||
)
|
||||
node_a.power_on()
|
||||
node_a.software_manager.get_open_ports()
|
||||
|
||||
node_b = Node(hostname="node_b", operating_state=NodeOperatingState.ON)
|
||||
nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0")
|
||||
node_b.connect_nic(nic_b)
|
||||
|
||||
Link(endpoint_a=nic_a, endpoint_b=nic_b)
|
||||
node_b = Computer(
|
||||
hostname="node_b",
|
||||
ip_address="192.168.0.11",
|
||||
subnet_mask="255.255.255.0",
|
||||
start_up_duration=0
|
||||
)
|
||||
node_b.power_on()
|
||||
network.connect(node_a.network_interface[1], node_b.network_interface[1])
|
||||
|
||||
assert node_a.ping("192.168.0.11")
|
||||
|
||||
@@ -37,26 +47,11 @@ def peer_to_peer() -> Tuple[Node, Node]:
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def peer_to_peer_secure_db() -> Tuple[Node, Node]:
|
||||
node_a = Node(hostname="node_a", operating_state=NodeOperatingState.ON)
|
||||
nic_a = NIC(ip_address="192.168.0.10", subnet_mask="255.255.255.0", operating_state=NodeOperatingState.ON)
|
||||
node_a.connect_nic(nic_a)
|
||||
node_a.software_manager.get_open_ports()
|
||||
def peer_to_peer_secure_db(peer_to_peer) -> Tuple[Computer, Computer]:
|
||||
node_a, node_b = peer_to_peer
|
||||
|
||||
node_b = Node(hostname="node_b", operating_state=NodeOperatingState.ON)
|
||||
nic_b = NIC(ip_address="192.168.0.11", subnet_mask="255.255.255.0")
|
||||
node_b.connect_nic(nic_b)
|
||||
|
||||
Link(endpoint_a=nic_a, endpoint_b=nic_b)
|
||||
|
||||
assert node_a.ping("192.168.0.11")
|
||||
|
||||
node_a.software_manager.install(DatabaseClient)
|
||||
node_a.software_manager.software["DatabaseClient"].configure(server_ip_address=IPv4Address("192.168.0.11"))
|
||||
node_a.software_manager.software["DatabaseClient"].run()
|
||||
|
||||
node_b.software_manager.install(DatabaseService)
|
||||
database_service: DatabaseService = node_b.software_manager.software["DatabaseService"] # noqa
|
||||
database_service.stop()
|
||||
database_service.password = "12345"
|
||||
database_service.start()
|
||||
return node_a, node_b
|
||||
|
||||
@@ -47,11 +47,11 @@ def test_ntp_client_server(create_ntp_network):
|
||||
|
||||
assert ntp_server.operating_state == ServiceOperatingState.RUNNING
|
||||
assert ntp_client.operating_state == ServiceOperatingState.RUNNING
|
||||
ntp_client.configure(ntp_server_ip_address=IPv4Address("192.168.0.2"))
|
||||
ntp_client.configure(ntp_server_ip_address=IPv4Address("192.168.1.3"))
|
||||
|
||||
assert ntp_client.time is None
|
||||
assert not ntp_client.time
|
||||
ntp_client.request_time()
|
||||
assert ntp_client.time is not None
|
||||
assert ntp_client.time
|
||||
first_time = ntp_client.time
|
||||
sleep(0.1)
|
||||
ntp_client.apply_timestep(1) # Check time advances
|
||||
@@ -68,7 +68,7 @@ def test_ntp_server_failure(create_ntp_network):
|
||||
|
||||
assert ntp_client.operating_state == ServiceOperatingState.RUNNING
|
||||
assert ntp_client.operating_state == ServiceOperatingState.RUNNING
|
||||
ntp_client.configure(ntp_server_ip_address=IPv4Address("192.168.0.2"))
|
||||
ntp_client.configure(ntp_server_ip_address=IPv4Address("192.168.1.3"))
|
||||
|
||||
# Turn off ntp server.
|
||||
ntp_server.stop()
|
||||
|
||||
Reference in New Issue
Block a user