From d8397461231a92670d73dabed900b0e0c80d92f9 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Mon, 7 May 2018 12:41:49 +0530 Subject: [PATCH] VMware: report failure if no snapshot exists on VM (#38651) This fix add correct reporting of failure if VM does not contain any snapshots for following operations - rename, remove and revert. Fixes: #37906 Signed-off-by: Abhijeet Kasurde --- lib/ansible/modules/cloud/vmware/vmware_guest_snapshot.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest_snapshot.py b/lib/ansible/modules/cloud/vmware/vmware_guest_snapshot.py index 8a799ce08f..b94777f41d 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest_snapshot.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest_snapshot.py @@ -279,7 +279,7 @@ class PyVmomiHelper(PyVmomi): def rename_snapshot(self, vm): if vm.snapshot is None: - self.module.exit_json(msg="virtual machine - %s doesn't have any" + self.module.fail_json(msg="virtual machine - %s doesn't have any" " snapshots" % (self.module.params.get('uuid') or self.module.params.get('name'))) snap_obj = self.get_snapshots_by_name_recursively(vm.snapshot.rootSnapshotList, @@ -303,8 +303,12 @@ class PyVmomiHelper(PyVmomi): def remove_or_revert_snapshot(self, vm): if vm.snapshot is None: + vm_name = (self.module.params.get('uuid') or self.module.params.get('name')) + if self.module.params.get('state') == 'revert': + self.module.fail_json(msg="virtual machine - %s does not" + " have any snapshots to revert to." % vm_name) self.module.exit_json(msg="virtual machine - %s doesn't have any" - " snapshots" % (self.module.params.get('uuid') or self.module.params.get('name'))) + " snapshots to remove." % vm_name) snap_obj = self.get_snapshots_by_name_recursively(vm.snapshot.rootSnapshotList, self.module.params["snapshot_name"])