1 # Copyright 2017 Intel 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 rest_framework import status
18 from django.test import TestCase
19 from django.test import Client
20 from lcm.pub.database.models import NSDModel, NSInstModel
21 from lcm.pub.utils.jobutil import JobUtil, JOB_TYPE
22 from lcm.ns.const import NS_INST_STATUS
23 from lcm.pub.utils import restcall
24 from lcm.ns.ns_heal import NSHealService
27 class TestHealNsViews(TestCase):
29 self.nsd_id = str(uuid.uuid4())
30 self.ns_package_id = str(uuid.uuid4())
31 self.ns_inst_id = str(uuid.uuid4())
32 self.job_id = JobUtil.create_job("NS", JOB_TYPE.HEAL_VNF, self.ns_inst_id)
33 NSDModel(id=self.ns_package_id, nsd_id=self.nsd_id, name='name').save()
35 self.client = Client()
36 self.context = '{"vnfs": ["a", "b"], "sfcs": ["c"], "vls": ["d", "e", "f"]}'
37 NSInstModel(id=self.ns_inst_id, name="abc", nspackage_id="7", nsd_id="111").save()
40 NSInstModel.objects.filter().delete()
42 @mock.patch.object(NSHealService, 'run')
43 def test_ns_heal(self, mock_run):
47 'description': 'description'}
48 response = self.client.post("/api/nslcm/v1/ns/%s/heal" % self.nsd_id, data=data)
49 self.failUnlessEqual(status.HTTP_202_ACCEPTED, response.status_code)
51 @mock.patch.object(restcall, 'call_req')
52 def test_ns_heal_thread(self, mock_call):
57 'description': 'description'
60 NSHealService(self.ns_inst_id, data, self.job_id).run()
61 self.assertEqual(NSInstModel.objects.get(id=self.ns_inst_id).status, NS_INST_STATUS.HEALING)
63 def test_swagger_ok(self):
64 resp = self.client.get("/api/nslcm/v1/swagger.json", format='json')
65 self.assertEqual(resp.status_code, status.HTTP_200_OK)