From e61bcc3438d3cf8fddc82e0b2ced771ae07dc12b Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Thu, 16 Nov 2017 06:42:27 +0000 Subject: [PATCH] Provide clear error message after failure (#32928) --- .../modules/cloud/vmware/vmware_guest.py | 3 +- .../tasks/create_guest_invalid_d1_c1_f0.yml | 68 +++++++++++++++++++ .../targets/vmware_guest/tasks/main.yml | 1 + 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 test/integration/targets/vmware_guest/tasks/create_guest_invalid_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 866905e8c7..9a22f784ee 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -1580,8 +1580,9 @@ def main(): # VM doesn't exist else: if module.params['state'] in ['poweredon', 'poweredoff', 'present', 'restarted', 'suspended']: - # Create it ... result = pyv.deploy_vm() + if result['failed']: + module.fail_json(msg='Failed to create a virtual machine : %s' % result['msg']) if result['failed']: module.fail_json(**result) diff --git a/test/integration/targets/vmware_guest/tasks/create_guest_invalid_d1_c1_f0.yml b/test/integration/targets/vmware_guest/tasks/create_guest_invalid_d1_c1_f0.yml new file mode 100644 index 0000000000..1920b94096 --- /dev/null +++ b/test/integration/targets/vmware_guest/tasks/create_guest_invalid_d1_c1_f0.yml @@ -0,0 +1,68 @@ +# Test code for the vmware_guest module. +# Copyright: (c) 2017, 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 +# +#- debug: var=vcsim_instance +# +#- name: get a list of Datacenter from vcsim +# uri: +# url: http://{{ vcsim }}:5000/govc_find?filter=DC +# register: datacenters +# +#- set_fact: dc1="{{ datacenters['json'][0] }}" +# +#- name: get a list of virtual machines from vcsim +# uri: +# url: http://{{ vcsim }}:5000/govc_find?filter=VM +# register: vms +# +#- set_fact: vm1="{{ vms['json'][0] }}" +# +#- name: create new virtual machine with invalid guest id +# vmware_guest: +# validate_certs: False +# hostname: "{{ vcsim }}" +# username: "{{ vcsim_instance['json']['username'] }}" +# password: "{{ vcsim_instance['json']['password'] }}" +# name: "{{ 'invalid_vm_' + vm1 | basename }}" +# guest_id: "invalid_guest_id" +# datacenter: "{{ (vm1|basename).split('_')[0] }}" +# hardware: +# num_cpus: 1 +# memory_mb: 512 +# disk: +# - size: 0gb +# type: thin +# autoselect_datastore: True +# state: present +# folder: "{{ vm1 | dirname }}" +# register: invalid_guest_0001_d1_c1_f0 +# ignore_errors: yes +# +#- debug: var=invalid_guest_0001_d1_c1_f0 +# +#- name: assert that changes were made +# assert: +# that: +# - "invalid_guest_0001_d1_c1_f0['changed'] == false" +# - "'configSpec.guestId' in invalid_guest_0001_d1_c1_f0['msg']" diff --git a/test/integration/targets/vmware_guest/tasks/main.yml b/test/integration/targets/vmware_guest/tasks/main.yml index 938c5655b6..81b987a535 100644 --- a/test/integration/targets/vmware_guest/tasks/main.yml +++ b/test/integration/targets/vmware_guest/tasks/main.yml @@ -19,3 +19,4 @@ - include: create_d1_c1_f0.yml - include: cdrom_d1_c1_f0.yml - include: create_rp_d1_c1_f0.yml +- include: create_guest_invalid_d1_c1_f0.yml