Skip to content

Commit 900afb4

Browse files
gmicollhercot
authored andcommitted
[ignore] Add test cases when using template_id for ndo_ntp_policy module.
1 parent 68a4abe commit 900afb4

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

plugins/modules/ndo_ntp_policy.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@
2424
template:
2525
description:
2626
- The name of the Fabric Policy template.
27+
- This parameter or O(template_id) is required.
2728
type: str
2829
aliases: [ fabric_policy_template ]
2930
template_id:
3031
description:
3132
- The ID of the Fabric Policy template.
33+
- This parameter or O(template) is required.
3234
type: str
3335
aliases: [ fabric_policy_template_id ]
3436
name:
@@ -168,7 +170,6 @@
168170
notes:
169171
- The O(template) must exist before using this module in your playbook.
170172
Use M(cisco.mso.ndo_template) to create the Fabric Policy template.
171-
- One of O(template) and O(template_id) is required but both are mutually exclusive.
172173
seealso:
173174
- module: cisco.mso.ndo_template
174175
extends_documentation_fragment: cisco.mso.modules
@@ -315,12 +316,12 @@ def main():
315316
argument_spec=argument_spec,
316317
supports_check_mode=True,
317318
required_if=[
318-
["state", "present", ["template", "template_id"], True],
319-
["state", "query", ["template", "template_id"], True],
320-
["state", "absent", ["template", "template_id"], True],
321319
["state", "absent", ["name", "uuid"], True],
322320
["state", "present", ["name", "uuid"], True],
323321
],
322+
required_one_of=[
323+
("template", "template_id"),
324+
],
324325
mutually_exclusive=[
325326
("template", "template_id"),
326327
],
@@ -402,15 +403,15 @@ def main():
402403
authState=authentication_state,
403404
)
404405

405-
if mso.existing and match:
406+
if match:
406407
append_update_ops_data(ops, match.details, ntp_policy_attrs_path, mso_values)
407408
mso.sanitize(match.details, collate=True)
408409
else:
409410
mso.sanitize(mso_values)
410411
ops.append(dict(op="add", path=ntp_policy_attrs_path, value=mso.sent))
411412

412413
elif state == "absent":
413-
if mso.existing and match:
414+
if match:
414415
ops.append(dict(op="remove", path=ntp_policy_attrs_path))
415416

416417
if not module.check_mode and ops:

tests/integration/targets/ndo_ntp_policy/tasks/main.yml

+23-11
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
cisco.mso.ndo_template:
5858
<<: *template_absent
5959
state: present
60+
register: nm_create_fabric_policy_template
6061

6162
# CREATE
6263

@@ -98,10 +99,10 @@
9899
<<: *create_ntp_policy
99100
register: nm_create_new_ntp_policy_again
100101

101-
- name: Create another NTP Policy with minimum requirements
102+
- name: Create another NTP Policy with minimum requirements using identifiers
102103
cisco.mso.ndo_ntp_policy: &create_ntp_policy_2
103104
<<: *mso_info
104-
template: ansible_fabric_policy_template
105+
template_id: '{{ nm_create_fabric_policy_template.current.templateId }}'
105106
name: ansible_test_ntp_policy_2
106107
state: present
107108
register: nm_create_another_ntp_policy
@@ -384,12 +385,19 @@
384385
state: query
385386
register: query_one_uuid
386387

387-
- name: Query all NTP Policy in the template
388+
- name: Query all NTP Policy in the template with template name
388389
cisco.mso.ndo_ntp_policy:
389390
<<: *mso_info
390391
template: ansible_fabric_policy_template
391392
state: query
392-
register: query_all
393+
register: query_all_with_name
394+
395+
- name: Query all NTP Policy in the template with template id
396+
cisco.mso.ndo_ntp_policy:
397+
<<: *mso_info
398+
template_id: '{{ nm_create_fabric_policy_template.current.templateId }}'
399+
state: query
400+
register: query_all_with_id
393401

394402
- name: Assert NTP Policy was queried
395403
assert:
@@ -398,10 +406,14 @@
398406
- query_one.current.name == "ansible_test_ntp_policy_2"
399407
- query_one_uuid is not changed
400408
- query_one_uuid.current.name == "ansible_test_ntp_policy_2"
401-
- query_all is not changed
402-
- query_all.current.0.name == "ansible_test_ntp_policy_changed"
403-
- query_all.current.1.name == "ansible_test_ntp_policy_2"
404-
- query_all.current | length == 2
409+
- query_all_with_name is not changed
410+
- query_all_with_name.current.0.name == "ansible_test_ntp_policy_changed"
411+
- query_all_with_name.current.1.name == "ansible_test_ntp_policy_2"
412+
- query_all_with_name.current | length == 2
413+
- query_all_with_id is not changed
414+
- query_all_with_id.current.0.name == "ansible_test_ntp_policy_changed"
415+
- query_all_with_id.current.1.name == "ansible_test_ntp_policy_2"
416+
- query_all_with_id.current | length == 2
405417

406418
# DELETE
407419

@@ -459,7 +471,7 @@
459471
<<: *mso_info
460472
template: ansible_fabric_policy_template
461473
state: query
462-
register: query_all_none
474+
register: query_all_with_name_none
463475

464476
- name: Update with non-existing UUID
465477
cisco.mso.ndo_ntp_policy:
@@ -473,8 +485,8 @@
473485
- name: Assert no NTP Policy found
474486
assert:
475487
that:
476-
- query_all_none is not changed
477-
- query_all_none.current == {}
488+
- query_all_with_name_none is not changed
489+
- query_all_with_name_none.current == {}
478490
- update_non_existing_uuid is failed
479491
- update_non_existing_uuid.msg == "NTP Policy with the UUID{{":"}} 'non-existing-uuid' not found"
480492

0 commit comments

Comments
 (0)