Skip to content

Commit 3f86be3

Browse files
authored
Merge pull request #102 from CiscoTestAutomation/release_24.7
release_24.7
2 parents 46cdcc1 + 1adae75 commit 3f86be3

File tree

14 files changed

+195
-2
lines changed

14 files changed

+195
-2
lines changed

docs/changelog/2024/july.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
July 2024
2+
==========
3+
4+
July 30 - Unicon v24.7
5+
------------------------
6+
7+
8+
9+
.. csv-table:: Module Versions
10+
:header: "Modules", "Versions"
11+
12+
``unicon.plugins``, v24.7
13+
``unicon``, v24.7
14+
15+
Install Instructions
16+
^^^^^^^^^^^^^^^^^^^^
17+
18+
.. code-block:: bash
19+
20+
bash$ pip install unicon.plugins
21+
bash$ pip install unicon
22+
23+
Upgrade Instructions
24+
^^^^^^^^^^^^^^^^^^^^
25+
26+
.. code-block:: bash
27+
28+
bash$ pip install --upgrade unicon.plugins
29+
bash$ pip install --upgrade unicon
30+
31+
Features and Bug Fixes:
32+
^^^^^^^^^^^^^^^^^^^^^^^
33+
34+
35+
36+
37+
Changelogs
38+
^^^^^^^^^^
39+
--------------------------------------------------------------------------------
40+
Fix
41+
--------------------------------------------------------------------------------
42+
43+
* generic
44+
* Updated with `sleep_time` to handle the copy command
45+
46+

docs/changelog/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Changelog
44
.. toctree::
55
:maxdepth: 2
66

7+
2024/july
78
2024/june
89
2024/may
910
2024/april

docs/changelog_plugins/2024/july.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
July 2024
2+
==========
3+
4+
July 30 - Unicon.Plugins v24.7
5+
------------------------
6+
7+
8+
9+
.. csv-table:: Module Versions
10+
:header: "Modules", "Versions"
11+
12+
``unicon.plugins``, v24.7
13+
``unicon``, v24.7
14+
15+
Install Instructions
16+
^^^^^^^^^^^^^^^^^^^^
17+
18+
.. code-block:: bash
19+
20+
bash$ pip install unicon.plugins
21+
bash$ pip install unicon
22+
23+
Upgrade Instructions
24+
^^^^^^^^^^^^^^^^^^^^
25+
26+
.. code-block:: bash
27+
28+
bash$ pip install --upgrade unicon.plugins
29+
bash$ pip install --upgrade unicon
30+
31+
Features and Bug Fixes:
32+
^^^^^^^^^^^^^^^^^^^^^^^
33+
34+
35+
36+
37+
Changelogs
38+
^^^^^^^^^^
39+
--------------------------------------------------------------------------------
40+
Fix
41+
--------------------------------------------------------------------------------
42+
43+
* iosxe
44+
* add "disable_selinux" parameter to bash_console service, to automatically
45+
46+

docs/changelog_plugins/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Plugins Changelog
44
.. toctree::
55
:maxdepth: 2
66

7+
2024/july
78
2024/june
89
2024/may
910
2024/april

src/unicon/plugins/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '24.6'
1+
__version__ = '24.7'
22

33
supported_chassis = [
44
'single_rp',

src/unicon/plugins/generic/service_implementation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import collections
2121
import ipaddress
2222
from itertools import chain
23+
import time
2324
import warnings
2425
from datetime import datetime, timedelta
2526

@@ -1666,6 +1667,9 @@ def call_service(self, reply=Dialog([]), *args, **kwargs): # noqa: C901
16661667
for retry_num in range(self.max_attempts):
16671668
spawn.sendline(copy_string)
16681669
try:
1670+
if (sleep_time := kwargs.get('sleep_time')):
1671+
con.log.info(f"sleep for {sleep_time} seconds")
1672+
time.sleep(sleep_time)
16691673
self.result = dialog.process(spawn,
16701674
context=copy_context,
16711675
timeout=timeout)

src/unicon/plugins/iosxe/cat9k/c9800cl/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11

22
from unicon.plugins.iosxe.cat9k.c9800 import IosXEc9800ServiceList, IosXEc9800SingleRpConnection, IosXEc9800DualRPConnection
3-
3+
from unicon.plugins.iosxe import service_implementation as svc
44

55
class IosXEc9800CLServiceList(IosXEc9800ServiceList):
66
def __init__(self):
77
super().__init__()
8+
self.rommon = svc.Rommon
89

910

1011

src/unicon/plugins/iosxe/service_implementation.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ def pre_service(self, *args, **kwargs):
165165
handle.context['_chassis'] = kwargs.get('chassis')
166166
else:
167167
handle.context.pop('_chassis', None)
168+
if kwargs.get('disable_selinux') is not None:
169+
handle.context['_disable_selinux'] = kwargs.get('disable_selinux')
170+
elif hasattr(self, 'disable_selinux'):
171+
handle.context['_disable_selinux'] = self.disable_selinux
172+
else:
173+
handle.context.pop('_disable_selinux', None)
168174
super().pre_service(*args, **kwargs)
169175

170176
class ContextMgr(GenericBashService.ContextMgr):
@@ -176,6 +182,12 @@ def __init__(self, connection, enable_bash=False, timeout=None, **kwargs):
176182

177183
def __enter__(self):
178184

185+
if self.conn.context.get('_disable_selinux'):
186+
try:
187+
self.conn.execute('set platform software selinux permissive')
188+
except SubCommandFailure:
189+
pass
190+
179191
self.conn.log.debug('+++ attaching bash shell +++')
180192
# enter shell prompt
181193
self.conn.state_machine.go_to(
@@ -190,6 +202,16 @@ def __enter__(self):
190202

191203
return self
192204

205+
def __exit__(self, type, value, traceback):
206+
res = super().__exit__(type, value, traceback)
207+
208+
if self.conn.context.get('_disable_selinux'):
209+
try:
210+
self.conn.execute('set platform software selinux default')
211+
except SubCommandFailure:
212+
pass
213+
214+
return res
193215

194216
class ResetStandbyRP(GenericResetStandbyRP):
195217
""" Service to reset the standby rp.

src/unicon/plugins/tests/mock_data/ios/ios_mock_copy.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,18 @@ wait_for_recovery:
7070
new_state: enable
7171
response: |
7272
sending keyboard interrupt
73+
74+
copy_src_bootflash:
75+
prompt: "Source filename []? "
76+
commands:
77+
"/c8000aep-universalk9.17.12.04.0.4708.SSA.bin":
78+
new_state: dest_file_name
79+
80+
dest_file_name:
81+
prompt: "Destination filename [c8000aep-universalk9.17.12.04.0.4708.SSA.bin]? "
82+
commands:
83+
"test/c8000aep-universalk9.17.12.04.0.4708.SSA.bin":
84+
new_state: enable
85+
response: |
86+
Copy in progress...CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
87+
787557605 bytes copied in 71.982 secs (10941035 bytes/sec)

src/unicon/plugins/tests/mock_data/ios/ios_mock_data.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ enable:
341341
new_state: exec_standby
342342
"redundancy switch-activity force":
343343
new_state: confirm_switch_activity
344+
"copy bootflash: usb:":
345+
new_state: copy_src_bootflash
344346
"copy flash: flash-3:":
345347
new_state: copy_src
346348
"copy tftp: bootflash:":

src/unicon/plugins/tests/mock_data/iosxe/iosxe_mock_data.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ general_enable:
300300
"copy somefile.bin flash:":
301301
new_state: confirm_abort_copy
302302

303+
"set platform software selinux permissive": ""
304+
305+
"set platform software selinux default": ""
306+
303307
general_maintence_mode_confirm:
304308
prompt: "Template default will be applied. Do you want to continue?[confirm] "
305309
commands:

src/unicon/plugins/tests/mock_data/iosxe/iosxe_mock_data_isr.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ enable_isr:
168168
"traceroute vrf MG501":
169169
new_state: traceroute_proto_isr
170170

171+
"set platform software selinux permissive":
172+
response:
173+
- |2
174+
^
175+
% Invalid input detected at '^' marker."
176+
177+
"set platform software selinux default":
178+
response:
179+
- |2
180+
^
181+
% Invalid input detected at '^' marker."
182+
171183
"not a real command":
172184
response:
173185
- |2

src/unicon/plugins/tests/test_copy_service.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ def test_copy_error_no_file(self):
117117
timeout=9)
118118
self.assertEqual(err.exception.args[0], 'Copy failed')
119119

120+
def test_copy_to_usb(self):
121+
test_output = self.d.copy(source = 'bootflash:', dest = 'usb:',
122+
source_file = '/c8000aep-universalk9.17.12.04.0.4708.SSA.bin',
123+
dest_file = 'test/c8000aep-universalk9.17.12.04.0.4708.SSA.bin',
124+
sleep_time = 10)
125+
expected_output = self.md.mock_data['dest_file_name']['commands']\
126+
['test/c8000aep-universalk9.17.12.04.0.4708.SSA.bin']['response']
127+
test_output = '\n'.join(test_output.splitlines())
128+
expected_output = '\n'.join(expected_output.splitlines())
129+
self.assertIn(expected_output, test_output)
130+
120131

121132
@patch.object(unicon.settings.Settings, 'POST_DISCONNECT_WAIT_SEC', 0)
122133
@patch.object(unicon.settings.Settings, 'GRACEFUL_DISCONNECT_WAIT_SEC', 0.2)

src/unicon/plugins/tests/test_plugin_iosxe.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,34 @@ def test_bash_chassis_standby(self):
529529
self.assertIn('WLC1#', c.spawn.match.match_output)
530530
c.disconnect()
531531

532+
def test_bash_disable_selinux(self):
533+
c = Connection(hostname='Router',
534+
start=['mock_device_cli --os iosxe --state general_enable --hostname Router'],
535+
os='iosxe',
536+
credentials=dict(default=dict(username='cisco', password='cisco')),
537+
log_buffer=True
538+
)
539+
with c.bash_console(disable_selinux=True) as console:
540+
self.assertIn('[Router_RP_0:/]$', c.spawn.match.match_output)
541+
console.execute('df /bootflash/')
542+
self.assertIn('set platform software selinux default', c.spawn.match.match_output)
543+
self.assertIn('Router#', c.spawn.match.match_output)
544+
c.disconnect()
545+
546+
def test_bash_disable_selinux_invalid_cmds(self):
547+
c = Connection(hostname='Router',
548+
start=['mock_device_cli --os iosxe --state enable_isr --hostname Router'],
549+
os='iosxe',
550+
credentials=dict(default=dict(username='cisco', password='cisco')),
551+
log_buffer=True
552+
)
553+
with c.bash_console(disable_selinux=True) as console:
554+
self.assertIn('[Router:/]$', c.spawn.match.match_output)
555+
console.execute('ls')
556+
self.assertIn('set platform software selinux default', c.spawn.match.match_output)
557+
self.assertIn('Router#', c.spawn.match.match_output)
558+
c.disconnect()
559+
532560
class TestIosXESDWANConfigure(unittest.TestCase):
533561

534562
def test_config_transaction(self):

0 commit comments

Comments
 (0)