Skip to content

Commit 409359f

Browse files
authored
Merge pull request #162 from projectsyn/fix/class-notfound-regexp-from-dict
Fix initialization for `ignore_class_notfound_regexp` in `Config::from_dict()`
2 parents 10e92a0 + 854f915 commit 409359f

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,11 @@ impl Config {
305305
PyValueError::new_err(format!("Error while setting option {kstr}: {e}"))
306306
})?;
307307
}
308+
cfg.compile_ignore_class_notfound_patterns().map_err(|e| {
309+
PyValueError::new_err(format!(
310+
"Error while compiling class_notfound_regexp patterns: {e}"
311+
))
312+
})?;
308313

309314
Ok(cfg)
310315
}

tests/test_ignore_class_notfound_regexp.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,24 @@ def test_ignore_regexp_update_config_render_n2():
3535

3636
n2 = r.nodeinfo("n2")
3737
assert n2 is not None
38+
39+
40+
def test_ignore_regexp_from_dict():
41+
config_options = {
42+
"nodes_uri": "nodes",
43+
"classes_uri": "classes",
44+
"ignore_class_notfound": True,
45+
"ignore_class_notfound_regexp": ["service\\..*", ".*missing.*"],
46+
}
47+
c = reclass_rs.Config.from_dict(
48+
"./tests/inventory-class-notfound-regexp", config_options
49+
)
50+
r = reclass_rs.Reclass.from_config(c)
51+
52+
n1 = r.nodeinfo("n1")
53+
assert n1 is not None
54+
55+
with pytest.raises(
56+
ValueError, match="Error while rendering n2: Class foo not found"
57+
):
58+
n2 = r.nodeinfo("n2")

0 commit comments

Comments
 (0)