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
This commit is contained in:
Shubham Potale 2019-10-11 20:52:47 +05:30
parent 1d375bd49e
commit 727129d958
2 changed files with 35 additions and 0 deletions

View File

@ -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)

View File

@ -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,