Add command for Fetch VNF package API
Added command support for downloading csar vnf package contents. Change-Id: I6371ebdf0dd9d127ca88bcd721a31036d11ea5fc Implements: bp enhance-vnf-package-support-part1
This commit is contained in:
parent
ac02653f21
commit
1736ae7895
@ -260,7 +260,8 @@ class DeleteVnfPackage(command.Command):
|
||||
|
||||
|
||||
class DownloadVnfPackage(command.Command):
|
||||
_description = _("Read VNFD of an on-boarded VNF Package")
|
||||
_description = _("Download VNF package contents or VNFD of an on-boarded "
|
||||
"VNF package.")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(DownloadVnfPackage, self).get_parser(prog_name)
|
||||
@ -272,9 +273,9 @@ class DownloadVnfPackage(command.Command):
|
||||
parser.add_argument(
|
||||
"--file",
|
||||
metavar="<FILE>",
|
||||
help=_("Local file to save downloaded vnfd data. "
|
||||
help=_("Local file to save downloaded VNF Package or VNFD data. "
|
||||
"If this is not specified and there is no redirection "
|
||||
"then vnfd data will not be saved.")
|
||||
"then data will not be saved.")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--vnfd",
|
||||
@ -308,15 +309,13 @@ class DownloadVnfPackage(command.Command):
|
||||
body = client.download_vnfd_from_vnf_package(
|
||||
parsed_args.vnf_package, parsed_args.type)
|
||||
|
||||
if parsed_args.file:
|
||||
sdk_utils.save_data(body, parsed_args.file)
|
||||
else:
|
||||
if not parsed_args.file:
|
||||
print(body)
|
||||
|
||||
return
|
||||
else:
|
||||
msg = ("Currently only download vnfd from on-boarded vnf package "
|
||||
"is supported. use --vnfd")
|
||||
sdk_utils.exit(msg)
|
||||
body = client.download_vnf_package(parsed_args.vnf_package)
|
||||
|
||||
sdk_utils.save_data(body, parsed_args.file)
|
||||
|
||||
|
||||
class UpdateVnfPackage(command.ShowOne):
|
||||
|
@ -560,3 +560,37 @@ class TestDownloadVnfPackage(TestVnfPackage):
|
||||
self.assertRaises(SystemExit,
|
||||
self.download_vnf_package.take_action,
|
||||
parsed_args)
|
||||
|
||||
def test_download_vnf_package(self):
|
||||
file_name = 'vnf_package_data.zip'
|
||||
test_file, temp_dir = _create_zip()
|
||||
|
||||
# file in which VNF Package data will be stored.
|
||||
# for testing purpose we are creating temporary zip file.
|
||||
local_file = tempfile.NamedTemporaryFile(suffix=file_name)
|
||||
vnf_package_data = open(test_file, 'rb').read()
|
||||
|
||||
arglist = [
|
||||
self._vnf_package['id'],
|
||||
'--file', local_file.name
|
||||
]
|
||||
verifylist = [
|
||||
('vnf_package', self._vnf_package['id']),
|
||||
('file', local_file.name)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.download_vnf_package, arglist,
|
||||
verifylist)
|
||||
|
||||
url = os.path.join(self.url, '/vnfpkgm/v1/vnf_packages',
|
||||
self._vnf_package['id'], 'package_content')
|
||||
|
||||
self.requests_mock.register_uri(
|
||||
'GET', url, headers={'content-type': 'application/zip'},
|
||||
content=vnf_package_data)
|
||||
|
||||
self.download_vnf_package.take_action(parsed_args)
|
||||
self.assertTrue(filecmp.cmp(test_file, local_file.name),
|
||||
"Downloaded contents don't match test file")
|
||||
self.assertTrue(self._check_valid_zip_file(local_file.name))
|
||||
shutil.rmtree(temp_dir)
|
||||
|
@ -754,6 +754,7 @@ class VnfPackageClient(ClientBase):
|
||||
vnfpackages_path = '/vnfpkgm/v1/vnf_packages'
|
||||
vnfpackage_path = '/vnfpkgm/v1/vnf_packages/%s'
|
||||
vnfpackage_vnfd_path = '/vnfpkgm/v1/vnf_packages/%s/vnfd'
|
||||
vnfpackage_download_path = '/vnfpkgm/v1/vnf_packages/%s/package_content'
|
||||
|
||||
def build_action(self, action):
|
||||
return action
|
||||
@ -794,6 +795,11 @@ class VnfPackageClient(ClientBase):
|
||||
base_path=self.vnfpackages_path),
|
||||
body=file_data)
|
||||
|
||||
@APIParamsCall
|
||||
def download_vnf_package(self, vnf_package):
|
||||
self.format = 'zip'
|
||||
return self.get(self.vnfpackage_download_path % vnf_package)
|
||||
|
||||
@APIParamsCall
|
||||
def download_vnfd_from_vnf_package(self, vnf_package, accept):
|
||||
"""Read VNFD of an on-boarded VNF Package.
|
||||
@ -1148,3 +1154,6 @@ class Client(object):
|
||||
def download_vnfd_from_vnf_package(self, vnf_package, accept):
|
||||
return self.vnf_package_client.download_vnfd_from_vnf_package(
|
||||
vnf_package, accept)
|
||||
|
||||
def download_vnf_package(self, vnf_package):
|
||||
return self.vnf_package_client.download_vnf_package(vnf_package)
|
||||
|
Loading…
Reference in New Issue
Block a user