Merge "Show proper error message for non-existing vnf package"

This commit is contained in:
Zuul 2020-01-21 02:40:41 +00:00 committed by Gerrit Code Review
commit e712c255d0
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,