Implemented terminate vnf instance API. * GET /vnflcm/v1/vnf_instances/{vnf_instance_id}/terminate Co-Authored-By: tpatil <tushar.vitthal.patil@gmail.com> Co-Authored-By: Shubham Potale <shubham.potale@nttdata.com> Co-Authored-By: Sameer Thakur <sameer.thakur@nttdata.com> Change-Id: I69b7ef12038aa410db7e50671df2931beb761223 Blueprint: support-etsi-nfv-specschanges/05/707805/36
parent
19ff0032f0
commit
fbb38266d6
@ -0,0 +1,54 @@
|
||||
# Copyright (C) 2020 NTT DATA
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oslo_log import log as logging
|
||||
|
||||
from tacker.objects import base
|
||||
from tacker.objects import fields
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@base.TackerObjectRegistry.register
|
||||
class TerminateVnfRequest(base.TackerObject, base.TackerPersistentObject):
|
||||
# Version 1.0: Initial version
|
||||
VERSION = '1.0'
|
||||
|
||||
fields = {
|
||||
'termination_type': fields.VnfInstanceTerminationTypeField(
|
||||
nullable=False),
|
||||
'graceful_termination_timeout': fields.IntegerField(nullable=True,
|
||||
default=0)
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def obj_from_primitive(cls, primitive, context):
|
||||
if 'tacker_object.name' in primitive:
|
||||
obj_terminate_vnf_req = super(
|
||||
TerminateVnfRequest, cls).obj_from_primitive(
|
||||
primitive, context)
|
||||
else:
|
||||
obj_terminate_vnf_req = TerminateVnfRequest._from_dict(primitive)
|
||||
|
||||
return obj_terminate_vnf_req
|
||||
|
||||
@classmethod
|
||||
def _from_dict(cls, data_dict):
|
||||
termination_type = data_dict.get('termination_type')
|
||||
graceful_termination_timeout = \
|
||||
data_dict.get('graceful_termination_timeout', 0)
|
||||
|
||||
return cls(termination_type=termination_type,
|
||||
graceful_termination_timeout=graceful_termination_timeout)
|
@ -0,0 +1,51 @@
|
||||
# Copyright (C) 2020 NTT DATA
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from tacker import context
|
||||
from tacker import objects
|
||||
from tacker.tests.unit.db.base import SqlTestCase
|
||||
|
||||
|
||||
class TestTerminateVnfRequest(SqlTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestTerminateVnfRequest, self).setUp()
|
||||
self.context = context.get_admin_context()
|
||||
|
||||
def _get_terminate_vnf_request(self):
|
||||
terminate_vnf_request = {
|
||||
'termination_type': 'GRACEFUL',
|
||||
'graceful_termination_timeout': 10
|
||||
}
|
||||
return terminate_vnf_request
|
||||
|
||||
def test_obj_from_primitive(self):
|
||||
terminate_vnf_request = self._get_terminate_vnf_request()
|
||||
result = objects.TerminateVnfRequest.obj_from_primitive(
|
||||
terminate_vnf_request, self.context)
|
||||
self.assertTrue(isinstance(result, objects.TerminateVnfRequest))
|
||||
self.assertEqual('GRACEFUL', result.termination_type)
|
||||
self.assertEqual(terminate_vnf_request['graceful_termination_timeout'],
|
||||
result.graceful_termination_timeout)
|
||||
|
||||
def test_obj_from_primitive_without_timeout(self):
|
||||
terminate_vnf_request = self._get_terminate_vnf_request()
|
||||
terminate_vnf_request.pop('graceful_termination_timeout')
|
||||
|
||||
result = objects.TerminateVnfRequest.obj_from_primitive(
|
||||
terminate_vnf_request, self.context)
|
||||
self.assertTrue(isinstance(result, objects.TerminateVnfRequest))
|
||||
self.assertEqual('GRACEFUL', result.termination_type)
|
||||
self.assertEqual(0, result.graceful_termination_timeout)
|
Loading…
Reference in new issue