2019-01-16 14:53:38 +01:00
|
|
|
# Test code for the MSO modules
|
2018-11-02 20:02:42 +01:00
|
|
|
# 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)
|
|
|
|
|
|
|
|
- name: Test that we have an ACI MultiSite host, username and password
|
|
|
|
fail:
|
2019-01-16 14:53:38 +01:00
|
|
|
msg: 'Please define the following variables: mso_hostname, mso_username and mso_password.'
|
|
|
|
when: mso_hostname is not defined or mso_username is not defined or mso_password is not defined
|
2018-11-02 20:02:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
# CLEAN ENVIRONMENT
|
|
|
|
- name: Remove tenant ansible_test2
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant: &tenant_absent
|
|
|
|
host: '{{ mso_hostname }}'
|
|
|
|
username: '{{ mso_username }}'
|
|
|
|
password: '{{ mso_password }}'
|
|
|
|
validate_certs: '{{ mso_validate_certs | default(false) }}'
|
|
|
|
use_ssl: '{{ mso_use_ssl | default(true) }}'
|
|
|
|
use_proxy: '{{ mso_use_proxy | default(true) }}'
|
|
|
|
output_level: '{{ mso_output_level | default("info") }}'
|
2018-11-02 20:02:42 +01:00
|
|
|
tenant: ansible_test2
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: Remove tenant ansible_test
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant:
|
2018-11-02 20:02:42 +01:00
|
|
|
<<: *tenant_absent
|
|
|
|
tenant: ansible_test
|
|
|
|
register: cm_remove_tenant
|
|
|
|
|
|
|
|
|
|
|
|
# ADD TENANT
|
|
|
|
- name: Add tenant (check_mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant: &tenant_present
|
|
|
|
host: '{{ mso_hostname }}'
|
|
|
|
username: '{{ mso_username }}'
|
|
|
|
password: '{{ mso_password }}'
|
|
|
|
validate_certs: '{{ mso_validate_certs | default(false) }}'
|
|
|
|
use_ssl: '{{ mso_use_ssl | default(true) }}'
|
|
|
|
use_proxy: '{{ mso_use_proxy | default(true) }}'
|
|
|
|
output_level: '{{ mso_output_level | default("info") }}'
|
2018-11-02 20:02:42 +01:00
|
|
|
tenant: ansible_test
|
2018-11-13 09:01:45 +01:00
|
|
|
display_name: Ansible test title
|
2018-11-02 20:02:42 +01:00
|
|
|
description: Ansible test tenant
|
|
|
|
state: present
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_add_tenant
|
|
|
|
|
|
|
|
- name: Verify cm_add_tenant
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_add_tenant is changed
|
|
|
|
- cm_add_tenant.previous == {}
|
|
|
|
- cm_add_tenant.current.id is not defined
|
2018-11-13 09:01:45 +01:00
|
|
|
- cm_add_tenant.current.name == 'ansible_test'
|
2018-11-02 20:02:42 +01:00
|
|
|
- cm_add_tenant.current.description == 'Ansible test tenant'
|
|
|
|
|
|
|
|
- name: Add tenant (normal mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant: *tenant_present
|
2018-11-02 20:02:42 +01:00
|
|
|
register: nm_add_tenant
|
|
|
|
|
|
|
|
- name: nm_Verify add_tenant
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- nm_add_tenant is changed
|
|
|
|
- nm_add_tenant.previous == {}
|
|
|
|
- nm_add_tenant.current.id is defined
|
2018-11-13 09:01:45 +01:00
|
|
|
- nm_add_tenant.current.name == 'ansible_test'
|
2018-11-02 20:02:42 +01:00
|
|
|
- nm_add_tenant.current.description == 'Ansible test tenant'
|
|
|
|
|
|
|
|
- name: Add tenant again (check_mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant: *tenant_present
|
2018-11-02 20:02:42 +01:00
|
|
|
check_mode: yes
|
|
|
|
register: cm_add_tenant_again
|
|
|
|
|
|
|
|
- name: Verify cm_add_tenant_again
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_add_tenant_again is not changed
|
2018-11-13 09:01:45 +01:00
|
|
|
- cm_add_tenant_again.previous.name == 'ansible_test'
|
2018-11-02 20:02:42 +01:00
|
|
|
- cm_add_tenant_again.previous.description == 'Ansible test tenant'
|
|
|
|
- cm_add_tenant_again.current.id == nm_add_tenant.current.id
|
2018-11-13 09:01:45 +01:00
|
|
|
- cm_add_tenant_again.current.name == 'ansible_test'
|
2018-11-02 20:02:42 +01:00
|
|
|
- cm_add_tenant_again.current.description == 'Ansible test tenant'
|
|
|
|
|
|
|
|
- name: Add tenant again (normal mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant: *tenant_present
|
2018-11-02 20:02:42 +01:00
|
|
|
register: nm_add_tenant_again
|
|
|
|
|
|
|
|
- name: Verify nm_add_tenant_again
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- nm_add_tenant_again is not changed
|
2018-11-13 09:01:45 +01:00
|
|
|
- nm_add_tenant_again.previous.name == 'ansible_test'
|
2018-11-02 20:02:42 +01:00
|
|
|
- nm_add_tenant_again.previous.description == 'Ansible test tenant'
|
|
|
|
- nm_add_tenant_again.current.id == nm_add_tenant.current.id
|
2018-11-13 09:01:45 +01:00
|
|
|
- nm_add_tenant_again.current.name == 'ansible_test'
|
2018-11-02 20:02:42 +01:00
|
|
|
- nm_add_tenant_again.current.description == 'Ansible test tenant'
|
|
|
|
|
|
|
|
|
|
|
|
# CHANGE TENANT
|
|
|
|
- name: Change tenant (check_mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant:
|
2018-11-02 20:02:42 +01:00
|
|
|
<<: *tenant_present
|
|
|
|
tenant_id: '{{ nm_add_tenant.current.id }}'
|
|
|
|
tenant: ansible_test2
|
|
|
|
description: Ansible test tenant 2
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_change_tenant
|
|
|
|
|
|
|
|
- name: Verify cm_change_tenant
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_change_tenant is changed
|
|
|
|
- cm_change_tenant.current.id == nm_add_tenant.current.id
|
2018-11-13 09:01:45 +01:00
|
|
|
- cm_change_tenant.current.name == 'ansible_test2'
|
2018-11-02 20:02:42 +01:00
|
|
|
- cm_change_tenant.current.description == 'Ansible test tenant 2'
|
|
|
|
|
|
|
|
- name: Change tenant (normal mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant:
|
2018-11-02 20:02:42 +01:00
|
|
|
<<: *tenant_present
|
|
|
|
tenant_id: '{{ nm_add_tenant.current.id }}'
|
|
|
|
tenant: ansible_test2
|
|
|
|
description: Ansible test tenant 2
|
|
|
|
output_level: debug
|
|
|
|
register: nm_change_tenant
|
|
|
|
|
|
|
|
- name: Verify nm_change_tenant
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- nm_change_tenant is changed
|
|
|
|
- nm_change_tenant.current.id == nm_add_tenant.current.id
|
2018-11-13 09:01:45 +01:00
|
|
|
- nm_change_tenant.current.name == 'ansible_test2'
|
2018-11-02 20:02:42 +01:00
|
|
|
- nm_change_tenant.current.description == 'Ansible test tenant 2'
|
|
|
|
|
|
|
|
- name: Change tenant again (check_mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant:
|
2018-11-02 20:02:42 +01:00
|
|
|
<<: *tenant_present
|
|
|
|
tenant_id: '{{ nm_add_tenant.current.id }}'
|
|
|
|
tenant: ansible_test2
|
|
|
|
description: Ansible test tenant 2
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_change_tenant_again
|
|
|
|
|
|
|
|
- name: Verify cm_change_tenant_again
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_change_tenant_again is not changed
|
|
|
|
- cm_change_tenant_again.current.id == nm_add_tenant.current.id
|
2018-11-13 09:01:45 +01:00
|
|
|
- cm_change_tenant_again.current.name == 'ansible_test2'
|
2018-11-02 20:02:42 +01:00
|
|
|
- cm_change_tenant_again.current.description == 'Ansible test tenant 2'
|
|
|
|
|
|
|
|
- name: Change tenant again (normal mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant:
|
2018-11-02 20:02:42 +01:00
|
|
|
<<: *tenant_present
|
|
|
|
tenant_id: '{{ nm_add_tenant.current.id }}'
|
|
|
|
tenant: ansible_test2
|
|
|
|
description: Ansible test tenant 2
|
|
|
|
register: nm_change_tenant_again
|
|
|
|
|
|
|
|
- name: Verify nm_change_tenant_again
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- nm_change_tenant_again is not changed
|
|
|
|
- nm_change_tenant_again.current.id == nm_add_tenant.current.id
|
2018-11-13 09:01:45 +01:00
|
|
|
- nm_change_tenant_again.current.name == 'ansible_test2'
|
2018-11-02 20:02:42 +01:00
|
|
|
- nm_change_tenant_again.current.description == 'Ansible test tenant 2'
|
|
|
|
|
|
|
|
|
|
|
|
# QUERY ALL TENANTS
|
|
|
|
- name: Query all tenants (check_mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant: &tenant_query
|
|
|
|
host: '{{ mso_hostname }}'
|
|
|
|
username: '{{ mso_username }}'
|
|
|
|
password: '{{ mso_password }}'
|
|
|
|
validate_certs: '{{ mso_validate_certs | default(false) }}'
|
|
|
|
use_ssl: '{{ mso_use_ssl | default(true) }}'
|
|
|
|
use_proxy: '{{ mso_use_proxy | default(true) }}'
|
|
|
|
output_level: '{{ mso_output_level | default("info") }}'
|
2018-11-02 20:02:42 +01:00
|
|
|
state: query
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_query_all_tenants
|
|
|
|
|
|
|
|
- name: Query all tenants (normal mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant: *tenant_query
|
2018-11-02 20:02:42 +01:00
|
|
|
register: nm_query_all_tenants
|
|
|
|
|
|
|
|
- name: Verify query_all_tenants
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_query_all_tenants is not changed
|
|
|
|
- nm_query_all_tenants is not changed
|
|
|
|
# NOTE: Order of tenants is not stable between calls
|
|
|
|
#- cm_query_all_tenants == nm_query_all_tenants
|
|
|
|
|
|
|
|
|
|
|
|
# QUERY A TENANT
|
|
|
|
- name: Query our tenant
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant:
|
2018-11-02 20:02:42 +01:00
|
|
|
<<: *tenant_query
|
|
|
|
tenant: ansible_test2
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_query_tenant
|
|
|
|
|
|
|
|
- name: Query our tenant
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant:
|
2018-11-02 20:02:42 +01:00
|
|
|
<<: *tenant_query
|
|
|
|
tenant: ansible_test2
|
|
|
|
register: nm_query_tenant
|
|
|
|
|
|
|
|
- name: Verify query_tenant
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_query_tenant is not changed
|
|
|
|
- cm_query_tenant.current.id == nm_add_tenant.current.id
|
2018-11-13 09:01:45 +01:00
|
|
|
- cm_query_tenant.current.name == 'ansible_test2'
|
2018-11-02 20:02:42 +01:00
|
|
|
- cm_query_tenant.current.description == 'Ansible test tenant 2'
|
|
|
|
- nm_query_tenant is not changed
|
|
|
|
- nm_query_tenant.current.id == nm_add_tenant.current.id
|
2018-11-13 09:01:45 +01:00
|
|
|
- nm_query_tenant.current.name == 'ansible_test2'
|
2018-11-02 20:02:42 +01:00
|
|
|
- nm_query_tenant.current.description == 'Ansible test tenant 2'
|
|
|
|
- cm_query_tenant == nm_query_tenant
|
|
|
|
|
|
|
|
|
|
|
|
# REMOVE TENANT
|
|
|
|
- name: Remove tenant (check_mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant: *tenant_absent
|
2018-11-02 20:02:42 +01:00
|
|
|
check_mode: yes
|
|
|
|
register: cm_remove_tenant
|
|
|
|
|
|
|
|
- name: Verify cm_remove_tenant
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_remove_tenant is changed
|
|
|
|
- cm_remove_tenant.current == {}
|
|
|
|
|
|
|
|
- name: Remove tenant (normal mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant: *tenant_absent
|
2018-11-02 20:02:42 +01:00
|
|
|
register: nm_remove_tenant
|
|
|
|
|
|
|
|
- name: Verify nm_remove_tenant
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- nm_remove_tenant is changed
|
|
|
|
- nm_remove_tenant.current == {}
|
|
|
|
|
|
|
|
- name: Remove tenant again (check_mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant: *tenant_absent
|
2018-11-02 20:02:42 +01:00
|
|
|
check_mode: yes
|
|
|
|
register: cm_remove_tenant_again
|
|
|
|
|
|
|
|
- name: Verify cm_remove_tenant_again
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_remove_tenant_again is not changed
|
|
|
|
- cm_remove_tenant_again.current == {}
|
|
|
|
|
|
|
|
- name: Remove tenant again (normal mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant: *tenant_absent
|
2018-11-02 20:02:42 +01:00
|
|
|
register: nm_remove_tenant_again
|
|
|
|
|
|
|
|
- name: Verify nm_remove_tenant_again
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- nm_remove_tenant_again is not changed
|
|
|
|
- nm_remove_tenant_again.current == {}
|
|
|
|
|
|
|
|
|
|
|
|
# QUERY NON-EXISTING TENANT
|
|
|
|
- name: Query non-existing tenant (check_mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant:
|
2018-11-02 20:02:42 +01:00
|
|
|
<<: *tenant_query
|
|
|
|
tenant: ansible_test
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_query_non_tenant
|
|
|
|
|
|
|
|
- name: Query non-existing tenant (normal mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_tenant:
|
2018-11-02 20:02:42 +01:00
|
|
|
<<: *tenant_query
|
|
|
|
tenant: ansible_test
|
|
|
|
register: nm_query_non_tenant
|
|
|
|
|
|
|
|
# TODO: Implement more tests
|
|
|
|
- name: Verify query_non_tenant
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_query_non_tenant is not changed
|
|
|
|
- nm_query_non_tenant is not changed
|
|
|
|
- cm_query_non_tenant == nm_query_non_tenant
|