1443 - changed IF statements from if initial ... if reference to if reference ... if final to compare the final state (state after red and blue actions) with the reference state (state with no red or blue action and with green normal network traffic occurring)

This commit is contained in:
SunilSamra
2023-05-30 11:40:40 +01:00
parent b255f557db
commit 0483eeca82

View File

@@ -93,7 +93,6 @@ def score_node_operating_state(final_node, initial_node, reference_node, config_
""" """
score = 0 score = 0
final_node_operating_state = final_node.hardware_state final_node_operating_state = final_node.hardware_state
initial_node_operating_state = initial_node.hardware_state
reference_node_operating_state = reference_node.hardware_state reference_node_operating_state = reference_node.hardware_state
if final_node_operating_state == reference_node_operating_state: if final_node_operating_state == reference_node_operating_state:
@@ -102,26 +101,26 @@ def score_node_operating_state(final_node, initial_node, reference_node, config_
else: else:
# We're different from the reference situation # We're different from the reference situation
# Need to compare initial and reference (current) state of node (i.e. at every step) # Need to compare initial and reference (current) state of node (i.e. at every step)
if initial_node_operating_state == HardwareState.ON: if reference_node_operating_state == HardwareState.ON:
if reference_node_operating_state == HardwareState.OFF: if final_node_operating_state == HardwareState.OFF:
score += config_values.off_should_be_on score += config_values.off_should_be_on
elif reference_node_operating_state == HardwareState.RESETTING: elif final_node_operating_state == HardwareState.RESETTING:
score += config_values.resetting_should_be_on score += config_values.resetting_should_be_on
else: else:
pass pass
elif initial_node_operating_state == HardwareState.OFF: elif reference_node_operating_state == HardwareState.OFF:
if reference_node_operating_state == HardwareState.ON: if final_node_operating_state == HardwareState.ON:
score += config_values.on_should_be_off score += config_values.on_should_be_off
elif reference_node_operating_state == HardwareState.RESETTING: elif final_node_operating_state == HardwareState.RESETTING:
score += config_values.resetting_should_be_off score += config_values.resetting_should_be_off
else: else:
pass pass
elif initial_node_operating_state == HardwareState.RESETTING: elif reference_node_operating_state == HardwareState.RESETTING:
if reference_node_operating_state == HardwareState.ON: if final_node_operating_state == HardwareState.ON:
score += config_values.on_should_be_resetting score += config_values.on_should_be_resetting
elif reference_node_operating_state == HardwareState.OFF: elif final_node_operating_state == HardwareState.OFF:
score += config_values.off_should_be_resetting score += config_values.off_should_be_resetting
elif reference_node_operating_state == HardwareState.RESETTING: elif final_node_operating_state == HardwareState.RESETTING:
score += config_values.resetting score += config_values.resetting
else: else:
pass pass
@@ -143,7 +142,6 @@ def score_node_os_state(final_node, initial_node, reference_node, config_values)
""" """
score = 0 score = 0
final_node_os_state = final_node.software_state final_node_os_state = final_node.software_state
initial_node_os_state = initial_node.software_state
reference_node_os_state = reference_node.software_state reference_node_os_state = reference_node.software_state
if final_node_os_state == reference_node_os_state: if final_node_os_state == reference_node_os_state:
@@ -152,28 +150,28 @@ def score_node_os_state(final_node, initial_node, reference_node, config_values)
else: else:
# We're different from the reference situation # We're different from the reference situation
# Need to compare initial and reference (current) state of node (i.e. at every step) # Need to compare initial and reference (current) state of node (i.e. at every step)
if initial_node_os_state == SoftwareState.GOOD: if reference_node_os_state == SoftwareState.GOOD:
if reference_node_os_state == SoftwareState.PATCHING: if final_node_os_state == SoftwareState.PATCHING:
score += config_values.patching_should_be_good score += config_values.patching_should_be_good
elif reference_node_os_state == SoftwareState.COMPROMISED: elif final_node_os_state == SoftwareState.COMPROMISED:
score += config_values.compromised_should_be_good score += config_values.compromised_should_be_good
else: else:
pass pass
elif initial_node_os_state == SoftwareState.PATCHING: elif reference_node_os_state == SoftwareState.PATCHING:
if reference_node_os_state == SoftwareState.GOOD: if final_node_os_state == SoftwareState.GOOD:
score += config_values.good_should_be_patching score += config_values.good_should_be_patching
elif reference_node_os_state == SoftwareState.COMPROMISED: elif final_node_os_state == SoftwareState.COMPROMISED:
score += config_values.compromised_should_be_patching score += config_values.compromised_should_be_patching
elif reference_node_os_state == SoftwareState.PATCHING: elif final_node_os_state == SoftwareState.PATCHING:
score += config_values.patching score += config_values.patching
else: else:
pass pass
elif initial_node_os_state == SoftwareState.COMPROMISED: elif reference_node_os_state == SoftwareState.COMPROMISED:
if reference_node_os_state == SoftwareState.GOOD: if final_node_os_state == SoftwareState.GOOD:
score += config_values.good_should_be_compromised score += config_values.good_should_be_compromised
elif reference_node_os_state == SoftwareState.PATCHING: elif final_node_os_state == SoftwareState.PATCHING:
score += config_values.patching_should_be_compromised score += config_values.patching_should_be_compromised
elif reference_node_os_state == SoftwareState.COMPROMISED: elif final_node_os_state == SoftwareState.COMPROMISED:
score += config_values.compromised score += config_values.compromised
else: else:
pass pass
@@ -195,12 +193,11 @@ def score_node_service_state(final_node, initial_node, reference_node, config_va
""" """
score = 0 score = 0
final_node_services: Dict[str, Service] = final_node.services final_node_services: Dict[str, Service] = final_node.services
initial_node_services: Dict[str, Service] = initial_node.services
reference_node_services: Dict[str, Service] = reference_node.services reference_node_services: Dict[str, Service] = reference_node.services
for service_key, final_service in final_node_services.items(): for service_key, final_service in final_node_services.items():
reference_service = reference_node_services[service_key] reference_service = reference_node_services[service_key]
initial_service = initial_node_services[service_key] final_service = final_node_services[service_key]
if final_service.software_state == reference_service.software_state: if final_service.software_state == reference_service.software_state:
# All is well - we're no different from the reference situation # All is well - we're no different from the reference situation
@@ -208,45 +205,45 @@ def score_node_service_state(final_node, initial_node, reference_node, config_va
else: else:
# We're different from the reference situation # We're different from the reference situation
# Need to compare initial and reference state of node (i.e. at every step) # Need to compare initial and reference state of node (i.e. at every step)
if initial_service.software_state == SoftwareState.GOOD: if reference_service.software_state == SoftwareState.GOOD:
if reference_service.software_state == SoftwareState.PATCHING: if final_service.software_state == SoftwareState.PATCHING:
score += config_values.patching_should_be_good score += config_values.patching_should_be_good
elif reference_service.software_state == SoftwareState.COMPROMISED: elif final_service.software_state == SoftwareState.COMPROMISED:
score += config_values.compromised_should_be_good score += config_values.compromised_should_be_good
elif reference_service.software_state == SoftwareState.OVERWHELMED: elif final_service.software_state == SoftwareState.OVERWHELMED:
score += config_values.overwhelmed_should_be_good score += config_values.overwhelmed_should_be_good
else: else:
pass pass
elif initial_service.software_state == SoftwareState.PATCHING: elif reference_service.software_state == SoftwareState.PATCHING:
if reference_service.software_state == SoftwareState.GOOD: if final_service.software_state == SoftwareState.GOOD:
score += config_values.good_should_be_patching score += config_values.good_should_be_patching
elif reference_service.software_state == SoftwareState.COMPROMISED: elif final_service.software_state == SoftwareState.COMPROMISED:
score += config_values.compromised_should_be_patching score += config_values.compromised_should_be_patching
elif reference_service.software_state == SoftwareState.OVERWHELMED: elif final_service.software_state == SoftwareState.OVERWHELMED:
score += config_values.overwhelmed_should_be_patching score += config_values.overwhelmed_should_be_patching
elif reference_service.software_state == SoftwareState.PATCHING: elif final_service.software_state == SoftwareState.PATCHING:
score += config_values.patching score += config_values.patching
else: else:
pass pass
elif initial_service.software_state == SoftwareState.COMPROMISED: elif reference_service.software_state == SoftwareState.COMPROMISED:
if reference_service.software_state == SoftwareState.GOOD: if final_service.software_state == SoftwareState.GOOD:
score += config_values.good_should_be_compromised score += config_values.good_should_be_compromised
elif reference_service.software_state == SoftwareState.PATCHING: elif final_service.software_state == SoftwareState.PATCHING:
score += config_values.patching_should_be_compromised score += config_values.patching_should_be_compromised
elif reference_service.software_state == SoftwareState.COMPROMISED: elif final_service.software_state == SoftwareState.COMPROMISED:
score += config_values.compromised score += config_values.compromised
elif reference_service.software_state == SoftwareState.OVERWHELMED: elif final_service.software_state == SoftwareState.OVERWHELMED:
score += config_values.overwhelmed_should_be_compromised score += config_values.overwhelmed_should_be_compromised
else: else:
pass pass
elif initial_service.software_state == SoftwareState.OVERWHELMED: elif reference_service.software_state == SoftwareState.OVERWHELMED:
if reference_service.software_state == SoftwareState.GOOD: if final_service.software_state == SoftwareState.GOOD:
score += config_values.good_should_be_overwhelmed score += config_values.good_should_be_overwhelmed
elif reference_service.software_state == SoftwareState.PATCHING: elif final_service.software_state == SoftwareState.PATCHING:
score += config_values.patching_should_be_overwhelmed score += config_values.patching_should_be_overwhelmed
elif reference_service.software_state == SoftwareState.COMPROMISED: elif final_service.software_state == SoftwareState.COMPROMISED:
score += config_values.compromised_should_be_overwhelmed score += config_values.compromised_should_be_overwhelmed
elif reference_service.software_state == SoftwareState.OVERWHELMED: elif final_service.software_state == SoftwareState.OVERWHELMED:
score += config_values.overwhelmed score += config_values.overwhelmed
else: else:
pass pass
@@ -267,7 +264,6 @@ def score_node_file_system(final_node, initial_node, reference_node, config_valu
""" """
score = 0 score = 0
final_node_file_system_state = final_node.file_system_state_actual final_node_file_system_state = final_node.file_system_state_actual
initial_node_file_system_state = initial_node.file_system_state_actual
reference_node_file_system_state = reference_node.file_system_state_actual reference_node_file_system_state = reference_node.file_system_state_actual
final_node_scanning_state = final_node.file_system_scanning final_node_scanning_state = final_node.file_system_scanning
@@ -280,66 +276,66 @@ def score_node_file_system(final_node, initial_node, reference_node, config_valu
else: else:
# We're different from the reference situation # We're different from the reference situation
# Need to compare initial and reference state of node (i.e. at every step) # Need to compare initial and reference state of node (i.e. at every step)
if initial_node_file_system_state == FileSystemState.GOOD: if reference_node_file_system_state == FileSystemState.GOOD:
if reference_node_file_system_state == FileSystemState.REPAIRING: if final_node_file_system_state == FileSystemState.REPAIRING:
score += config_values.repairing_should_be_good score += config_values.repairing_should_be_good
elif reference_node_file_system_state == FileSystemState.RESTORING: elif final_node_file_system_state == FileSystemState.RESTORING:
score += config_values.restoring_should_be_good score += config_values.restoring_should_be_good
elif reference_node_file_system_state == FileSystemState.CORRUPT: elif final_node_file_system_state == FileSystemState.CORRUPT:
score += config_values.corrupt_should_be_good score += config_values.corrupt_should_be_good
elif reference_node_file_system_state == FileSystemState.DESTROYED: elif final_node_file_system_state == FileSystemState.DESTROYED:
score += config_values.destroyed_should_be_good score += config_values.destroyed_should_be_good
else: else:
pass pass
elif initial_node_file_system_state == FileSystemState.REPAIRING: elif reference_node_file_system_state == FileSystemState.REPAIRING:
if reference_node_file_system_state == FileSystemState.GOOD: if final_node_file_system_state == FileSystemState.GOOD:
score += config_values.good_should_be_repairing score += config_values.good_should_be_repairing
elif reference_node_file_system_state == FileSystemState.RESTORING: elif final_node_file_system_state == FileSystemState.RESTORING:
score += config_values.restoring_should_be_repairing score += config_values.restoring_should_be_repairing
elif reference_node_file_system_state == FileSystemState.CORRUPT: elif final_node_file_system_state == FileSystemState.CORRUPT:
score += config_values.corrupt_should_be_repairing score += config_values.corrupt_should_be_repairing
elif reference_node_file_system_state == FileSystemState.DESTROYED: elif final_node_file_system_state == FileSystemState.DESTROYED:
score += config_values.destroyed_should_be_repairing score += config_values.destroyed_should_be_repairing
elif reference_node_file_system_state == FileSystemState.REPAIRING: elif final_node_file_system_state == FileSystemState.REPAIRING:
score += config_values.repairing score += config_values.repairing
else: else:
pass pass
elif initial_node_file_system_state == FileSystemState.RESTORING: elif reference_node_file_system_state == FileSystemState.RESTORING:
if reference_node_file_system_state == FileSystemState.GOOD: if final_node_file_system_state == FileSystemState.GOOD:
score += config_values.good_should_be_restoring score += config_values.good_should_be_restoring
elif reference_node_file_system_state == FileSystemState.REPAIRING: elif final_node_file_system_state == FileSystemState.REPAIRING:
score += config_values.repairing_should_be_restoring score += config_values.repairing_should_be_restoring
elif reference_node_file_system_state == FileSystemState.CORRUPT: elif final_node_file_system_state == FileSystemState.CORRUPT:
score += config_values.corrupt_should_be_restoring score += config_values.corrupt_should_be_restoring
elif reference_node_file_system_state == FileSystemState.DESTROYED: elif final_node_file_system_state == FileSystemState.DESTROYED:
score += config_values.destroyed_should_be_restoring score += config_values.destroyed_should_be_restoring
elif reference_node_file_system_state == FileSystemState.RESTORING: elif final_node_file_system_state == FileSystemState.RESTORING:
score += config_values.restoring score += config_values.restoring
else: else:
pass pass
elif initial_node_file_system_state == FileSystemState.CORRUPT: elif reference_node_file_system_state == FileSystemState.CORRUPT:
if reference_node_file_system_state == FileSystemState.GOOD: if final_node_file_system_state == FileSystemState.GOOD:
score += config_values.good_should_be_corrupt score += config_values.good_should_be_corrupt
elif reference_node_file_system_state == FileSystemState.REPAIRING: elif final_node_file_system_state == FileSystemState.REPAIRING:
score += config_values.repairing_should_be_corrupt score += config_values.repairing_should_be_corrupt
elif reference_node_file_system_state == FileSystemState.RESTORING: elif final_node_file_system_state == FileSystemState.RESTORING:
score += config_values.restoring_should_be_corrupt score += config_values.restoring_should_be_corrupt
elif reference_node_file_system_state == FileSystemState.DESTROYED: elif final_node_file_system_state == FileSystemState.DESTROYED:
score += config_values.destroyed_should_be_corrupt score += config_values.destroyed_should_be_corrupt
elif reference_node_file_system_state == FileSystemState.CORRUPT: elif final_node_file_system_state == FileSystemState.CORRUPT:
score += config_values.corrupt score += config_values.corrupt
else: else:
pass pass
elif initial_node_file_system_state == FileSystemState.DESTROYED: elif reference_node_file_system_state == FileSystemState.DESTROYED:
if reference_node_file_system_state == FileSystemState.GOOD: if final_node_file_system_state == FileSystemState.GOOD:
score += config_values.good_should_be_destroyed score += config_values.good_should_be_destroyed
elif reference_node_file_system_state == FileSystemState.REPAIRING: elif final_node_file_system_state == FileSystemState.REPAIRING:
score += config_values.repairing_should_be_destroyed score += config_values.repairing_should_be_destroyed
elif reference_node_file_system_state == FileSystemState.RESTORING: elif final_node_file_system_state == FileSystemState.RESTORING:
score += config_values.restoring_should_be_destroyed score += config_values.restoring_should_be_destroyed
elif reference_node_file_system_state == FileSystemState.CORRUPT: elif final_node_file_system_state == FileSystemState.CORRUPT:
score += config_values.corrupt_should_be_destroyed score += config_values.corrupt_should_be_destroyed
elif reference_node_file_system_state == FileSystemState.DESTROYED: elif final_node_file_system_state == FileSystemState.DESTROYED:
score += config_values.destroyed score += config_values.destroyed
else: else:
pass pass