Skip to content

Commit

Permalink
[ignore] aci_rest add annotation to children and fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samiib committed Oct 31, 2023
1 parent 0f29c6f commit 37f922d
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 15 deletions.
11 changes: 8 additions & 3 deletions plugins/modules/aci_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,21 +312,26 @@ def update_qsl(url, params):

def add_annotation(annotation, payload):
"""Add annotation to payload only if it has not already been added"""
if annotation:
if annotation and isinstance(payload, dict):
for key, val in payload.items():
if key in ANNOTATION_UNSUPPORTED:
return
continue
att = val.get("attributes", {})
if "annotation" not in att.keys():
att["annotation"] = annotation
# Recursively add annotation to children
children = val.get("children", None)
if children:
for child in children:
add_annotation(annotation, child)


def add_annotation_xml(annotation, tree):
"""Add annotation to payload xml only if it has not already been added"""
if annotation:
for element in tree.iter():
if element.tag in ANNOTATION_UNSUPPORTED:
return
continue
ann = element.get("annotation")
if ann is None:
element.set("annotation", annotation)
Expand Down
58 changes: 57 additions & 1 deletion tests/integration/targets/aci_rest/tasks/json_inline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,66 @@
}
register: nm_add_tag_no_annotation

- name: Remove tenant
cisco.aci.aci_rest: *tenant_absent

- name: Add tenant with children objects including annotation
cisco.aci.aci_rest:
host: '{{ aci_hostname }}'
username: '{{ aci_username }}'
password: '{{ aci_password }}'
validate_certs: '{{ aci_validate_certs | default(false) }}'
use_ssl: '{{ aci_use_ssl | default(true) }}'
use_proxy: '{{ aci_use_proxy | default(true) }}'
output_level: '{{ aci_output_level | default("info") }}'
path: /api/mo/uni.json
method: post
annotation: test:inoption
content:
{
"fvTenant": {
"attributes": {
"descr": "Ansible test tenant",
"name": "ansible_test"
},
"children": [
{
"fvCtx": {
"attributes": {
"name": "VRF1"
}
}
},
{
"fvAp": {
"attributes": {
"name": "Application1"
},
"children": [
{
"fvAEPg": {
"attributes": {
"name": "WebTier",
"annotation": "test:inchild"
}
}
}
]
}
}
]
}
}
register: nm_add_tenant_annotation_children

- name: Verify annotation support
assert:
that:
- nm_add_tenant_annotation_option.imdata.0.fvTenant.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_content.imdata.0.fvTenant.attributes.annotation == "test:incontent"
- nm_add_tenant_annotation_option_content.imdata.0.fvTenant.attributes.annotation == "test:optionincontent"
- nm_add_tag_no_annotation.imdata.0.tagTag.attributes.annotation is undefined
- nm_add_tag_no_annotation.imdata.0.tagTag.attributes.annotation is undefined
- nm_add_tenant_annotation_children.imdata.0.fvTenant.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.0.fvAp.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.0.fvAp.children.0.fvAEPg.attributes.annotation == "test:inchild"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.2.fvCtx.attributes.annotation == "test:inoption"
60 changes: 58 additions & 2 deletions tests/integration/targets/aci_rest/tasks/json_string.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
use_ssl: '{{ aci_use_ssl | default(true) }}'
use_proxy: '{{ aci_use_proxy | default(true) }}'
output_level: '{{ aci_output_level | default("info") }}'
path: /api/mo/uni/tn-ansible_test_annotation1/tagKey-foo.json
path: /api/mo/uni/tn-ansible_test/tagKey-foo.json
method: post
annotation: test:inoption
content: |
Expand All @@ -276,10 +276,66 @@
}
register: nm_add_tag_no_annotation

- name: Remove tenant
cisco.aci.aci_rest: *tenant_absent

- name: Add tenant with children objects including annotation
cisco.aci.aci_rest:
host: '{{ aci_hostname }}'
username: '{{ aci_username }}'
password: '{{ aci_password }}'
validate_certs: '{{ aci_validate_certs | default(false) }}'
use_ssl: '{{ aci_use_ssl | default(true) }}'
use_proxy: '{{ aci_use_proxy | default(true) }}'
output_level: '{{ aci_output_level | default("info") }}'
path: /api/mo/uni.json
method: post
annotation: test:inoption
content: |
{
"fvTenant": {
"attributes": {
"descr": "Ansible test tenant",
"name": "ansible_test"
},
"children": [
{
"fvCtx": {
"attributes": {
"name": "VRF1"
}
}
},
{
"fvAp": {
"attributes": {
"name": "Application1"
},
"children": [
{
"fvAEPg": {
"attributes": {
"name": "WebTier",
"annotation": "test:inchild"
}
}
}
]
}
}
]
}
}
register: nm_add_tenant_annotation_children

- name: Verify annotation support
assert:
that:
- nm_add_tenant_annotation_option.imdata.0.fvTenant.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_content.imdata.0.fvTenant.attributes.annotation == "test:incontent"
- nm_add_tenant_annotation_option_content.imdata.0.fvTenant.attributes.annotation == "test:optionincontent"
- nm_add_tag_no_annotation.imdata.0.tagTag.attributes.annotation is undefined
- nm_add_tag_no_annotation.imdata.0.tagTag.attributes.annotation is undefined
- nm_add_tenant_annotation_children.imdata.0.fvTenant.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.0.fvAp.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.0.fvAp.children.0.fvAEPg.attributes.annotation == "test:inchild"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.2.fvCtx.attributes.annotation == "test:inoption"
31 changes: 28 additions & 3 deletions tests/integration/targets/aci_rest/tasks/xml_file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
output_path: "/tmp/ansible_output_file.log"

- name: Ensure tenant does not exists using ans_test_delete xml template
cisco.aci.aci_rest:
cisco.aci.aci_rest: &tenant_delete
<<: *aci_info
path: /api/mo/uni.xml
src: "./targets/aci_rest/tasks/xml_files/tn-ans_test_delete.xml"
Expand Down Expand Up @@ -260,6 +260,9 @@
src: "./targets/aci_rest/tasks/xml_files/tn-ans_test_annotation.xml"
register: nm_add_tenant_annotation_content

- name: Remove tenant
cisco.aci.aci_rest: *tenant_delete

- name: Add tenant with annotation in content and option
cisco.aci.aci_rest:
host: '{{ aci_hostname }}'
Expand Down Expand Up @@ -290,10 +293,32 @@
src: "./targets/aci_rest/tasks/xml_files/tag.xml"
register: nm_add_tag_no_annotation

- name: Remove tenant
cisco.aci.aci_rest: *tenant_delete

- name: Add tenant with children objects including annotation
cisco.aci.aci_rest:
host: '{{ aci_hostname }}'
username: '{{ aci_username }}'
password: '{{ aci_password }}'
validate_certs: '{{ aci_validate_certs | default(false) }}'
use_ssl: '{{ aci_use_ssl | default(true) }}'
use_proxy: '{{ aci_use_proxy | default(true) }}'
output_level: '{{ aci_output_level | default("info") }}'
path: /api/mo/uni.xml
method: post
annotation: test:inoption
src: "./targets/aci_rest/tasks/xml_files/tn-ans_test_annotation_children.xml"
register: nm_add_tenant_annotation_children

- name: Verify annotation support
assert:
that:
- nm_add_tenant_annotation_option.imdata.0.fvTenant.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_content.imdata.0.fvTenant.attributes.annotation == "test:incontent"
- nm_add_tenant_annotation_content.imdata.0.fvTenant.attributes.annotation == "test:optionincontent"
- nm_add_tenant_annotation_option_content.imdata.0.fvTenant.attributes.annotation == "test:optionincontent"
- nm_add_tag_no_annotation.imdata.0.tagTag.attributes.annotation is undefined
- nm_add_tag_no_annotation.imdata.0.tagTag.attributes.annotation is undefined
- nm_add_tenant_annotation_children.imdata.0.fvTenant.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.0.fvAp.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.0.fvAp.children.0.fvAEPg.attributes.annotation == "test:inchild"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.1.fvCtx.attributes.annotation == "test:inoption"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<fvTenant name="ans_test_create" descr="Ansible test tenant xml">
<fvCtx name="VRF1"/>
<fvAp name="Application1">
<fvAEPg name="WebTier" annotation="test:inchild"/>
</fvAp>
</fvTenant>
38 changes: 33 additions & 5 deletions tests/integration/targets/aci_rest/tasks/xml_string.yml
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
method: post
annotation: test:inoption
content:
<fvTenant name="ansible_test" desc="Ansible test tenant"/>
<fvTenant name="ansible_test" descr="Ansible test tenant"/>
register: nm_add_tenant_annotation_option

- name: Add tenant with annotation in content
Expand All @@ -274,7 +274,7 @@
path: /api/mo/uni.xml
method: post
content:
<fvTenant name="ansible_test" desc="Ansible test tenant" annotation="test:incontent"/>
<fvTenant name="ansible_test" descr="Ansible test tenant" annotation="test:incontent"/>
register: nm_add_tenant_annotation_content

- name: Add tenant with annotation in content and option
Expand All @@ -290,7 +290,7 @@
method: post
annotation: test:inoption
content:
<fvTenant name="ansible_test" desc="Ansible test tenant" annotation="test:optionincontent"/>
<fvTenant name="ansible_test" descr="Ansible test tenant" annotation="test:optionincontent"/>
register: nm_add_tenant_annotation_option_content

- name: Add tag to tenant with annotation unsupported
Expand All @@ -302,17 +302,45 @@
use_ssl: '{{ aci_use_ssl | default(true) }}'
use_proxy: '{{ aci_use_proxy | default(true) }}'
output_level: '{{ aci_output_level | default("info") }}'
path: /api/mo/uni/tn-ansible_test/tagKey-foo.json
path: /api/mo/uni/tn-ansible_test/tagKey-foo.xml
method: post
annotation: test:inoption
content:
<tagTag value="bar"/>
register: nm_add_tag_no_annotation

- name: Remove tenant
cisco.aci.aci_rest: *tenant_absent

- name: Add tenant with children objects including annotation
cisco.aci.aci_rest:
host: '{{ aci_hostname }}'
username: '{{ aci_username }}'
password: '{{ aci_password }}'
validate_certs: '{{ aci_validate_certs | default(false) }}'
use_ssl: '{{ aci_use_ssl | default(true) }}'
use_proxy: '{{ aci_use_proxy | default(true) }}'
output_level: '{{ aci_output_level | default("info") }}'
path: /api/mo/uni.xml
method: post
annotation: test:inoption
content:
<fvTenant name="ansible_test" descr="Ansible test tenant">
<fvCtx name="VRF1"/>
<fvAp name="Application1">
<fvAEPg name="WebTier" annotation="test:inchild"/>
</fvAp>
</fvTenant>
register: nm_add_tenant_annotation_children

- name: Verify annotation support
assert:
that:
- nm_add_tenant_annotation_option.imdata.0.fvTenant.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_content.imdata.0.fvTenant.attributes.annotation == "test:incontent"
- nm_add_tenant_annotation_option_content.imdata.0.fvTenant.attributes.annotation == "test:optionincontent"
- nm_add_tag_no_annotation.imdata.0.tagTag.attributes.annotation is undefined
- nm_add_tag_no_annotation.imdata.0.tagTag.attributes.annotation is undefined
- nm_add_tenant_annotation_children.imdata.0.fvTenant.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.0.fvAp.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.0.fvAp.children.0.fvAEPg.attributes.annotation == "test:inchild"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.1.fvCtx.attributes.annotation == "test:inoption"
38 changes: 38 additions & 0 deletions tests/integration/targets/aci_rest/tasks/yaml_inline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,48 @@
value: bar
register: nm_add_tag_no_annotation

- name: Remove tenant
cisco.aci.aci_rest: *tenant_absent

- name: Add tenant with children objects including annotation
cisco.aci.aci_rest:
host: '{{ aci_hostname }}'
username: '{{ aci_username }}'
password: '{{ aci_password }}'
validate_certs: '{{ aci_validate_certs | default(false) }}'
use_ssl: '{{ aci_use_ssl | default(true) }}'
use_proxy: '{{ aci_use_proxy | default(true) }}'
output_level: '{{ aci_output_level | default("info") }}'
path: /api/mo/uni.json
method: post
annotation: test:inoption
content:
fvTenant:
attributes:
descr: Ansible test tenant
name: ansible_test
children:
- fvCtx:
attributes:
name: VRF1
- fvAp:
attributes:
name: Application1
children:
- fvAEPg:
attributes:
name: WebTier
annotation: test:inchild
register: nm_add_tenant_annotation_children

- name: Verify annotation support
assert:
that:
- nm_add_tenant_annotation_option.imdata.0.fvTenant.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_content.imdata.0.fvTenant.attributes.annotation == "test:incontent"
- nm_add_tenant_annotation_option_content.imdata.0.fvTenant.attributes.annotation == "test:optionincontent"
- nm_add_tag_no_annotation.imdata.0.tagTag.attributes.annotation is undefined
- nm_add_tenant_annotation_children.imdata.0.fvTenant.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.0.fvAp.attributes.annotation == "test:inoption"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.0.fvAp.children.0.fvAEPg.attributes.annotation == "test:inchild"
- nm_add_tenant_annotation_children.imdata.0.fvTenant.children.2.fvCtx.attributes.annotation == "test:inoption"
Loading

0 comments on commit 37f922d

Please sign in to comment.