Skip to content

Commit

Permalink
Merge pull request #170 from CiscoTestAutomation/release_24.6
Browse files Browse the repository at this point in the history
Releasing v24.6
  • Loading branch information
omehrabi authored Jun 26, 2024
2 parents 77b5f80 + 6b49eb0 commit 9e1343b
Show file tree
Hide file tree
Showing 212 changed files with 6,733 additions and 568 deletions.
18 changes: 18 additions & 0 deletions pkgs/clean-pkg/changelog/2024/june.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--------------------------------------------------------------------------------
Fix
--------------------------------------------------------------------------------

* iosxe
* Modified InstallRemoveInactive
* Modified logic to search image using regular expression in remove_inactive_pkgs
* Added c9800_cl stages back


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

* clean
* Added ConfigureInterfaces stage


62 changes: 54 additions & 8 deletions pkgs/clean-pkg/sdk_generator/output/github_clean.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,41 @@
}
}
},
"ApplySelfSignedCert": {
"folders": {
"iosxe": {
"folders": {
"cat9k": {
"folders": {
"c9800": {
"folders": {
"c9800_cl": {
"doc": " This stage configures the self-signed-certificate for the given trustpoint.\n\n Stage Schema\n ------------\n apply_self_signed_cert:\n\n key_size (int, optional): Key size to be configured. Default is 2048\n\n signature_algorithm (str, optional): Algorithm to be applied. Default is sha256\n\n encryption_type (int, optional): Encryption type to be configured. Default is 0\n\n password (str): Password to be configured for the trustpoint.\n\n timeout (int, optional): Execute timeout in seconds. Defaults to 300.\n\n Examples:\n apply_self_signed_cert:\n key_size:2048\n signature_algorithm:sha256\n encryption_type:0\n password:cisco123\n timeout: 150\n ",
"module_name": "stages.iosxe.cat9k.c9800.c9800_cl.stages",
"package": "genie.libs.clean",
"tokens": {
"submodel": "c9800_cl"
},
"uid": "ApplySelfSignedCert",
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/cat9k/c9800/c9800_cl/stages.py#L19"
}
},
"tokens": {
"model": "c9800"
}
}
},
"tokens": {
"platform": "cat9k"
}
}
},
"tokens": {
"os": "iosxe"
}
}
}
},
"BackupFileOnDevice": {
"doc": "This stage copies an existing file on the device and prepends 'backup_'\nto the start of the file name.\n\nStage Schema\n------------\nbackup_file_on_device:\n\n copy_dir (str): Directory containing file to be backed up\n\n copy_file (str): File to be backed up\n\n overwrite (bool, optional): Overwrite the file if exists. Defaults to True.\n\n timeout (int, optional): Copy timeout in second. Defaults to 300.\n\nExample\n-------\nbackup_file_on_device:\n copy_dir: bootflash:\n copy_file: ISSUCleanGolden.cfg\n",
"folders": {},
Expand Down Expand Up @@ -184,6 +219,14 @@
}
}
},
"ConfigureInterfaces": {
"doc": "This stage configures interfaces on the device.\n\n This stages uses genie Conf objects and build_config() API to configure \n interfaces on devices.\n\nStage Schema\n------------\nconfigure_interfaces:\n interfaces:\n <interfaces>: # regex, default: '.*'\n attributes ('list', optional): List of interface attributes to configure.\n Default: [enabled, speed, breakout]\n\nExample\n-------\nconfigure_interfaces:\n interfaces:\n <interface>: # regex\n attributes:\n - enabled\n - speed\n - ipv4\n",
"folders": {},
"module_name": "stages.stages",
"package": "genie.libs.clean",
"uid": "ConfigureInterfaces",
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/stages.py#L2940"
},
"ConfigureManagement": {
"doc": "This stage configures the management IP settings on the device.\n\nStage Schema\n------------\nconfigure_management:\n\n address ('dict', optional): Address(es) to configure on the device (syntax: address/mask) (optional)\n ipv4 ('str') or ('list'): ipv4 address\n ipv6 ('str') or ('list'): ipv6 address\n\n gateway: (dict, optional) Gateway address(es) for default route\n ipv4 ('str') or ('list'): ipv4 gateway address\n ipv6 ('str') or ('list'): ipv6 gateway address\n\n vrf (str, optional): VRF to use for management interface\n\n interface (str, optional): Management interface to use\n\n routes ('dict', optional):\n ipv4 (list of 'dict'): ipv4 routes\n - subnet: (str) subnet including mask\n next_hop: (str) next_hop for this subnet\n ipv6 (list of 'dict'): ipv6 routes\n - subnet: (str) subnet including mask\n next_hop: (str) next_hop for this subnet\n\n dhcp_timeout ('int', optional): DHCP timeout in seconds (default: 30)\n\n protocols ('list', optional): [list of protocols]\n\n set_hostname (bool): Configure device hostname (default: True)\n\n\nExample\n-------\nconfigure_management:\n vrf: Mgmt-vrf\n\n",
"folders": {},
Expand All @@ -202,7 +245,7 @@
"os": "iosxe"
},
"uid": "ConfigureReplace",
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/stages.py#L2025"
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/stages.py#L2026"
}
}
},
Expand Down Expand Up @@ -257,7 +300,7 @@
"os": "iosxe"
},
"uid": "Connect",
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/stages.py#L2081"
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/stages.py#L2082"
},
"linux": {
"folders": {
Expand Down Expand Up @@ -311,7 +354,7 @@
"os": "iosxe"
},
"uid": "CopyToDevice",
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/stages.py#L1380"
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/stages.py#L1381"
}
},
"module_name": "stages.stages",
Expand Down Expand Up @@ -478,7 +521,7 @@
"os": "iosxe"
},
"uid": "InstallImage",
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/stages.py#L534"
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/stages.py#L535"
},
"iosxr": {
"folders": {
Expand Down Expand Up @@ -540,7 +583,7 @@
"os": "iosxe"
},
"uid": "InstallPackages",
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/stages.py#L787"
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/stages.py#L788"
}
}
},
Expand Down Expand Up @@ -655,7 +698,7 @@
"os": "iosxe"
},
"uid": "Reload",
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/stages.py#L871"
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/stages.py#L872"
}
},
"module_name": "stages.stages",
Expand All @@ -673,7 +716,7 @@
"os": "iosxe"
},
"uid": "ResetConfiguration",
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/stages.py#L2263"
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/stages.py#L2264"
}
}
},
Expand Down Expand Up @@ -707,7 +750,7 @@
"os": "iosxe"
},
"uid": "RommonBoot",
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/stages.py#L1118"
"url": "https://github.com/CiscoTestAutomation/genielibs/tree/master/pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/stages.py#L1119"
}
}
},
Expand Down Expand Up @@ -1141,6 +1184,9 @@
"ncs540",
"sdwan",
"wsim"
],
"submodel": [
"c9800_cl"
]
}
}
2 changes: 1 addition & 1 deletion pkgs/clean-pkg/src/genie/libs/clean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'''

# metadata
__version__ = '24.5'
__version__ = '24.6'
__author__ = 'Cisco Systems Inc.'
__contact__ = ['[email protected]', '[email protected]']
__copyright__ = 'Copyright (c) 2019, Cisco Systems Inc.'
Expand Down
3 changes: 2 additions & 1 deletion pkgs/clean-pkg/src/genie/libs/clean/stages/iosxe/stages.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,11 @@ def remove_inactive_pkgs(self, steps, device, images, timeout=TIMEOUT):
with steps.start("Removing inactive packages") as step:

def _check_for_system_image(spawn, system_image=None):
if system_image and system_image in spawn.buffer:
if system_image and re.search(f"{system_image}\r", spawn.buffer):
log.debug(f'{system_image} is among the files to be deleted. send no so the {system_image} is not deleted. ')
spawn.sendline('n')
else:
log.debug(f'{system_image} is not among the files to be deleted. Hence, send yes to delete files.')
spawn.sendline('y')
# split the image on the [:/] and pick up the image name
image = re.split(r'[:/]', images[0])[-1]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
connect: &connect
preface: |
Trying mock_device ...
Connected to mock_device.
Escape character is ''^]''.
prompt: "%N#"

execute: &execute
show version | include operating mode: ''

remove_inactive_no:
<<: *connect
commands:
? ''
: new_state: execute1

execute1:
commands:
<<: *execute
install remove inactive:
new_state: do_you_want_to_remove1
prompt: "%N#"

do_you_want_to_remove1:
preface:
timing:
- 0:,0,0.05
response: |
install_remove: START Tue May 28 18:23:26 UTC 2024
install_remove: Removing IMG
Cleaning up unnecessary package files
No path specified, will use booted path /bootflash//packages.conf
Cleaning /bootflash
Scanning boot directory for packages ... done.
Preparing packages list to delete ...
[R0]: /bootflash/packages.conf File is in use, will not delete.
The following files will be deleted:
[R0]: /bootflash/image.bin
[R0]: /bootflash/image.bin.conf
prompt: Do you want to remove the above files? [y/n]
commands:
"n":
timing:
- 0:,0,0.05
response: |
[1] R0 Add succeed with reason: User Rejected Deletion
SUCCESS: install_remove Tue May 28 18:23:27 UTC 2024
new_state: execute1

remove_inactive_yes:
<<: *connect
commands:
? ''
: new_state: execute2

execute2:
commands:
<<: *execute
install remove inactive:
new_state: do_you_want_to_remove2
prompt: "%N#"

do_you_want_to_remove2:
preface:
timing:
- 0:,0,0.05
response: |
install_remove: START Tue May 28 18:23:26 UTC 2024
install_remove: Removing IMG
Cleaning up unnecessary package files
No path specified, will use booted path /bootflash//packages.conf
Cleaning /bootflash
Scanning boot directory for packages ... done.
Preparing packages list to delete ...
[R0]: /bootflash/packages.conf File is in use, will not delete.
The following files will be deleted:
[R0]: /bootflash/image.bin.conf
prompt: Do you want to remove the above files? [y/n]
commands:
"y":
timing:
- 0:,0,0.05
response: |
Deleting file /bootflash/image.bin.conf ... done.
SUCCESS: Files deleted.
--- Starting Post_Remove_Cleanup ---
Performing REMOVE_POSTCHECK on all members
Finished Post_Remove_Cleanup
SUCCESS: install_remove Sat Jun 01 19:50:22 UTC 2024
new_state: execute1
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import unittest

from pyats.results import Passed
from pyats.topology import loader
from pyats.aetest.steps import Steps
from genie.libs.clean.stages.iosxe.stages import InstallRemoveInactive


class TestIosXEConnect(unittest.TestCase):
""" Run unit testing on a mocked IOSXE c8kv device """

@classmethod
def setUpClass(cls):
# Make sure we have a unique Steps() object for result verification
cls.steps = Steps()

cls.image = 'image.bin'

# And we want the following methods to be mocked to simulate the stage.
cls.install_remove_inactive = InstallRemoveInactive()

def test_install_remove_inactive_pass_n(self):

testbed = """
devices:
router:
connections:
defaults:
class: unicon.Unicon
a:
command: mock_device_cli --os iosxe --mock_data_dir mock_data --state remove_inactive_no
protocol: unknown
os: iosxe
platform: c8kv
type: router
"""
self.testbed = loader.load(testbed)
self.device = self.testbed.devices['router']
self.device.connect(
learn_hostname=True,
init_config_commands=[],
init_exec_commands=[]
)

with self.assertLogs(level='DEBUG') as log:
self.install_remove_inactive(steps=self.steps, device=self.device, images=[self.image])
self.assertIn(f'{self.image} is among the files to be deleted. send no so the {self.image} is not deleted.', log.output[1])

# Check the results is as expected.
self.assertEqual(Passed, self.steps.details[0].result)


def test_install_remove_inactive_pass_y(self):

testbed = """
devices:
router:
connections:
defaults:
class: unicon.Unicon
a:
command: mock_device_cli --os iosxe --mock_data_dir mock_data --state remove_inactive_yes
protocol: unknown
os: iosxe
platform: c8kv
type: router
"""
self.testbed = loader.load(testbed)
self.device = self.testbed.devices['router']
self.device.connect(
learn_hostname=True,
init_config_commands=[],
init_exec_commands=[]
)

with self.assertLogs(level='DEBUG') as log:
self.install_remove_inactive(steps=self.steps, device=self.device, images=[self.image])
self.assertIn(f'{self.image} is not among the files to be deleted. Hence, send yes to delete files.', log.output[1])

# Check the results is as expected.
self.assertEqual(Passed, self.steps.details[0].result)
Loading

0 comments on commit 9e1343b

Please sign in to comment.