Add list vnf instance API

Implemented list vnf instances API.

* GET /vnflcm/v1/vnf_instances

Co-authored-By: Ajay Parja <ajay.parja@nttdata.com>
Co-authored-By: Shubham Potale <shubham.potale@nttdata.com>

Change-Id: I1f5d9110e857111232a4ffd4b9c4b229c03a46f8
Blueprint: support-etsi-nfv-specs
This commit is contained in:
tpatil 2020-03-15 15:46:05 +00:00
parent cff8c75682
commit c45c877f36
5 changed files with 55 additions and 4 deletions

View File

@ -69,3 +69,7 @@ class ViewBuilder(object):
def show(self, vnf_instance):
return self._get_vnf_instance_info(vnf_instance)
def index(self, vnf_instances):
return [self._get_vnf_instance_info(vnf_instance)
for vnf_instance in vnf_instances]

View File

@ -202,8 +202,12 @@ class VnfLcmController(wsgi.Controller):
return self._view_builder.show(vnf_instance)
@wsgi.response(http_client.OK)
@wsgi.expected_errors((http_client.FORBIDDEN))
def index(self, request):
raise webob.exc.HTTPNotImplemented()
context = request.environ['tacker.context']
vnf_instances = objects.VnfInstanceList.get_all(context)
return self._view_builder.index(vnf_instances)
def delete(self, request, id):
raise webob.exc.HTTPNotImplemented()

View File

@ -76,7 +76,18 @@ rules = [
'path': '/vnflcm/v1/vnf_instances/{vnfInstanceId}/heal'
}
]
)
),
policy.DocumentedRuleDefault(
name=VNFLCM % 'index',
check_str=base.RULE_ADMIN_OR_OWNER,
description="Query VNF instances.",
operations=[
{
'method': 'GET',
'path': '/vnflcm/v1/vnf_instances'
}
]
),
]

View File

@ -972,3 +972,35 @@ class TestController(base.TestCase):
expected_type=expected_type))
self.assertEqual(expected_message, exception.msg)
@mock.patch.object(objects.VnfInstanceList, "get_all")
def test_index(self, mock_vnf_list):
req = fake_request.HTTPRequest.blank('/vnf_instances')
vnf_instance_1 = fakes.return_vnf_instance()
vnf_instance_2 = fakes.return_vnf_instance(
fields.VnfInstanceState.INSTANTIATED)
mock_vnf_list.return_value = [vnf_instance_1, vnf_instance_2]
resp = self.controller.index(req)
expected_result = [fakes.fake_vnf_instance_response(),
fakes.fake_vnf_instance_response(
fields.VnfInstanceState.INSTANTIATED)]
self.assertEqual(expected_result, resp)
@mock.patch.object(objects.VnfInstanceList, "get_all")
def test_index_empty_response(self, mock_vnf_list):
req = fake_request.HTTPRequest.blank('/vnf_instances')
mock_vnf_list.return_value = []
resp = self.controller.index(req)
self.assertEqual([], resp)
@ddt.data('HEAD', 'PUT', 'DELETE', 'PATCH')
def test_index_invalid_http_method(self, method):
# Wrong HTTP method
req = fake_request.HTTPRequest.blank(
'/vnf_instances')
req.headers['Content-Type'] = 'application/json'
req.method = method
resp = req.get_response(self.app)
self.assertEqual(http_client.METHOD_NOT_ALLOWED, resp.status_code)

View File

@ -1043,8 +1043,8 @@ class Resource(Application):
if not response:
resp_obj = None
if isinstance(action_result, (dict, str)) \
or action_result is None:
if (isinstance(action_result, (dict, list, str)) or
action_result is None):
resp_obj = ResponseObject(action_result)
elif isinstance(action_result, ResponseObject):
resp_obj = action_result