-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from projectsyn/feat/ignore_class_notfound_re…
…gexp Add support for reclass option `ignore_class_notfound_regexp`
- Loading branch information
Showing
14 changed files
with
197 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/node/node_render_tests_ignore_class_notfound_regexp.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::types::Value; | ||
use crate::{Config, Reclass}; | ||
|
||
#[test] | ||
fn test_render_n1() { | ||
let mut c = Config::new( | ||
Some("./tests/inventory-class-notfound-regexp"), | ||
None, | ||
None, | ||
None, | ||
) | ||
.unwrap(); | ||
c.load_from_file("reclass-config.yml").unwrap(); | ||
let r = Reclass::new_from_config(c).unwrap(); | ||
|
||
let n1 = r.render_node("n1").unwrap(); | ||
assert_eq!( | ||
n1.classes, | ||
vec!["service.foo", "service.bar", "missing", "a", "amissing"] | ||
); | ||
assert_eq!( | ||
n1.parameters.get(&"a".into()), | ||
Some(&Value::Literal("a".into())) | ||
); | ||
} | ||
|
||
#[test] | ||
fn test_render_n2() { | ||
let mut c = Config::new( | ||
Some("./tests/inventory-class-notfound-regexp"), | ||
None, | ||
None, | ||
None, | ||
) | ||
.unwrap(); | ||
c.load_from_file("reclass-config.yml").unwrap(); | ||
let r = Reclass::new_from_config(c).unwrap(); | ||
|
||
let n2 = r.render_node("n2"); | ||
assert!(n2.is_err()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
parameters: | ||
a: a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
parameters: | ||
b: b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
parameters: | ||
c: c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
parameters: | ||
d: d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
classes: | ||
- service.foo | ||
- service.bar | ||
- missing | ||
- a | ||
- amissing | ||
|
||
parameters: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
classes: | ||
- foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Add reclass-config.yml for Kapitan/Python reclass | ||
nodes_uri: nodes | ||
classes_uri: classes | ||
compose_node_name: false | ||
allow_none_override: true | ||
ignore_class_notfound: true | ||
ignore_class_notfound_regexp: | ||
- service\..* | ||
- .*missing.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import pytest | ||
|
||
import reclass_rs | ||
|
||
|
||
def test_ignore_regexp_render_n1(): | ||
r = reclass_rs.Reclass.from_config( | ||
"./tests/inventory-class-notfound-regexp", "reclass-config.yml" | ||
) | ||
assert r.config.ignore_class_notfound_regexp == ["service\\..*", ".*missing.*"] | ||
|
||
n1 = r.nodeinfo("n1") | ||
|
||
assert n1 is not None | ||
|
||
|
||
def test_ignore_regexp_render_n2(): | ||
r = reclass_rs.Reclass.from_config( | ||
"./tests/inventory-class-notfound-regexp", "reclass-config.yml" | ||
) | ||
assert r.config.ignore_class_notfound_regexp == ["service\\..*", ".*missing.*"] | ||
|
||
with pytest.raises( | ||
ValueError, match="Error while rendering n2: Class foo not found" | ||
): | ||
n2 = r.nodeinfo("n2") | ||
|
||
|
||
def test_ignore_regexp_update_config_render_n2(): | ||
r = reclass_rs.Reclass.from_config( | ||
"./tests/inventory-class-notfound-regexp", "reclass-config.yml" | ||
) | ||
r.set_ignore_class_notfound_regexp([".*"]) | ||
assert r.config.ignore_class_notfound_regexp == [".*"] | ||
|
||
n2 = r.nodeinfo("n2") | ||
assert n2 is not None |