Skip to content

Commit

Permalink
[minor_change] Allow site configuration for tenant policy template ty…
Browse files Browse the repository at this point in the history
…pes in ndo_template module
  • Loading branch information
akinross authored and lhercot committed Oct 9, 2024
1 parent 6d391d2 commit 500702e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion plugins/module_utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"template_type": "tenantPolicy", # templateType in payload
"template_type_container": "tenantPolicyTemplate", # templateType container in payload
"tenant": True, # tenant required
"site_amount": 0, # site amount, 0 = no sites, 1 = 1 site, 2 = multiple sites
"site_amount": 2, # 1 = 1 site, 2 = multiple sites
"template_container": True, # configuration is set in template container in payload
},
"l3out": {
Expand Down
10 changes: 5 additions & 5 deletions plugins/modules/ndo_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
template: ansible_tenant_policy
template_type: tenant
tenant: ansible_test_tenant
sites:
- name: ansible_test_site
state: present
- name: Create a new l3out policy template
Expand Down Expand Up @@ -182,9 +184,6 @@ def main():
if tenant_id and not TEMPLATE_TYPES[template_type]["tenant"]:
mso.fail_json(msg="Tenant cannot be attached to template of type {0}.".format(template_type))

if site_ids and TEMPLATE_TYPES[template_type]["site_amount"] == 0:
mso.fail_json(msg="Site cannot be attached to template of type {0}.".format(template_type))

if not tenant_id and TEMPLATE_TYPES[template_type]["tenant"]:
mso.fail_json(msg="Tenant must be provided for template of type {0}.".format(template_type))

Expand Down Expand Up @@ -233,7 +232,7 @@ def main():

# Set template specific payload in functions to increase readability due to the amount of different templates with small differences
if template_type == "tenant":
set_tenant_template_payload(payload, template_type, tenant_id)
set_tenant_template_payload(payload, template_type, tenant_id, site_ids)
elif template_type == "l3out":
set_l3out_template_payload(payload, template_type, tenant_id, site_ids[0])
elif template_type == "fabric_policy":
Expand Down Expand Up @@ -263,8 +262,9 @@ def main():
mso.exit_json()


def set_tenant_template_payload(payload, template_type, tenant_id):
def set_tenant_template_payload(payload, template_type, tenant_id, site_ids):
payload[TEMPLATE_TYPES[template_type]["template_type_container"]].update({"template": {"tenantId": tenant_id}})
payload[TEMPLATE_TYPES[template_type]["template_type_container"]].update({"sites": [{"siteId": site_id} for site_id in site_ids]})


def set_l3out_template_payload(payload, template_type, tenant_id, site_id):
Expand Down
18 changes: 7 additions & 11 deletions tests/integration/targets/ndo_template/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@
template: ansible_tenant_policy_changed
template_id: '{{ nm_create_new_tenant_policy_template_again.current.templateId }}'
state: present
sites:
- name: '{{ mso_site | default("ansible_test") }}'
- name: ansible_test_2
check_mode: true
register: cm_update_tenant_policy_template

Expand Down Expand Up @@ -306,6 +309,7 @@
- cm_update_tenant_policy_template.current.templateType == 'tenantPolicy'
- cm_update_tenant_policy_template.current.templateId is defined
- cm_update_tenant_policy_template.current.tenantPolicyTemplate.template.tenantId is defined
- cm_update_tenant_policy_template.current.tenantPolicyTemplate.sites | length == 2
- nm_update_tenant_policy_template is changed
- nm_update_tenant_policy_template.previous.displayName == 'ansible_tenant_policy'
- nm_update_tenant_policy_template.previous.templateType == 'tenantPolicy'
Expand All @@ -314,16 +318,19 @@
- nm_update_tenant_policy_template.current.displayName == 'ansible_tenant_policy_changed'
- nm_update_tenant_policy_template.current.templateType == 'tenantPolicy'
- nm_update_tenant_policy_template.current.templateId is defined
- nm_update_tenant_policy_template.current.tenantPolicyTemplate.sites | length == 2
- nm_update_tenant_policy_template.current.tenantPolicyTemplate.template.tenantId is defined
- nm_update_tenant_policy_template_again is not changed
- nm_update_tenant_policy_template_again.previous.displayName == 'ansible_tenant_policy_changed'
- nm_update_tenant_policy_template_again.previous.templateType == 'tenantPolicy'
- nm_update_tenant_policy_template_again.previous.templateId is defined
- nm_update_tenant_policy_template_again.previous.tenantPolicyTemplate.template.tenantId is defined
- nm_update_tenant_policy_template_again.previous.tenantPolicyTemplate.sites | length == 2
- nm_update_tenant_policy_template_again.current.displayName == 'ansible_tenant_policy_changed'
- nm_update_tenant_policy_template_again.current.templateType == 'tenantPolicy'
- nm_update_tenant_policy_template_again.current.templateId is defined
- nm_update_tenant_policy_template_again.current.tenantPolicyTemplate.template.tenantId is defined
- nm_update_tenant_policy_template_again.current.tenantPolicyTemplate.sites | length == 2
- nm_update_new_fabric_policy_template_0_2_sites is changed
- nm_update_new_fabric_policy_template_0_2_sites.previous.displayName == 'ansible_fabric_policy_template'
- nm_update_new_fabric_policy_template_0_2_sites.previous.fabricPolicyTemplate.sites is not defined
Expand Down Expand Up @@ -414,15 +421,6 @@
state: present
register: err_unknown_template_id
ignore_errors: true

- name: Error on not allowed input site
cisco.mso.ndo_template:
<<: *update_tenant_policy_template
sites:
- name: '{{ mso_site | default("ansible_test") }}'
state: present
register: err_not_allowed_site_id
ignore_errors: true

- name: Error on not allowed template_type change
cisco.mso.ndo_template:
Expand Down Expand Up @@ -501,8 +499,6 @@
that:
- err_unknown_template_id is failed
- err_unknown_template_id.msg.startswith("Provided template id 'unknown_id' does not exist. Existing templates:")
- err_not_allowed_site_id is failed
- err_not_allowed_site_id.msg == "Site cannot be attached to template of type tenant."
- err_not_allowed_template_type_change is failed
- err_not_allowed_template_type_change.msg == "Template type cannot be changed."
- err_not_allowed_site_change is failed
Expand Down

0 comments on commit 500702e

Please sign in to comment.