From 0acef98dc4425dd5f3f981aac52186d0da1a837a Mon Sep 17 00:00:00 2001 From: Mariusz Mazur Date: Wed, 3 Apr 2019 10:46:24 +0200 Subject: [PATCH] kubevirt_cdi_upload: add more error handling (#54041) --- .../modules/cloud/kubevirt/kubevirt_cdi_upload.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/cloud/kubevirt/kubevirt_cdi_upload.py b/lib/ansible/modules/cloud/kubevirt/kubevirt_cdi_upload.py index 17d43b2bdfe..98a224126ff 100644 --- a/lib/ansible/modules/cloud/kubevirt/kubevirt_cdi_upload.py +++ b/lib/ansible/modules/cloud/kubevirt/kubevirt_cdi_upload.py @@ -161,10 +161,20 @@ class KubeVirtCDIUpload(KubernetesRawModule): headers = {'Authorization': "Bearer {0}".format(result['result']['status']['token'])} url = "{0}/{1}/upload".format(upload_host, API) - requests.post(url, data=imgfile, headers=headers, verify=upload_host_verify_ssl) + ret = requests.post(url, data=imgfile, headers=headers, verify=upload_host_verify_ssl) + + if ret.status_code != 200: + self.fail_request("Something went wrong while uploading data", method='POST', url=url, + reason=ret.reason, status_code=ret.status_code) self.exit_json(changed=True) + def fail_request(self, msg, **kwargs): + req_info = {} + for k, v in kwargs.items(): + req_info['req_' + k] = v + self.fail_json(msg=msg, **req_info) + def main(): module = KubeVirtCDIUpload()