| 1 |
# Test code for the vmware_vswitch module. |
| 2 |
# Copyright: (c) 2017, Abhijeet Kasurde <[email protected]> |
| 3 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
|
| 5 |
- name: Run tests and clean up |
| 6 |
block: |
| 7 |
- import_role: |
| 8 |
name: prepare_vmware_tests |
| 9 |
vars: |
| 10 |
setup_attach_host: true |
| 11 |
|
| 12 |
- name: Ensure the vswitch is not already here |
| 13 |
include_tasks: teardown.yml |
| 14 |
|
| 15 |
- name: Add a nic to a switch |
| 16 |
vmware_vswitch: |
| 17 |
hostname: '{{ esxi1 }}' |
| 18 |
username: '{{ esxi_user }}' |
| 19 |
password: '{{ esxi_password }}' |
| 20 |
validate_certs: false |
| 21 |
switch: vmswitch_0001 |
| 22 |
nics: vmnic1 |
| 23 |
state: present |
| 24 |
register: add_nic_run |
| 25 |
- debug: var=add_nic_run |
| 26 |
- assert: |
| 27 |
that: |
| 28 |
- add_nic_run.changed == true |
| 29 |
|
| 30 |
- name: Add a nic to a switch again |
| 31 |
vmware_vswitch: |
| 32 |
hostname: '{{ esxi1 }}' |
| 33 |
username: '{{ esxi_user }}' |
| 34 |
password: '{{ esxi_password }}' |
| 35 |
validate_certs: false |
| 36 |
switch: vmswitch_0001 |
| 37 |
nics: vmnic1 |
| 38 |
state: present |
| 39 |
register: add_nic_again_run |
| 40 |
- assert: |
| 41 |
that: |
| 42 |
- add_nic_again_run.changed == false |
| 43 |
|
| 44 |
- name: Remove a nic from a switch |
| 45 |
vmware_vswitch: |
| 46 |
hostname: '{{ esxi1 }}' |
| 47 |
username: '{{ esxi_user }}' |
| 48 |
password: '{{ esxi_password }}' |
| 49 |
validate_certs: false |
| 50 |
switch: vmswitch_0001 |
| 51 |
state: present |
| 52 |
register: remove_nic_run |
| 53 |
- debug: var=remove_nic_run |
| 54 |
- assert: |
| 55 |
that: |
| 56 |
- remove_nic_run.changed == true |
| 57 |
|
| 58 |
- name: Remove a nic from a switch again |
| 59 |
vmware_vswitch: |
| 60 |
hostname: '{{ esxi1 }}' |
| 61 |
username: '{{ esxi_user }}' |
| 62 |
password: '{{ esxi_password }}' |
| 63 |
validate_certs: false |
| 64 |
switch: vmswitch_0001 |
| 65 |
state: present |
| 66 |
register: remove_nic_again_run |
| 67 |
- debug: var=remove_nic_run |
| 68 |
- assert: |
| 69 |
that: |
| 70 |
- remove_nic_again_run.changed == false |
| 71 |
|
| 72 |
- name: Remove a switch |
| 73 |
vmware_vswitch: |
| 74 |
hostname: '{{ esxi1 }}' |
| 75 |
username: '{{ esxi_user }}' |
| 76 |
password: '{{ esxi_password }}' |
| 77 |
validate_certs: false |
| 78 |
switch: vmswitch_0001 |
| 79 |
state: absent |
| 80 |
register: remove_nic_run |
| 81 |
- assert: |
| 82 |
that: |
| 83 |
- remove_nic_run is changed |
| 84 |
|
| 85 |
- name: Remove a switch again |
| 86 |
vmware_vswitch: |
| 87 |
hostname: '{{ esxi1 }}' |
| 88 |
username: '{{ esxi_user }}' |
| 89 |
password: '{{ esxi_password }}' |
| 90 |
validate_certs: false |
| 91 |
switch: vmswitch_0001 |
| 92 |
state: absent |
| 93 |
register: remove_nic_again_run |
| 94 |
- assert: |
| 95 |
that: |
| 96 |
- not (remove_nic_again_run is changed) |
| 97 |
|
| 98 |
- name: Add vswitch to a specific host system |
| 99 |
vmware_vswitch: |
| 100 |
validate_certs: false |
| 101 |
hostname: '{{ vcenter_hostname }}' |
| 102 |
username: '{{ vcenter_username }}' |
| 103 |
password: '{{ vcenter_password }}' |
| 104 |
switch: vmswitch_0002 |
| 105 |
nics: vmnic1 |
| 106 |
esxi_hostname: '{{ esxi2 }}' |
| 107 |
register: add_vswitch_with_host_system |
| 108 |
- debug: var=add_vswitch_with_host_system |
| 109 |
- assert: |
| 110 |
that: |
| 111 |
- add_vswitch_with_host_system is changed |
| 112 |
|
| 113 |
- name: Add a vSwitch with a network policy |
| 114 |
vmware_vswitch: |
| 115 |
hostname: '{{ esxi1 }}' |
| 116 |
username: '{{ esxi_user }}' |
| 117 |
password: '{{ esxi_password }}' |
| 118 |
validate_certs: false |
| 119 |
switch: vmswitch_0001 |
| 120 |
nics: |
| 121 |
- vmnic1 |
| 122 |
- vmnic2 |
| 123 |
state: present |
| 124 |
security: |
| 125 |
forged_transmits: true |
| 126 |
mac_changes: true |
| 127 |
traffic_shaping: |
| 128 |
enabled: true |
| 129 |
average_bandwidth: 100000 |
| 130 |
peak_bandwidth: 100000 |
| 131 |
burst_size: 102400 |
| 132 |
teaming: |
| 133 |
active_adapters: vmnic1 |
| 134 |
standby_adapters: vmnic2 |
| 135 |
register: add_vswitch_netpol_run |
| 136 |
- debug: var=add_vswitch_netpol_run |
| 137 |
- assert: |
| 138 |
that: |
| 139 |
- add_vswitch_netpol_run.changed == true |
| 140 |
|
| 141 |
- name: Add a vSwitch with a network policy again (idempotency check) |
| 142 |
vmware_vswitch: |
| 143 |
hostname: '{{ esxi1 }}' |
| 144 |
username: '{{ esxi_user }}' |
| 145 |
password: '{{ esxi_password }}' |
| 146 |
validate_certs: false |
| 147 |
switch: vmswitch_0001 |
| 148 |
nics: |
| 149 |
- vmnic1 |
| 150 |
- vmnic2 |
| 151 |
state: present |
| 152 |
security: |
| 153 |
forged_transmits: true |
| 154 |
mac_changes: true |
| 155 |
traffic_shaping: |
| 156 |
enabled: true |
| 157 |
average_bandwidth: 100000 |
| 158 |
peak_bandwidth: 100000 |
| 159 |
burst_size: 102400 |
| 160 |
teaming: |
| 161 |
active_adapters: vmnic1 |
| 162 |
standby_adapters: vmnic2 |
| 163 |
register: add_vswitch_netpol_again_run |
| 164 |
- assert: |
| 165 |
that: |
| 166 |
- add_vswitch_netpol_again_run.changed == false |
| 167 |
|
| 168 |
- name: Update a vSwitch network policy |
| 169 |
vmware_vswitch: |
| 170 |
hostname: '{{ esxi1 }}' |
| 171 |
username: '{{ esxi_user }}' |
| 172 |
password: '{{ esxi_password }}' |
| 173 |
validate_certs: false |
| 174 |
switch: vmswitch_0001 |
| 175 |
nics: |
| 176 |
- vmnic1 |
| 177 |
- vmnic2 |
| 178 |
state: present |
| 179 |
security: |
| 180 |
forged_transmits: false |
| 181 |
mac_changes: true |
| 182 |
traffic_shaping: |
| 183 |
enabled: false |
| 184 |
teaming: |
| 185 |
active_adapters: |
| 186 |
- vmnic1 |
| 187 |
- vmnic2 |
| 188 |
standby_adapters: [] |
| 189 |
register: update_vswitch_netpol_run |
| 190 |
- debug: var=update_vswitch_netpol_run |
| 191 |
- assert: |
| 192 |
that: |
| 193 |
- update_vswitch_netpol_run.changed == true |
| 194 |
|
| 195 |
- name: Update a vSwitch network policy again (idempotency check) |
| 196 |
vmware_vswitch: |
| 197 |
hostname: '{{ esxi1 }}' |
| 198 |
username: '{{ esxi_user }}' |
| 199 |
password: '{{ esxi_password }}' |
| 200 |
validate_certs: false |
| 201 |
switch: vmswitch_0001 |
| 202 |
nics: |
| 203 |
- vmnic1 |
| 204 |
- vmnic2 |
| 205 |
state: present |
| 206 |
security: |
| 207 |
forged_transmits: false |
| 208 |
mac_changes: true |
| 209 |
traffic_shaping: |
| 210 |
enabled: false |
| 211 |
teaming: |
| 212 |
active_adapters: |
| 213 |
- vmnic1 |
| 214 |
- vmnic2 |
| 215 |
standby_adapters: [] |
| 216 |
register: update_vswitch_netpol_again_run |
| 217 |
- assert: |
| 218 |
that: |
| 219 |
- update_vswitch_netpol_again_run.changed == false |
| 220 |
|
| 221 |
always: |
| 222 |
- include_tasks: teardown.yml |
| 223 |
|
| 224 |
- name: Create Switch with special characters |
| 225 |
vmware_vswitch: |
| 226 |
hostname: "{{ esxi1 }}" |
| 227 |
username: "{{ esxi_user }}" |
| 228 |
password: "{{ esxi_password }}" |
| 229 |
validate_certs: false |
| 230 |
switch: 'Switch\%' |
| 231 |
state: present |
| 232 |
register: create_switch_with_special_characters_result |
| 233 |
|
| 234 |
- assert: |
| 235 |
that: |
| 236 |
- create_switch_with_special_characters_result.changed is sameas true |
| 237 |
|
| 238 |
- name: Create Switch with special characters(idempotency check) |
| 239 |
vmware_vswitch: |
| 240 |
hostname: "{{ esxi1 }}" |
| 241 |
username: "{{ esxi_user }}" |
| 242 |
password: "{{ esxi_password }}" |
| 243 |
validate_certs: false |
| 244 |
switch: 'Switch\%' |
| 245 |
state: present |
| 246 |
register: create_switch_with_special_characters_idempotency_check_result |
| 247 |
|
| 248 |
- assert: |
| 249 |
that: |
| 250 |
- create_switch_with_special_characters_idempotency_check_result.changed is sameas false |
| 251 |
|
| 252 |
- name: Delete Switch with special characters |
| 253 |
vmware_vswitch: |
| 254 |
hostname: "{{ esxi1 }}" |
| 255 |
username: "{{ esxi_user }}" |
| 256 |
password: "{{ esxi_password }}" |
| 257 |
validate_certs: false |
| 258 |
switch: 'Switch\%' |
| 259 |
state: absent |
| 260 |
register: delete_switch_with_special_characters_result |
| 261 |
|
| 262 |
- assert: |
| 263 |
that: |
| 264 |
- delete_switch_with_special_characters_result.changed is sameas true |
| 265 |
|
| 266 |
- name: Delete Switch with special characters(idempotency check) |
| 267 |
vmware_vswitch: |
| 268 |
hostname: "{{ esxi1 }}" |
| 269 |
username: "{{ esxi_user }}" |
| 270 |
password: "{{ esxi_password }}" |
| 271 |
validate_certs: false |
| 272 |
switch: 'Switch\%' |
| 273 |
state: absent |
| 274 |
register: delete_switch_with_special_characters_idempotency_check_result |
| 275 |
|
| 276 |
- assert: |
| 277 |
that: |
| 278 |
- delete_switch_with_special_characters_idempotency_check_result.changed is sameas false |