1 # Copyright 2019 ZTE Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
17 from django.test import TestCase, Client
18 from rest_framework import status
20 from lcm.ns.biz.ns_terminate import TerminateNsService
21 from lcm.pub.database.models import NfInstModel, NSInstModel
24 class TestTerminateNsApi(TestCase):
26 self.client = Client()
27 self.url = "/api/nslcm/v1/ns_instances/%s/terminate"
30 self.vnffg_id = str(uuid.uuid4())
31 self.vim_id = str(uuid.uuid4())
32 self.job_id = str(uuid.uuid4())
33 self.nf_uuid = '1-1-1'
34 self.tenant = "tenantname"
35 model = {"metadata": {
39 "vnfdVersion": "V00001",
40 "vnfVersion": "V5.10.20",
43 "description": "PGW VNFD description",
45 "vnfExtendType": "driver"
47 NSInstModel(id=self.ns_inst_id, name="ns_name", status='null').save()
48 NfInstModel.objects.create(nfinstid=self.nf_inst_id, nf_name='name_1', vnf_id='1',
49 vnfm_inst_id='1', ns_inst_id='1-1-1,2-2-2',
50 max_cpu='14', max_ram='12296', max_hd='101', max_shd="20", max_net=10,
51 status='null', mnfinstid=self.nf_uuid, package_id='pkg1',
52 vnfd_model=str(model))
55 NSInstModel.objects.all().delete()
56 NfInstModel.objects.all().delete()
58 @mock.patch.object(TerminateNsService, 'run')
59 def test_terminate_vnf(self, mock_run):
60 mock_run.re.return_value = "1"
61 req_data = {"terminationTime": "2019-03-25T09:10:35.610"}
62 response = self.client.post(self.url % self.ns_inst_id, data=req_data)
63 self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
64 self.assertIsNotNone(response['Location'])
66 def test_method_not_allowed(self):
67 response = self.client.put(self.url % '1', data={}, format='json')
68 self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code)
69 response = self.client.patch(self.url % '1', data={}, format='json')
70 self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code)
71 response = self.client.delete(self.url % '1', data={}, format='json')
72 self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code)
73 response = self.client.get(self.url % '1', data={}, format='json')
74 self.failUnlessEqual(status.HTTP_405_METHOD_NOT_ALLOWED, response.status_code)