diff --git a/netutils/config/parser.py b/netutils/config/parser.py index 17c8a6a3..ea870955 100644 --- a/netutils/config/parser.py +++ b/netutils/config/parser.py @@ -1402,6 +1402,9 @@ def build_config_relationship(self) -> t.List[ConfigLine]: if line is None: break elif self.is_banner_start(line): + # if line at this position is identified as a banner start, we also need to set the delimiter + if not self.delimiter: + self.set_delimiter(line) line = self._build_banner(line) # type: ignore self._update_config_lines(line) diff --git a/tests/unit/test_parser.py b/tests/unit/test_parser.py index ac72bbe8..c5d034a9 100644 --- a/tests/unit/test_parser.py +++ b/tests/unit/test_parser.py @@ -78,3 +78,31 @@ def test_duplicate_line(): ) with pytest.raises(IndexError, match=r".*This error is likely from a duplicate line detected.*"): compliance.parser_map["cisco_ios"](logging).config_lines # pylint: disable=expression-not-assigned + + +def test_banner_delimiter_iosxr(): + banner_cfg = ( + "banner motd ^This is the first line of a test banner.\n" + "This is the second line of a test banner.\n" + "This is the third line of a test banner.^\n" + "\n" + "ntp\n" + " server 192.0.2.1\n" + " server 192.0.2.2\n" + ) + delimiter = compliance.parser_map["cisco_iosxr"](banner_cfg).delimiter + assert delimiter == "^" + + +def test_banner_eof_delimiter_iosxr(): + banner_cfg = ( + "ntp\n" + " server 192.0.2.1\n" + " server 192.0.2.2\n" + "\n" + "banner motd ^This is the first line of a test banner.\n" + "This is the second line of a test banner.\n" + "This is the third line of a test banner.^\n" + ) + delimiter = compliance.parser_map["cisco_iosxr"](banner_cfg).delimiter + assert delimiter == "^"