Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Simplified guest module #2052

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ requires_ansible: '>=2.15.0'

action_groups:
vmware:
- guest
- vcenter_domain_user_group_info
- vcenter_extension
- vcenter_extension_info
Expand Down
1,199 changes: 1,199 additions & 0 deletions plugins/modules/guest.py

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tests/integration/targets/guest/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cloud/vcenter
needs/target/prepare_vmware_tests
zuul/vmware/vcenter_1esxi
4 changes: 4 additions & 0 deletions tests/integration/targets/guest/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
guest_test_playbooks:
- boot_firmware_d1_c1_f0.yml
- create_d1_c1_f0.yml
- create_guest_invalid_d1_c1_f0.yml
77 changes: 77 additions & 0 deletions tests/integration/targets/guest/tasks/boot_firmware_d1_c1_f0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Test code for the guest module.
# Copyright: (c) 2018, Abhijeet Kasurde <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

- &create_test_vm1
name: create new VMs with boot_firmware as 'bios'
guest:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: test_vm1
guest_id: centos64Guest
datacenter: "{{ dc1 }}"
esxi_hostname: '{{ esxi1 }}'
hardware:
num_cpus: 1
boot_firmware: "bios"
memory_mb: 128
state: present
folder: "{{ f0 }}"
register: create_d1_c1_f0

- debug: var=create_d1_c1_f0

- name: assert that changes were made
assert:
that:
- create_d1_c1_f0 is changed

- <<: *create_test_vm1
name: create new VMs again with boot_firmware as 'bios'
register: create_d1_c1_f0_again

- debug: var=create_d1_c1_f0_again

- name: assert that changes were not made
assert:
that:
- create_d1_c1_f0_again is not changed

- &create_test_vm2
name: create new VMs with boot_firmware as 'efi'
guest:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: test_vm2
guest_id: centos64Guest
datacenter: "{{ dc1 }}"
esxi_hostname: '{{ esxi1 }}'
hardware:
num_cpus: 1
boot_firmware: "efi"
memory_mb: 128
state: present
folder: "{{ f0 }}"
register: create_d1_c1_f0

- debug: var=create_d1_c1_f0

- name: assert that changes were made
assert:
that:
- create_d1_c1_f0 is changed

- <<: *create_test_vm2
name: create new VMs again with boot_firmware as 'efi'
register: create_d1_c1_f0_again

- debug: var=create_d1_c1_f0

- name: assert that changes were not made
assert:
that:
- create_d1_c1_f0_again is not changed
119 changes: 119 additions & 0 deletions tests/integration/targets/guest/tasks/create_d1_c1_f0.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Test code for the guest module.
# Copyright: (c) 2017, James Tanner <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

- &create_test_vm1
name: create new VM
guest:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: test_vm1
guest_id: centos64Guest
datacenter: "{{ dc1 }}"
esxi_hostname: '{{ esxi1 }}'
hardware:
num_cpus: 1
num_cpu_cores_per_socket: 1
memory_mb: 128
hotadd_memory: true
hotadd_cpu: false
memory_reservation: 128
memory_reservation_lock: false
nested_virt: true
hotremove_cpu: true
mem_limit: 8096
mem_reservation: 4096
cpu_limit: 8096
cpu_reservation: 4096
max_connections: 10
state: present
folder: '{{ f0 }}'
register: create_d1_c1_f0

- debug: var=create_d1_c1_f0

- name: assert that changes were made
assert:
that:
- create_d1_c1_f0 is changed

- <<: *create_test_vm1
name: create the VM again
register: create_d1_c1_f0_again

- debug: var=create_d1_c1_f0_again

- name: assert that no changes were made after re-creating
assert:
that:
- create_d1_c1_f0_again is not changed

- &modify_test_vm1
name: modify the new VM
guest:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: test_vm1
guest_id: centos64Guest
datacenter: "{{ dc1 }}"
esxi_hostname: '{{ esxi1 }}'
hardware:
num_cpus: 2
memory_mb: 128
state: present
folder: '{{ f0 }}'
register: modify_d1_c1_f0

- debug: var=modify_d1_c1_f0

- name: assert that changes were made with modification
assert:
that:
- modify_d1_c1_f0 is changed

- <<: *modify_test_vm1
name: re-modify the new VMs
register: modify_d1_c1_f0_again

- debug: var=modify_d1_c1_f0_again

- name: assert that no changes were made when re-modified
assert:
that:
- modify_d1_c1_f0_again is not changed

- &delete_test_vm1
name: delete the new VMs
guest:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: test_vm1
datacenter: "{{ dc1 }}"
esxi_hostname: '{{ esxi1 }}'
state: absent
folder: '{{ f0 }}'
register: delete_d1_c1_f0

- debug: var=delete_d1_c1_f0

- name: assert that changes were made with deletion
assert:
that:
- delete_d1_c1_f0 is changed

- <<: *delete_test_vm1
name: re-delete the new VMs
register: delete_d1_c1_f0_again

- debug: var=delete_d1_c1_f0_again

- name: assert that no changes were made with redeletion
assert:
that:
- delete_d1_c1_f0_again is not changed
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Test code for the guest module.
# Copyright: (c) 2017, Abhijeet Kasurde <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

- name: create new virtual machine with invalid guest id
guest:
validate_certs: false
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: invalid_vm
guest_id: "invalid_guest_id"
datacenter: "{{ dc1 }}"
esxi_hostname: '{{ esxi1 }}'
hardware:
num_cpus: 1
memory_mb: 128
state: present
folder: "{{ f0 }}"
register: invalid_guest_0001_d1_c1_f0
ignore_errors: true

- debug: var=invalid_guest_0001_d1_c1_f0

- name: assert that no changes were made
assert:
that:
- "not (invalid_guest_0001_d1_c1_f0 is changed)"
- "'configSpec.guestId' in invalid_guest_0001_d1_c1_f0['msg']"
18 changes: 18 additions & 0 deletions tests/integration/targets/guest/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Test code for the guest module.
# Copyright: (c) 2017, James Tanner <[email protected]>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

- import_role:
name: prepare_vmware_tests
vars:
setup_attach_host: true
setup_datacenter: true
setup_datastore: true
setup_dvswitch: true
setup_resource_pool: true
setup_dvs_portgroup: true

- include_tasks: run_test_playbook.yml
with_items: '{{ guest_test_playbooks }}'
loop_control:
loop_var: test_playbook
32 changes: 32 additions & 0 deletions tests/integration/targets/guest/tasks/run_test_playbook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
- block:
- include_tasks: '{{ test_playbook }}'
always:
- name: Collect the list of the existing VM
vmware.vmware_rest.vcenter_vm_info:
vcenter_hostname: '{{ vcenter_hostname }}'
vcenter_username: '{{ vcenter_username }}'
vcenter_password: '{{ vcenter_password }}'
vcenter_validate_certs: false
register: existing_vms
until: existing_vms is not failed
- name: Turn off the VM
vmware.vmware_rest.vcenter_vm_power:
vcenter_hostname: '{{ vcenter_hostname }}'
vcenter_username: '{{ vcenter_username }}'
vcenter_password: '{{ vcenter_password }}'
vcenter_validate_certs: false
state: stop
vm: '{{ item.vm }}'
with_items: "{{ existing_vms.value }}"
ignore_errors: true
- name: Clean up VM
vmware.vmware_rest.vcenter_vm:
vcenter_hostname: '{{ vcenter_hostname }}'
vcenter_username: '{{ vcenter_username }}'
vcenter_password: '{{ vcenter_password }}'
vcenter_validate_certs: false
state: absent
vm: '{{ item.vm }}'
with_items: "{{ existing_vms.value }}"
when:
- not item.name.startswith("vCLS")