Skip to content

Commit cae99fd

Browse files
authored
Refactor: Update known role EOS Config input keys (#44)
1 parent 8f5e686 commit cae99fd

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

rust/validation/src/validation/dict.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ use crate::{
1818

1919
use super::Validation;
2020

21+
// This must be kept up to date when adding role keys in eos_cli_config_gen schema.
22+
// TODO: Eventually this will go away as we stop warning.
2123
const EOS_CLI_CONFIG_GEN_ROLE_KEYS: [&str; 6] = [
2224
"eos_cli_config_gen_documentation",
2325
"custom_templates",
2426
"eos_cli_config_gen_configuration",
25-
"avd_eos_cli_config_gen_input_dir",
27+
"read_structured_config_from_file",
2628
"avd_eos_cli_config_gen_validate_inputs_batch_size",
2729
"avd_structured_config_file_format",
2830
];
@@ -85,7 +87,8 @@ fn validate_keys(schema: &Dict, input: &Map<String, Value>, ctx: &mut Context) {
8587
// When at the root level, if warn_eos_cli_config_gen_keys is enabled, get the keys from the eos_cli_config_gen schema.
8688
let eos_cli_config_gen_keys: Option<&OrderMap<String, AnySchema>> = {
8789
if ctx.state.path.is_empty() && ctx.configuration.warn_eos_cli_config_gen_keys {
88-
<&Dict>::try_from(&ctx.store.eos_cli_config_gen).ok()
90+
<&Dict>::try_from(&ctx.store.eos_cli_config_gen)
91+
.ok()
8992
.and_then(|d| d.keys.as_ref())
9093
} else {
9194
None
@@ -901,13 +904,15 @@ mod tests {
901904
#[test]
902905
fn validate_eos_designs_with_eos_cli_config_gen_role_keys_no_warning() {
903906
// Test that the special eos_cli_config_gen role keys are ignored without warnings.
904-
// These keys are: eos_cli_config_gen_documentation, custom_templates, eos_cli_config_gen_configuration
905907
let store = get_test_store();
906908
let input = serde_json::json!({
907909
"key3": "valid_eos_designs_key",
908-
"eos_cli_config_gen_documentation": "should be ignored",
910+
"avd_eos_cli_config_gen_validate_inputs_batch_size": "should be ignored",
911+
"avd_structured_config_file_format": "should be ignored",
909912
"custom_templates": "should be ignored",
910-
"eos_cli_config_gen_configuration": "should be ignored"
913+
"eos_cli_config_gen_configuration": "should be ignored",
914+
"eos_cli_config_gen_documentation": "should be ignored",
915+
"read_structured_config_from_file": "should be ignored",
911916
});
912917

913918
let configuration = Configuration {

tests/validation/test_validate_json.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,16 @@ def test_validate_json_with_eos_cli_config_gen_role_keys_no_warning() -> None:
6868
"""Test that special eos_cli_config_gen role keys are silently ignored without warnings."""
6969
from pyavd_utils.validation import Configuration
7070

71-
# These special keys should be ignored: eos_cli_config_gen_documentation, custom_templates, eos_cli_config_gen_configuration
71+
# These special keys should be ignored
7272
config = Configuration(warn_eos_cli_config_gen_keys=True)
7373
json_as_str = (
74-
'{"fabric_name": "TEST_FABRIC", "eos_cli_config_gen_documentation": "docs", '
75-
'"custom_templates": "templates", "eos_cli_config_gen_configuration": "config"}'
74+
'{"fabric_name": "TEST_FABRIC", '
75+
'"avd_eos_cli_config_gen_validate_inputs_batch_size": 10,'
76+
'"avd_structured_config_file_format": "yaml",'
77+
'"custom_templates": "templates",'
78+
'"eos_cli_config_gen_configuration": "config",'
79+
'"eos_cli_config_gen_documentation": "docs",'
80+
'"read_structured_config_from_file": "file"}'
7681
)
7782
validation_result = validate_json(json_as_str, "eos_designs", config)
7883

0 commit comments

Comments
 (0)