From a4f08617d4ebea343c1c166a5edfca3c28b1342f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A9ri=20Le=20Bouder?= Date: Thu, 16 May 2019 10:22:18 -0400 Subject: [PATCH] VMware: vmware_datastore_maintenancemode: check params (#56515) Check the `datastore` parameter and raise an error if nothing has been found. --- changelogs/fragments/vmware_maintenance_mode_params.yaml | 2 ++ .../modules/cloud/vmware/vmware_datastore_maintenancemode.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/vmware_maintenance_mode_params.yaml diff --git a/changelogs/fragments/vmware_maintenance_mode_params.yaml b/changelogs/fragments/vmware_maintenance_mode_params.yaml new file mode 100644 index 00000000000..aa7750c004a --- /dev/null +++ b/changelogs/fragments/vmware_maintenance_mode_params.yaml @@ -0,0 +1,2 @@ +minor_changes: + - vmware_datastore_maintenancemode - Raise an error if the datastore does not exist. diff --git a/lib/ansible/modules/cloud/vmware/vmware_datastore_maintenancemode.py b/lib/ansible/modules/cloud/vmware/vmware_datastore_maintenancemode.py index a86d9cb31e1..7ad6d9f352f 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_datastore_maintenancemode.py +++ b/lib/ansible/modules/cloud/vmware/vmware_datastore_maintenancemode.py @@ -120,7 +120,10 @@ class VmwareDatastoreMaintenanceMgr(PyVmomi): datastore_cluster = self.params.get('datastore_cluster') self.datastore_objs = [] if datastore_name: - self.datastore_objs = [self.find_datastore_by_name(datastore_name=datastore_name)] + ds = self.find_datastore_by_name(datastore_name=datastore_name) + if not ds: + self.module.fail_json(msg='Failed to find datastore "%(datastore)s".' % self.params) + self.datastore_objs = [ds] elif cluster_name: cluster = find_cluster_by_name(self.content, cluster_name) if not cluster: