ktbyers / netmiko

Multi-vendor library to simplify Paramiko SSH connections to network devices
MIT License
3.61k stars 1.31k forks source link

ruckus_fastiron - getting this error for most basic command - TypeError: can only concatenate str (not "NoneType") to str #3390

Open TPSreports2020 opened 8 months ago

TPSreports2020 commented 8 months ago

Description of Issue/Question

I have some super basic code that used to work and now it always returns "TypeError: can only concatenate str (not "NoneType") to str" - I have tried adding longer read_timeout values and explicitly adding expect_string=r"#", but I understand that this is already set for ruckus_fastiron?

Setup

Netmiko version

netmiko==4.2.0

Netmiko device_type (if relevant to the issue)

(Paste device_type between quotes below)

ruckus_fastiron

Steps to Reproduce the Issue

Error Traceback

(Paste the complete traceback of the exception between quotes below)

mymachine Scripts % python3 ruckusICX.py
Traceback (most recent call last):
  File "/Users/tannersears/Scripts/ruckusICX.py", line 16, in <module>
    with ConnectHandler(**ruckus_fastiron) as net_connect:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/netmiko/ssh_dispatcher.py", line 388, in ConnectHandler
    return ConnectionClass(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/netmiko/base_connection.py", line 462, in __init__
    self._open()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/netmiko/base_connection.py", line 468, in _open
    self._try_session_preparation()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/netmiko/base_connection.py", line 963, in _try_session_preparation
    self.session_preparation()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/netmiko/ruckus/ruckus_fastiron.py", line 17, in session_preparation
    self.enable()
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/netmiko/ruckus/ruckus_fastiron.py", line 46, in enable
    new_data = self.read_until_prompt_or_pattern(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/netmiko/base_connection.py", line 835, in read_until_prompt_or_pattern
    return self.read_until_pattern(
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/netmiko/base_connection.py", line 706, in read_until_pattern
    output = output + match_str
             ~~~~~~~^~~~~~~~~~~

Relevant Python code

(Please try to essentialize your Python code to the minimum code needed to reproduce the issue) (Paste the code between the quotes below)

from netmiko import ConnectHandler

ruckus_fastiron = {
    "device_type": "ruckus_fastiron",
    "host": "192.168.0.69",
    "username": "super",
    "password": "password"
}

# Show command that we execute.
command = "show version"

with ConnectHandler(**ruckus_fastiron) as net_connect:
    # Enable mode
    # net_connect.enable()
    # print(net_connect.find_prompt())

    output = net_connect.send_command(command)

# Automatically cleans-up the output so that only the show output is returned
print()
print(output)
print()

I also get the same output if I just run :

from netmiko import ConnectHandler

ruckus_fastiron = {
    "device_type": "ruckus_fastiron",
    "host": "192.168.0.69",
    "username": "super",
    "password": "password"
}

with ConnectHandler(**ruckus_fastiron) as net_connect:
    print(net_connect.find_prompt())
TPSreports2020 commented 8 months ago

I upgraded to 4.3.0 and still get same output

tkapica commented 8 months ago

The same issue with my ruckus access point dirty hack to make it work (I removed set_base_prompt from session_preparation and made enable method to brute force login (I retry it in case help is not shown))

from retry import retry

class RuckusSHH(RuckusFastironSSH): def session_preparation(self) -> None: """FastIron requires to be enable mode to disable paging.""" self._test_channel_read() self.enable() self.disable_paging(command="skip-page-display")

Clear the read buffer

    time.sleep(0.3 * self.global_delay_factor)
    self.clear_buffer()

@retry(Exception, tries=5)
def enable(
        self,
        cmd: str = "enable",
        pattern: str = "",
        enable_pattern: Optional[str] = None,
        check_state: bool = True,
        re_flags: int = re.IGNORECASE,
) -> str:
    self.read_until_prompt_or_pattern(
        pattern="Please login:", re_flags=re_flags, read_entire_line=True, read_timeout=1)
    self.write_channel(self.normalize_cmd(self.username))
    time.sleep(1)
    self.read_until_prompt_or_pattern(
        pattern="password:", re_flags=re_flags, read_entire_line=True, read_timeout=1)
    self.write_channel(self.normalize_cmd(self.secret))
    time.sleep(1)
    return self.send_command("help", read_timeout=1)

   Maybe it will be helpful until netmiko creates proper fix.
ktbyers commented 8 months ago

@TPSreports2020 It looks like Netmiko is failing on this enable() call here:

https://github.com/ktbyers/netmiko/blob/develop/netmiko/ruckus/ruckus_fastiron.py#L17

I would probably try turning on Netmiko logging and see if that gives us more clues.

https://github.com/ktbyers/netmiko/blob/develop/COMMON_ISSUES.md#enable-netmiko-logging-of-all-reads-and-writes-of-the-communications-channel

Either that or enable the Netmiko session_log.

The None Type concatenation error just means None was returned in a context when a string was expected, but we need to figure out why that happened.

Is this a FastIron switch or is this an access-point?

It is possible that Netmiko is failing to properly identify the base_prompt and this is causing a failure later on.

TPSreports2020 commented 7 months ago

I found that if I keep running it, sometimes it works, but not sure why.. Here are the log files for a time where it worked and a time it failed.

icx-miko-fail.log icx-miko-test-working.log

semirke commented 3 weeks ago

Same randomly appearing issue here, too, with fastiron.