#2257: added way to ensure nodes are on at start + more test to make sure nodes are on when added via config

This commit is contained in:
Czar Echavez
2024-02-26 14:34:34 +00:00
parent d738a23709
commit f2d7a2fc16
3 changed files with 22 additions and 4 deletions

View File

@@ -359,13 +359,18 @@ class PrimaiteGame:
for nic_num, nic_cfg in node_cfg["network_interfaces"].items():
new_node.connect_nic(NIC(ip_address=nic_cfg["ip_address"], subnet_mask=nic_cfg["subnet_mask"]))
new_node.start_up_duration = int(node_cfg.get("start_up_duration", 3))
new_node.shut_down_duration = int(node_cfg.get("shut_down_duration", 3))
# temporarily set to 0 so all nodes are initially on
new_node.start_up_duration = 0
new_node.shut_down_duration = 0
net.add_node(new_node)
new_node.power_on()
game.ref_map_nodes[node_ref] = new_node.uuid
# set start up and shut down duration
new_node.start_up_duration = int(node_cfg.get("start_up_duration", 3))
new_node.shut_down_duration = int(node_cfg.get("shut_down_duration", 3))
# 2. create links between nodes
for link_cfg in links_cfg:
node_a = net.nodes[game.ref_map_nodes[link_cfg["endpoint_a_ref"]]]

View File

@@ -1,6 +1,7 @@
import pytest
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.network.hardware.nodes.network.firewall import Firewall
@@ -20,7 +21,10 @@ def test_firewall_is_in_configuration(dmz_config):
"""Test that the firewall exists in the configuration file."""
network: Network = dmz_config
assert network.get_node_by_hostname("firewall")
firewall: Firewall = network.get_node_by_hostname("firewall")
assert firewall
assert firewall.operating_state == NodeOperatingState.ON
def test_firewall_routes_are_correctly_added(dmz_config):
@@ -39,6 +43,11 @@ def test_firewall_routes_are_correctly_added(dmz_config):
assert external_computer.ping(client_1.network_interface[1].ip_address)
assert external_server.ping(client_1.network_interface[1].ip_address)
# client_1 should be able to ping other nodes
assert client_1.ping(dmz_server.network_interface[1].ip_address)
assert client_1.ping(external_computer.network_interface[1].ip_address)
assert client_1.ping(external_server.network_interface[1].ip_address)
def test_firewall_acl_rules_correctly_added(dmz_config):
"""

View File

@@ -1,6 +1,7 @@
import pytest
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.network.hardware.nodes.network.router import ACLAction, Router
@@ -19,7 +20,10 @@ def test_router_is_in_configuration(dmz_config):
"""Test that the router exists in the configuration file."""
network: Network = dmz_config
assert network.get_node_by_hostname("router_1")
router_1: Router = network.get_node_by_hostname("router_1")
assert router_1
assert router_1.operating_state == NodeOperatingState.ON
def test_router_routes_are_correctly_added(dmz_config):