Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: A comma in running_config breaks the ciscoconfparse2.Diff output #16

Open
1 task done
temonumentum opened this issue Jan 17, 2025 · 1 comment
Open
1 task done
Labels
bug Something isn't working information-required This bug needs more information to be fixed.

Comments

@temonumentum
Copy link

temonumentum commented Jan 17, 2025

Contact Details

[email protected]

What happened?

Hello! Thanks for this awesome tool. I had been using it with customers for the last 6 months (when I discovered it), and really saved me a lot of work.

ciscoconfparse2.Diff does not work as expected when it finds commas in lines such as descriptions or the banner.

In the following examples I am using ciscoconfparse2.Diff to compare a configuration file (a backup of the running-config of a router) and a running-configuration (taken using SSH of the same router).

For example:

Having the following banner in a configuration template:

banner login ^C
******************************** NOTICE ********************************

This is a private computer system.
It is for authorized use only. Users (authorized or unauthorized)
have no explicit or implicit expectation of privacy.
Any or all uses of this system and all files on this system may be
intercepted, monitored, recorded, copied, audited, inspected, and
disclosed to authorized site, information security, and law enforcement
personnel, as well as authorized officials of other agencies, both
domestic and foreign. By using this system, the user consents to such
interception, monitoring, recording, copying, auditing, inspection, and
disclosure at the discretion of authorized site or personnel.

Unauthorized or improper use of this system may result in civil and
criminal penalties. By continuing to access this system you indicate
your awareness of and consent to these terms and conditions of use.
DISCONNECT IMMEDIATELY if you do not agree to the conditions stated in
this warning.
***********************************************************************
^C

and having the exact same banner in the running configuration of a Cisco IOS XDR router.

C8500-12X#sh run | begin banner
banner login ^CC
******************************** NOTICE ********************************

This is a private computer system.
It is for authorized use only. Users (authorized or unauthorized)
have no explicit or implicit expectation of privacy.
Any or all uses of this system and all files on this system may be
intercepted, monitored, recorded, copied, audited, inspected, and
disclosed to authorized site, information security, and law enforcement
personnel, as well as authorized officials of other agencies, both
domestic and foreign. By using this system, the user consents to such
interception, monitoring, recording, copying, auditing, inspection, and
disclosure at the discretion of authorized site or personnel.

Unauthorized or improper use of this system may result in civil and
criminal penalties. By continuing to access this system you indicate
your awareness of and consent to these terms and conditions of use.
DISCONNECT IMMEDIATELY if you do not agree to the conditions stated in
this warning.

***********************************************************************
^C

When I run ciscoconfparse2.Diff, the output will look like the following (I am running ciscoconfparse2.Diff through Ansible, that's the reason the output result.differences is in YAML)

result.differences:
- |-
    no banner login ^CC
    ******************************** NOTICE ********************************
  
    This is a private computer system.
    It is for authorized use only. Users (authorized or unauthorized)
    have no explicit or implicit expectation of privacy.
    Any or all uses of this system and all files on this system may be
    intercepted, monitored, recorded, copied, audited, inspected, and
    disclosed to authorized site, information security, and law enforcement
    personnel, as well as authorized officials of other agencies, both
    domestic and foreign. By using this system, the user consents to such
    interception, monitoring, recording, copying, auditing, inspection, and
    disclosure at the discretion of authorized site or personnel.
  
    Unauthorized or improper use of this system may result in civil and
    criminal penalties. By continuing to access this system you indicate
    your awareness of and consent to these terms and conditions of use.
    DISCONNECT IMMEDIATELY if you do not agree to the conditions stated in
    this warning.
  
    ***********************************************************************
    ^C
  - |-
    banner login ^C
    ******************************** NOTICE ********************************
  
    This is a private computer system.
    It is for authorized use only. Users (authorized or unauthorized)
    have no explicit or implicit expectation of privacy.
    Any or all uses of this system and all files on this system may be
    intercepted
     monitored
     recorded
     copied
     audited
     inspected
     and
    disclosed to authorized site
     information security
     and law enforcement
    personnel
     as well as authorized officials of other agencies
     both
    domestic and foreign. By using this system
     the user consents to such
    interception
     monitoring
     recording
     copying
     auditing
     inspection
     and
    disclosure at the discretion of authorized site or personnel.
  
    Unauthorized or improper use of this system may result in civil and
    criminal penalties. By continuing to access this system you indicate
    your awareness of and consent to these terms and conditions of use.
    DISCONNECT IMMEDIATELY if you do not agree to the conditions stated in
    this warning.
  
    ***********************************************************************
    ^C

When I take the commas out of the banner in both, the configuration template and the running config, the result is quite neat and as expected, no differences are shown:

result.differences: []

An extra example can be provided using class maps.

If I add the following class map to my configuration template and to my running-config, I expect to find no differences, nevertheless, something happens with the commas and the output is not the one expected:

Class map added:

class-map match-any system-cpp-police-sw-forward
  description Sw forwarding, L2 LVX data packets, LOGGING, Transit Traffic

ciscoconfparse2.Diff output:

result.differences:
  - class-map match-any system-cpp-police-sw-forward
  - '  no description Sw forwarding, L2 LVX data packets, LOGGING, Transit Traffic'
  - '  description Sw forwarding'
  - '  L2 LVX data packets'
  - '  LOGGING'
  - '  Transit Traffic'

CiscoConfParse Version

ciscoconfparse2 == 0.7.73

What Operating System are you using?

Linux - Debian, Ubuntu, CentOS, RHEL or others

What Python version(s) have this problem?

Python 3.11

Show us how to reproduce the problem. Please tell us if the problem is specific to certain inputs or situations.

Run `ciscoconfparse.Diff` comparing two configs that have commas on the descriptions, or in any place where commas can be configured, such as a banner.

Python tracebacks

No Tracebacks

Relevant log output

Code of Conduct

@temonumentum temonumentum added the bug Something isn't working label Jan 17, 2025
@temonumentum temonumentum changed the title [Bug]: A comma in running_config breaks the ciscoconfparse.Diff [Bug]: A comma in running_config breaks the ciscoconfparse2.Diff Jan 17, 2025
@temonumentum temonumentum changed the title [Bug]: A comma in running_config breaks the ciscoconfparse2.Diff [Bug]: A comma in running_config breaks the ciscoconfparse2.Diff Jan 17, 2025
@temonumentum temonumentum changed the title [Bug]: A comma in running_config breaks the ciscoconfparse2.Diff [Bug]: A comma in running_config breaks the ciscoconfparse2.Diff output Jan 17, 2025
@mpenning
Copy link
Owner

mpenning commented Jan 18, 2025

Thank you for reaching out.

I do not know what you're doing with ansible. Please remove ansible from the problem and reproduce with strictly ciscoconfparse2, such as a script like this (which BTW does not seem to have a problem)...

from ciscoconfparse2 import Diff

CONF1 = """!
banner motd ^C
Hello World
^C
!
end
"""

CONF2 = """!
banner motd ^C
Hello, World
^C
!
end
"""

result = Diff(CONF1, CONF2).get_diff()
print(result)

This prints an expected result with no problem:

['no banner motd ^C\nHello World\n^C', 'banner motd ^C\nHello, World\n^C']

@mpenning mpenning added the information-required This bug needs more information to be fixed. label Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working information-required This bug needs more information to be fixed.
Projects
None yet
Development

No branches or pull requests

2 participants