Delete vnf package if operationalState is DISABLED

Presently, vnf package can be deleted when it's operationalState is
'ENABLED'.

As per pre-condition rule, vnf package can be deleted only when
it's operationalState is 'DISABLED' and it's usageState is 'NOT_IN_USE.

This patch fixes this issue and now vnf package will be deleted only
when it's operationalState is 'DISABLED' and it's usageState is 'NOT_IN_USE.

Note: I have fixed windows style line ending issue in vnf_packages.inc.
Also, updated 'Delete VNF Package' API doc to include 409 error.

Change-Id: Id4d50264d1052a09e6ce527b6aab1bb941fdc6af
Closes-Bug: #1862864
This commit is contained in:
tpatil 2020-02-12 02:45:20 +00:00
parent e82d982d7b
commit 33f92086f4
3 changed files with 286 additions and 248 deletions

View File

@ -161,6 +161,11 @@ Delete VNF Package
Deletes a given VNF Package.
**Preconditions**
The vnf package ``operationalState`` value must be ``DISABLED`` and it's
``usageState`` value must be ``NOT_IN_USE``.
Response Codes
--------------
@ -173,6 +178,7 @@ Response Codes
- 401
- 403
- 404
- 409
Request Parameters
------------------

View File

@ -102,7 +102,8 @@ class VnfPkgmController(wsgi.Controller):
return self._view_builder.index(request, vnf_packages)
@wsgi.response(http_client.NO_CONTENT)
@wsgi.expected_errors((http_client.FORBIDDEN, http_client.NOT_FOUND))
@wsgi.expected_errors((http_client.FORBIDDEN, http_client.NOT_FOUND,
http_client.CONFLICT))
def delete(self, request, id):
context = request.environ['tacker.context']
context.can(vnf_package_policies.VNFPKGM % 'delete')
@ -119,13 +120,18 @@ class VnfPkgmController(wsgi.Controller):
msg = _("Can not find requested vnf package: %s") % id
raise webob.exc.HTTPNotFound(explanation=msg)
if vnf_package.operational_state == \
fields.PackageUsageStateType.IN_USE:
msg = _("VNF Package %(id)s usage state is %(state)s")
if (vnf_package.operational_state ==
fields.PackageOperationalStateType.ENABLED or
vnf_package.usage_state ==
fields.PackageUsageStateType.IN_USE):
msg = _("VNF Package %(id)s cannot be deleted as it's "
"operational state is %(operational_state)s and usage "
"state is %(usage_state)s.")
raise webob.exc.HTTPConflict(
explanation=msg % {
"id": id,
"state": fields.PackageOperationalStateType.ENABLED})
"operational_state": vnf_package.operational_state,
"usage_state": vnf_package.usage_state})
# Delete vnf_package
self.rpc_api.delete_vnf_package(context, vnf_package)

View File

@ -22,6 +22,8 @@ from webob import exc
from tacker.api.vnfpkgm.v1 import controller
from tacker.conductor.conductorrpc.vnf_pkgm_rpc import VNFPackageRPCAPI
from tacker.glance_store import store as glance_store
from tacker import objects
from tacker.objects import fields
from tacker.objects import vnf_package
from tacker.objects.vnf_package import VnfPackagesList
from tacker.tests import constants
@ -121,6 +123,30 @@ class TestController(base.TestCase):
self.assertRaises(exc.HTTPNotFound, self.controller.delete,
req, constants.INVALID_UUID)
@mock.patch.object(objects.VnfPackage, "get_by_id")
def test_delete_with_operational_state_enabled(self, mock_vnf_by_id):
req = fake_request.HTTPRequest.blank(
'/vnfpkgm/v1/vnf_packages/%s' % constants.UUID)
vnf_package_dict = fakes.fake_vnf_package()
vnf_package_dict['operational_state'] = \
fields.PackageOperationalStateType.ENABLED
vnf_package = objects.VnfPackage(**vnf_package_dict)
mock_vnf_by_id.return_value = vnf_package
self.assertRaises(exc.HTTPConflict, self.controller.delete,
req, constants.UUID)
@mock.patch.object(vnf_package.VnfPackage, "get_by_id")
def test_delete_with_usage_state_in_use(self, mock_vnf_by_id):
req = fake_request.HTTPRequest.blank(
'/vnfpkgm/v1/vnf_packages/%s' % constants.UUID)
vnf_package_dict = fakes.fake_vnf_package()
vnf_package_dict['usage_state'] = \
fields.PackageUsageStateType.IN_USE
vnf_package = objects.VnfPackage(**vnf_package_dict)
mock_vnf_by_id.return_value = vnf_package
self.assertRaises(exc.HTTPConflict, self.controller.delete,
req, constants.UUID)
@mock.patch.object(glance_store, 'store_csar')
@mock.patch.object(VNFPackageRPCAPI, "upload_vnf_package_content")
@mock.patch.object(vnf_package.VnfPackage, "get_by_id")