#2042: ntp_client test

This commit is contained in:
Nick Todd
2023-11-16 15:04:01 +00:00
parent 0c544a9a26
commit 7ee2c4220a
2 changed files with 30 additions and 1 deletions

View File

@@ -100,7 +100,7 @@ class NTPClient(Service):
def apply_timestep(self, timestep: int) -> None:
"""
For each timestep request the time tfrom the NTP server.
For each timestep request the time from the NTP server.
In this instance, if any multi-timestep processes are currently
occurring (such as restarting or installation), then they are brought one step closer to
@@ -114,3 +114,7 @@ class NTPClient(Service):
# request time from server
ntp_request = NTPPacket(NTPRequest())
self.send(ntp_request)
return True
else:
self.sys_log.debug(f"{self.name} ntp client not running")
return False

View File

@@ -0,0 +1,25 @@
from primaite.simulator.network.hardware.nodes.computer import Computer
from primaite.simulator.network.hardware.nodes.server import Server
from primaite.simulator.network.protocols.ntp import NTPPacket
from primaite.simulator.system.services.ntp.ntp_client import NTPClient
from primaite.simulator.system.services.ntp.ntp_server import NTPServer
from primaite.simulator.system.services.service import ServiceOperatingState
# Define one node to be an NTP server and another node to be a NTP Client.
def test_ntp_client_server(network):
server: Server = network.get_node_by_hostname("ntp_server")
client: Computer = network.get_node_by_hostname("ntp_client")
ntp_server: NTPServer = server.software_manager.software["NTP_Server"]
ntp_client: NTPClient = client.software_manager.software["NTP_Client"]
assert ntp_server.operating_state == ServiceOperatingState.RUNNING
assert ntp_client.operating_state == ServiceOperatingState.RUNNING
ntp_client.send(payload=NTPPacket())
assert ntp_server.receive() is True
assert ntp_client.receive() is True
assert ntp_client.apply_timestep(1) is True