2018-01-23 14:45:31 +01:00
|
|
|
# Test code for the UCS modules
|
|
|
|
# Copyright 2017, David Soper (@dsoper2)
|
|
|
|
|
|
|
|
- name: Test that we have a UCS host, UCS username, and UCS password
|
|
|
|
fail:
|
|
|
|
msg: 'Please define the following variables: ucs_hostname, ucs_username and ucs_password.'
|
|
|
|
when: ucs_hostname is not defined or ucs_username is not defined or ucs_password is not defined
|
|
|
|
vars:
|
|
|
|
login_info: &login_info
|
|
|
|
hostname: "{{ ucs_hostname }}"
|
|
|
|
username: "{{ ucs_username }}"
|
|
|
|
password: "{{ ucs_password }}"
|
|
|
|
|
|
|
|
|
|
|
|
# Setup (clean environment)
|
|
|
|
- name: vNIC template absent
|
|
|
|
ucs_vnic_template: &vnic_templates_absent
|
|
|
|
<<: *login_info
|
|
|
|
name: vNIC-A-B
|
|
|
|
state: absent
|
|
|
|
|
2018-06-29 15:48:48 +02:00
|
|
|
- name: vNIC primary template absent
|
|
|
|
ucs_vnic_template: &vnic_primary_templates_absent
|
|
|
|
<<: *login_info
|
|
|
|
name: vNIC-A
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: vNIC secondary template absent
|
|
|
|
ucs_vnic_template: &vnic_secondary_templates_absent
|
|
|
|
<<: *login_info
|
|
|
|
name: vNIC-B
|
|
|
|
state: absent
|
|
|
|
|
2018-01-23 14:45:31 +01:00
|
|
|
|
|
|
|
# Test present (check_mode)
|
|
|
|
- name: vNIC template present (check_mode)
|
|
|
|
ucs_vnic_template: &vnic_templates_present
|
|
|
|
<<: *login_info
|
|
|
|
name: vNIC-A-B
|
|
|
|
fabric: A-B
|
|
|
|
vlans_list:
|
|
|
|
- name: default
|
|
|
|
native: 'yes'
|
2018-06-29 15:48:48 +02:00
|
|
|
- name: 10
|
2018-01-23 14:45:31 +01:00
|
|
|
check_mode: yes
|
|
|
|
register: cm_vnic_templates_present
|
|
|
|
|
2018-06-29 15:48:48 +02:00
|
|
|
- name: vNIC primary template present (check_mode)
|
|
|
|
ucs_vnic_template: &vnic_primary_templates_present
|
|
|
|
<<: *login_info
|
|
|
|
name: vNIC-A
|
|
|
|
fabric: A
|
|
|
|
redundancy_type: primary
|
|
|
|
peer_redundancy_templ: vNIC-B
|
|
|
|
template_type: updating-template
|
|
|
|
mtu: '9000'
|
|
|
|
mac_pool: MAC-Pool-A
|
|
|
|
network_control_policy: Enable-CDP-LLDP
|
|
|
|
vlans_list:
|
|
|
|
- name: default
|
|
|
|
native: 'yes'
|
|
|
|
- name: finance
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_vnic_primary_templates_present
|
|
|
|
|
|
|
|
- name: vNIC secondary template present (check_mode)
|
|
|
|
ucs_vnic_template: &vnic_secondary_templates_present
|
|
|
|
<<: *login_info
|
|
|
|
name: vNIC-B
|
|
|
|
fabric: B
|
|
|
|
redundancy_type: secondary
|
|
|
|
peer_redundancy_templ: vNIC-A
|
|
|
|
mac_pool: MAC-Pool-B
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_vnic_secondary_templates_present
|
|
|
|
|
2018-01-23 14:45:31 +01:00
|
|
|
|
|
|
|
# Present (normal mode)
|
|
|
|
- name: vNIC template present (normal mode)
|
|
|
|
ucs_vnic_template: *vnic_templates_present
|
|
|
|
register: nm_vnic_templates_present
|
|
|
|
|
2018-06-29 15:48:48 +02:00
|
|
|
- name: vNIC primary template present (normal mode)
|
|
|
|
ucs_vnic_template: *vnic_primary_templates_present
|
|
|
|
register: nm_vnic_primary_templates_present
|
|
|
|
|
|
|
|
- name: vNIC secondary template present (normal mode)
|
|
|
|
ucs_vnic_template: *vnic_secondary_templates_present
|
|
|
|
register: nm_vnic_secondary_templates_present
|
|
|
|
|
2018-01-23 14:45:31 +01:00
|
|
|
|
|
|
|
# Test present again (idempotent)
|
|
|
|
- name: vNIC template present again (check_mode)
|
|
|
|
ucs_vnic_template: *vnic_templates_present
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_vnic_templates_present_again
|
|
|
|
|
2018-06-29 15:48:48 +02:00
|
|
|
- name: vNIC primary template present again (check_mode)
|
|
|
|
ucs_vnic_template: *vnic_primary_templates_present
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_vnic_primary_templates_present_again
|
|
|
|
|
|
|
|
- name: vNIC secondary template present again (check_mode)
|
|
|
|
ucs_vnic_template: *vnic_secondary_templates_present
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_vnic_secondary_templates_present_again
|
|
|
|
|
2018-01-23 14:45:31 +01:00
|
|
|
|
|
|
|
# Present again (normal mode)
|
|
|
|
- name: vNIC template present again (normal mode)
|
|
|
|
ucs_vnic_template: *vnic_templates_present
|
|
|
|
register: nm_vnic_templates_present_again
|
|
|
|
|
2018-06-29 15:48:48 +02:00
|
|
|
- name: vNIC primary template present again (normal mode)
|
|
|
|
ucs_vnic_template: *vnic_primary_templates_present
|
|
|
|
register: nm_vnic_primary_templates_present_again
|
|
|
|
|
|
|
|
- name: vNIC secondary template present again (normal mode)
|
|
|
|
ucs_vnic_template: *vnic_secondary_templates_present
|
|
|
|
register: nm_vnic_secondary_templates_present_again
|
|
|
|
|
2018-01-23 14:45:31 +01:00
|
|
|
|
|
|
|
# Verfiy present
|
|
|
|
- name: Verify vNIC template present results
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_vnic_templates_present.changed == nm_vnic_templates_present.changed == true
|
|
|
|
- cm_vnic_templates_present_again.changed == nm_vnic_templates_present_again.changed == false
|
2018-06-29 15:48:48 +02:00
|
|
|
- cm_vnic_primary_templates_present.changed == nm_vnic_primary_templates_present.changed == true
|
|
|
|
- cm_vnic_primary_templates_present_again.changed == nm_vnic_primary_templates_present_again.changed == false
|
|
|
|
- cm_vnic_secondary_templates_present.changed == nm_vnic_secondary_templates_present.changed == true
|
|
|
|
- cm_vnic_secondary_templates_present_again.changed == nm_vnic_secondary_templates_present_again.changed == false
|
2018-01-23 14:45:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Test change (check_mode)
|
2018-06-29 15:48:48 +02:00
|
|
|
- name: vNIC template change (check_mode)
|
2018-01-23 14:45:31 +01:00
|
|
|
ucs_vnic_template: &vnic_templates_change
|
|
|
|
<<: *vnic_templates_present
|
2018-06-29 15:48:48 +02:00
|
|
|
vlans_list:
|
|
|
|
- name: default
|
|
|
|
native: 'yes'
|
|
|
|
- name: 10
|
|
|
|
state: absent
|
2018-01-23 14:45:31 +01:00
|
|
|
check_mode: yes
|
2018-06-29 15:48:48 +02:00
|
|
|
register: cm_vnic_templates_change
|
2018-01-23 14:45:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Change (normal mode)
|
2018-06-29 15:48:48 +02:00
|
|
|
- name: vNIC template change (normal mode)
|
2018-01-23 14:45:31 +01:00
|
|
|
ucs_vnic_template: *vnic_templates_change
|
2018-06-29 15:48:48 +02:00
|
|
|
register: nm_vnic_templates_change
|
2018-01-23 14:45:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Test change again (idempotent)
|
2018-06-29 15:48:48 +02:00
|
|
|
- name: vNIC template change again (check_mode)
|
2018-01-23 14:45:31 +01:00
|
|
|
ucs_vnic_template: *vnic_templates_change
|
|
|
|
check_mode: yes
|
2018-06-29 15:48:48 +02:00
|
|
|
register: cm_vnic_templates_change_again
|
2018-01-23 14:45:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Change again (normal mode)
|
2018-06-29 15:48:48 +02:00
|
|
|
- name: vNIC template change again (normal mode)
|
2018-01-23 14:45:31 +01:00
|
|
|
ucs_vnic_template: *vnic_templates_change
|
2018-06-29 15:48:48 +02:00
|
|
|
register: nm_vnic_templates_change_again
|
2018-01-23 14:45:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Verfiy change
|
|
|
|
- name: Verify vNIC template change results
|
|
|
|
assert:
|
|
|
|
that:
|
2018-06-29 15:48:48 +02:00
|
|
|
- cm_vnic_templates_change.changed == nm_vnic_templates_change.changed == true
|
|
|
|
- cm_vnic_templates_change_again.changed == nm_vnic_templates_change_again.changed == false
|
2018-01-23 14:45:31 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Teardown (clean environment)
|
|
|
|
- name: vNIC template absent (check_mode)
|
|
|
|
ucs_vnic_template: *vnic_templates_absent
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_vnic_templates_absent
|
|
|
|
|
2018-06-29 15:48:48 +02:00
|
|
|
- name: vNIC primary template absent (check_mode)
|
|
|
|
ucs_vnic_template: *vnic_primary_templates_absent
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_vnic_primary_templates_absent
|
|
|
|
|
|
|
|
- name: vNIC secondary template absent (check_mode)
|
|
|
|
ucs_vnic_template: *vnic_secondary_templates_absent
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_vnic_secondary_templates_absent
|
|
|
|
|
2018-01-23 14:45:31 +01:00
|
|
|
|
|
|
|
# Absent (normal mode)
|
|
|
|
- name: vNIC template absent (normal mode)
|
|
|
|
ucs_vnic_template: *vnic_templates_absent
|
|
|
|
register: nm_vnic_templates_absent
|
|
|
|
|
2018-06-29 15:48:48 +02:00
|
|
|
- name: vNIC primary template absent (normal mode)
|
|
|
|
ucs_vnic_template: *vnic_primary_templates_absent
|
|
|
|
register: nm_vnic_primary_templates_absent
|
|
|
|
|
|
|
|
- name: vNIC secondary template absent (normal mode)
|
|
|
|
ucs_vnic_template: *vnic_secondary_templates_absent
|
|
|
|
register: nm_vnic_secondary_templates_absent
|
|
|
|
|
2018-01-23 14:45:31 +01:00
|
|
|
|
|
|
|
# Test absent again (idempotent)
|
|
|
|
- name: vNIC template absent again (check_mode)
|
|
|
|
ucs_vnic_template: *vnic_templates_absent
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_vnic_templates_absent_again
|
|
|
|
|
2018-06-29 15:48:48 +02:00
|
|
|
- name: vNIC primary template absent again (check_mode)
|
|
|
|
ucs_vnic_template: *vnic_primary_templates_absent
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_vnic_primary_templates_absent_again
|
|
|
|
|
|
|
|
- name: vNIC secondary template absent again (check_mode)
|
|
|
|
ucs_vnic_template: *vnic_secondary_templates_absent
|
|
|
|
check_mode: yes
|
|
|
|
register: cm_vnic_secondary_templates_absent_again
|
|
|
|
|
2018-01-23 14:45:31 +01:00
|
|
|
|
|
|
|
# Absent again (normal mode)
|
|
|
|
- name: vNIC template absent again (normal mode)
|
|
|
|
ucs_vnic_template: *vnic_templates_absent
|
|
|
|
register: nm_vnic_templates_absent_again
|
|
|
|
|
2018-06-29 15:48:48 +02:00
|
|
|
- name: vNIC primary template absent again (normal mode)
|
|
|
|
ucs_vnic_template: *vnic_primary_templates_absent
|
|
|
|
register: nm_vnic_primary_templates_absent_again
|
|
|
|
|
|
|
|
- name: vNIC secondary template absent again (normal mode)
|
|
|
|
ucs_vnic_template: *vnic_secondary_templates_absent
|
|
|
|
register: nm_vnic_secondary_templates_absent_again
|
|
|
|
|
2018-01-23 14:45:31 +01:00
|
|
|
|
|
|
|
# Verfiy absent
|
|
|
|
- name: Verify vNIC template absent results
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- cm_vnic_templates_absent.changed == nm_vnic_templates_absent.changed == true
|
|
|
|
- cm_vnic_templates_absent_again.changed == nm_vnic_templates_absent_again.changed == false
|
2018-06-29 15:48:48 +02:00
|
|
|
- cm_vnic_primary_templates_absent.changed == nm_vnic_primary_templates_absent.changed == true
|
|
|
|
- cm_vnic_primary_templates_absent_again.changed == nm_vnic_primary_templates_absent_again.changed == false
|
|
|
|
- cm_vnic_secondary_templates_absent.changed == nm_vnic_secondary_templates_absent.changed == true
|
|
|
|
- cm_vnic_secondary_templates_absent_again.changed == nm_vnic_secondary_templates_absent_again.changed == false
|