Skip to content

Commit 2e77a8b

Browse files
committed
[ignore] Remove pagination as the URL query param pageSize is not working as intended and add test task and example in Documentation for URL query string using orderBy.
1 parent 1af1af1 commit 2e77a8b

File tree

2 files changed

+22
-40
lines changed

2 files changed

+22
-40
lines changed

Diff for: plugins/modules/nd_rest.py

+10-40
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,6 @@
4747
- The file path containing the body of the HTTP request.
4848
type: path
4949
aliases: [ config_file ]
50-
page_size:
51-
description:
52-
- The number of items to return in a single page.
53-
type: int
54-
page:
55-
description:
56-
- The page number to return.
57-
type: int
5850
extends_documentation_fragment:
5951
- cisco.nd.modules
6052
- cisco.nd.check_mode
@@ -132,6 +124,15 @@
132124
method: get
133125
register: query_all
134126
127+
- name: Query all Security Domains ordered by name using GET method
128+
cisco.nd.nd_rest:
129+
host: nd
130+
username: admin
131+
password: SomeSecretPassword
132+
path: /nexus/infra/api/aaa/v4/securitydomains?orderBy=spec.name
133+
method: get
134+
register: query_all_ordered_by_name
135+
135136
- name: Remove Security Domain using DELETE method
136137
cisco.nd.nd_rest:
137138
host: nd
@@ -184,12 +185,7 @@
184185
import json
185186
import os
186187

187-
# Optional, only used for YAML validation and update a URL
188-
try:
189-
from urllib.parse import parse_qsl, urlencode, urlparse, urlunparse
190-
HAS_URLPARSE = True
191-
except Exception:
192-
HAS_URLPARSE = False
188+
# Optional, only used for YAML validation
193189
try:
194190
import yaml
195191

@@ -203,21 +199,6 @@
203199
from ansible.module_utils._text import to_text
204200

205201

206-
def update_qsl(url, params):
207-
"""Add or update a URL query string"""
208-
209-
if HAS_URLPARSE:
210-
url_parts = list(urlparse(url))
211-
query = dict(parse_qsl(url_parts[4]))
212-
query.update(params)
213-
url_parts[4] = urlencode(query)
214-
return urlunparse(url_parts)
215-
elif "?" in url:
216-
return url + "&" + "&".join(["%s=%s" % (k, v) for k, v in params.items()])
217-
else:
218-
return url + "?" + "&".join(["%s=%s" % (k, v) for k, v in params.items()])
219-
220-
221202
def main():
222203
argument_spec = nd_argument_spec()
223204
argument_spec.update(
@@ -230,8 +211,6 @@ def main():
230211
),
231212
content=dict(type="raw", aliases=["payload"]),
232213
file_path=dict(type="path", aliases=["config_file"]),
233-
page=dict(type="int"),
234-
page_size=dict(type="int"),
235214
)
236215

237216
module = AnsibleModule(
@@ -242,8 +221,6 @@ def main():
242221
content = module.params.get("content")
243222
path = module.params.get("path")
244223
file_path = module.params.get("config_file")
245-
page = module.params.get("page")
246-
page_size = module.params.get("page_size")
247224

248225
nd = NDModule(module)
249226

@@ -276,13 +253,6 @@ def main():
276253
nd.existing = nd.previous = sanitize(nd.query_obj(path, ignore_not_found_error=True), ND_REST_KEYS_TO_SANITIZE)
277254
nd.result["previous"] = nd.previous
278255

279-
# Check paginition
280-
if method == "GET":
281-
if page:
282-
path = update_qsl(path, {"page": page})
283-
if page_size:
284-
path = update_qsl(path, {"page-size": page_size})
285-
286256
# Perform request
287257
if module.check_mode:
288258
nd.result["jsondata"] = content

Diff for: tests/integration/targets/nd_rest/tasks/json_inline.yml

+12
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@
121121
method: get
122122
register: quey_all_security_domains
123123

124+
- name: Query all Sites ordered by name with GET method (url query string test)
125+
cisco.nd.nd_rest:
126+
<<: *nd_info
127+
path: /nexus/api/sitemanagement/v4/sites?orderBy=spec.name
128+
method: get
129+
register: query_all_sites_ordered
130+
124131
- name: Assert query tasks with GET method for nd_rest module
125132
ansible.builtin.assert:
126133
that:
@@ -132,6 +139,11 @@
132139
- quey_all_security_domains.current["items"][1].spec.name == "ansible_security_domain_test"
133140
- quey_all_security_domains.jsondata["items"][0].spec.name == "all"
134141
- quey_all_security_domains.jsondata["items"][1].spec.name == "ansible_security_domain_test"
142+
- query_all_sites_ordered is not changed
143+
- query_all_sites_ordered.current["items"][0].spec.name == "ansible_test"
144+
- query_all_sites_ordered.current["items"][1].spec.name == "ansible_test_2"
145+
- query_all_sites_ordered.jsondata["items"][0].spec.name == "ansible_test"
146+
- query_all_sites_ordered.jsondata["items"][1].spec.name == "ansible_test_2"
135147

136148
# DELETE tasks
137149

0 commit comments

Comments
 (0)