Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix iosxr netconf plugin response namespace #49238

Merged
merged 3 commits into from
Nov 29, 2018

Conversation

ganeshrn
Copy link
Member

@ganeshrn ganeshrn commented Nov 28, 2018

SUMMARY
  • iosxr netconf plugin removes namespace by default
    for all the responses as parsing of xml is easier without namespace in iosxr module. However, to
    validate the response received from the device against yang model requires namespace to be
    present.
  • Add a parameter in iosxr netconf plugin API's to control if the namespace
    should be removed from the response or not.
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

netconf/iosxr.py

ADDITIONAL INFORMATION

*  iosxr netconf plugin removes namespace by default
   for all the responses as parsing of xml is easier
   without namepsace in iosxr module. However to validate
   the response received from device against yang model requires
   namespace to be present in resposne.
*  Add a parameter in iosxr netconf plugin to control if namespace
   should be removed from response or not.
@ansibot
Copy link
Contributor

ansibot commented Nov 28, 2018

Hi @ganeshrn, thank you for submitting this pull-request!

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Nov 28, 2018

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. needs_triage Needs a first human triage before being processed. networking Network category support:network This issue/PR relates to code supported by the Ansible Network Team. labels Nov 28, 2018
@ganeshrn ganeshrn removed the needs_triage Needs a first human triage before being processed. label Nov 28, 2018
@ansibot
Copy link
Contributor

ansibot commented Nov 28, 2018

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

lib/ansible/plugins/netconf/iosxr.py:161:43: E127 continuation line over-indented for visual indent

click here for bot help

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Nov 28, 2018
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Nov 28, 2018
@ganeshrn ganeshrn requested a review from gdpak November 28, 2018 15:37
@@ -389,7 +392,10 @@ def get_oper(module, filter=None):

if filter is not None:
try:
response = conn.get(filter)
if is_netconf(module):
response = conn.get(filter, remove_ns=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is existing bug in this code. iosxr netconf connection plugin's 'get' method does not have any non-keyword argument. so here probably passing a keyword arg might not work.

'conn.get(filter=filter, remove_ns=True)'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is fixed on devel, however, I will change as you suggested since same iosxr plugin will be copied in yang role that is currently dependent on 2.7 Ansible version.

@@ -436,7 +442,7 @@ def load_config(module, command_filter, commit=False, replace=False,

try:
for filter in to_list(command_filter):
conn.edit_config(filter)
conn.edit_config(filter, remove_ns=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. below should work

-                conn.edit_config(filter)
+                conn.edit_config(config=filter, remove_ns=True)

@@ -125,56 +125,80 @@ def guess_network_os(obj):

# TODO: change .xml to .data_xml, when ncclient supports data_xml on all platforms
@ensure_connected
def get(self, filter=None):
def get(self, filter=None, remove_ns=False):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure of history but why do we need remove_ns at first place ? is it for conversion to json ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc this logic was added to iosxr plugin so that parsing of XML response string using lxml library in the iosxr declarative modules is easier. If the namespace is present in the XML string the XPath traversal in declarative modules requires adding nested namespaces to traversal logic thus making it complex.

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Nov 28, 2018
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Nov 29, 2018
@ganeshrn
Copy link
Member Author

@gdpak Thank you for review.

@ganeshrn ganeshrn merged commit 829fc0f into ansible:devel Nov 29, 2018
@ganeshrn ganeshrn deleted the iosxr_netconf_fix branch November 29, 2018 07:51
ganeshrn added a commit to ganeshrn/ansible that referenced this pull request Nov 29, 2018
* Fix iosxr netconf plugin response namespace

*  iosxr netconf plugin removes namespace by default
   for all the responses as parsing of xml is easier
   without namepsace in iosxr module. However to validate
   the response received from device against yang model requires
   namespace to be present in resposne.
*  Add a parameter in iosxr netconf plugin to control if namespace
   should be removed from response or not.

* Fix CI issues

* Fix review comment

(cherry picked from commit 829fc0f)
abadger pushed a commit that referenced this pull request Dec 4, 2018
* Fix iosxr netconf plugin response namespace

*  iosxr netconf plugin removes namespace by default
   for all the responses as parsing of xml is easier
   without namepsace in iosxr module. However to validate
   the response received from device against yang model requires
   namespace to be present in resposne.
*  Add a parameter in iosxr netconf plugin to control if namespace
   should be removed from response or not.

* Fix CI issues

* Fix review comment

(cherry picked from commit 829fc0f)
@dagwieers dagwieers added iosxr Cisco IOSXR community cisco Cisco technologies labels Feb 22, 2019
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. cisco Cisco technologies core_review In order to be merged, this PR must follow the core review workflow. iosxr Cisco IOSXR community networking Network category support:network This issue/PR relates to code supported by the Ansible Network Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants