From 245a4d30b966575236be0625d3b16667bf4b8cbd Mon Sep 17 00:00:00 2001 From: jctanner Date: Thu, 13 Jul 2017 22:02:33 -0400 Subject: [PATCH] vmware_guest: fix datastore selection on equal sized disks and add tests (#26774) * Fix datastore selection on equal sized disks and add tests --- .../modules/cloud/vmware/vmware_guest.py | 2 +- .../vmware_guest/tasks/clone_d1_c1_f0.yml | 40 +++++++++++++++++++ .../targets/vmware_guest/tasks/main.yml | 2 + 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 test/integration/targets/vmware_guest/tasks/clone_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 f8f5b1cf16..275fa250b2 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -1086,7 +1086,7 @@ class PyVmomiHelper(object): datastore_freespace = 0 for ds in datastores: - if ds.summary.freeSpace > datastore_freespace: + if (ds.summary.freeSpace > datastore_freespace) or (ds.summary.freeSpace == datastore_freespace and not datastore): # If datastore field is provided, filter destination datastores if 'datastore' in self.params['disk'][0] and \ isinstance(self.params['disk'][0]['datastore'], str) and \ diff --git a/test/integration/targets/vmware_guest/tasks/clone_d1_c1_f0.yml b/test/integration/targets/vmware_guest/tasks/clone_d1_c1_f0.yml new file mode 100644 index 0000000000..fb677ea917 --- /dev/null +++ b/test/integration/targets/vmware_guest/tasks/clone_d1_c1_f0.yml @@ -0,0 +1,40 @@ +- 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: 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: set state to poweroff on all VMs + vmware_guest: + validate_certs: False + hostname: "{{ vcsim }}" + username: "{{ vcsim_instance['json']['username'] }}" + password: "{{ vcsim_instance['json']['password'] }}" + name: "{{ 'newvm_' + item|basename }}" + template: "{{ item|basename }}" + datacenter: "{{ (item|basename).split('_')[0] }}" + disk: + - size: 0gb + 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]" diff --git a/test/integration/targets/vmware_guest/tasks/main.yml b/test/integration/targets/vmware_guest/tasks/main.yml index 16a812151b..9a8b5856c2 100644 --- a/test/integration/targets/vmware_guest/tasks/main.yml +++ b/test/integration/targets/vmware_guest/tasks/main.yml @@ -2,6 +2,7 @@ pip: name: pyvmomi state: latest + when: "{{ ansible_user_id == 'root' }}" - name: store the vcenter container ip set_fact: @@ -10,3 +11,4 @@ - include: poweroff_d1_c1_f0.yml - include: poweroff_d1_c1_f1.yml +- include: clone_d1_c1_f0.yml