Repository: ktbyers/netmiko
Issue: Cisco ASA connect failure when device is already in enable mode after login

Works in version 3.1.0 and breaks in version 3.3.0.

If the device is not in enable mode at login then it works correctly and goes into enable mode allowing the script to continue.

If the device drops to enable mode at login (aaa authorization exec LOCAL auto-enable) then we get the below traceback at login using 3.3.0 but not with 3.1.0.

```
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/paramiko/channel.py", line 699, in recv
    out = self.in_buffer.read(nbytes, self.timeout)
  File "/usr/local/lib/python3.6/site-packages/paramiko/buffered_pipe.py", line 164, in read
    raise PipeTimeout()
paramiko.buffered_pipe.PipeTimeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/netmiko/base_connection.py", line 569, in _read_channel_expect
    new_data = self.remote_conn.recv(MAX_BUFFER)
  File "/usr/local/lib/python3.6/site-packages/paramiko/channel.py", line 701, in recv
    raise socket.timeout()
socket.timeout

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/netmiko/base_connection.py", line 1680, in enable
    pattern=pattern, re_flags=re_flags
  File "/usr/local/lib/python3.6/site-packages/netmiko/base_connection.py", line 669, in read_until_prompt_or_pattern
    return self._read_channel_expect(combined_pattern, re_flags=re_flags)
  File "/usr/local/lib/python3.6/site-packages/netmiko/base_connection.py", line 580, in _read_channel_expect
    "Timed-out reading channel, data not available."
netmiko.ssh_exception.NetmikoTimeoutException: Timed-out reading channel, data not available.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "vpn_stats.py", line 313, in <module>
    vpnstats()
  File "vpn_stats.py", line 308, in vpnstats
    vpn_sess_obj.updateVpnSessionStats()
  File "vpn_stats.py", line 235, in updateVpnSessionStats
    cmd_out = self.__ciscoSessions(fw[X].strip())
  File "vpn_stats.py", line 138, in __ciscoSessions
    secret=self.password)
  File "/usr/local/lib/python3.6/site-packages/netmiko/ssh_dispatcher.py", line 315, in ConnectHandler
    return ConnectionClass(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/netmiko/cisco/cisco_asa_ssh.py", line 15, in __init__
    return super().__init__(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/netmiko/base_connection.py", line 346, in __init__
    self._open()
  File "/usr/local/lib/python3.6/site-packages/netmiko/base_connection.py", line 352, in _open
    self._try_session_preparation()
  File "/usr/local/lib/python3.6/site-packages/netmiko/base_connection.py", line 788, in _try_session_preparation
    self.session_preparation()
  File "/usr/local/lib/python3.6/site-packages/netmiko/cisco/cisco_asa_ssh.py", line 35, in session_preparation
    self.enable()
  File "/usr/local/lib/python3.6/site-packages/netmiko/cisco/cisco_asa_ssh.py", line 28, in enable
    cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags
  File "/usr/local/lib/python3.6/site-packages/netmiko/cisco_base_connection.py", line 25, in enable
    cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags
  File "/usr/local/lib/python3.6/site-packages/netmiko/base_connection.py", line 1690, in enable
    raise ValueError(msg)
ValueError: Failed to enter enable mode. Please ensure you pass the 'secret' argument to ConnectHandler.
```


Changed files:
netmiko/cisco/cisco_asa_ssh.py

diff --git a/netmiko/cisco/cisco_asa_ssh.py b/netmiko/cisco/cisco_asa_ssh.py
index 92dfc393..544a79ed 100644
--- a/netmiko/cisco/cisco_asa_ssh.py
+++ b/netmiko/cisco/cisco_asa_ssh.py
@@ -14,23 +14,16 @@ class CiscoAsaSSH(CiscoSSHConnection):
         kwargs.setdefault("allow_auto_change", True)
         return super().__init__(*args, **kwargs)
 
-    def check_config_mode(self, check_string=")#", pattern=r"[>\\#]"):
-        return super().check_config_mode(check_string=check_string, pattern=pattern)
-
-    def enable(
-        self,
-        cmd="enable",
-        pattern="ssword",
-        enable_pattern=r"\\#",
-        re_flags=re.IGNORECASE,
-    ):
-        return super().enable(
-            cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags
-        )
-
     def session_preparation(self):
         """Prepare the session after the connection has been established."""
 
+        # Make sure the ASA is ready
+        command = "show curpriv\\n"
+        self.write_channel(command)
+        self.read_until_pattern(pattern=re.escape(command.strip()))
+
+        # The 'enable' call requires the base_prompt to be set.
+        self.set_base_prompt()
         if self.secret:
             self.enable()
         else:
@@ -49,6 +42,20 @@ class CiscoAsaSSH(CiscoSSHConnection):
 
         self.set_base_prompt()
 
+    def check_config_mode(self, check_string=")#", pattern=r"[>\\#]"):
+        return super().check_config_mode(check_string=check_string, pattern=pattern)
+
+    def enable(
+        self,
+        cmd="enable",
+        pattern="ssword",
+        enable_pattern=r"\\#",
+        re_flags=re.IGNORECASE,
+    ):
+        return super().enable(
+            cmd=cmd, pattern=pattern, enable_pattern=enable_pattern, re_flags=re_flags
+        )
+
     def send_command_timing(self, *args, **kwargs):
         """
         If the ASA is in multi-context mode, then the base_prompt needs to be