Add delete vnf instance API
Implemented delete vnf instance API. * DELETE /vnflcm/v1/vnf_instances/{vnf_instance_id} Co-authored-By: Ajay Parja <ajay.parja@nttdata.com> Co-authored-By: Niraj Singh <niraj.singh@nttdata.com> Blueprint: support-etsi-nfv-specs Change-Id: I66040705a2f2c15e3aa84112226ce77ab5a7e18d
This commit is contained in:
parent
31beaa32b8
commit
840d754822
@ -209,8 +209,20 @@ class VnfLcmController(wsgi.Controller):
|
|||||||
vnf_instances = objects.VnfInstanceList.get_all(context)
|
vnf_instances = objects.VnfInstanceList.get_all(context)
|
||||||
return self._view_builder.index(vnf_instances)
|
return self._view_builder.index(vnf_instances)
|
||||||
|
|
||||||
|
@check_vnf_state(action="delete",
|
||||||
|
instantiation_state=[fields.VnfInstanceState.NOT_INSTANTIATED],
|
||||||
|
task_state=[None])
|
||||||
|
def _delete(self, context, vnf_instance):
|
||||||
|
vnf_instance.destroy(context)
|
||||||
|
|
||||||
|
@wsgi.response(http_client.NO_CONTENT)
|
||||||
|
@wsgi.expected_errors((http_client.FORBIDDEN, http_client.NOT_FOUND,
|
||||||
|
http_client.CONFLICT))
|
||||||
def delete(self, request, id):
|
def delete(self, request, id):
|
||||||
raise webob.exc.HTTPNotImplemented()
|
context = request.environ['tacker.context']
|
||||||
|
|
||||||
|
vnf_instance = self._get_vnf_instance(context, id)
|
||||||
|
self._delete(context, vnf_instance)
|
||||||
|
|
||||||
@check_vnf_state(action="instantiate",
|
@check_vnf_state(action="instantiate",
|
||||||
instantiation_state=[fields.VnfInstanceState.NOT_INSTANTIATED],
|
instantiation_state=[fields.VnfInstanceState.NOT_INSTANTIATED],
|
||||||
|
@ -88,6 +88,17 @@ rules = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
policy.DocumentedRuleDefault(
|
||||||
|
name=VNFLCM % 'delete',
|
||||||
|
check_str=base.RULE_ADMIN_OR_OWNER,
|
||||||
|
description="Delete an Individual VNF instance.",
|
||||||
|
operations=[
|
||||||
|
{
|
||||||
|
'method': 'DELETE',
|
||||||
|
'path': '/vnflcm/v1/vnf_instances/{vnfInstanceId}'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -1004,3 +1004,88 @@ class TestController(base.TestCase):
|
|||||||
req.method = method
|
req.method = method
|
||||||
resp = req.get_response(self.app)
|
resp = req.get_response(self.app)
|
||||||
self.assertEqual(http_client.METHOD_NOT_ALLOWED, resp.status_code)
|
self.assertEqual(http_client.METHOD_NOT_ALLOWED, resp.status_code)
|
||||||
|
|
||||||
|
@mock.patch.object(objects.vnf_instance, "_vnf_instance_get_by_id")
|
||||||
|
@mock.patch.object(objects.vnf_instance, '_destroy_vnf_instance')
|
||||||
|
def test_delete(self, mock_destroy_vnf_instance, mock_vnf_by_id):
|
||||||
|
req = fake_request.HTTPRequest.blank(
|
||||||
|
'/vnf_instances/%s' % uuidsentinel.vnf_instance_id)
|
||||||
|
req.method = 'DELETE'
|
||||||
|
mock_vnf_by_id.return_value = fakes.return_vnf_instance()
|
||||||
|
req.headers['Content-Type'] = 'application/json'
|
||||||
|
|
||||||
|
# Call delete API
|
||||||
|
resp = req.get_response(self.app)
|
||||||
|
|
||||||
|
self.assertEqual(http_client.NO_CONTENT, resp.status_code)
|
||||||
|
mock_destroy_vnf_instance.assert_called_once()
|
||||||
|
|
||||||
|
@mock.patch.object(objects.VnfInstance, "get_by_id")
|
||||||
|
def test_delete_with_non_existing_vnf_instance(self, mock_vnf_by_id):
|
||||||
|
req = fake_request.HTTPRequest.blank(
|
||||||
|
'/vnf_instances/%s' % uuidsentinel.vnf_instance_id)
|
||||||
|
req.method = 'DELETE'
|
||||||
|
|
||||||
|
mock_vnf_by_id.side_effect = exceptions.VnfInstanceNotFound
|
||||||
|
|
||||||
|
# Call delete API
|
||||||
|
resp = req.get_response(self.app)
|
||||||
|
|
||||||
|
self.assertEqual(http_client.NOT_FOUND, resp.status_code)
|
||||||
|
self.assertEqual("Can not find requested vnf instance: %s" %
|
||||||
|
uuidsentinel.vnf_instance_id,
|
||||||
|
resp.json['itemNotFound']['message'])
|
||||||
|
|
||||||
|
def test_delete_with_invalid_uuid(self):
|
||||||
|
req = fake_request.HTTPRequest.blank(
|
||||||
|
'/vnf_instances/%s' % constants.INVALID_UUID)
|
||||||
|
req.method = 'DELETE'
|
||||||
|
|
||||||
|
# Call delete API
|
||||||
|
resp = req.get_response(self.app)
|
||||||
|
|
||||||
|
self.assertEqual(http_client.NOT_FOUND, resp.status_code)
|
||||||
|
self.assertEqual("Can not find requested vnf instance: %s" %
|
||||||
|
constants.INVALID_UUID,
|
||||||
|
resp.json['itemNotFound']['message'])
|
||||||
|
|
||||||
|
@mock.patch.object(objects.VnfInstance, "get_by_id")
|
||||||
|
def test_delete_with_incorrect_instantiation_state(self, mock_vnf_by_id):
|
||||||
|
req = fake_request.HTTPRequest.blank(
|
||||||
|
'/vnf_instances/%s' % uuidsentinel.vnf_instance_id)
|
||||||
|
req.method = 'DELETE'
|
||||||
|
|
||||||
|
vnf_instance = fakes.return_vnf_instance(
|
||||||
|
fields.VnfInstanceState.INSTANTIATED)
|
||||||
|
mock_vnf_by_id.return_value = vnf_instance
|
||||||
|
|
||||||
|
# Call delete API
|
||||||
|
resp = req.get_response(self.app)
|
||||||
|
|
||||||
|
self.assertEqual(http_client.CONFLICT, resp.status_code)
|
||||||
|
expected_msg = ("Vnf instance %s in instantiation_state "
|
||||||
|
"INSTANTIATED. Cannot delete while the vnf instance "
|
||||||
|
"is in this state.")
|
||||||
|
self.assertEqual(expected_msg % uuidsentinel.vnf_instance_id,
|
||||||
|
resp.json['conflictingRequest']['message'])
|
||||||
|
|
||||||
|
@mock.patch.object(objects.VnfInstance, "get_by_id")
|
||||||
|
def test_delete_with_incorrect_task_state(self, mock_vnf_by_id):
|
||||||
|
req = fake_request.HTTPRequest.blank(
|
||||||
|
'/vnf_instances/%s' % uuidsentinel.vnf_instance_id)
|
||||||
|
req.method = 'DELETE'
|
||||||
|
|
||||||
|
vnf_instance = fakes.return_vnf_instance(
|
||||||
|
fields.VnfInstanceState.NOT_INSTANTIATED,
|
||||||
|
task_state=fields.VnfInstanceTaskState.ERROR)
|
||||||
|
mock_vnf_by_id.return_value = vnf_instance
|
||||||
|
|
||||||
|
# Call delete API
|
||||||
|
resp = req.get_response(self.app)
|
||||||
|
|
||||||
|
self.assertEqual(http_client.CONFLICT, resp.status_code)
|
||||||
|
expected_msg = ("Vnf instance %s in task_state ERROR. "
|
||||||
|
"Cannot delete while the vnf instance "
|
||||||
|
"is in this state.")
|
||||||
|
self.assertEqual(expected_msg % uuidsentinel.vnf_instance_id,
|
||||||
|
resp.json['conflictingRequest']['message'])
|
||||||
|
Loading…
Reference in New Issue
Block a user