From 791e565802a46b07ae917ed9722140ec217aa6b6 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Mon, 22 Jul 2019 10:44:19 +0530 Subject: [PATCH] VMware: Additional testcase for mem_reservation (#59365) Signed-off-by: Abhijeet Kasurde --- .../modules/cloud/vmware/vmware_guest.py | 4 +- .../targets/vmware_guest/tasks/main.yml | 4 + .../vmware_guest/tasks/mem_reservation.yml | 82 +++++++++++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py index a65cc0f522..1c903114f6 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -896,7 +896,9 @@ class PyVmomiHelper(PyVmomi): rai_change_detected = True if 'mem_reservation' in self.params['hardware'] or 'memory_reservation' in self.params['hardware']: - mem_reservation = self.params['hardware'].get('mem_reservation') or self.params['hardware'].get('memory_reservation') + mem_reservation = self.params['hardware'].get('mem_reservation') + if mem_reservation is None: + mem_reservation = self.params['hardware'].get('memory_reservation') try: mem_reservation = int(mem_reservation) except ValueError: diff --git a/test/integration/targets/vmware_guest/tasks/main.yml b/test/integration/targets/vmware_guest/tasks/main.yml index 9e3e8a44fe..a54b0df8d7 100644 --- a/test/integration/targets/vmware_guest/tasks/main.yml +++ b/test/integration/targets/vmware_guest/tasks/main.yml @@ -116,6 +116,10 @@ - newvm_mk_conn_DC0_H0_VM1 - newvm_mem_res_DC0_H0_VM0 - newvm_mem_res_DC0_H0_VM1 + - newvm_no_mem_DC0_H0_VM0 + - newvm_no_mem_DC0_H0_VM1 + - memory_res_DC0_H0_VM0 + - memory_res_DC0_H0_VM1 - thin_DC0_H0_VM0 - thin_DC0_H0_VM1 - thick_DC0_H0_VM0 diff --git a/test/integration/targets/vmware_guest/tasks/mem_reservation.yml b/test/integration/targets/vmware_guest/tasks/mem_reservation.yml index e6edacaeee..3ab61cddad 100644 --- a/test/integration/targets/vmware_guest/tasks/mem_reservation.yml +++ b/test/integration/targets/vmware_guest/tasks/mem_reservation.yml @@ -44,3 +44,85 @@ assert: that: - "mem_reserve_result_0002.results|map(attribute='changed')|unique|list == [false]" + + - &add_memory_reserve + name: Create new VMs with memory_reservation as 0 + vmware_guest: + validate_certs: False + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + name: "{{ 'memory_res_' + item.name }}" + guest_id: centos64Guest + datacenter: "{{ dc1 }}" + hardware: + num_cpus: 4 + memory_mb: 512 + memory_reservation: 0 + disk: + - size: 1gb + type: thin + autoselect_datastore: True + state: present + folder: "{{ item.folder }}" + with_items: "{{ virtual_machines }}" + register: memory_reserve_result_0003 + + - debug: var=memory_reserve_result_0003 + + - name: Assert that changes were made + assert: + that: + - "memory_reserve_result_0003.results|map(attribute='changed')|unique|list == [true]" + + - <<: *add_memory_reserve + name: Again create new VMs with memory_reservation as 0 + register: memory_reserve_result_0004 + + - debug: var=memory_reserve_result_0004 + + - name: Assert that changes were not made + assert: + that: + - "memory_reserve_result_0004.results|map(attribute='changed')|unique|list == [false]" + + - &no_memory_reserve + name: Create new VMs without memory_reservation or mem_reservation + vmware_guest: + validate_certs: False + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + name: "{{ 'newvm_no_mem_' + item.name }}" + guest_id: centos64Guest + datacenter: "{{ dc1 }}" + hardware: + num_cpus: 4 + memory_mb: 512 + memory_reservation: 0 + disk: + - size: 1gb + type: thin + autoselect_datastore: True + state: present + folder: "{{ item.folder }}" + with_items: "{{ virtual_machines }}" + register: no_memory_reserve_result_0005 + + - debug: var=no_memory_reserve_result_0005 + + - name: Assert that changes were made + assert: + that: + - "no_memory_reserve_result_0005.results|map(attribute='changed')|unique|list == [true]" + + - <<: *no_memory_reserve + name: Again create new VMs without memory_reservation or mem_reservation + register: no_memory_reserve_result_0006 + + - debug: var=no_memory_reserve_result_0006 + + - name: Assert that changes were not made + assert: + that: + - "no_memory_reserve_result_0006.results|map(attribute='changed')|unique|list == [false]"