Skip to content

Commit

Permalink
Added test file for node mgmt epg
Browse files Browse the repository at this point in the history
  • Loading branch information
shrsr authored and lhercot committed Dec 10, 2020
1 parent 0573bfb commit 279aaff
Show file tree
Hide file tree
Showing 3 changed files with 268 additions and 13 deletions.
48 changes: 35 additions & 13 deletions plugins/modules/aci_node_mgmt_epg.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
required: true
bd:
description:
- The in-band bridge domain
- The in-band bridge domain which is used when type is in band
type: str
encap:
description:
- The in-band access encapsulation
- The in-band access encapsulation which is used when type is in band
type: str
state:
description:
Expand Down Expand Up @@ -82,6 +82,24 @@
state: query
delegate_to: localhost
- name: Query all in band mgmt epg
cisco.aci.aci_node_mgmt_epg:
host: "Host IP"
username: admin
password: SomeSecretePassword
band_type: in_band
state: query
delegate_to: localhost
- name: Query all out of band mgmt epg
cisco.aci.aci_node_mgmt_epg:
host: "Host IP"
username: admin
password: SomeSecretePassword
band_type: out_of_band
state: query
delegate_to: localhost
- name: Remove in band mgmt epg
cisco.aci.aci_node_mgmt_epg:
host: "Host IP"
Expand Down Expand Up @@ -217,8 +235,7 @@ def main():
supports_check_mode=True,
required_if=[
['state', 'absent', ['epg']],
['state', 'present', ['epg']],
['type', 'in_band', ['bd', 'encap']]
['state', 'present', ['epg']]
]
)

Expand All @@ -228,14 +245,19 @@ def main():
encap = module.params.get('encap')
state = module.params.get('state')

child_configs = [
dict(
mgmtRsMgmtBD=dict(
attributes=dict(
tnFvBDName=bd,
child_configs = []
child_class = []
if type == 'in_band':
child_configs = [
dict(
mgmtRsMgmtBD=dict(
attributes=dict(
tnFvBDName=bd,
),
),
),
)]
)]

child_class = ['mgmtRsMgmtBD']

class_map = dict(
in_band=list([
Expand All @@ -255,7 +277,7 @@ def main():
target_filter={'name': 'mgmt'},
),
subclass_1=dict(
aci_class='mgmtp',
aci_class='mgmtMgmtP',
aci_rn='mgmtp-default',
module_object='default',
target_filter={'name': 'default'},
Expand All @@ -266,7 +288,7 @@ def main():
module_object=epg,
target_filter={'name': epg},
),
child_classes=['mgmtRsMgmtBD'],
child_classes=child_class,
)

aci.get_existing()
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/targets/aci_node_mgmt_epg/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# No ACI simulator yet, so not enabled
# unsupported
231 changes: 231 additions & 0 deletions tests/integration/targets/aci_node_mgmt_epg/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
# Test code for the ACI modules
# Copyright: (c) 2020, Shreyas Srish (@shrsr)

# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)

- name: Test that we have an ACI APIC host, ACI username and ACI password
fail:
msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.'
when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined

- name: Set vars
set_fact:
aci_info: &aci_info
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: debug

# Clean Environment
- name: Remove node mgmt in_band epg
aci_node_mgmt_epg:
<<: *aci_info
type: in_band
epg: ansible-inband
encap: vlan-1
bd: bd1
state: absent

- name: Remove node mgmt out_of_band epg
aci_node_mgmt_epg:
<<: *aci_info
type: out_of_band
epg: ansible-outofband
state: absent

# Add operations
- name: Add node mgmt in_band epg in check mode
aci_node_mgmt_epg:
<<: *aci_info
type: in_band
epg: ansible-inband
encap: vlan-1
bd: bd1
state: present
check_mode: yes
register: add_cm_inband

- name: Add node mgmt out_of_band epg in check mode
aci_node_mgmt_epg:
<<: *aci_info
type: out_of_band
epg: ansible-outofband
state: present
check_mode: yes
register: add_cm_outofband

- name: Add node mgmt in_band epg in normal mode
aci_node_mgmt_epg:
<<: *aci_info
type: in_band
epg: ansible-inband
encap: vlan-1
bd: bd1
state: present
register: add_nm_inband

- name: Add node mgmt out_of_band epg in normal mode
aci_node_mgmt_epg:
<<: *aci_info
type: out_of_band
epg: ansible-outofband
state: present
register: add_nm_outofband

- name: Add node mgmt in_band epg in normal mode again
aci_node_mgmt_epg:
<<: *aci_info
type: in_band
epg: ansible-inband
encap: vlan-1
bd: bd1
state: present
register: add_nm_inband_again

- name: Add node mgmt out_of_band epg in normal mode again
aci_node_mgmt_epg:
<<: *aci_info
type: out_of_band
epg: ansible-outofband
state: present
register: add_nm_outofband_again

- name: Add another node mgmt in_band epg in normal mode
aci_node_mgmt_epg:
<<: *aci_info
type: in_band
epg: ansible-inband-2
encap: vlan-2
bd: bd2
state: present
register: add_nm_inband_2

- name: Add another node mgmt out_of_band epg in normal mode
aci_node_mgmt_epg:
<<: *aci_info
type: out_of_band
epg: ansible-outofband-2
state: present
register: add_nm_outofband_2

- name: Verify add operations
assert:
that:
- add_cm_inband is changed
- add_cm_inband.sent.mgmtInB.attributes.name == 'ansible-inband'
- add_cm_inband.sent.mgmtInB.children.0.mgmtRsMgmtBD.attributes.tnFvBDName == 'bd1'
- add_cm_outofband is changed
- add_cm_outofband.sent.mgmtOoB.attributes.name == 'ansible-outofband'
- add_nm_inband is changed
- add_nm_inband.current.0.mgmtInB.attributes.name == 'ansible-inband'
- add_nm_inband.current.0.mgmtInB.children.0.mgmtRsMgmtBD.attributes.tnFvBDName == 'bd1'
- add_nm_outofband is changed
- add_nm_outofband.current.0.mgmtOoB.attributes.name == 'ansible-outofband'
- add_nm_inband_again is not changed
- add_nm_inband_again.current.0.mgmtInB.attributes.name == 'ansible-inband'
- add_nm_outofband_again is not changed
- add_nm_outofband_again.current.0.mgmtOoB.attributes.name == 'ansible-outofband'
- add_nm_inband_2 is changed
- add_nm_inband_2.current.0.mgmtInB.attributes.name == 'ansible-inband-2'
- add_nm_inband_2.current.0.mgmtInB.children.0.mgmtRsMgmtBD.attributes.tnFvBDName == 'bd2'
- add_nm_outofband_2 is changed
- add_nm_outofband_2.current.0.mgmtOoB.attributes.name == 'ansible-outofband-2'

# Query operations
- name: Query node mgmt in_band epg
aci_node_mgmt_epg:
<<: *aci_info
type: in_band
epg: ansible-inband
encap: vlan-1
bd: bd1
state: query
register: query_inband

- name: Query node mgmt out_of_band epg
aci_node_mgmt_epg:
<<: *aci_info
type: out_of_band
epg: ansible-outofband
state: query
register: query_outofband

- name: Query all in band
aci_node_mgmt_epg:
<<: *aci_info
type: in_band
state: query
register: query_all_inband

- name: Query all out of band
aci_node_mgmt_epg:
<<: *aci_info
type: out_of_band
state: query
register: query_all_outofband

- name: Verify query operations
assert:
that:
- query_inband is not changed
- query_inband.current.0.mgmtInB.attributes.name == 'ansible-inband'
- query_inband.current.0.mgmtInB.children.0.mgmtRsMgmtBD.attributes.tnFvBDName == 'bd1'
- query_outofband is not changed
- query_outofband.current.0.mgmtOoB.attributes.name == 'ansible-outofband'
- query_all_inband.current.0.mgmtMgmtP.children | length == 2
- query_all_outofband.current.0.mgmtMgmtP.children | length == 2

# Remove operations
- name: Remove node mgmt in_band epg
aci_node_mgmt_epg:
<<: *aci_info
type: in_band
epg: ansible-inband-2
state: absent
register: remove_inband_2

- name: Remove node mgmt out_of_band epg
aci_node_mgmt_epg:
<<: *aci_info
type: out_of_band
epg: ansible-outofband-2
state: absent
register: remove_outofband_2

- name: Remove node mgmt in_band epg again
aci_node_mgmt_epg:
<<: *aci_info
type: in_band
epg: ansible-inband-2
state: absent
register: remove_inband_2_again

- name: Verify remove operations
assert:
that:
- remove_inband_2 is changed
- remove_inband_2.previous.0.mgmtInB.attributes.name == 'ansible-inband-2'
- remove_outofband_2 is changed
- remove_outofband_2.previous.0.mgmtOoB.attributes.name == 'ansible-outofband-2'
- remove_inband_2_again is not changed
- remove_inband_2_again.previous == []

# Clean environment for other ci test cases
- name: Remove node mgmt in_band epg
aci_node_mgmt_epg:
<<: *aci_info
type: in_band
epg: ansible-inband
encap: vlan-1
bd: bd1
state: absent

- name: Remove node mgmt out_of_band epg
aci_node_mgmt_epg:
<<: *aci_info
type: out_of_band
epg: ansible-outofband
state: absent

0 comments on commit 279aaff

Please sign in to comment.