| 1 |
# Test code for the vmware_resource_pool 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 |
- import_role: |
| 6 |
name: prepare_vmware_tests |
| 7 |
vars: |
| 8 |
setup_attach_host: true |
| 9 |
setup_resource_pool: true |
| 10 |
|
| 11 |
# Tests on cluster |
| 12 |
- name: set the vmware_resource_pool module default values |
| 13 |
module_defaults: |
| 14 |
vmware_resource_pool: |
| 15 |
hostname: "{{ vcenter_hostname }}" |
| 16 |
username: "{{ vcenter_username }}" |
| 17 |
password: "{{ vcenter_password }}" |
| 18 |
validate_certs: false |
| 19 |
datacenter: "{{ dc1 }}" |
| 20 |
cluster: "{{ ccr1 }}" |
| 21 |
|
| 22 |
block: |
| 23 |
- name: add resource pool with check_mode |
| 24 |
vmware_resource_pool: |
| 25 |
resource_pool: test_resource_001 |
| 26 |
check_mode: true |
| 27 |
register: resource_result_001 |
| 28 |
|
| 29 |
- assert: |
| 30 |
that: |
| 31 |
- resource_result_001.changed is sameas true |
| 32 |
|
| 33 |
- name: add resource pool |
| 34 |
vmware_resource_pool: |
| 35 |
resource_pool: test_resource_001 |
| 36 |
register: resource_result_002 |
| 37 |
|
| 38 |
- assert: |
| 39 |
that: |
| 40 |
- resource_result_002.changed is sameas true |
| 41 |
- resource_result_002.resource_pool_config is defined |
| 42 |
- resource_result_002.resource_pool_config.name == "test_resource_001" |
| 43 |
|
| 44 |
- name: add resource pool(idempotency check) |
| 45 |
vmware_resource_pool: |
| 46 |
resource_pool: test_resource_001 |
| 47 |
register: resource_result_003 |
| 48 |
|
| 49 |
- assert: |
| 50 |
that: |
| 51 |
- resource_result_003.changed is sameas false |
| 52 |
|
| 53 |
- name: change resource pool config with the custom default value and check_mode |
| 54 |
vmware_resource_pool: |
| 55 |
resource_pool: test_resource_001 |
| 56 |
mem_shares: custom |
| 57 |
cpu_shares: custom |
| 58 |
check_mode: true |
| 59 |
register: resource_result_004 |
| 60 |
|
| 61 |
- assert: |
| 62 |
that: |
| 63 |
- resource_result_004.changed is sameas true |
| 64 |
|
| 65 |
- name: change resource pool config with the custom default value |
| 66 |
vmware_resource_pool: |
| 67 |
resource_pool: test_resource_001 |
| 68 |
mem_shares: custom |
| 69 |
cpu_shares: custom |
| 70 |
register: resource_result_005 |
| 71 |
|
| 72 |
- assert: |
| 73 |
that: |
| 74 |
- resource_result_005.changed is sameas true |
| 75 |
- resource_result_005.resource_pool_config is defined |
| 76 |
- resource_result_005.resource_pool_config.cpuAllocation.shares.level == 'custom' |
| 77 |
- resource_result_005.resource_pool_config.cpuAllocation.shares.shares == 4000 |
| 78 |
- resource_result_005.resource_pool_config.memoryAllocation.shares.level == 'custom' |
| 79 |
- resource_result_005.resource_pool_config.memoryAllocation.shares.shares == 163840 |
| 80 |
|
| 81 |
- name: change resource pool config with the custom default value(idempotency check) |
| 82 |
vmware_resource_pool: |
| 83 |
resource_pool: test_resource_001 |
| 84 |
mem_shares: custom |
| 85 |
cpu_shares: custom |
| 86 |
register: resource_result_006 |
| 87 |
|
| 88 |
- assert: |
| 89 |
that: |
| 90 |
- resource_result_006.changed is sameas false |
| 91 |
- resource_result_006.resource_pool_config is defined |
| 92 |
|
| 93 |
- name: change resource pool config with the allocation_shares |
| 94 |
vmware_resource_pool: |
| 95 |
resource_pool: test_resource_001 |
| 96 |
mem_shares: custom |
| 97 |
mem_allocation_shares: 1000 |
| 98 |
cpu_shares: custom |
| 99 |
cpu_allocation_shares: 1000 |
| 100 |
register: resource_result_007 |
| 101 |
|
| 102 |
- assert: |
| 103 |
that: |
| 104 |
- resource_result_007.changed is sameas true |
| 105 |
- resource_result_007.resource_pool_config is defined |
| 106 |
- resource_result_007.resource_pool_config.cpuAllocation.shares.level == 'custom' |
| 107 |
- resource_result_007.resource_pool_config.cpuAllocation.shares.shares == 1000 |
| 108 |
- resource_result_007.resource_pool_config.memoryAllocation.shares.level == 'custom' |
| 109 |
- resource_result_007.resource_pool_config.memoryAllocation.shares.shares == 1000 |
| 110 |
|
| 111 |
- name: change resource pool config with the allocation_shares(idempotency check) |
| 112 |
vmware_resource_pool: |
| 113 |
resource_pool: test_resource_001 |
| 114 |
mem_shares: custom |
| 115 |
mem_allocation_shares: 1000 |
| 116 |
cpu_shares: custom |
| 117 |
cpu_allocation_shares: 1000 |
| 118 |
register: resource_result_008 |
| 119 |
|
| 120 |
- assert: |
| 121 |
that: |
| 122 |
- resource_result_008.changed is sameas false |
| 123 |
- resource_result_008.resource_pool_config is defined |
| 124 |
|
| 125 |
- name: change resource pool config with some option and check_mode |
| 126 |
vmware_resource_pool: |
| 127 |
resource_pool: test_resource_001 |
| 128 |
mem_shares: normal |
| 129 |
mem_limit: 1 |
| 130 |
mem_reservation: 1 |
| 131 |
mem_expandable_reservations: false |
| 132 |
cpu_shares: normal |
| 133 |
cpu_limit: 1 |
| 134 |
cpu_reservation: 1 |
| 135 |
cpu_expandable_reservations: false |
| 136 |
check_mode: true |
| 137 |
register: resource_result_009 |
| 138 |
|
| 139 |
- assert: |
| 140 |
that: |
| 141 |
- resource_result_009.changed is sameas true |
| 142 |
|
| 143 |
- name: change resource pool config with some option |
| 144 |
vmware_resource_pool: |
| 145 |
resource_pool: test_resource_001 |
| 146 |
mem_shares: normal |
| 147 |
mem_limit: 1 |
| 148 |
mem_reservation: 1 |
| 149 |
mem_expandable_reservations: false |
| 150 |
cpu_shares: normal |
| 151 |
cpu_limit: 1 |
| 152 |
cpu_reservation: 1 |
| 153 |
cpu_expandable_reservations: false |
| 154 |
register: resource_result_010 |
| 155 |
|
| 156 |
- assert: |
| 157 |
that: |
| 158 |
- resource_result_010.changed is sameas true |
| 159 |
- resource_result_010.resource_pool_config is defined |
| 160 |
- resource_result_010.resource_pool_config.cpuAllocation.shares.level == 'normal' |
| 161 |
- resource_result_010.resource_pool_config.cpuAllocation.limit == 1 |
| 162 |
- resource_result_010.resource_pool_config.cpuAllocation.reservation == 1 |
| 163 |
- resource_result_010.resource_pool_config.cpuAllocation.expandableReservation is sameas false |
| 164 |
- resource_result_010.resource_pool_config.memoryAllocation.shares.level == 'normal' |
| 165 |
- resource_result_010.resource_pool_config.memoryAllocation.limit == 1 |
| 166 |
- resource_result_010.resource_pool_config.memoryAllocation.reservation == 1 |
| 167 |
- resource_result_010.resource_pool_config.memoryAllocation.expandableReservation is sameas false |
| 168 |
|
| 169 |
- name: change resource pool config with some option(idempotency check) |
| 170 |
vmware_resource_pool: |
| 171 |
resource_pool: test_resource_001 |
| 172 |
mem_shares: normal |
| 173 |
mem_limit: 1 |
| 174 |
mem_reservation: 1 |
| 175 |
mem_expandable_reservations: false |
| 176 |
cpu_shares: normal |
| 177 |
cpu_limit: 1 |
| 178 |
cpu_reservation: 1 |
| 179 |
cpu_expandable_reservations: false |
| 180 |
register: resource_result_011 |
| 181 |
|
| 182 |
- assert: |
| 183 |
that: |
| 184 |
- resource_result_011.changed is sameas false |
| 185 |
- resource_result_011.resource_pool_config is defined |
| 186 |
|
| 187 |
- name: remove resource pool with check_mode |
| 188 |
vmware_resource_pool: |
| 189 |
resource_pool: test_resource_001 |
| 190 |
state: absent |
| 191 |
check_mode: true |
| 192 |
register: resource_result_012 |
| 193 |
|
| 194 |
- assert: |
| 195 |
that: |
| 196 |
- resource_result_012.changed is sameas true |
| 197 |
|
| 198 |
- name: remove resource pool |
| 199 |
vmware_resource_pool: |
| 200 |
resource_pool: test_resource_001 |
| 201 |
state: absent |
| 202 |
register: resource_result_013 |
| 203 |
|
| 204 |
- assert: |
| 205 |
that: |
| 206 |
- resource_result_013.changed is sameas true |
| 207 |
- resource_result_013.resource_pool_config is defined |
| 208 |
|
| 209 |
- name: remove resource pool(idempotency check) |
| 210 |
vmware_resource_pool: |
| 211 |
resource_pool: test_resource_001 |
| 212 |
state: absent |
| 213 |
register: resource_result_014 |
| 214 |
|
| 215 |
- assert: |
| 216 |
that: |
| 217 |
- resource_result_014.changed is sameas false |
| 218 |
- resource_result_014.resource_pool_config is defined |
| 219 |
|
| 220 |
# Tests on ESXi host |
| 221 |
- name: set the vmware_resource_pool module default values without cluster parameter |
| 222 |
module_defaults: |
| 223 |
vmware_resource_pool: |
| 224 |
hostname: "{{ vcenter_hostname }}" |
| 225 |
username: "{{ vcenter_username }}" |
| 226 |
password: "{{ vcenter_password }}" |
| 227 |
validate_certs: false |
| 228 |
datacenter: "{{ dc1 }}" |
| 229 |
esxi_hostname: "{{ esxi2 }}" |
| 230 |
|
| 231 |
block: |
| 232 |
# Remove ESXi host from cluster for tests |
| 233 |
- name: Enter maintenance mode |
| 234 |
vmware.vmware.esxi_maintenance_mode: |
| 235 |
hostname: "{{ vcenter_hostname }}" |
| 236 |
username: "{{ vcenter_username }}" |
| 237 |
password: "{{ vcenter_password }}" |
| 238 |
validate_certs: false |
| 239 |
esxi_host_name: "{{ esxi2 }}" |
| 240 |
enable_maintenance_mode: true |
| 241 |
|
| 242 |
- name: Remove ESXi |
| 243 |
vmware.vmware.esxi_host: |
| 244 |
hostname: "{{ vcenter_hostname }}" |
| 245 |
username: "{{ vcenter_username }}" |
| 246 |
password: "{{ vcenter_password }}" |
| 247 |
validate_certs: false |
| 248 |
datacenter: "{{ dc1 }}" |
| 249 |
esxi_host_name: "{{ esxi2 }}" |
| 250 |
state: absent |
| 251 |
|
| 252 |
- name: Re-add ESXi outside of cluster |
| 253 |
vmware.vmware.esxi_host: |
| 254 |
hostname: "{{ vcenter_hostname }}" |
| 255 |
username: "{{ vcenter_username }}" |
| 256 |
password: "{{ vcenter_password }}" |
| 257 |
validate_certs: false |
| 258 |
datacenter: "{{ dc1 }}" |
| 259 |
folder: "{{ dc1 }}/host" |
| 260 |
esxi_host_name: "{{ esxi2 }}" |
| 261 |
esxi_username: '{{ esxi_user }}' |
| 262 |
esxi_password: '{{ esxi_password }}' |
| 263 |
state: present |
| 264 |
|
| 265 |
- name: Exit maintenance mode |
| 266 |
vmware.vmware.esxi_maintenance_mode: |
| 267 |
hostname: "{{ vcenter_hostname }}" |
| 268 |
username: "{{ vcenter_username }}" |
| 269 |
password: "{{ vcenter_password }}" |
| 270 |
validate_certs: false |
| 271 |
esxi_host_name: "{{ esxi2 }}" |
| 272 |
enable_maintenance_mode: false |
| 273 |
|
| 274 |
- name: add resource pool to ESXi with check_mode |
| 275 |
vmware_resource_pool: |
| 276 |
resource_pool: test_resource_015 |
| 277 |
check_mode: true |
| 278 |
register: resource_result_015 |
| 279 |
|
| 280 |
- assert: |
| 281 |
that: |
| 282 |
- resource_result_015.changed is sameas true |
| 283 |
|
| 284 |
- name: add resource pool to ESXi |
| 285 |
vmware_resource_pool: |
| 286 |
resource_pool: test_resource_015 |
| 287 |
register: resource_result_016 |
| 288 |
|
| 289 |
- assert: |
| 290 |
that: |
| 291 |
- resource_result_016.changed is sameas true |
| 292 |
|
| 293 |
- name: add resource pool to ESXi(idempotency check) |
| 294 |
vmware_resource_pool: |
| 295 |
resource_pool: test_resource_015 |
| 296 |
register: resource_result_017 |
| 297 |
|
| 298 |
- assert: |
| 299 |
that: |
| 300 |
- resource_result_017.changed is sameas false |
| 301 |
|
| 302 |
- name: change resource pool config with the custom default value and check_mode |
| 303 |
vmware_resource_pool: |
| 304 |
resource_pool: test_resource_015 |
| 305 |
mem_shares: custom |
| 306 |
cpu_shares: custom |
| 307 |
check_mode: true |
| 308 |
register: resource_result_018 |
| 309 |
|
| 310 |
- assert: |
| 311 |
that: |
| 312 |
- resource_result_018.changed is sameas true |
| 313 |
|
| 314 |
- name: change resource pool config with the custom default value |
| 315 |
vmware_resource_pool: |
| 316 |
resource_pool: test_resource_015 |
| 317 |
mem_shares: custom |
| 318 |
cpu_shares: custom |
| 319 |
register: resource_result_019 |
| 320 |
|
| 321 |
- assert: |
| 322 |
that: |
| 323 |
- resource_result_019.changed is sameas true |
| 324 |
- resource_result_019.resource_pool_config is defined |
| 325 |
- resource_result_019.resource_pool_config.cpuAllocation.shares.level == 'custom' |
| 326 |
- resource_result_019.resource_pool_config.cpuAllocation.shares.shares == 4000 |
| 327 |
- resource_result_019.resource_pool_config.memoryAllocation.shares.level == 'custom' |
| 328 |
- resource_result_019.resource_pool_config.memoryAllocation.shares.shares == 163840 |
| 329 |
|
| 330 |
- name: remove resource pool from ESXi with check_mode |
| 331 |
vmware_resource_pool: |
| 332 |
resource_pool: test_resource_015 |
| 333 |
state: absent |
| 334 |
check_mode: true |
| 335 |
register: resource_result_020 |
| 336 |
|
| 337 |
- assert: |
| 338 |
that: |
| 339 |
- resource_result_020.changed is sameas true |
| 340 |
|
| 341 |
- name: remove resource pool from ESXi |
| 342 |
vmware_resource_pool: |
| 343 |
resource_pool: test_resource_015 |
| 344 |
state: absent |
| 345 |
register: resource_result_021 |
| 346 |
|
| 347 |
- assert: |
| 348 |
that: |
| 349 |
- resource_result_021.changed is sameas true |
| 350 |
|
| 351 |
- name: remove resource pool from ESXi(idempotency check) |
| 352 |
vmware_resource_pool: |
| 353 |
resource_pool: test_resource_015 |
| 354 |
state: absent |
| 355 |
register: resource_result_023 |
| 356 |
|
| 357 |
- assert: |
| 358 |
that: |
| 359 |
- resource_result_023.changed is sameas false |
| 360 |
|
| 361 |
- name: set the vmware_resource_pool module default values without cluster and esxi_hostnamme parameter |
| 362 |
module_defaults: |
| 363 |
vmware_resource_pool: |
| 364 |
hostname: "{{ vcenter_hostname }}" |
| 365 |
username: "{{ vcenter_username }}" |
| 366 |
password: "{{ vcenter_password }}" |
| 367 |
validate_certs: false |
| 368 |
datacenter: "{{ dc1 }}" |
| 369 |
parent_resource_pool: DC0_C0_RP1 |
| 370 |
|
| 371 |
block: |
| 372 |
- name: add resource pool to Parent Resource Pool with check_mode |
| 373 |
vmware_resource_pool: |
| 374 |
resource_pool: test_resource_024 |
| 375 |
check_mode: true |
| 376 |
register: resource_result_024 |
| 377 |
|
| 378 |
- assert: |
| 379 |
that: |
| 380 |
- resource_result_024.changed is sameas true |
| 381 |
|
| 382 |
- name: add resource pool to Parent Resource Pool |
| 383 |
vmware_resource_pool: |
| 384 |
resource_pool: test_resource_024 |
| 385 |
register: resource_result_025 |
| 386 |
|
| 387 |
- assert: |
| 388 |
that: |
| 389 |
- resource_result_025.changed is sameas true |
| 390 |
|
| 391 |
- name: add resource pool to Parent Resource Pool(idempotency check) |
| 392 |
vmware_resource_pool: |
| 393 |
resource_pool: test_resource_024 |
| 394 |
register: resource_result_026 |
| 395 |
|
| 396 |
- assert: |
| 397 |
that: |
| 398 |
- resource_result_026.changed is sameas false |
| 399 |
|
| 400 |
- name: change resource pool config with the custom default value and check_mode |
| 401 |
vmware_resource_pool: |
| 402 |
resource_pool: test_resource_024 |
| 403 |
mem_shares: custom |
| 404 |
cpu_shares: custom |
| 405 |
check_mode: true |
| 406 |
register: resource_result_027 |
| 407 |
|
| 408 |
- assert: |
| 409 |
that: |
| 410 |
- resource_result_027.changed is sameas true |
| 411 |
|
| 412 |
- name: change resource pool config with the custom default value |
| 413 |
vmware_resource_pool: |
| 414 |
resource_pool: test_resource_024 |
| 415 |
mem_shares: custom |
| 416 |
cpu_shares: custom |
| 417 |
register: resource_result_028 |
| 418 |
|
| 419 |
- assert: |
| 420 |
that: |
| 421 |
- resource_result_028.changed is sameas true |
| 422 |
- resource_result_028.resource_pool_config is defined |
| 423 |
- resource_result_028.resource_pool_config.cpuAllocation.shares.level == 'custom' |
| 424 |
- resource_result_028.resource_pool_config.cpuAllocation.shares.shares == 4000 |
| 425 |
- resource_result_028.resource_pool_config.memoryAllocation.shares.level == 'custom' |
| 426 |
- resource_result_028.resource_pool_config.memoryAllocation.shares.shares == 163840 |
| 427 |
|
| 428 |
- name: remove resource pool from Parent Resource Pool with check_mode |
| 429 |
vmware_resource_pool: |
| 430 |
resource_pool: test_resource_024 |
| 431 |
state: absent |
| 432 |
check_mode: true |
| 433 |
register: resource_result_029 |
| 434 |
|
| 435 |
- assert: |
| 436 |
that: |
| 437 |
- resource_result_029.changed is sameas true |
| 438 |
|
| 439 |
- name: remove resource pool from Parent Resource Pool |
| 440 |
vmware_resource_pool: |
| 441 |
resource_pool: test_resource_024 |
| 442 |
state: absent |
| 443 |
register: resource_result_030 |
| 444 |
|
| 445 |
- assert: |
| 446 |
that: |
| 447 |
- resource_result_030.changed is sameas true |
| 448 |
|
| 449 |
- name: remove resource pool from Parent Resource Pool(idempotency check) |
| 450 |
vmware_resource_pool: |
| 451 |
resource_pool: test_resource_024 |
| 452 |
state: absent |
| 453 |
register: resource_result_031 |
| 454 |
|
| 455 |
- assert: |
| 456 |
that: |
| 457 |
- resource_result_031.changed is sameas false |