Skip to content

Indented banner raises ValueError and loses the whole config: is_banner_start and regex_banner disagree #907

Description

@ggiesen

Environment

  • Python version: 3.12.13
  • netutils version: 1.19.1

Expected Behavior

A line that is_banner_start() accepts should be parseable by regex_banner.

Observed Behavior

They disagree, and the whole config is lost rather than one line.

is_banner_start() matches the stripped line (line.lstrip().startswith(...)), while CiscoConfigParser.regex_banner requires banner at column 0:

^(banner\s+\S+|\s*vacant-message)\s+(?P<banner_delimiter>\^C|.)

An indented banner is therefore detected as a banner start, fails to resolve a delimiter, and the banner_end setter raises. The exception leaves __init__, so one such line makes the entire config unparseable.

Two hints that this is an oversight rather than intent: in that pattern the vacant-message alternative allows \s* and the banner one does not; and ASAConfigParser parses an indented banner, including the one shipped at tests/unit/mock/config/parser/base/cisco_asa/asa_nested_banner_sent.txt, while IOS, NX-OS and EOS raise on the same input.

Steps to Reproduce

  1. pip install netutils==1.19.1

  2. Run:

    from netutils.config.parser import IOSConfigParser
    IOSConfigParser("group-policy P attributes\n banner value hello\n")
    # ValueError: There was an error parsing your banner, the end of the banner could not be found
    

ASAConfigParser on that same input returns ['group-policy P attributes', ' banner value hello']. The sample is ASA syntax, chosen because netutils already ships a fixture for it; the point is that the two functions disagree, not that the line is valid IOS.

Possible fixes

Allow leading whitespace in regex_banner, or stop stripping in is_banner_start(). If the former, note the delimiter group . also matches the first character of a following word, so \^C|[^\w\s] may be wanted with it.

Happy to PR against develop.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions