diff --git a/lib/ansible/module_utils/vmware.py b/lib/ansible/module_utils/vmware.py index 260651011b..d418f92c90 100644 --- a/lib/ansible/module_utils/vmware.py +++ b/lib/ansible/module_utils/vmware.py @@ -370,7 +370,7 @@ def get_current_snap_obj(snapshots, snapob): def list_snapshots(vm): result = {} - snapshot = _get_vm_prop(vm, ('vm', 'snapshot')) + snapshot = _get_vm_prop(vm, ('snapshot',)) if not snapshot: return result if vm.snapshot is None: diff --git a/test/integration/targets/vmware_guest_facts/tasks/main.yml b/test/integration/targets/vmware_guest_facts/tasks/main.yml index 13e88a8edc..8f4f98020e 100644 --- a/test/integration/targets/vmware_guest_facts/tasks/main.yml +++ b/test/integration/targets/vmware_guest_facts/tasks/main.yml @@ -90,3 +90,65 @@ - "guest_facts_0002['instance']['hw_name'] == vm1 | basename" - "guest_facts_0002['instance']['hw_product_uuid'] is defined" - "guest_facts_0002['instance']['hw_product_uuid'] == vm1_uuid" + +# Testcase 0003: Get details about virtual machines without snapshots using UUID +- name: get empty list of snapshots from virtual machine using UUID + vmware_guest_facts: + validate_certs: False + hostname: "{{ vcsim }}" + username: "{{ vcsim_instance['json']['username'] }}" + password: "{{ vcsim_instance['json']['password'] }}" + datacenter: "{{ dc1 | basename }}" + uuid: "{{ vm1_uuid }}" + register: guest_facts_0003 + +- debug: msg="{{ guest_facts_0003 }}" + +- assert: + that: + - "guest_facts_0003['instance']['snapshots']|length == 0" + - "guest_facts_0003['instance']['current_snapshot'] is none" + +# Testcase 0004: Get details about virtual machines with two snapshots using UUID +- name: Create first snapshot + vmware_guest_snapshot: + validate_certs: False + hostname: "{{ vcsim }}" + username: "{{ vcsim_instance['json']['username'] }}" + password: "{{ vcsim_instance['json']['password'] }}" + datacenter: "{{ dc1 | basename }}" + name: "{{ vm1 | basename }}" + folder: "{{ vm1 | dirname }}" + state: present + snapshot_name: snap1 + +- name: Create second snapshot + vmware_guest_snapshot: + validate_certs: False + hostname: "{{ vcsim }}" + username: "{{ vcsim_instance['json']['username'] }}" + password: "{{ vcsim_instance['json']['password'] }}" + datacenter: "{{ dc1 | basename }}" + name: "{{ vm1 | basename }}" + folder: "{{ vm1 | dirname }}" + state: present + snapshot_name: snap2 + +- name: get list of snapshots from virtual machine using UUID + vmware_guest_facts: + validate_certs: False + hostname: "{{ vcsim }}" + username: "{{ vcsim_instance['json']['username'] }}" + password: "{{ vcsim_instance['json']['password'] }}" + datacenter: "{{ dc1 | basename }}" + uuid: "{{ vm1_uuid }}" + register: guest_facts_0004 + +- debug: msg="{{ guest_facts_0004 }}" + +- assert: + that: + - "guest_facts_0004['instance']['snapshots'] is defined" + - "guest_facts_0004['instance']['snapshots'][0]['name'] == 'snap1'" + - "guest_facts_0004['instance']['snapshots'][1]['name'] == 'snap2'" + - "guest_facts_0004['instance']['current_snapshot']['name'] == 'snap2'" \ No newline at end of file