#2716 Agent logging now sits outside of the simulation output log directory, updated dev-mode CLI to include agent logging and added additional tests.

This commit is contained in:
Archer.Bowen
2024-07-10 13:36:37 +01:00
parent 48645d2e72
commit 239f5b86c0
11 changed files with 187 additions and 55 deletions

View File

@@ -67,7 +67,7 @@ def test_dev_mode_config_sys_log_level():
# check defaults
assert PRIMAITE_CONFIG["developer_mode"]["sys_log_level"] == "DEBUG" # DEBUG by default
result = cli(["dev-mode", "config", "-level", "WARNING"])
result = cli(["dev-mode", "config", "--sys-log-level", "WARNING"])
assert "sys_log_level=WARNING" in result.output # should print correct value
@@ -78,10 +78,30 @@ def test_dev_mode_config_sys_log_level():
assert "sys_log_level=INFO" in result.output # should print correct value
# config should reflect that log level is WARNING
# config should reflect that log level is INFO
assert PRIMAITE_CONFIG["developer_mode"]["sys_log_level"] == "INFO"
def test_dev_mode_config_agent_log_level():
"""Check that the agent log level can be changed via CLI."""
# check defaults
assert PRIMAITE_CONFIG["developer_mode"]["agent_log_level"] == "DEBUG" # DEBUG by default
result = cli(["dev-mode", "config", "-level", "WARNING"])
assert "agent_log_level=WARNING" in result.output # should print correct value
# config should reflect that log level is WARNING
assert PRIMAITE_CONFIG["developer_mode"]["agent_log_level"] == "WARNING"
result = cli(["dev-mode", "config", "--agent-log-level", "INFO"])
assert "agent_log_level=INFO" in result.output # should print correct value
# config should reflect that log level is INFO
assert PRIMAITE_CONFIG["developer_mode"]["agent_log_level"] == "INFO"
def test_dev_mode_config_sys_logs_enable_disable():
"""Test that the system logs output can be enabled or disabled."""
# check defaults
@@ -112,6 +132,36 @@ def test_dev_mode_config_sys_logs_enable_disable():
assert PRIMAITE_CONFIG["developer_mode"]["output_sys_logs"] is False
def test_dev_mode_config_agent_logs_enable_disable():
"""Test that the agent logs output can be enabled or disabled."""
# check defaults
assert PRIMAITE_CONFIG["developer_mode"]["output_agent_logs"] is False # False by default
result = cli(["dev-mode", "config", "--output-agent-logs"])
assert "output_agent_logs=True" in result.output # should print correct value
# config should reflect that output_agent_logs is True
assert PRIMAITE_CONFIG["developer_mode"]["output_agent_logs"]
result = cli(["dev-mode", "config", "--no-agent-logs"])
assert "output_agent_logs=False" in result.output # should print correct value
# config should reflect that output_agent_logs is True
assert PRIMAITE_CONFIG["developer_mode"]["output_agent_logs"] is False
result = cli(["dev-mode", "config", "-agent"])
assert "output_agent_logs=True" in result.output # should print correct value
# config should reflect that output_agent_logs is True
assert PRIMAITE_CONFIG["developer_mode"]["output_agent_logs"]
result = cli(["dev-mode", "config", "-nagent"])
assert "output_agent_logs=False" in result.output # should print correct value
# config should reflect that output_agent_logs is True
assert PRIMAITE_CONFIG["developer_mode"]["output_agent_logs"] is False
def test_dev_mode_config_pcap_logs_enable_disable():
"""Test that the pcap logs output can be enabled or disabled."""
# check defaults

View File

@@ -29,11 +29,11 @@ def test_debug_agent_log_level(agentlog, capsys):
test_string = str(uuid4())
agentlog.debug(msg=test_string, time_step=0)
agentlog.info(msg=test_string, time_step=0)
agentlog.warning(msg=test_string, time_step=0)
agentlog.error(msg=test_string, time_step=0)
agentlog.critical(msg=test_string, time_step=0)
agentlog.debug(msg=test_string)
agentlog.info(msg=test_string)
agentlog.warning(msg=test_string)
agentlog.error(msg=test_string)
agentlog.critical(msg=test_string)
captured = "".join(capsys.readouterr())
@@ -52,11 +52,11 @@ def test_info_agent_log_level(agentlog, capsys):
test_string = str(uuid4())
agentlog.debug(msg=test_string, time_step=0)
agentlog.info(msg=test_string, time_step=0)
agentlog.warning(msg=test_string, time_step=0)
agentlog.error(msg=test_string, time_step=0)
agentlog.critical(msg=test_string, time_step=0)
agentlog.debug(msg=test_string)
agentlog.info(msg=test_string)
agentlog.warning(msg=test_string)
agentlog.error(msg=test_string)
agentlog.critical(msg=test_string)
captured = "".join(capsys.readouterr())
@@ -75,11 +75,11 @@ def test_warning_agent_log_level(agentlog, capsys):
test_string = str(uuid4())
agentlog.debug(msg=test_string, time_step=0)
agentlog.info(msg=test_string, time_step=0)
agentlog.warning(msg=test_string, time_step=0)
agentlog.error(msg=test_string, time_step=0)
agentlog.critical(msg=test_string, time_step=0)
agentlog.debug(msg=test_string)
agentlog.info(msg=test_string)
agentlog.warning(msg=test_string)
agentlog.error(msg=test_string)
agentlog.critical(msg=test_string)
captured = "".join(capsys.readouterr())
@@ -98,11 +98,11 @@ def test_error_agent_log_level(agentlog, capsys):
test_string = str(uuid4())
agentlog.debug(msg=test_string, time_step=0)
agentlog.info(msg=test_string, time_step=0)
agentlog.warning(msg=test_string, time_step=0)
agentlog.error(msg=test_string, time_step=0)
agentlog.critical(msg=test_string, time_step=0)
agentlog.debug(msg=test_string)
agentlog.info(msg=test_string)
agentlog.warning(msg=test_string)
agentlog.error(msg=test_string)
agentlog.critical(msg=test_string)
captured = "".join(capsys.readouterr())
@@ -121,11 +121,11 @@ def test_critical_agent_log_level(agentlog, capsys):
test_string = str(uuid4())
agentlog.debug(msg=test_string, time_step=0)
agentlog.info(msg=test_string, time_step=0)
agentlog.warning(msg=test_string, time_step=0)
agentlog.error(msg=test_string, time_step=0)
agentlog.critical(msg=test_string, time_step=0)
agentlog.debug(msg=test_string)
agentlog.info(msg=test_string)
agentlog.warning(msg=test_string)
agentlog.error(msg=test_string)
agentlog.critical(msg=test_string)
captured = "".join(capsys.readouterr())