feature\898:

This commit is contained in:
Brian Kanyora
2023-06-02 16:13:16 +01:00
parent 051cd7da2b
commit a48b217cf3
3 changed files with 36 additions and 11 deletions

View File

@@ -217,3 +217,10 @@ class ActiveNode(Node):
self.file_system_state_actual = FileSystemState.GOOD
self.software_state = SoftwareState.GOOD
def update_booting_status(self):
super().update_booting_status()
if self.booting_count <= 0:
self.file_system_state_actual =FileSystemState.GOOD
self.software_state = SoftwareState.GOOD

View File

@@ -194,3 +194,9 @@ class ServiceNode(ActiveNode):
if self.resetting_count <= 0:
for service in self.services.values():
service.software_state = SoftwareState.GOOD
def update_booting_status(self):
super().update_booting_status()
if self.booting_count <= 0:
for service in self.services.values():
service.software_state =SoftwareState.GOOD

View File

@@ -1,8 +1,10 @@
"""Used to test Active Node functions."""
import pytest
from primaite.common.enums import FileSystemState, HardwareState, SoftwareState
from primaite.common.enums import FileSystemState, HardwareState, SoftwareState, NodeType, Priority
from primaite.common.service import Service
from primaite.nodes.active_node import ActiveNode
from primaite.common.config_values_main import ConfigValuesMain
from primaite.nodes.service_node import ServiceNode
@@ -17,23 +19,24 @@ def test_node_resets_correctly(starting_operating_state, expected_operating_stat
Tests that a node resets correctly.
"""
active_node = ActiveNode(
node_id = 0,
node_id = "0",
name = "node",
node_type = "COMPUTER",
priority = "1",
node_type = NodeType.COMPUTER,
priority = Priority.P1,
hardware_state = starting_operating_state,
ip_address = "192.168.0.1",
software_state = SoftwareState.GOOD,
file_system_state = "GOOD",
config_values = 1,
software_state = SoftwareState.COMPROMISED,
file_system_state = FileSystemState.CORRUPT,
config_values = ConfigValuesMain(),
)
for x in range(5):
active_node.update_resetting_status()
assert active_node.software_state == SoftwareState.GOOD
assert active_node.file_system_state_actual == FileSystemState.GOOD
assert active_node.hardware_state == expected_operating_state
@pytest.mark.parametrize(
"operating_state, expected_operating_state",
[
@@ -44,7 +47,7 @@ def test_node_boots_correctly(operating_state, expected_operating_state):
"""
Tests that a node boots correctly.
"""
active_node = ActiveNode(
service_node = ServiceNode(
node_id = 0,
name = "node",
node_type = "COMPUTER",
@@ -55,11 +58,20 @@ def test_node_boots_correctly(operating_state, expected_operating_state):
file_system_state = "GOOD",
config_values = 1,
)
service_attributes = Service(
name = "node",
port = "80",
software_state = SoftwareState.COMPROMISED
)
service_node.add_service(
service_attributes
)
for x in range(5):
active_node.update_booting_status()
service_node.update_booting_status()
assert active_node.hardware_state == expected_operating_state
assert service_attributes.software_state == SoftwareState.GOOD
assert service_node.hardware_state == expected_operating_state
@pytest.mark.parametrize(
"operating_state, expected_operating_state",