Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aci_taboo_contract: Add integration tests and examples #36276

Merged
merged 1 commit into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 36 additions & 9 deletions lib/ansible/modules/network/aci/aci_taboo_contract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright: (c) 2018, Dag Wieers (dagwieers) <dag@wieers.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
Expand Down Expand Up @@ -54,15 +55,40 @@
extends_documentation_fragment: aci
'''

# FIXME: Add more, better examples
EXAMPLES = r'''
- aci_taboo_contract:
host: '{{ inventory_hostname }}'
username: '{{ username }}'
password: '{{ password }}'
taboo_contract: '{{ taboo_contract }}'
description: '{{ descr }}'
tenant: '{{ tenant }}'
- name: Add taboo contract
aci_taboo_contract:
host: '{{ aci_hostname }}'
username: '{{ aci_username }}'
password: '{{ aci_password }}'
tenant: ansible_test
taboo_contract: taboo_contract_test
state: present

- name: Remove taboo contract
aci_taboo_contract:
host: '{{ aci_hostname }}'
username: '{{ aci_username }}'
password: '{{ aci_password }}'
tenant: ansible_test
taboo_contract: taboo_contract_test
state: absent

- name: Query all taboo contracts
aci_taboo_contract:
host: '{{ aci_hostname }}'
username: '{{ aci_username }}'
password: '{{ aci_password }}'
state: query

- name: Query a specific taboo contract
aci_taboo_contract:
host: '{{ aci_hostname }}'
username: '{{ aci_username }}'
password: '{{ aci_password }}'
tenant: ansible_test
taboo_contract: taboo_contract_test
state: query
'''

RETURN = r'''
Expand Down Expand Up @@ -225,7 +251,8 @@ def main():
aci_class='vzTaboo',
class_config=dict(
name=taboo_contract,
descr=description, scope=scope,
descr=description,
scope=scope,
),
)

Expand Down
Empty file.
275 changes: 275 additions & 0 deletions test/integration/targets/aci_taboo_contract/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
# Test code for the ACI modules
# Copyright: (c) 2018, Dag Wieers (dagwieers) <dag@wieers.com>

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


# CLEAN ENVIRONMENT
- name: Remove taboo contract
aci_taboo_contract: &taboo_contract_absent
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: info
tenant: ansible_test
taboo_contract: taboo_contract_test
state: absent

- name: Add tenant
aci_tenant:
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: info
tenant: ansible_test
state: present


# ADD TABOO CONTRACT
- name: Add taboo contract (check_mode)
aci_taboo_contract: &taboo_contract_present
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: info
tenant: ansible_test
taboo_contract: taboo_contract_test
state: present
check_mode: yes
register: cm_add_taboo_contract

- name: Add taboo contract (normal mode)
aci_taboo_contract: *taboo_contract_present
register: nm_add_taboo_contract

- name: Verify add_taboo_contract
assert:
that:
- cm_add_taboo_contract.changed == nm_add_taboo_contract.changed == true
- 'cm_add_taboo_contract.sent == nm_add_taboo_contract.sent == {"vzTaboo": {"attributes": {"name": "taboo_contract_test"}}}'
- 'cm_add_taboo_contract.proposed == nm_add_taboo_contract.proposed == {"vzTaboo": {"attributes": {"name": "taboo_contract_test"}}}'
- cm_add_taboo_contract.previous == nm_add_taboo_contract.previous == []
# NOTE: We cannot fix this easily
- cm_add_taboo_contract.current == []
- nm_add_taboo_contract.current.0.vzTaboo.attributes.descr == ''
- nm_add_taboo_contract.current.0.vzTaboo.attributes.dn == 'uni/tn-ansible_test/taboo-taboo_contract_test'
- nm_add_taboo_contract.current.0.vzTaboo.attributes.name == 'taboo_contract_test'

- name: Add taboo_contract again (check_mode)
aci_taboo_contract: *taboo_contract_present
check_mode: yes
register: cm_add_taboo_contract_again

- name: Add taboo contract again (normal mode)
aci_taboo_contract: *taboo_contract_present
register: nm_add_taboo_contract_again

- name: Verify add_taboo_contract_again
assert:
that:
- cm_add_taboo_contract_again.changed == nm_add_taboo_contract_again.changed == false
- cm_add_taboo_contract_again.current == nm_add_taboo_contract_again.current == nm_add_taboo_contract.current


# CHANGE TABOO CONTRACT
- name: Change description of taboo contract (check_mode)
aci_taboo_contract:
<<: *taboo_contract_present
description: Ansible test taboo contract
check_mode: yes
register: cm_add_taboo_contract_descr

- name: Change description of taboo contract (normal mode)
aci_taboo_contract:
<<: *taboo_contract_present
description: Ansible test taboo contract
register: nm_add_taboo_contract_descr

- name: Verify add_taboo_contract_descr
assert:
that:
- cm_add_taboo_contract_descr.changed == nm_add_taboo_contract_descr.changed == true
- 'cm_add_taboo_contract_descr.sent == nm_add_taboo_contract_descr.sent == {"vzTaboo": {"attributes": {"descr": "Ansible test taboo contract"}}}'
- 'cm_add_taboo_contract_descr.proposed == nm_add_taboo_contract_descr.proposed == {"vzTaboo": {"attributes": {"descr": "Ansible test taboo contract", "name": "taboo_contract_test"}}}'
- cm_add_taboo_contract_descr.previous == nm_add_taboo_contract_descr.previous == cm_add_taboo_contract_descr.current == nm_add_taboo_contract.current
- nm_add_taboo_contract_descr.current.0.vzTaboo.attributes.descr == 'Ansible test taboo contract'
- nm_add_taboo_contract_descr.current.0.vzTaboo.attributes.dn == 'uni/tn-ansible_test/taboo-taboo_contract_test'
- nm_add_taboo_contract_descr.current.0.vzTaboo.attributes.name == 'taboo_contract_test'

- name: Change description of taboo contract again (check_mode)
aci_taboo_contract:
<<: *taboo_contract_present
description: Ansible test taboo contract
check_mode: yes
register: cm_add_taboo_contract_descr_again

- name: Change description of taboo contract again (normal mode)
aci_taboo_contract:
<<: *taboo_contract_present
description: Ansible test taboo contract
register: nm_add_taboo_contract_descr_again

- name: Verify add_taboo_contract_descr_again
assert:
that:
- cm_add_taboo_contract_descr_again.changed == nm_add_taboo_contract_descr_again.changed == false
- cm_add_taboo_contract_descr_again.current == nm_add_taboo_contract_descr_again.current == nm_add_taboo_contract_descr.current


# ADD TABOO CONTRACT AGAIN
- name: Add taboo contract again with no description (check_mode)
aci_taboo_contract: *taboo_contract_present
check_mode: yes
register: cm_add_taboo_contract_again_no_descr

- name: Add taboo contract again with no description (normal mode)
aci_taboo_contract: *taboo_contract_present
register: nm_add_taboo_contract_again_no_descr

- name: Verify add_taboo_contract_again_no_descr
assert:
that:
- cm_add_taboo_contract_again_no_descr.changed == nm_add_taboo_contract_again_no_descr.changed == false
- cm_add_taboo_contract_again_no_descr.current == nm_add_taboo_contract_again_no_descr.current == nm_add_taboo_contract_descr.current


# QUERY ALL TABOO CONTRACTS
- name: Query all taboo contracts (check_mode)
aci_taboo_contract: &taboo_contract_query
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) }}'
state: query
check_mode: yes
register: cm_query_all_taboo_contracts

- name: Query all taboo contracts (normal mode)
aci_taboo_contract: *taboo_contract_query
register: nm_query_all_taboo_contracts

- name: Verify query_all_taboo_contracts
assert:
that:
- cm_query_all_taboo_contracts.changed == nm_query_all_taboo_contracts.changed == false
- cm_query_all_taboo_contracts == nm_query_all_taboo_contracts
- cm_query_all_taboo_contracts.current|length >= 1


# QUERY A TABOO CONTRACT
- name: Query our taboo contract
aci_taboo_contract:
<<: *taboo_contract_query
tenant: ansible_test
taboo_contract: taboo_contract_test
check_mode: yes
register: cm_query_taboo_contract

- name: Query our taboo contract
aci_taboo_contract:
<<: *taboo_contract_query
tenant: ansible_test
taboo_contract: taboo_contract_test
register: nm_query_taboo_contract

- name: Verify query_taboo_contract
assert:
that:
- cm_query_taboo_contract.changed == nm_query_taboo_contract.changed == false
- cm_query_taboo_contract == nm_query_taboo_contract
- nm_query_taboo_contract.current.0.vzTaboo.attributes.descr == 'Ansible test taboo contract'
- nm_query_taboo_contract.current.0.vzTaboo.attributes.dn == 'uni/tn-ansible_test/taboo-taboo_contract_test'
- nm_query_taboo_contract.current.0.vzTaboo.attributes.name == 'taboo_contract_test'


# REMOVE TABOO CONTRACT
- name: Remove taboo contract (check_mode)
aci_taboo_contract: *taboo_contract_absent
check_mode: yes
register: cm_remove_taboo_contract

- name: Remove taboo contract (normal mode)
aci_taboo_contract: *taboo_contract_absent
register: nm_remove_taboo_contract

- name: Verify remove_taboo_contract
assert:
that:
- cm_remove_taboo_contract.changed == nm_remove_taboo_contract.changed == true
- 'cm_remove_taboo_contract.current == cm_remove_taboo_contract.previous == nm_remove_taboo_contract.previous == [{"vzTaboo": {"attributes": {"descr": "Ansible test taboo contract", "dn": "uni/tn-ansible_test/taboo-taboo_contract_test", "name": "taboo_contract_test", "nameAlias": "", "ownerKey": "", "ownerTag": ""}}}]'
- nm_remove_taboo_contract.current == []

- name: Remove taboo contract again (check_mode)
aci_taboo_contract: *taboo_contract_absent
check_mode: yes
register: cm_remove_taboo_contract_again

- name: Remove taboo contract again (normal mode)
aci_taboo_contract: *taboo_contract_absent
register: nm_remove_taboo_contract_again

- name: Verify remove_taboo_contract_again
assert:
that:
- cm_remove_taboo_contract_again.changed == nm_remove_taboo_contract_again.changed == false
- cm_remove_taboo_contract_again.proposed == nm_remove_taboo_contract_again.proposed == {}
- cm_remove_taboo_contract_again.sent == nm_remove_taboo_contract_again.sent == {}
- cm_remove_taboo_contract_again.previous == nm_remove_taboo_contract_again.previous == []
- cm_remove_taboo_contract_again.current == nm_remove_taboo_contract_again.current == []


# QUERY NON-EXISTING TABOO CONTRACT
- name: Query non-existing taboo contract (check_mode)
aci_taboo_contract:
<<: *taboo_contract_query
tenant: ansible_test
taboo_contract: taboo_contract_test
check_mode: yes
register: cm_query_non_taboo_contract

- name: Query non-existing taboo contract (normal mode)
aci_taboo_contract:
<<: *taboo_contract_query
tenant: ansible_test
taboo_contract: taboo_contract_test
register: nm_query_non_taboo_contract

# TODO: Implement more tests
- name: Verify query_non_taboo_contract
assert:
that:
- cm_query_non_taboo_contract.changed == nm_query_non_taboo_contract.changed == false
- cm_remove_taboo_contract_again.previous == nm_remove_taboo_contract_again.previous == []
- cm_remove_taboo_contract_again.current == nm_remove_taboo_contract_again.current == []


# PROVOKE ERRORS
- name: Error when required parameter is missing
aci_taboo_contract:
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: info
state: present
ignore_errors: yes
register: error_on_missing_required_param

- name: Assertion test - present
assert:
that:
- error_on_missing_required_param.failed == true
- 'error_on_missing_required_param.msg == "state is present but all of the following are missing: tenant, taboo_contract"'
2 changes: 1 addition & 1 deletion test/integration/targets/aci_vlan_pool/tasks/dynamic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
check_mode: yes
register: cm_query_dynamic_vlan_pool

- name: Query ourdynamic vlan pool
- name: Query our dynamic vlan pool
aci_vlan_pool:
<<: *dynamic_vlan_pool_query
pool: anstest
Expand Down
2 changes: 1 addition & 1 deletion test/integration/targets/aci_vlan_pool/tasks/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
check_mode: yes
register: cm_query_static_vlan_pool

- name: Query ourstatic vlan pool
- name: Query our static vlan pool
aci_vlan_pool:
<<: *static_vlan_pool_query
pool: anstest
Expand Down