mpenning / ciscoconfparse2

Parse, Audit, Query, Build, and Modify Arista / Cisco / Juniper / Palo Alto / F5 configurations.
http://www.pennington.net/py/ciscoconfparse2/
GNU General Public License v3.0
35 stars 7 forks source link

[Bug]: Diff class error #8

Closed codingnetworksb closed 7 months ago

codingnetworksb commented 7 months ago

Contact Details

codingnetworks@gmail.com

What happened?

I tried to test the Diff Script that i found on the official documentation: http://www.pennington.net/py/ciscoconfparse2/tutorial_build_diffs.html#diff-script

for "old_config" i created the file "fullconfig.conf" with the following content:

interface Ethernet1/0/0
 description Connected to crouter1 Gi1 - 172.17.10.1/30
 undo shutdown
 ip address 172.17.10.2 255.255.255.0
 undo dcn
 undo dcn mode vlan
#
interface Ethernet1/0/1
 description Connected to crouter2 Gi2 - 172.17.50.1/30
 undo shutdown
 ip address 172.17.50.2 255.255.255.0
 undo dcn
 undo dcn mode vlan
#
interface Ethernet1/0/2
 description Connected to hrouter2 GE1/0/2 - 172.17.60.2/30
 undo shutdown
 ip address 172.17.60.1 255.255.255.0
 undo dcn mode vlan
#
interface Ethernet1/0/3
 description Management 192.168.56.103/24
 undo shutdown
 ip address 192.168.56.103 255.255.255.0
 undo dcn mode vlan
#
interface Ethernet1/0/4
 undo shutdown
 undo dcn mode vlan
#
interface Ethernet1/0/5
 undo shutdown
 undo dcn mode vlan
#
interface Ethernet1/0/6
 undo shutdown
 undo dcn mode vlan
#
interface Ethernet1/0/7
 undo shutdown
 undo dcn mode vlan
#
interface Ethernet1/0/8
 undo shutdown
 undo dcn mode vlan
#
interface Ethernet1/0/9
 undo shutdown
 undo dcn mode vlan
#
interface GigabitEthernet0/0/0
 undo shutdown

For "new_config" i created the file "newconfig.conf" with the following content

interface Ethernet1/0/2
shutdown

When I got to this line.:

diff = Diff(old_config=old_config, new_config=new_config)

I had an error, that i think could be a bug. See the part of the traceback that catched my attention:

in _load_from_string_lines
    for line in config_text.splitlines():
                └ ['interface Ethernet1/0/2', 'shutdown']

AttributeError: 'list' object has no attribute 'splitlines'

The code is expecting object "config_text" to be a String and convert it to a list. But it seems that it was already converted to a List in a step before.

CiscoConfParse Version

0.7.33

What Operating System are you using?

Linux - Debian, Ubuntu, CentOS, RHEL or others

What Python version(s) have this problem?

Python 3.10

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

from ciscoconfparse2.ciscoconfparse2 import Diff

# Parse the original configuration
old_config = 'fullconfig.conf'
new_config = 'newconfig.conf'

diff = Diff(old_config=old_config, new_config=new_config)

Python tracebacks

2024-04-06 13:13:54.391 | ERROR    | __main__:<module>:1 - An error has been caught in function '<module>', process 'MainProcess' (44632), thread 'MainThread' (140103149501312):
Traceback (most recent call last):

> File "<stdin>", line 1, in <module>
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/ciscoconfparse2/ciscoconfparse2.py", line 3716, in __init__
    self.host.load_generated_config(new_config)
    │    │                          └ ['interface Ethernet1/0/2', 'shutdown']
    │    └ <member 'host' of 'Diff' objects>
    └ <ciscoconfparse2.ciscoconfparse2.Diff object at 0x7f6c4aecc100>
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/host.py", line 127, in load_generated_config
    self._generated_config = self._load_config(config_text)
    │    │                   │    │            └ ['interface Ethernet1/0/2', 'shutdown']
    │    │                   │    └ <function Host._load_config at 0x7f6c4c069fc0>
    │    │                   └ Host(hostname=example_hostname)
    │    └ None
    └ Host(hostname=example_hostname)
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/host.py", line 164, in _load_config
    hier.load_from_string(config_text)
    │    │                └ ['interface Ethernet1/0/2', 'shutdown']
    │    └ <function HConfig.load_from_string at 0x7f6c4bfee680>
    └ HConfig(host=Host(hostname=example_hostname))
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/root.py", line 140, in load_from_string
    self._load_from_string_lines(config_text)
    │    │                       └ ['interface Ethernet1/0/2', 'shutdown']
    │    └ <function HConfig._load_from_string_lines at 0x7f6c4bfeee60>
    └ HConfig(host=Host(hostname=example_hostname))
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/root.py", line 337, in _load_from_string_lines
    for line in config_text.splitlines():
                └ ['interface Ethernet1/0/2', 'shutdown']

AttributeError: 'list' object has no attribute 'splitlines'
2024-04-06 13:13:54.391 | ERROR    | __main__:<module>:1 - An error has been caught in function '<module>', process 'MainProcess' (44632), thread 'MainThread' (140103149501312):
Traceback (most recent call last):

> File "<stdin>", line 1, in <module>
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/ciscoconfparse2/ciscoconfparse2.py", line 3716, in __init__
    self.host.load_generated_config(new_config)
    │    │                          └ ['interface Ethernet1/0/2', 'shutdown']
    │    └ <member 'host' of 'Diff' objects>
    └ <ciscoconfparse2.ciscoconfparse2.Diff object at 0x7f6c4aecc100>
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/host.py", line 127, in load_generated_config
    self._generated_config = self._load_config(config_text)
    │    │                   │    │            └ ['interface Ethernet1/0/2', 'shutdown']
    │    │                   │    └ <function Host._load_config at 0x7f6c4c069fc0>
    │    │                   └ Host(hostname=example_hostname)
    │    └ None
    └ Host(hostname=example_hostname)
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/host.py", line 164, in _load_config
    hier.load_from_string(config_text)
    │    │                └ ['interface Ethernet1/0/2', 'shutdown']
    │    └ <function HConfig.load_from_string at 0x7f6c4bfee680>
    └ HConfig(host=Host(hostname=example_hostname))
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/root.py", line 140, in load_from_string
    self._load_from_string_lines(config_text)
    │    │                       └ ['interface Ethernet1/0/2', 'shutdown']
    │    └ <function HConfig._load_from_string_lines at 0x7f6c4bfeee60>
    └ HConfig(host=Host(hostname=example_hostname))
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/root.py", line 337, in _load_from_string_lines
    for line in config_text.splitlines():
                └ ['interface Ethernet1/0/2', 'shutdown']

AttributeError: 'list' object has no attribute 'splitlines'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/loguru/_logger.py", line 1277, in catch_wrapper
    return function(*args, **kwargs)
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/ciscoconfparse2/ciscoconfparse2.py", line 3716, in __init__
    self.host.load_generated_config(new_config)
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/host.py", line 127, in load_generated_config
    self._generated_config = self._load_config(config_text)
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/host.py", line 164, in _load_config
    hier.load_from_string(config_text)
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/root.py", line 140, in load_from_string
    self._load_from_string_lines(config_text)
  File "/home/malvarez/.pyenv/versions/venv_napalm_vrp/lib/python3.10/site-packages/hier_config/root.py", line 337, in _load_from_string_lines
    for line in config_text.splitlines():
AttributeError: 'list' object has no attribute 'splitlines'

Relevant log output

No Logs

Code of Conduct

mpenning commented 7 months ago

Thank you for finding this; it should be fixed in Version 0.7.36. Please confirm and close, if-so.

codingnetworksb commented 7 months ago

I confirmed you that the issue is solved in Version 0.7.36. I'm closing the issue. Thanks!