Skip to content

Commit

Permalink
dual banner test case single banner feature search (networktocode#445)
Browse files Browse the repository at this point in the history
* dual banner test case single banner feature search
* Refactor test, implement dual banner fix (networktocode#456)
* Refactor test, implement dual banner fix
* Add tests for multiple banners

---------

Co-authored-by: Anthony House <[email protected]>

---------

Co-authored-by: Jeff Kala <[email protected]>
Co-authored-by: housepbass <[email protected]>
Co-authored-by: Anthony House <[email protected]>
  • Loading branch information
4 people authored Feb 9, 2024
1 parent 5bcf145 commit 61505c0
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 1 deletion.
4 changes: 4 additions & 0 deletions netutils/config/compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ def section_config(feature: t.Dict[str, t.Union[str, bool, t.List[str]]], device
os_parser = parser_map[network_os]
config_parsed = os_parser(device_cfg)
for line in config_parsed.config_lines:
# If multiple banners, line after first banner will be None.
# This conditional allows multiple banners in config.
if not line.config_line:
continue
if match:
if line.parents: # pylint: disable=no-else-continue
section_config_list.append(line.config_line)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
hostname dual-banner
!
banner exec ^C
=========
actual config exec banner
-========
^C
banner motd ^C
======
actual config motd banner
======
|| ($hostname) ||
^C
!
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
hostname dual-banner
!
banner exec ^C
=========
actual config exec banner
-========
^C
banner motd ^C
======
actual config motd banner
======
|| ($hostname) ||
^C
!
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feature = {"name": "exec banner", "ordered": False, "section": ["banner exec"]}
network_os = "cisco_ios"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
hostname dual-banner
!
banner exec ^C
=========
intended config exec banner
-========
^C
banner motd ^C
======
intended config motd banner
======
|| ($hostname) ||
^C
!
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
data = {
"compliant": False,
"missing": "banner exec ^C\n=========\nintended config exec banner\n-========^C",
"extra": "banner exec ^C\n=========\nactual config exec banner\n-========^C",
"cannot_parse": True,
"unordered_compliant": False,
"ordered_compliant": False,
"actual": "banner exec ^C\n=========\nactual config exec banner\n-========^C",
"intended": "banner exec ^C\n=========\nintended config exec banner\n-========^C",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feature = {"name": "exec banner", "ordered": False, "section": ["banner"]}
network_os = "cisco_ios"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
hostname dual-banner
!
banner exec ^C
=========
intended config exec banner
-========
^C
banner motd ^C
======
intended config motd banner
======
|| ($hostname) ||
^C
!
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
hostname dual-banner
!
banner exec ^C
=========
actual config exec banner
-========
^C
banner motd ^C
======
actual config motd banner
======
|| ($hostname) ||
^C
!
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feature = {"name": "exec banner", "ordered": False, "section": ["banner motd"]}
network_os = "cisco_ios"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
hostname dual-banner
!
banner exec ^C
=========
intended config exec banner
-========
^C
banner motd ^C
======
intended config motd banner
======
|| ($hostname) ||
^C
!
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
data = {
"compliant": False,
"missing": "banner motd ^C\n======\nintended config motd banner\n======\n || ($hostname) ||^C",
"extra": "banner motd ^C\n======\nactual config motd banner\n======\n || ($hostname) ||^C",
"cannot_parse": True,
"unordered_compliant": False,
"ordered_compliant": False,
"actual": "banner motd ^C\n======\nactual config motd banner\n======\n || ($hostname) ||^C",
"intended": "banner motd ^C\n======\nintended config motd banner\n======\n || ($hostname) ||^C",
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
data = {
"compliant": False,
"missing": "banner exec ^C\n=========\nintended config exec banner\n-========^C\nbanner motd ^C\n======\nintended config motd banner\n======\n || ($hostname) ||^C",
"extra": "banner exec ^C\n=========\nactual config exec banner\n-========^C\nbanner motd ^C\n======\nactual config motd banner\n======\n || ($hostname) ||^C",
"cannot_parse": True,
"unordered_compliant": False,
"ordered_compliant": False,
"actual": "banner exec ^C\n=========\nactual config exec banner\n-========^C\nbanner motd ^C\n======\nactual config motd banner\n======\n || ($hostname) ||^C",
"intended": "banner exec ^C\n=========\nintended config exec banner\n-========^C\nbanner motd ^C\n======\nintended config motd banner\n======\n || ($hostname) ||^C",
}
7 changes: 6 additions & 1 deletion tests/unit/test_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ def test_feature_compliance(_file, get_text_data, get_python_data):
received_data = get_python_data(truncate_file + "_received.py", "data")
feature = get_python_data(truncate_file + "_feature.py", "feature")
nos = get_python_data(truncate_file + "_feature.py", "network_os")
assert compliance.feature_compliance(feature, actual_config, intended_config, nos) == received_data

# Parse feature configs from config files
backup_str = compliance.section_config(feature, actual_config, nos)
intended_str = compliance.section_config(feature, intended_config, nos)

assert compliance.feature_compliance(feature, backup_str, intended_str, nos) == received_data


def test_incorrect_cfg_type():
Expand Down

0 comments on commit 61505c0

Please sign in to comment.