2019-01-16 14:53:38 +01:00
|
|
|
# Test code for the MSO modules
|
2018-11-02 20:07:10 +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:07:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
# CLEAN ENVIRONMENT
|
2018-12-20 18:18:46 +01:00
|
|
|
- name: Remove site 2
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site: &site_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") }}'
|
|
|
|
site: '{{ mso_site | default("ansible_test") }}_2'
|
2018-11-02 20:07:10 +01:00
|
|
|
state: absent
|
|
|
|
|
2018-12-20 18:18:46 +01:00
|
|
|
- name: Remove site
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site:
|
2018-11-02 20:07:10 +01:00
|
|
|
<<: *site_absent
|
2019-01-16 14:53:38 +01:00
|
|
|
site: '{{ mso_site | default("ansible_test") }}'
|
2018-11-02 20:07:10 +01:00
|
|
|
register: cm_remove_site
|
|
|
|
|
|
|
|
|
|
|
|
# ADD SITE
|
|
|
|
- name: Add site (check_mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site: &site_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") }}'
|
|
|
|
site: '{{ mso_site | default("ansible_test") }}'
|
2018-11-02 20:07:10 +01:00
|
|
|
apic_username: admin
|
|
|
|
apic_password: '{{ apic_password }}'
|
2018-11-13 09:01:45 +01:00
|
|
|
apic_site_id: 101
|
2018-11-02 20:07:10 +01:00
|
|
|
urls:
|
2018-12-20 18:18:46 +01:00
|
|
|
- https://{{ apic_hostname }}
|
|
|
|
location:
|
|
|
|
latitude: 50.887318
|
|
|
|
longitude: 4.447084
|
|
|
|
labels:
|
|
|
|
- Diegem
|
|
|
|
- EMEA
|
|
|
|
- POD51
|
2018-11-02 20:07:10 +01:00
|
|
|
state: present
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_add_site
|
|
|
|
|
|
|
|
- name: Verify cm_add_site
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_add_site is changed
|
|
|
|
- cm_add_site.previous == {}
|
|
|
|
- cm_add_site.current.id is not defined
|
2019-01-16 14:53:38 +01:00
|
|
|
- cm_add_site.current.name == mso_site|default("ansible_test")
|
2018-11-02 20:07:10 +01:00
|
|
|
|
|
|
|
- name: Add site (normal mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site: *site_present
|
2018-11-02 20:07:10 +01:00
|
|
|
register: nm_add_site
|
|
|
|
|
|
|
|
- name: nm_Verify add_site
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- nm_add_site is changed
|
|
|
|
- nm_add_site.previous == {}
|
|
|
|
- nm_add_site.current.id is defined
|
2019-01-16 14:53:38 +01:00
|
|
|
- nm_add_site.current.name == mso_site|default("ansible_test")
|
2018-11-02 20:07:10 +01:00
|
|
|
|
|
|
|
- name: Add site again (check_mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site: *site_present
|
2018-11-02 20:07:10 +01:00
|
|
|
check_mode: yes
|
|
|
|
register: cm_add_site_again
|
|
|
|
|
|
|
|
- name: Verify cm_add_site_again
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_add_site_again is not changed
|
2019-01-16 14:53:38 +01:00
|
|
|
- cm_add_site_again.previous.name == mso_site|default("ansible_test")
|
2018-11-02 20:07:10 +01:00
|
|
|
- cm_add_site_again.current.id == nm_add_site.current.id
|
2019-01-16 14:53:38 +01:00
|
|
|
- cm_add_site_again.current.name == mso_site|default("ansible_test")
|
2018-11-02 20:07:10 +01:00
|
|
|
|
|
|
|
- name: Add site again (normal mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site: *site_present
|
2018-11-02 20:07:10 +01:00
|
|
|
register: nm_add_site_again
|
|
|
|
|
|
|
|
- name: Verify nm_add_site_again
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- nm_add_site_again is not changed
|
2019-01-16 14:53:38 +01:00
|
|
|
- nm_add_site_again.previous.name == mso_site|default("ansible_test")
|
2018-11-02 20:07:10 +01:00
|
|
|
- nm_add_site_again.current.id == nm_add_site.current.id
|
2019-01-16 14:53:38 +01:00
|
|
|
- nm_add_site_again.current.name == mso_site|default("ansible_test")
|
2018-11-02 20:07:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
# CHANGE SITE
|
|
|
|
- name: Change site (check_mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site:
|
2018-11-02 20:07:10 +01:00
|
|
|
<<: *site_present
|
|
|
|
site_id: '{{ nm_add_site.current.id }}'
|
2019-01-16 14:53:38 +01:00
|
|
|
site: '{{ mso_site | default("ansible_test") }}_2'
|
2018-11-02 20:07:10 +01:00
|
|
|
check_mode: yes
|
|
|
|
register: cm_change_site
|
|
|
|
|
|
|
|
- name: Verify cm_change_site
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_change_site is changed
|
|
|
|
- cm_change_site.current.id == nm_add_site.current.id
|
2019-01-16 14:53:38 +01:00
|
|
|
- cm_change_site.current.name == '{{ mso_site | default("ansible_test") }}_2'
|
2018-11-02 20:07:10 +01:00
|
|
|
|
|
|
|
- name: Change site (normal mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site:
|
2018-11-02 20:07:10 +01:00
|
|
|
<<: *site_present
|
|
|
|
site_id: '{{ nm_add_site.current.id }}'
|
2019-01-16 14:53:38 +01:00
|
|
|
site: '{{ mso_site | default("ansible_test") }}_2'
|
2018-11-02 20:07:10 +01:00
|
|
|
output_level: debug
|
|
|
|
register: nm_change_site
|
|
|
|
|
|
|
|
- name: Verify nm_change_site
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- nm_change_site is changed
|
|
|
|
- nm_change_site.current.id == nm_add_site.current.id
|
2019-01-16 14:53:38 +01:00
|
|
|
- nm_change_site.current.name == '{{ mso_site | default("ansible_test") }}_2'
|
2018-11-02 20:07:10 +01:00
|
|
|
|
|
|
|
- name: Change site again (check_mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site:
|
2018-11-02 20:07:10 +01:00
|
|
|
<<: *site_present
|
|
|
|
site_id: '{{ nm_add_site.current.id }}'
|
2019-01-16 14:53:38 +01:00
|
|
|
site: '{{ mso_site | default("ansible_test") }}_2'
|
2018-11-02 20:07:10 +01:00
|
|
|
check_mode: yes
|
|
|
|
register: cm_change_site_again
|
|
|
|
|
|
|
|
- name: Verify cm_change_site_again
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_change_site_again is not changed
|
|
|
|
- cm_change_site_again.current.id == nm_add_site.current.id
|
2019-01-16 14:53:38 +01:00
|
|
|
- cm_change_site_again.current.name == '{{ mso_site | default("ansible_test") }}_2'
|
2018-11-02 20:07:10 +01:00
|
|
|
|
|
|
|
- name: Change site again (normal mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site:
|
2018-11-02 20:07:10 +01:00
|
|
|
<<: *site_present
|
|
|
|
site_id: '{{ nm_add_site.current.id }}'
|
2019-01-16 14:53:38 +01:00
|
|
|
site: '{{ mso_site | default("ansible_test") }}_2'
|
2018-11-02 20:07:10 +01:00
|
|
|
register: nm_change_site_again
|
|
|
|
|
|
|
|
- name: Verify nm_change_site_again
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- nm_change_site_again is not changed
|
|
|
|
- nm_change_site_again.current.id == nm_add_site.current.id
|
2019-01-16 14:53:38 +01:00
|
|
|
- nm_change_site_again.current.name == '{{ mso_site | default("ansible_test") }}_2'
|
2018-11-02 20:07:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
# QUERY ALL SITES
|
|
|
|
- name: Query all sites (check_mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site: &site_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:07:10 +01:00
|
|
|
state: query
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_query_all_sites
|
|
|
|
|
|
|
|
- name: Query all sites (normal mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site: *site_query
|
2018-11-02 20:07:10 +01:00
|
|
|
register: nm_query_all_sites
|
|
|
|
|
|
|
|
- name: Verify query_all_sites
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_query_all_sites is not changed
|
|
|
|
- nm_query_all_sites is not changed
|
|
|
|
# NOTE: Order of sites is not stable between calls
|
|
|
|
#- cm_query_all_sites == nm_query_all_sites
|
|
|
|
|
|
|
|
|
|
|
|
# QUERY A SITE
|
|
|
|
- name: Query our site
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site:
|
2018-11-02 20:07:10 +01:00
|
|
|
<<: *site_query
|
2019-01-16 14:53:38 +01:00
|
|
|
site: '{{ mso_site | default("ansible_test") }}_2'
|
2018-11-02 20:07:10 +01:00
|
|
|
check_mode: yes
|
|
|
|
register: cm_query_site
|
|
|
|
|
|
|
|
- name: Query our site
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site:
|
2018-11-02 20:07:10 +01:00
|
|
|
<<: *site_query
|
2019-01-16 14:53:38 +01:00
|
|
|
site: '{{ mso_site | default("ansible_test") }}_2'
|
2018-11-02 20:07:10 +01:00
|
|
|
register: nm_query_site
|
|
|
|
|
|
|
|
- name: Verify query_site
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_query_site is not changed
|
|
|
|
- cm_query_site.current.id == nm_add_site.current.id
|
2019-01-16 14:53:38 +01:00
|
|
|
- cm_query_site.current.name == '{{ mso_site | default("ansible_test") }}_2'
|
2018-11-02 20:07:10 +01:00
|
|
|
- nm_query_site is not changed
|
|
|
|
- nm_query_site.current.id == nm_add_site.current.id
|
2019-01-16 14:53:38 +01:00
|
|
|
- nm_query_site.current.name == '{{ mso_site | default("ansible_test") }}_2'
|
2018-11-02 20:07:10 +01:00
|
|
|
- cm_query_site == nm_query_site
|
|
|
|
|
|
|
|
|
|
|
|
# REMOVE SITE
|
|
|
|
- name: Remove site (check_mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site: *site_absent
|
2018-11-02 20:07:10 +01:00
|
|
|
check_mode: yes
|
|
|
|
register: cm_remove_site
|
|
|
|
|
|
|
|
- name: Verify cm_remove_site
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_remove_site is changed
|
|
|
|
- cm_remove_site.current == {}
|
|
|
|
|
|
|
|
- name: Remove site (normal mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site: *site_absent
|
2018-11-02 20:07:10 +01:00
|
|
|
register: nm_remove_site
|
|
|
|
|
|
|
|
- name: Verify nm_remove_site
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- nm_remove_site is changed
|
|
|
|
- nm_remove_site.current == {}
|
|
|
|
|
|
|
|
- name: Remove site again (check_mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site: *site_absent
|
2018-11-02 20:07:10 +01:00
|
|
|
check_mode: yes
|
|
|
|
register: cm_remove_site_again
|
|
|
|
|
|
|
|
- name: Verify cm_remove_site_again
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_remove_site_again is not changed
|
|
|
|
- cm_remove_site_again.current == {}
|
|
|
|
|
|
|
|
- name: Remove site again (normal mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site: *site_absent
|
2018-11-02 20:07:10 +01:00
|
|
|
register: nm_remove_site_again
|
|
|
|
|
|
|
|
- name: Verify nm_remove_site_again
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- nm_remove_site_again is not changed
|
|
|
|
- nm_remove_site_again.current == {}
|
|
|
|
|
|
|
|
|
|
|
|
# QUERY NON-EXISTING SITE
|
|
|
|
- name: Query non-existing site (check_mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site:
|
2018-11-02 20:07:10 +01:00
|
|
|
<<: *site_query
|
2019-01-16 14:53:38 +01:00
|
|
|
site: '{{ mso_site | default("ansible_test") }}'
|
2018-11-02 20:07:10 +01:00
|
|
|
check_mode: yes
|
|
|
|
register: cm_query_non_site
|
|
|
|
|
|
|
|
- name: Query non-existing site (normal mode)
|
2019-01-16 14:53:38 +01:00
|
|
|
mso_site:
|
2018-11-02 20:07:10 +01:00
|
|
|
<<: *site_query
|
2019-01-16 14:53:38 +01:00
|
|
|
site: '{{ mso_site | default("ansible_test") }}'
|
2018-11-02 20:07:10 +01:00
|
|
|
register: nm_query_non_site
|
|
|
|
|
|
|
|
# TODO: Implement more tests
|
|
|
|
- name: Verify query_non_site
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_query_non_site is not changed
|
|
|
|
- nm_query_non_site is not changed
|
|
|
|
- cm_query_non_site == nm_query_non_site
|