Skip to content

Commit

Permalink
[ignore] Remove pagination as the URL query param pageSize is not wor…
Browse files Browse the repository at this point in the history
…king as intended and add test task for URL query string using orderBy.
  • Loading branch information
gmicol committed Feb 27, 2025
1 parent 1af1af1 commit 0569e6a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 30 deletions.
30 changes: 0 additions & 30 deletions plugins/modules/nd_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@
- The file path containing the body of the HTTP request.
type: path
aliases: [ config_file ]
page_size:
description:
- The number of items to return in a single page.
type: int
page:
description:
- The page number to return.
type: int
extends_documentation_fragment:
- cisco.nd.modules
- cisco.nd.check_mode
Expand Down Expand Up @@ -203,21 +195,6 @@
from ansible.module_utils._text import to_text


def update_qsl(url, params):
"""Add or update a URL query string"""

if HAS_URLPARSE:
url_parts = list(urlparse(url))
query = dict(parse_qsl(url_parts[4]))
query.update(params)
url_parts[4] = urlencode(query)
return urlunparse(url_parts)
elif "?" in url:
return url + "&" + "&".join(["%s=%s" % (k, v) for k, v in params.items()])
else:
return url + "?" + "&".join(["%s=%s" % (k, v) for k, v in params.items()])


def main():
argument_spec = nd_argument_spec()
argument_spec.update(
Expand Down Expand Up @@ -276,13 +253,6 @@ def main():
nd.existing = nd.previous = sanitize(nd.query_obj(path, ignore_not_found_error=True), ND_REST_KEYS_TO_SANITIZE)
nd.result["previous"] = nd.previous

# Check paginition
if method == "GET":
if page:
path = update_qsl(path, {"page": page})
if page_size:
path = update_qsl(path, {"page-size": page_size})

# Perform request
if module.check_mode:
nd.result["jsondata"] = content
Expand Down
12 changes: 12 additions & 0 deletions tests/integration/targets/nd_rest/tasks/json_inline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@
method: get
register: quey_all_security_domains

- name: Query all Sites ordered by name with GET method (url query string test)
cisco.nd.nd_rest:
<<: *nd_info
path: /nexus/api/sitemanagement/v4/sites?orderBy=spec.name
method: get
register: query_all_sites_ordered

- name: Assert query tasks with GET method for nd_rest module
ansible.builtin.assert:
that:
Expand All @@ -132,6 +139,11 @@
- quey_all_security_domains.current["items"][1].spec.name == "ansible_security_domain_test"
- quey_all_security_domains.jsondata["items"][0].spec.name == "all"
- quey_all_security_domains.jsondata["items"][1].spec.name == "ansible_security_domain_test"
- query_all_sites_ordered is not changed
- query_all_sites_ordered.current["items"][0].spec.name == "ansible_test"
- query_all_sites_ordered.current["items"][1].spec.name == "ansible_test_2"
- query_all_sites_ordered.jsondata["items"][0].spec.name == "ansible_test"
- query_all_sites_ordered.jsondata["items"][1].spec.name == "ansible_test_2"

# DELETE tasks

Expand Down

0 comments on commit 0569e6a

Please sign in to comment.