Merged PR 291: #2357 - Allow empty nodes, links, and agents arrays in config file

## Summary
Allowed the config to not have nodes, links and agents and still be parsed

## Test process
Tested with config file that doesn't have any simulation key/value pair

## Checklist
- [X] PR is linked to a **work item**
- [X] **acceptance criteria** of linked ticket are met
- [X] performed **self-review** of the code
- [X] written **tests** for any new functionality added with this PR
- [ ] updated the **documentation** if this PR changes or adds functionality
- [ ] written/updated **design docs** if this PR implements new functionality
- [ ] updated the **change log**
- [X] ran **pre-commit** checks for code style
- [ ] attended to any **TO-DOs** left in the code

#2357 - Allowed the config to not have nodes, links and agents and still be parsed

Related work items: #2357
This commit is contained in:
Christopher McCarthy
2024-03-02 19:30:22 +00:00
3 changed files with 59 additions and 5 deletions

View File

@@ -0,0 +1,31 @@
training_config:
rl_framework: SB3
rl_algorithm: PPO
seed: 333
n_learn_episodes: 1
n_eval_episodes: 5
max_steps_per_episode: 128
deterministic_eval: false
n_agents: 1
agent_references:
- defender
io_settings:
save_checkpoints: true
checkpoint_interval: 5
save_step_metadata: false
save_pcap_logs: true
save_sys_logs: true
game:
max_episode_length: 256
ports:
- ARP
- DNS
- HTTP
- POSTGRES_SERVER
protocols:
- ICMP
- TCP
- UDP

View File

@@ -0,0 +1,19 @@
import yaml
from primaite.game.game import PrimaiteGame
from tests import TEST_ASSETS_ROOT
CONFIG_FILE = TEST_ASSETS_ROOT / "configs" / "no_nodes_links_agents_network.yaml"
def test_no_nodes_links_agents_config():
"""Tests PrimaiteGame can be created from config file where there are no nodes, links, agents in the config file."""
with open(CONFIG_FILE, "r") as f:
cfg = yaml.safe_load(f)
game = PrimaiteGame.from_config(cfg)
network = game.simulation.network
assert len(network.nodes) == 0
assert len(network.links) == 0