From 727129d9586fa7a594927b418005c1f10278d17e Mon Sep 17 00:00:00 2001 From: Shubham Potale Date: Fri, 11 Oct 2019 20:52:47 +0530 Subject: [PATCH] Show proper error message for non-existing vnf package When you pass non-existing vnf package uuid to ``vnf package upload`` command as shown below, it doesn't show user-friendly message as it's shown in case ``vnf package show`` command. $openstack vnf package upload --path sample_vnf_pkg.zip dummy-id "404-tackerFault" This patch fixes this issue and now it will output below error message: $openstack vnf package upload --path sample_vnf_pkg.zip dummy-id Can not find requested vnf package: dummy-id Change-Id: I84de0140463d6bd834d3bcc22f6a6cea1fef9130 Closes-Bug: #1799683 --- .../tests/unit/osc/v1/test_vnf_package.py | 31 +++++++++++++++++++ tackerclient/v1_0/client.py | 4 +++ 2 files changed, 35 insertions(+) diff --git a/tackerclient/tests/unit/osc/v1/test_vnf_package.py b/tackerclient/tests/unit/osc/v1/test_vnf_package.py index fc78e341..8322dbf1 100644 --- a/tackerclient/tests/unit/osc/v1/test_vnf_package.py +++ b/tackerclient/tests/unit/osc/v1/test_vnf_package.py @@ -326,3 +326,34 @@ class TestUploadVnfPackage(TestVnfPackage): self.upload_vnf_package.take_action, parsed_args) # Delete temporary folder shutil.rmtree(temp_dir) + + def test_upload_vnf_package_failed_with_404_not_found(self): + # Scenario in which vnf package is not found + zip_file, temp_dir = _create_zip() + arglist = [ + 'dumy-id', + "--path", zip_file + ] + verifylist = [ + ('path', zip_file), + ('vnf_package', 'dumy-id') + ] + + parsed_args = self.check_parser(self.upload_vnf_package, arglist, + verifylist) + + error_message = "Can not find requested vnf package: dummy-id" + body = {"itemNotFound": {"message": error_message, "code": 404}} + url = self.url + '/vnfpkgm/v1/vnf_packages/dumy-id/package_content' + + self.requests_mock.register_uri( + 'PUT', url, json=body, + status_code=404) + + exception = self.assertRaises( + exceptions.TackerClientException, + self.upload_vnf_package.take_action, parsed_args) + + self.assertEqual(error_message, exception.message) + # Delete temporary folder + shutil.rmtree(temp_dir) diff --git a/tackerclient/v1_0/client.py b/tackerclient/v1_0/client.py index 834cc8cc..bc2fd30f 100644 --- a/tackerclient/v1_0/client.py +++ b/tackerclient/v1_0/client.py @@ -205,6 +205,10 @@ class ClientBase(object): action, method, body=body, content_type=self.content_type()) + if ('application/json' in resp.headers.get('Content-Type', + 'application/json')): + self.format = 'json' + status_code = resp.status_code if status_code in (requests.codes.ok, requests.codes.created,