napalm-automation / napalm

Network Automation and Programmability Abstraction Layer with Multivendor support
Apache License 2.0
2.26k stars 555 forks source link

napalm cli does not parse the transport optional arg #2007

Closed gioccher closed 1 year ago

gioccher commented 1 year ago

Description of Issue/Question

Specifying --optional_args "transport=ssh" when running the napalm console app produces an error. Transport for eos was introduced in https://github.com/napalm-automation/napalm/pull/1502

Did you follow the steps from https://github.com/napalm-automation/napalm#faq

Setup

napalm version

napalm==4.1.0
nornir-napalm==0.4.0

Network operating system version

Arista CCS-720XP-48ZC2-F
Hardware version: 11.20
Serial number: xxx
Hardware MAC address: xxx
System MAC address: xxx

Software image version: 4.29.3M
Architecture: i686
Internal build version: 4.29.3M-31391479.4293M
Internal build ID: f4f7d173-d28c-4f4a-94bc-52220b7ac5ea
Image format version: 3.0
Image optimization: Strata-4GB

Uptime: 12 weeks, 5 days, 11 hours and 35 minutes
Total memory: 3982764 kB
Free memory: 2370728 kB

Steps to Reproduce the Issue

Error Traceback

2023-09-08 12:27:20,202 - napalm - DEBUG - Starting napalm's debugging tool
2023-09-08 12:27:20,202 - napalm - DEBUG - Gathering napalm packages
2023-09-08 12:27:20,202 - napalm - DEBUG - napalm==4.1.0
2023-09-08 12:27:20,202 - napalm - DEBUG - get_network_driver - Calling with args: ('eos',), {}
2023-09-08 12:27:20,202 - napalm - DEBUG - get_network_driver - Successful
Traceback (most recent call last):
  File "/opt/homebrew/bin/napalm", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/napalm/base/clitools/cl_napalm.py", line 308, in main
    run_tests(args)
  File "/opt/homebrew/lib/python3.11/site-packages/napalm/base/clitools/cl_napalm.py", line 269, in run_tests
    optional_args = helpers.parse_optional_args(args.optional_args)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/napalm/base/clitools/helpers.py", line 131, in parse_optional_args
    return {
           ^
  File "/opt/homebrew/lib/python3.11/site-packages/napalm/base/clitools/helpers.py", line 132, in <dictcomp>
    x.split("=")[0]: ast.literal_eval(x.split("=")[1])
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ast.py", line 110, in literal_eval
    return _convert(node_or_string)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ast.py", line 109, in _convert
    return _convert_signed_num(node)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ast.py", line 83, in _convert_signed_num
    return _convert_num(node)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ast.py", line 74, in _convert_num
    _raise_malformed_node(node)
  File "/opt/homebrew/Cellar/python@3.11/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ast.py", line 71, in _raise_malformed_node
    raise ValueError(msg + f': {node!r}')
ValueError: malformed node or string on line 1: <ast.Name object at 0x110fdb130>
bewing commented 1 year ago

Can you try again with napalm --user "myusername" --password "mypassword" --vendor eos --optional_args "transport=\"ssh\"" --debug 10.1.2.3 call get_facts ? I believe AST is expecting a valid python statement, so it needs a quoted string

gioccher commented 1 year ago

Thank you, that did the trick