CiscoTestAutomation / rest

pyATS | Genie REST API Connector
10 stars 23 forks source link

fix: issue #110 #112

Closed netgab closed 1 year ago

netgab commented 1 year ago

Overview

Proposed code to fix issue#110

Added:

Changed

Removed

netgab commented 1 year ago

Sorry (contrib newbie) ... I just saw, that the tests must be altered as well (src/rest/connector/tests/test_iosxe.py).
Currently, the def test_connect method is defined like no IOS-XE method reacts ... ... I'll check this as well.

netgab commented 1 year ago

I also modified the .gitignore, because I wanted to exclude a Python virtual environment folder. To run the test locally on my machine I did the following:

# Install needed packages into a virtual environment
python3 -m venv venv
python3 -m pip install --upgrade build
python3 -m pip install --upgrade pip
python3 -m pip install -e .
python3 -m pip install pyats[library]
python3 -m pip install requests_mock

# Run tests
python3 -m tests.test_iosxe
netgab commented 1 year ago

Also a side node and something to consider: Despite that the connect method does not work for IOS-XE devices at the moment, the module is currently designed, that users currently access the RESTCONF resources using the prefix /restconf/data<RESTCONF-RESOURCE>. Example is highlighted here.

My modifications change the user interface by defaulting to the /restconf/data base path as this is the default for IOS-XE. So a user formerly accessed a RESTCONF resource using:

device.rest.get("/restconf/data/IOS-XE-native:native")

with my modifications, the behavior changed to:

device.rest.get("/IOS-XE-native:native")

This breaks backwards compatibility to older scripts for IOS-XE devices.
However this is more consistent and user friendly in regards to RESTCONF. Just because RESTCONF resources in the YANG model are not described with the path /restconf/data.

For example, please refer to https://yangcatalog.org/yang-search/yang_tree/Cisco-IOS-XE-native@2022-07-01 The path to the corresponding resource is outlined using /ios:native or /Cisco-IOS-XE-native:native.
So a user does not need to care about the platform specific base path when using the module with my specifications. Just open the YANG model and use exactely the path (Sensor Path) as outlined.

However, to preserve backward compatibility, the code (and tests) may be modified, that only the connect method is fixed.

Anyway - for my specific problem I already implemented a local (for my use only) workaround and currently don't need RESTCONF in pyATS. If this PR is too much hassle for the code maintainers, please just close this PR without merging. I just wanted to start trying to contribute to this project. However, maybe this was not a good idea, because I have no idea about the contributing, development and design guidelines in your project.

ThomasJRyan commented 1 year ago

Hi there! Sorry it's taken so long to reply to this and thank you for the contribution!

Overall this does seem like a desirable change, however I see you've mentioned it would break backwards compatibility. As we have many people who use older versions and devices that is considered a large issue that we can't really allow to happen.

If you're able to rework this PR in a way that doesn't affect backwards compatibility then we would love to have the contribution!

netgab commented 1 year ago

Hi @ThomasJRyan, so I removed the default base URL for IOS-XE RESTCONF. The user still needs to pass the full URL for GET, POST, ... requests (so no behavior change).

Changelog:

Overview

Proposed code to fix issue#110

Changed

Removed

netgab commented 1 year ago

please add changelog

Where? Which file? Do you mean in docs/changelog/2023 ... Then I don't know which file, because I have no idea when you guys will merge my requests (will it be in Sept or Oct)? :) This is why I added the changelog here (above) that you guys may copy / paste it on the final release.

omehrabi commented 1 year ago

I see what you mean please under changelog create a new folder for undistributed and add the changlog over there

netgab commented 1 year ago

hey @ThomasJRyan and @omehrabi , I added the changelog as requested. Hopefully it's ok

netgab commented 1 year ago

Until next time :) Thanks for being so patient with me!