From 604fcb55aebd9c77fe37611451175f69cc70e607 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Fri, 27 Jul 2018 09:18:04 +0530 Subject: [PATCH] VMware: add support for boot option firmware (#42730) This fix adds support for the boot option 'firmware' Fixes: #42541 Signed-off-by: Abhijeet Kasurde --- .../modules/cloud/vmware/vmware_guest.py | 12 ++ .../tasks/boot_firmware_d1_c1_f0.yml | 149 ++++++++++++++++++ .../targets/vmware_guest/tasks/main.yml | 3 +- 3 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 test/integration/targets/vmware_guest/tasks/boot_firmware_d1_c1_f0.yml diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py index a97cd8382b..6213cf1bcd 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -144,6 +144,8 @@ options: Please check VMware documentation for correct virtual machine hardware version. Incorrect hardware version may lead to failure in deployment. If hardware version is already equal to the given version then no action is taken. version_added: 2.6' + - ' - C(boot_firmware) (string): Choose which firmware should be used to boot the virtual machine. + Allowed values are "bios" and "efi". version_added: 2.7' guest_id: description: @@ -387,6 +389,7 @@ EXAMPLES = r''' hotremove_cpu: True hotadd_memory: False version: 12 # Hardware version of virtual machine + boot_firmware: "efi" cdrom: type: iso iso_path: "[datastore1] livecd.iso" @@ -946,6 +949,15 @@ class PyVmomiHelper(PyVmomi): if vm_obj is None or self.configspec.memoryReservationLockedToMax != vm_obj.config.memoryReservationLockedToMax: self.change_detected = True + if 'boot_firmware' in self.params['hardware']: + boot_firmware = self.params['hardware']['boot_firmware'].lower() + if boot_firmware not in ('bios', 'efi'): + self.module.fail_json(msg="hardware.boot_firmware value is invalid [%s]." + " Need one of ['bios', 'efi']." % boot_firmware) + self.configspec.firmware = boot_firmware + if vm_obj is None or self.configspec.firmware != vm_obj.config.firmware: + self.change_detected = True + def configure_cdrom(self, vm_obj): # Configure the VM CD-ROM if "cdrom" in self.params and self.params["cdrom"]: diff --git a/test/integration/targets/vmware_guest/tasks/boot_firmware_d1_c1_f0.yml b/test/integration/targets/vmware_guest/tasks/boot_firmware_d1_c1_f0.yml new file mode 100644 index 0000000000..c922e5e33c --- /dev/null +++ b/test/integration/targets/vmware_guest/tasks/boot_firmware_d1_c1_f0.yml @@ -0,0 +1,149 @@ +# Test code for the vmware_guest module. +# Copyright: (c) 2018, Abhijeet Kasurde +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +- name: Wait for Flask controller to come up online + wait_for: + host: "{{ vcsim }}" + port: 5000 + state: started + +- name: kill vcsim + uri: + url: http://{{ vcsim }}:5000/killall +- name: start vcsim with no folders + uri: + url: http://{{ vcsim }}:5000/spawn?datacenter=1&cluster=1&folder=0 + register: vcsim_instance + +- name: Wait for Flask controller to come up online + wait_for: + host: "{{ vcsim }}" + port: 443 + state: started + +- name: get a list of VMS from vcsim + uri: + url: http://{{ vcsim }}:5000/govc_find?filter=VM + register: vmlist + +- debug: var=vcsim_instance +- debug: var=vmlist + +- name: create new VMs with boot_firmware as 'bios' + vmware_guest: + validate_certs: False + hostname: "{{ vcsim }}" + username: "{{ vcsim_instance['json']['username'] }}" + password: "{{ vcsim_instance['json']['password'] }}" + name: "{{ 'newvm_' + item|basename }}" + guest_id: centos64Guest + datacenter: "{{ (item|basename).split('_')[0] }}" + hardware: + num_cpus: 4 + boot_firmware: "bios" + memory_mb: 512 + disk: + - size: 1gb + type: thin + autoselect_datastore: True + state: poweredoff + folder: "{{ item|dirname }}" + with_items: "{{ vmlist['json'] }}" + register: clone_d1_c1_f0 + +- debug: var=clone_d1_c1_f0 + +- name: assert that changes were made + assert: + that: + - "clone_d1_c1_f0.results|map(attribute='changed')|unique|list == [true]" + +# VCSIM does not recognizes existing VMs boot firmware +#- name: create new VMs again with boot_firmware as 'bios' +# vmware_guest: +# validate_certs: False +# hostname: "{{ vcsim }}" +# username: "{{ vcsim_instance['json']['username'] }}" +# password: "{{ vcsim_instance['json']['password'] }}" +# name: "{{ 'newvm_' + item|basename }}" +# guest_id: centos64Guest +# datacenter: "{{ (item|basename).split('_')[0] }}" +# hardware: +# num_cpus: 4 +# boot_firmware: "bios" +# memory_mb: 512 +# disk: +# - size: 1gb +# type: thin +# autoselect_datastore: True +# state: poweredoff +# folder: "{{ item|dirname }}" +# with_items: "{{ vmlist['json'] }}" +# register: clone_d1_c1_f0 + +#- debug: var=clone_d1_c1_f0 + +#- name: assert that changes were not made +# assert: +# that: +# - "clone_d1_c1_f0.results|map(attribute='changed')|unique|list == [false]" + +- name: create new VMs with boot_firmware as 'efi' + vmware_guest: + validate_certs: False + hostname: "{{ vcsim }}" + username: "{{ vcsim_instance['json']['username'] }}" + password: "{{ vcsim_instance['json']['password'] }}" + name: "{{ 'newvm_efi_' + item|basename }}" + guest_id: centos64Guest + datacenter: "{{ (item|basename).split('_')[0] }}" + hardware: + num_cpus: 4 + boot_firmware: "efi" + memory_mb: 512 + disk: + - size: 1gb + type: thin + autoselect_datastore: True + state: poweredoff + folder: "{{ item|dirname }}" + with_items: "{{ vmlist['json'] }}" + register: clone_d1_c1_f0 + +- debug: var=clone_d1_c1_f0 + +- name: assert that changes were made + assert: + that: + - "clone_d1_c1_f0.results|map(attribute='changed')|unique|list == [true]" + +# VCSIM does not recognizes existing VMs boot firmware +#- name: create new VMs again with boot_firmware as 'efi' +# vmware_guest: +# validate_certs: False +# hostname: "{{ vcsim }}" +# username: "{{ vcsim_instance['json']['username'] }}" +# password: "{{ vcsim_instance['json']['password'] }}" +# name: "{{ 'newvm_efi_' + item|basename }}" +# guest_id: centos64Guest +# datacenter: "{{ (item|basename).split('_')[0] }}" +# hardware: +# num_cpus: 4 +# boot_firmware: "efi" +# memory_mb: 512 +# disk: +# - size: 1gb +# type: thin +# autoselect_datastore: True +# state: poweredoff +# folder: "{{ item|dirname }}" +# with_items: "{{ vmlist['json'] }}" +# register: clone_d1_c1_f0 + +#- debug: var=clone_d1_c1_f0 + +#- name: assert that changes were not made +# assert: +# that: +# - "clone_d1_c1_f0.results|map(attribute='changed')|unique|list == [false]" diff --git a/test/integration/targets/vmware_guest/tasks/main.yml b/test/integration/targets/vmware_guest/tasks/main.yml index 4db0af91ea..ec24028faa 100644 --- a/test/integration/targets/vmware_guest/tasks/main.yml +++ b/test/integration/targets/vmware_guest/tasks/main.yml @@ -30,4 +30,5 @@ - include: disk_size_d1_c1_f0.yml - include: network_with_device.yml - include: disk_mode_d1_c1_f0.yml -- include: linked_clone_d1_c1_f0.yml \ No newline at end of file +- include: linked_clone_d1_c1_f0.yml +- include: boot_firmware_d1_c1_f0.yml