#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:
Chris McCarthy
2024-02-07 23:05:34 +00:00
parent 5e25fefa14
commit 0c96fef3ec
29 changed files with 270 additions and 235 deletions

View File

@@ -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

View File

@@ -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()