summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gvnfmadapter/driver/interfaces/tests.py98
-rw-r--r--gvnfmadapter/driver/interfaces/views.py12
2 files changed, 77 insertions, 33 deletions
diff --git a/gvnfmadapter/driver/interfaces/tests.py b/gvnfmadapter/driver/interfaces/tests.py
index 9dece6a..4f57096 100644
--- a/gvnfmadapter/driver/interfaces/tests.py
+++ b/gvnfmadapter/driver/interfaces/tests.py
@@ -228,40 +228,90 @@ class InterfacesTest(TestCase):
@mock.patch.object(restcall, 'call_req')
def test_grantvnf(self, mock_call_req):
- vim_info = {
- "vim": {
- "accessinfo": {
- "tenant": "admin"
+ data = {
+ "vnfInstanceId": "1",
+ "vnfLcmOpOccId": "2",
+ "vnfdId": "3",
+ "flavourId": "4",
+ "operation": "INSTANTIATE",
+ "isAutomaticInvocation": True,
+ "instantiationLevelId": "5",
+ "addResources": [
+ {
+ "id": "1",
+ "type": "COMPUTE",
+ "vduId": "2",
+ "resourceTemplateId": "3",
+ "resourceTemplate": {
+ "vimConnectionId": "4",
+ "resourceProviderId": "5",
+ "resourceId": "6",
+ "vimLevelResourceType": "7"
+ }
+ }
+ ],
+ "placementConstraints": [
+ {
+ "affinityOrAntiAffinity": "AFFINITY",
+ "scope": "NFVI_POP",
+ "resource": [
+ {
+ "idType": "RES_MGMT",
+ "resourceId": "1",
+ "vimConnectionId": "2",
+ "resourceProviderId": "3"
+ }
+ ]
+ }
+ ],
+ "vimConstraints": [
+ {
+ "sameResourceGroup": True,
+ "resource": [
+ {
+ "idType": "RES_MGMT",
+ "resourceId": "1",
+ "vimConnectionId": "2",
+ "resourceProviderId": "3"
+ }
+ ]
+ }
+ ],
+ "additionalParams": {},
+ "_links": {
+ "vnfLcmOpOcc": {
+ "href": "1"
},
- "vimid": "516cee95-e8ca-4d26-9268-38e343c2e31e"
+ "vnfInstance": {
+ "href": "2"
+ }
}
}
- req_data = {
- "vnfmid": "13232222",
- "nfvoid": "03212234",
- "vimid": "12345678",
- "exvimidlist ": "exvimid",
- "tenant": " tenant1",
- "vnfinstanceid": "1234",
- "operationright": "0",
- "vmlist": [
- {
- "vmflavor": "SMP",
- "vmnumber": "3"
- },
+ grant_resp_data = {
+ "id": "1",
+ "vnfInstanceId": "1",
+ "vnfLcmOpOccId": "2",
+ "vimConnections": [
{
- "vmflavor": "CMP",
- "vmnumber": "3"
+ "id": "1",
+ "vimId": "1"
}
]
}
- mock_call_req.return_value = [0, json.JSONEncoder().encode(vim_info), '201']
+ mock_call_req.return_value = [0, json.JSONEncoder().encode(grant_resp_data), '201']
response = self.client.put("/api/gvnfmdriver/v1/resource/grant",
- data=json.dumps(req_data), content_type='application/json')
+ data=json.dumps(data), content_type='application/json')
self.assertEqual(status.HTTP_201_CREATED, response.status_code)
expect_resp_data = {
- "vimid": "516cee95-e8ca-4d26-9268-38e343c2e31e",
- "tenant": "admin"
+ "id": "1",
+ "vnfInstanceId": "1",
+ "vnfLcmOpOccId": "2",
+ "vimConnections": [
+ {
+ "id": "1",
+ "vimId": "1"
+ }
+ ]
}
self.assertDictEqual(expect_resp_data, response.data)
diff --git a/gvnfmadapter/driver/interfaces/views.py b/gvnfmadapter/driver/interfaces/views.py
index b2eab99..ae40bb6 100644
--- a/gvnfmadapter/driver/interfaces/views.py
+++ b/gvnfmadapter/driver/interfaces/views.py
@@ -244,20 +244,14 @@ class VnfGrantInfo(APIView):
def put(self, request, vnfmtype):
try:
logger.debug("[grantvnf] req_data = %s", request.data)
- ret = req_by_msb('api/nslcm/v1/grantvnf', "POST", content=json.JSONEncoder().encode(request.data))
+ ret = req_by_msb('api/nslcm/v2/grants', "POST", content=json.JSONEncoder().encode(request.data))
logger.debug("ret = %s", ret)
if ret[0] != 0:
logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
raise GvnfmDriverException('Failed to grant vnf.')
resp = json.JSONDecoder().decode(ret[1])
- vim_info = resp['vim']
- accessinfo = ignorcase_get(resp['vim'], 'accessinfo')
- resp_data = {
- 'vimid': ignorcase_get(vim_info, 'vimid'),
- 'tenant': ignorcase_get(accessinfo, 'tenant')
- }
- logger.debug("[%s]resp_data=%s", fun_name(), resp_data)
- return Response(data=resp_data, status=status.HTTP_201_CREATED)
+ logger.debug("[%s]resp_data=%s", fun_name(), resp)
+ return Response(data=resp, status=status.HTTP_201_CREATED)
except GvnfmDriverException as e:
logger.error('Grant vnf failed, detail message: %s' % e.message)
return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)