Skip to content

Commit

Permalink
Merge pull request #97 from CiscoTestAutomation/release_24.3
Browse files Browse the repository at this point in the history
Release 24.3
  • Loading branch information
omehrabi committed Mar 27, 2024
2 parents ddf617c + 9e8c3f2 commit 3c39dcb
Show file tree
Hide file tree
Showing 42 changed files with 682 additions and 73 deletions.
76 changes: 76 additions & 0 deletions docs/changelog/2024/march.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
March 2024
==========

- Unicon v24.3
------------------------



.. csv-table:: Module Versions
:header: "Modules", "Versions"

``unicon.plugins``, v24.3
``unicon``, v24.3

Install Instructions
^^^^^^^^^^^^^^^^^^^^

.. code-block:: bash
bash$ pip install unicon.plugins
bash$ pip install unicon
Upgrade Instructions
^^^^^^^^^^^^^^^^^^^^

.. code-block:: bash
bash$ pip install --upgrade unicon.plugins
bash$ pip install --upgrade unicon
Features and Bug Fixes:
^^^^^^^^^^^^^^^^^^^^^^^




Changelogs
^^^^^^^^^^
--------------------------------------------------------------------------------
New
--------------------------------------------------------------------------------

* backend
* Option to use `UNICON_BACKEND` environment variable to select backend


--------------------------------------------------------------------------------
Fix
--------------------------------------------------------------------------------

* bases
* connection
* add operating_mode to the connection object


--------------------------------------------------------------------------------
New
--------------------------------------------------------------------------------

* discovery_tokens
* Add prompt_recovery to dialog

* iosxe
* Connection provider
* Add support for operating mode detection on connect()


--------------------------------------------------------------------------------
Fix
--------------------------------------------------------------------------------

* iosxr
* Modified connection provider
* Updated connection provider for handeling token discovery.


1 change: 1 addition & 0 deletions docs/changelog/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
.. toctree::
:maxdepth: 2

2024/march
2024/february
2024/january
2023/november
Expand Down
54 changes: 54 additions & 0 deletions docs/changelog_plugins/2024/march.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
March 2024
==========

- Unicon.Plugins v24.3
------------------------



.. csv-table:: Module Versions
:header: "Modules", "Versions"

``unicon.plugins``, v24.3
``unicon``, v24.3

Install Instructions
^^^^^^^^^^^^^^^^^^^^

.. code-block:: bash
bash$ pip install unicon.plugins
bash$ pip install unicon
Upgrade Instructions
^^^^^^^^^^^^^^^^^^^^

.. code-block:: bash
bash$ pip install --upgrade unicon.plugins
bash$ pip install --upgrade unicon
Features and Bug Fixes:
^^^^^^^^^^^^^^^^^^^^^^^




Changelogs
^^^^^^^^^^
--------------------------------------------------------------------------------
Fix
--------------------------------------------------------------------------------

* cheetah/ap
* Add more prompt handler to statemachine

* token discovery
* Add more prompt to dialog
* Update dialog timeout

* generic
* Added encryption selection pattern
* Removed duplicate enable_secret_handler and setup_enter_selection functions


1 change: 1 addition & 0 deletions docs/changelog_plugins/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Plugins Changelog
.. toctree::
:maxdepth: 2

2024/march
2024/february
2024/january
2023/november
Expand Down
2 changes: 1 addition & 1 deletion src/unicon/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '24.2'
__version__ = '24.3'

supported_chassis = [
'single_rp',
Expand Down
4 changes: 3 additions & 1 deletion src/unicon/plugins/cheetah/ap/statemachine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from unicon.plugins.generic.statemachine import GenericSingleRpStateMachine
from unicon.plugins.generic.statements import GenericStatements
from unicon.plugins.generic.statements import GenericStatements, default_statement_list
from unicon.statemachine import State, Path, StateMachine
from unicon.eal.dialogs import Dialog, Statement
from unicon.plugins.generic.patterns import GenericPatterns
Expand Down Expand Up @@ -46,3 +46,5 @@ def create(self):
self.add_path(enable_to_shell)
self.add_path(shell_to_enable)
self.add_path(enable_to_disable)

self.add_default_statements(default_statement_list)
2 changes: 1 addition & 1 deletion src/unicon/plugins/generic/connection_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ def get_connection_dialog(self):
self.connection.settings.PASSWORD_PROMPT)
return con.connect_reply + \
Dialog(custom_auth_stmt + connection_statement_list
if custom_auth_stmt else connection_statement_list)
if custom_auth_stmt else connection_statement_list)
2 changes: 2 additions & 0 deletions src/unicon/plugins/generic/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,5 @@ def __init__(self):
self.get_cursor_position = r'\x1b\[6n'

self.new_password = r'^(Enter new password|Confirm password):\s*$'

self.enter_your_encryption_selection_2 = r'^.*?Enter your encryption selection( \[2])?:\s*$'
3 changes: 2 additions & 1 deletion src/unicon/plugins/generic/service_statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ def config_session_locked_handler(context):
generic_statements.syslog_msg_stmt,
# Below statements have loop_continue=False
password_stmt, press_enter, press_return,
connection_closed_stmt, eof_statement
connection_closed_stmt, eof_statement,
generic_statements.enter_your_encryption_selection_stmt
]

# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
Expand Down
48 changes: 14 additions & 34 deletions src/unicon/plugins/generic/statements.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,16 @@ def syslog_wait_send_return(spawn, session):
session['buffer_len'] = len(spawn.buffer)


def chatty_term_wait(spawn, trim_buffer=False):
def chatty_term_wait(spawn, trim_buffer=False, wait_time=None):
""" Wait some time for any chatter to cease from the device.
"""
chatty_wait_time = wait_time or spawn.settings.ESCAPE_CHAR_CHATTY_TERM_WAIT
for retry_number in range(spawn.settings.ESCAPE_CHAR_CHATTY_TERM_WAIT_RETRIES):

if buffer_settled(spawn, spawn.settings.ESCAPE_CHAR_CHATTY_TERM_WAIT):
if buffer_settled(spawn, chatty_wait_time):
break
else:
buffer_wait(spawn, spawn.settings.ESCAPE_CHAR_CHATTY_TERM_WAIT * (retry_number + 1))
buffer_wait(spawn, chatty_wait_time * (retry_number + 1))

else:
spawn.log.warning('The buffer has not settled because the device is chatty. '
Expand Down Expand Up @@ -334,35 +335,6 @@ def setup_enter_selection(spawn, context):
spawn.sendline('2')


def enable_secret_handler(spawn, context, session):
if 'password_attempts' not in session:
session['password_attempts'] = 1
else:
session['password_attempts'] += 1
if session.password_attempts > spawn.settings.PASSWORD_ATTEMPTS:
raise UniconAuthenticationError('Too many enable password retries')

enable_credential_password = get_enable_credential_password(context=context)
if enable_credential_password and len(enable_credential_password) >= \
spawn.settings.ENABLE_SECRET_MIN_LENGTH:
spawn.sendline(enable_credential_password)
else:
spawn.log.warning('Using enable secret from TEMP_ENABLE_SECRET setting')
enable_secret = spawn.settings.TEMP_ENABLE_SECRET
context['setup_selection'] = 0
spawn.sendline(enable_secret)


def setup_enter_selection(spawn, context):
selection = context.get('setup_selection')
if selection is not None:
if str(selection) == '0':
spawn.log.warning('Not saving setup configuration')
spawn.sendline(f'{selection}')
else:
spawn.sendline('2')


def ssh_tacacs_handler(spawn, context):
result = False
start_cmd = spawn.spawn_command
Expand Down Expand Up @@ -758,6 +730,12 @@ def __init__(self):
loop_continue=True,
continue_timer=False)

self.enter_your_encryption_selection_stmt = Statement(pattern=pat.enter_your_encryption_selection_2,
action=setup_enter_selection,
args=None,
loop_continue=True,
continue_timer=True)

#############################################################
# Statement lists
#############################################################
Expand Down Expand Up @@ -803,7 +781,8 @@ def __init__(self):

initial_statement_list = [generic_statements.init_conf_stmt,
generic_statements.mgmt_setup_stmt,
generic_statements.enter_your_selection_stmt
generic_statements.enter_your_selection_stmt,
generic_statements.enter_your_encryption_selection_stmt
]


Expand All @@ -817,4 +796,5 @@ def __init__(self):
default_statement_list + \
authentication_statement_list + \
initial_statement_list + \
pre_connection_statement_list
pre_connection_statement_list

6 changes: 3 additions & 3 deletions src/unicon/plugins/iosxe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from unicon.bases.routers.connection import BaseSingleRpConnection
from unicon.plugins.iosxe.statemachine import IosXESingleRpStateMachine
from unicon.plugins.iosxe.statemachine import IosXEDualRpStateMachine
from unicon.plugins.generic import GenericSingleRpConnectionProvider,\
GenericDualRPConnection
from unicon.plugins.iosxe.connection_provider import IosxeSingleRpConnectionProvider
from unicon.plugins.generic import GenericDualRPConnection
from unicon.plugins.iosxe.settings import IosXESettings

from unicon.plugins.iosxe import service_implementation as svc
Expand Down Expand Up @@ -55,7 +55,7 @@ class IosXESingleRpConnection(BaseSingleRpConnection):
platform = None
chassis_type = 'single_rp'
state_machine_class = IosXESingleRpStateMachine
connection_provider_class = GenericSingleRpConnectionProvider
connection_provider_class = IosxeSingleRpConnectionProvider
subcommand_list = IosXEServiceList
settings = IosXESettings()

Expand Down
70 changes: 70 additions & 0 deletions src/unicon/plugins/iosxe/connection_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

import re
from unicon.eal.dialogs import Dialog
from unicon.eal.dialogs import Statement
from unicon.plugins.generic.connection_provider import GenericSingleRpConnectionProvider
from unicon.plugins.generic.patterns import GenericPatterns
from unicon.statemachine import State
from unicon.plugins.generic.statements import chatty_term_wait
from unicon.plugins.utils import get_device_mode


class IosxeSingleRpConnectionProvider(GenericSingleRpConnectionProvider):
""" Implements Iosxe singleRP Connection Provider,
This class overrides the base class with the
additional dialogs and steps required for
connecting to any device via generic implementation
"""
def __init__(self, *args, **kwargs):

""" Initializes the generic connection provider
"""
super().__init__(*args, **kwargs)


def learn_tokens(self):
con = self.connection
if (not con.learn_tokens or not con.settings.LEARN_DEVICE_TOKENS)\
and not con.operating_mode:
# make sure device is in valid unicon state
con.sendline()
con.state_machine.go_to('any',
con.spawn,
context=con.context,
prompt_recovery=con.prompt_recovery)
# If the learn token is not enabled we need to see if the device is in Controller-Managed mode
# or it's in autonomous mode. If the device is in Controller-Managed mode, enable token discovery.
if get_device_mode(con) == 'Controller-Managed':
# The device is in Controller-Manged mode so we need to learn the abstraction tokens.
con.overwrite_testbed_tokens = True
con.learn_tokens = True
# "operating_mode" attribute is added to the connection object to avoid getting in a loop
con.operating_mode = True
# Add learn tokens state to state machine so it can use a looser
# prompt pattern to match. Required for at least some Linux prompts
if 'learn_tokens_state' not in [str(s) for s in con.state_machine.states]:
self.learn_tokens_state = State('learn_tokens_state',
GenericPatterns().learn_os_prompt)
con.state_machine.add_state(self.learn_tokens_state)

# The first thing we need to is to send stop PnP discovery otherwise device will not execute any command.
con.spawn.sendline('pnpa service discovery stop')
# The device may reload after the command we get the dialog statements from reload service and try to handle that
dialog = con.reload.dialog
dialog.append(Statement(pattern=GenericPatterns().enable_prompt,action=None,
args=None, loop_continue=False, continue_timer=False))
dialog.process(con.spawn,
context=con.context,
timeout=con.settings.RELOAD_WAIT,
prompt_recovery=con.prompt_recovery)
# The device may be chatty at this time we need to wait for
# it to to settle down.
chatty_wait_time = con.settings.CONTROLLER_MODE_CHATTY_WAIT_TIME
chatty_term_wait(con.spawn, trim_buffer=True, wait_time=chatty_wait_time)
con.sendline()
con.state_machine.go_to('any',
con.spawn,
context=con.context,
prompt_recovery=con.prompt_recovery)
super().learn_tokens()

3 changes: 3 additions & 0 deletions src/unicon/plugins/iosxe/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def __init__(self):

self.RELOAD_WAIT = 300

# wait time for buffer to settle down
self.CONTROLLER_MODE_CHATTY_WAIT_TIME = 5

self.CONFIG_LOCK_RETRY_SLEEP = 30
self.CONFIG_LOCK_RETRIES = 10

Expand Down
Loading

0 comments on commit 3c39dcb

Please sign in to comment.