Skip to content

Commit

Permalink
[ignore] Added required_if to synce and ptp
Browse files Browse the repository at this point in the history
  • Loading branch information
sajagana authored and lhercot committed Jan 24, 2025
1 parent a7ecd2d commit 2eb73b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 90 deletions.
28 changes: 8 additions & 20 deletions plugins/modules/ndo_node_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def main():
admin_state=dict(type="str", choices=["enabled", "disabled"]),
quality_level=dict(type="str", choices=list(SYNC_E_QUALITY_LEVEL_OPTION)),
),
required_if=[["state", "enabled", ["admin_state", "quality_level"]]],
),
ptp=dict(
type="dict",
Expand All @@ -222,6 +223,7 @@ def main():
node_domain=dict(type="int"),
priority_2=dict(type="int"),
),
required_if=[["state", "enabled", ["node_domain", "priority_2"]]],
),
state=dict(type="str", default="query", choices=["absent", "query", "present"]),
)
Expand Down Expand Up @@ -296,28 +298,14 @@ def main():
mso_values["description"] = description

if synce is not None:
synce_map = dict()
if synce.get("admin_state"):
synce_map["adminState"] = synce.get("admin_state")

if synce.get("quality_level"):
synce_map["qlOption"] = SYNC_E_QUALITY_LEVEL_OPTION.get(synce.get("quality_level"))

if synce_map:
mso_values["synce"] = synce_map
mso_values["synce"] = dict(adminState=synce.get("admin_state"), qlOption=SYNC_E_QUALITY_LEVEL_OPTION.get(synce.get("quality_level")))

if ptp is not None:
ptp_map = dict()
if ptp.get("node_domain"):
ptp_map["domain"] = ptp.get("node_domain")

if ptp.get("priority_2") is not None:
ptp_map["prio2"] = ptp.get("priority_2")

if ptp_map:
# Add the Priority 1 fixed value 128 to the PTP settings during initialization
ptp_map["prio1"] = 128
mso_values["ptp"] = ptp_map
mso_values["ptp"] = dict(
domain=ptp.get("node_domain"),
prio2=ptp.get("priority_2"),
prio1=128,
)

ops.append(dict(op="add", path=node_setting_path, value=copy.deepcopy(mso_values)))

Expand Down
81 changes: 11 additions & 70 deletions tests/integration/targets/ndo_node_setting/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,7 @@
ansible.builtin.assert:
that:
- nt_ns1_synce is not changed
- nt_ns1_synce.current.description == "Updated description"
- nt_ns1_synce.current.name == "ns1"
- nt_ns1_synce.current.ptp.domain == 25
- nt_ns1_synce.current.ptp.prio1 == 128
- nt_ns1_synce.current.ptp.prio2 == 128
- nt_ns1_synce.current.uuid is defined
- nt_ns1_synce.msg is match ('MSO Error 400{{':'}} {"errors"{{':'}}\\["validation failed for mno.ndo.cisco.com/v1.SyncEthNodePol\\.(adminState|qlOption){{':'}} invalid value ","validation failed for mno.ndo.cisco.com/v1.SyncEthNodePol\\.(adminState|qlOption){{':'}} invalid value "\\]}')
- nt_ns1_synce.previous.description == "Updated description"
- nt_ns1_synce.previous.name == "ns1"
- nt_ns1_synce.previous.ptp.domain == 25
- nt_ns1_synce.previous.ptp.prio1 == 128
- nt_ns1_synce.previous.ptp.prio2 == 128
- nt_ns1_synce.msg == "state is enabled but all of the following are missing{{':'}} admin_state, quality_level found in synce"

- name: Clear ns1 ptp values
cisco.mso.ndo_node_setting:
Expand Down Expand Up @@ -274,13 +263,7 @@
ansible.builtin.assert:
that:
- nt_ns1_ptp is not changed
- nt_ns1_ptp.current.description == "Updated description"
- nt_ns1_ptp.current.name == "ns1"
- nt_ns1_ptp.current.uuid is defined
- nt_ns1_ptp.msg == 'MSO Error 400{{":"}} {"errors"{{":"}}["Invalid value 0 for Domain, allowed{{":"}} 24 - 43"]}'
- nt_ns1_ptp.previous.description == "Updated description"
- nt_ns1_ptp.previous.name == "ns1"
- nt_ns1_ptp.previous.uuid is defined
- nt_ns1_ptp.msg == "state is enabled but all of the following are missing{{':'}} node_domain, priority_2 found in ptp"

- name: Query ns1 Node Settings with UUID
cisco.mso.ndo_node_setting:
Expand Down Expand Up @@ -390,46 +373,6 @@
- add_ns2.current.uuid is defined
- add_ns2.previous == {}

- name: Create ns3 with empty synce
cisco.mso.ndo_node_setting:
<<: *mso_info
template: '{{ ansible_fabric_template | default("ansible_test") }}'
name: "ns3"
synce:
state: "enabled"
state: "present"
ignore_errors: true
register: add_ns3_synce

- name: Assertion check for create ns3 with empty synce
ansible.builtin.assert:
that:
- add_ns3_synce is changed
- add_ns3_synce.current.description == ""
- add_ns3_synce.current.name == "ns3"
- add_ns3_synce.current.uuid is defined
- add_ns3_synce.current.synce is not defined

- name: Create ns4 with empty ptp
cisco.mso.ndo_node_setting:
<<: *mso_info
template: '{{ ansible_fabric_template | default("ansible_test") }}'
name: "ns4"
ptp:
state: "enabled"
state: "present"
ignore_errors: true
register: add_ns4_ptp

- name: Assertion check for create ns4 with empty ptp
ansible.builtin.assert:
that:
- add_ns4_ptp is changed
- add_ns4_ptp.current.description == ""
- add_ns4_ptp.current.name == "ns4"
- add_ns4_ptp.current.uuid is defined
- add_ns4_ptp.current.ptp is not defined

- name: Query all Node Settings
cisco.mso.ndo_node_setting:
<<: *mso_info
Expand All @@ -441,28 +384,26 @@
ansible.builtin.assert:
that:
- query_all_ns_again is not changed
- query_all_ns_again.current | length == 4
- query_all_ns_again.current | length == 2
- "'ns1_new' in query_all_ns_again.current | map(attribute='name') | list"
- "'ns2' in query_all_ns_again.current | map(attribute='name') | list"
- "'ns3' in query_all_ns_again.current | map(attribute='name') | list"
- "'ns4' in query_all_ns_again.current | map(attribute='name') | list"

- name: Remove ns4 Node Settings with UUID
- name: Remove ns2 Node Settings with UUID
cisco.mso.ndo_node_setting:
<<: *mso_info
template: '{{ ansible_fabric_template | default("ansible_test") }}'
uuid: "{{ add_ns4_ptp.current.uuid }}"
uuid: "{{ add_ns2.current.uuid }}"
state: "absent"
register: rm_ns4_uuid
register: rm_ns2_uuid

- name: Assertion check for remove ns4 Node Settings with UUID
ansible.builtin.assert:
that:
- rm_ns4_uuid is changed
- rm_ns4_uuid.current == {}
- rm_ns4_uuid.previous.description == ""
- rm_ns4_uuid.previous.name == "ns4"
- rm_ns4_uuid.previous.uuid is defined
- rm_ns2_uuid is changed
- rm_ns2_uuid.current == {}
- rm_ns2_uuid.previous.description == "Updated description"
- rm_ns2_uuid.previous.name == "ns2"
- rm_ns2_uuid.previous.uuid is defined

- name: Remove ns1_new Node Settings with check_mode
cisco.mso.ndo_node_setting:
Expand Down

0 comments on commit 2eb73b6

Please sign in to comment.