| 1 |
# Test code for the vmware_migrate_vmk module. |
| 2 |
# Copyright: (c) 2020, sky-joker <[email protected]> |
| 3 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
|
| 5 |
- import_role: |
| 6 |
name: prepare_vmware_tests |
| 7 |
vars: |
| 8 |
setup_attach_host: true |
| 9 |
|
| 10 |
- name: "Prepare integration tests for vmware_migrate_vmk module" |
| 11 |
block: |
| 12 |
- name: "Gather host facts from vCenter" |
| 13 |
vmware_host_facts: |
| 14 |
hostname: "{{ vcenter_hostname }}" |
| 15 |
username: "{{ vcenter_username }}" |
| 16 |
password: "{{ vcenter_password }}" |
| 17 |
validate_certs: false |
| 18 |
esxi_hostname: "{{ esxi1 }}" |
| 19 |
register: gather_host_facts_from_vcenter_result |
| 20 |
|
| 21 |
- name: "Set variables for integration test" |
| 22 |
set_fact: |
| 23 |
vswitch_pg_name_for_test: vSwitchForVMwareMigrateVmkPG |
| 24 |
dvswitch_pg_name_for_test: dvSwitchForVMwareMigrateVmkPG |
| 25 |
device_name: >- |
| 26 |
vmk{{ ( gather_host_facts_from_vcenter_result.ansible_facts.ansible_interfaces |
| 27 |
| last |
| 28 |
| regex_replace('vmk(.*)', '\1') |
| 29 |
| int + 1 ) |
| 30 |
}} |
| 31 |
|
| 32 |
- name: "Gather vSwitch info" |
| 33 |
vmware_vswitch_info: |
| 34 |
hostname: "{{ vcenter_hostname }}" |
| 35 |
username: "{{ vcenter_username }}" |
| 36 |
password: "{{ vcenter_password }}" |
| 37 |
validate_certs: false |
| 38 |
esxi_hostname: "{{ esxi1 }}" |
| 39 |
register: gather_vswitch_info_result |
| 40 |
|
| 41 |
- name: "Create a new vSwitch block" |
| 42 |
when: |
| 43 |
- "not '{{ switch1 }}' in gather_vswitch_info_result.hosts_vswitch_info[esxi1]" |
| 44 |
block: |
| 45 |
- name: "Create a new vSwitch" |
| 46 |
vmware_vswitch: |
| 47 |
hostname: "{{ vcenter_hostname }}" |
| 48 |
username: "{{ vcenter_username }}" |
| 49 |
password: "{{ vcenter_password }}" |
| 50 |
validate_certs: false |
| 51 |
esxi_hostname: "{{ esxi1 }}" |
| 52 |
switch: "{{ switch1 }}" |
| 53 |
register: create_new_vswitch_result |
| 54 |
|
| 55 |
- assert: |
| 56 |
that: |
| 57 |
- create_new_vswitch_result.changed is sameas true |
| 58 |
|
| 59 |
- name: "Create a new port group of vSwitch" |
| 60 |
vmware_portgroup: |
| 61 |
hostname: "{{ vcenter_hostname }}" |
| 62 |
username: "{{ vcenter_username }}" |
| 63 |
password: "{{ vcenter_password }}" |
| 64 |
validate_certs: false |
| 65 |
esxi_hostname: "{{ esxi1 }}" |
| 66 |
switch: "{{ switch1 }}" |
| 67 |
portgroup: "{{ vswitch_pg_name_for_test }}" |
| 68 |
register: create_new_vswitch_pg_result |
| 69 |
|
| 70 |
- assert: |
| 71 |
that: |
| 72 |
- create_new_vswitch_pg_result.changed is sameas true |
| 73 |
|
| 74 |
- name: "Gather dvSwitch info" |
| 75 |
vmware_dvswitch_info: |
| 76 |
hostname: "{{ vcenter_hostname }}" |
| 77 |
username: "{{ vcenter_username }}" |
| 78 |
password: "{{ vcenter_password }}" |
| 79 |
validate_certs: false |
| 80 |
register: gather_dvswitch_info_result |
| 81 |
|
| 82 |
- name: "Create a new dvSwitch block" |
| 83 |
when: |
| 84 |
- >- |
| 85 |
gather_dvswitch_info_result.distributed_virtual_switches |
| 86 |
| map(attribute='configure.name') |
| 87 |
| map('regex_search',dvswitch1) |
| 88 |
| list |
| 89 |
| length == 0 |
| 90 |
block: |
| 91 |
- name: "Create a new dvSwitch" |
| 92 |
vmware_dvswitch: |
| 93 |
hostname: "{{ vcenter_hostname }}" |
| 94 |
username: "{{ vcenter_username }}" |
| 95 |
password: "{{ vcenter_password }}" |
| 96 |
validate_certs: false |
| 97 |
datacenter_name: "{{ dc1 }}" |
| 98 |
switch_name: "{{ dvswitch1 }}" |
| 99 |
switch_version: 6.5.0 |
| 100 |
uplink_quantity: 2 |
| 101 |
state: present |
| 102 |
register: create_new_dvswitch_result |
| 103 |
|
| 104 |
- assert: |
| 105 |
that: |
| 106 |
- create_new_dvswitch_result.changed is sameas true |
| 107 |
|
| 108 |
- name: "Add ESXi host to dvSwitch" |
| 109 |
vmware_dvs_host: |
| 110 |
hostname: "{{ vcenter_hostname }}" |
| 111 |
username: "{{ vcenter_username }}" |
| 112 |
password: "{{ vcenter_password }}" |
| 113 |
validate_certs: false |
| 114 |
esxi_hostname: "{{ esxi1 }}" |
| 115 |
switch_name: "{{ dvswitch1 }}" |
| 116 |
state: present |
| 117 |
register: add_esxi_host_dvswitch_result |
| 118 |
|
| 119 |
- assert: |
| 120 |
that: |
| 121 |
- add_esxi_host_dvswitch_result.changed is sameas true |
| 122 |
|
| 123 |
- name: "Create new a port group of dvSwitch" |
| 124 |
vmware_dvs_portgroup: |
| 125 |
hostname: "{{ vcenter_hostname }}" |
| 126 |
username: "{{ vcenter_username }}" |
| 127 |
password: "{{ vcenter_password }}" |
| 128 |
validate_certs: false |
| 129 |
switch_name: "{{ dvswitch1 }}" |
| 130 |
portgroup_name: "{{ dvswitch_pg_name_for_test }}" |
| 131 |
port_binding: 'static' |
| 132 |
port_allocation: 'fixed' |
| 133 |
num_ports: 8 |
| 134 |
vlan_id: 0 |
| 135 |
state: present |
| 136 |
register: create_new_dvswitch_pg_result |
| 137 |
|
| 138 |
- assert: |
| 139 |
that: |
| 140 |
- create_new_dvswitch_pg_result.changed is sameas true |
| 141 |
|
| 142 |
- name: "Create a new vmkernel" |
| 143 |
vmware_vmkernel: |
| 144 |
hostname: "{{ vcenter_hostname }}" |
| 145 |
username: "{{ vcenter_username }}" |
| 146 |
password: "{{ vcenter_password }}" |
| 147 |
validate_certs: false |
| 148 |
esxi_hostname: "{{ esxi1 }}" |
| 149 |
vswitch_name: "{{ switch1 }}" |
| 150 |
portgroup_name: "{{ vswitch_pg_name_for_test }}" |
| 151 |
device: "{{ device_name }}" |
| 152 |
network: |
| 153 |
type: 'static' |
| 154 |
ip_address: 192.168.0.254 |
| 155 |
subnet_mask: 255.255.255.0 |
| 156 |
register: prepare_integration_tests_result |
| 157 |
|
| 158 |
- assert: |
| 159 |
that: |
| 160 |
- prepare_integration_tests_result.changed is sameas true |
| 161 |
|
| 162 |
- name: "Run integration tests for vmware_migrate_vmk module" |
| 163 |
block: |
| 164 |
- name: "Migrate Management vmk from vSwitch to dvSwitch" |
| 165 |
vmware_migrate_vmk: |
| 166 |
hostname: "{{ vcenter_hostname }}" |
| 167 |
username: "{{ vcenter_username }}" |
| 168 |
password: "{{ vcenter_password }}" |
| 169 |
validate_certs: false |
| 170 |
esxi_hostname: "{{ esxi1 }}" |
| 171 |
device: "{{ device_name }}" |
| 172 |
current_switch_name: "{{ switch1 }}" |
| 173 |
current_portgroup_name: "{{ vswitch_pg_name_for_test }}" |
| 174 |
migrate_switch_name: "{{ dvswitch1 }}" |
| 175 |
migrate_portgroup_name: "{{ dvswitch_pg_name_for_test }}" |
| 176 |
register: migrate_management_vmk_vswitch_to_dvswitch_result |
| 177 |
|
| 178 |
- assert: |
| 179 |
that: |
| 180 |
- migrate_management_vmk_vswitch_to_dvswitch_result.changed is sameas true |
| 181 |
|
| 182 |
- name: "Migrate Management vmk from vSwitch to dvSwitch (idempotency check)" |
| 183 |
vmware_migrate_vmk: |
| 184 |
hostname: "{{ vcenter_hostname }}" |
| 185 |
username: "{{ vcenter_username }}" |
| 186 |
password: "{{ vcenter_password }}" |
| 187 |
validate_certs: false |
| 188 |
esxi_hostname: "{{ esxi1 }}" |
| 189 |
device: "{{ device_name }}" |
| 190 |
current_switch_name: "{{ switch1 }}" |
| 191 |
current_portgroup_name: "{{ vswitch_pg_name_for_test }}" |
| 192 |
migrate_switch_name: "{{ dvswitch1 }}" |
| 193 |
migrate_portgroup_name: "{{ dvswitch_pg_name_for_test }}" |
| 194 |
register: migrate_management_vmk_vswitch_to_dvswitch_idempotency_check_result |
| 195 |
|
| 196 |
- assert: |
| 197 |
that: |
| 198 |
- migrate_management_vmk_vswitch_to_dvswitch_idempotency_check_result.changed is sameas false |
| 199 |
|
| 200 |
- name: "Migrate Management vmk from dvSwitch to vSwitch" |
| 201 |
vmware_migrate_vmk: |
| 202 |
hostname: "{{ vcenter_hostname }}" |
| 203 |
username: "{{ vcenter_username }}" |
| 204 |
password: "{{ vcenter_password }}" |
| 205 |
validate_certs: false |
| 206 |
esxi_hostname: "{{ esxi1 }}" |
| 207 |
device: "{{ device_name }}" |
| 208 |
current_switch_name: "{{ dvswitch1 }}" |
| 209 |
current_portgroup_name: "{{ dvswitch_pg_name_for_test }}" |
| 210 |
migrate_switch_name: "{{ switch1 }}" |
| 211 |
migrate_portgroup_name: "{{ vswitch_pg_name_for_test }}" |
| 212 |
register: migrate_management_vmk_dvswitch_to_vswitch_result |
| 213 |
|
| 214 |
- assert: |
| 215 |
that: |
| 216 |
- migrate_management_vmk_dvswitch_to_vswitch_result.changed is sameas true |
| 217 |
|
| 218 |
- name: "Migrate Management vmk from dvSwitch to vSwitch (idempotency check)" |
| 219 |
vmware_migrate_vmk: |
| 220 |
hostname: "{{ vcenter_hostname }}" |
| 221 |
username: "{{ vcenter_username }}" |
| 222 |
password: "{{ vcenter_password }}" |
| 223 |
validate_certs: false |
| 224 |
esxi_hostname: "{{ esxi1 }}" |
| 225 |
device: "{{ device_name }}" |
| 226 |
current_switch_name: "{{ dvswitch1 }}" |
| 227 |
current_portgroup_name: "{{ dvswitch_pg_name_for_test }}" |
| 228 |
migrate_switch_name: "{{ switch1 }}" |
| 229 |
migrate_portgroup_name: "{{ vswitch_pg_name_for_test }}" |
| 230 |
register: migrate_management_vmk_dvswitch_to_vswitch_idempotency_check_result |
| 231 |
|
| 232 |
- assert: |
| 233 |
that: |
| 234 |
- migrate_management_vmk_dvswitch_to_vswitch_idempotency_check_result.changed is sameas false |
| 235 |
|
| 236 |
always: |
| 237 |
- name: "Delete the used vmkernel for integration test" |
| 238 |
vmware_vmkernel: |
| 239 |
hostname: "{{ vcenter_hostname }}" |
| 240 |
username: "{{ vcenter_username }}" |
| 241 |
password: "{{ vcenter_password }}" |
| 242 |
validate_certs: false |
| 243 |
esxi_hostname: "{{ esxi1 }}" |
| 244 |
vswitch_name: "{{ switch1 }}" |
| 245 |
portgroup_name: "{{ vswitch_pg_name_for_test }}" |
| 246 |
device: "{{ device_name }}" |
| 247 |
state: absent |
| 248 |
|
| 249 |
- name: "Delete the used dvSwitch for integration test" |
| 250 |
vmware_dvswitch: |
| 251 |
hostname: "{{ vcenter_hostname }}" |
| 252 |
username: "{{ vcenter_username }}" |
| 253 |
password: "{{ vcenter_password }}" |
| 254 |
validate_certs: false |
| 255 |
datacenter: "{{ dc1 }}" |
| 256 |
switch: "{{ dvswitch1 }}" |
| 257 |
uplink_quantity: 1 |
| 258 |
state: absent |
| 259 |
|
| 260 |
- name: "Delete the used vSwitch for integration test" |
| 261 |
vmware_vswitch: |
| 262 |
hostname: "{{ vcenter_hostname }}" |
| 263 |
username: "{{ vcenter_username }}" |
| 264 |
password: "{{ vcenter_password }}" |
| 265 |
validate_certs: false |
| 266 |
esxi_hostname: "{{ esxi1 }}" |
| 267 |
switch: "{{ switch1 }}" |
| 268 |
state: absent |