mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
module_utils: vmware.py. Incorrect chain of attributes to obtain snapshots from virtual machine (#32669)
* Update vmware.py Incorrect chain of attributes to obtain snapshots from virtual machine. Module 'vmware_guest_facts' uses method 'gather_vm_facts' of vmware.py and always gets empty list of snapshots. * Added test for module vmware_guest_facts. Checked VM snapshots. * Fixed tests for vmware_guest_facts. Ignored certificate for vmware_guest_snapshot module.
This commit is contained in:
parent
cabd7f078b
commit
c56dcb7afa
2 changed files with 63 additions and 1 deletions
|
@ -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:
|
||||
|
|
|
@ -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'"
|
Loading…
Reference in a new issue