Add ut cases for heal vnf 13/85013/1
authorfujinhua <fu.jinhua@zte.com.cn>
Thu, 11 Apr 2019 06:40:00 +0000 (14:40 +0800)
committerfujinhua <fu.jinhua@zte.com.cn>
Thu, 11 Apr 2019 06:40:00 +0000 (14:40 +0800)
Change-Id: I8cded9c137443c80a9f224262a1d3635561cc3a1
Issue-ID: VFC-1306
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
lcm/lcm/nf/tests/test_heal_vnf.py
lcm/lcm/nf/views/heal_vnf_view.py

index 17f3e5e..14743b2 100644 (file)
@@ -54,6 +54,16 @@ class TestNFInstantiate(TestCase):
         response = self.client.post("/api/vnflcm/v1/vnf_instances/12/heal", data=req_data, format='json')\r
         self.failUnlessEqual(status.HTTP_404_NOT_FOUND, response.status_code)\r
 \r
+    def test_heal_vnf_conflict(self):\r
+        req_data = {}\r
+        NfInstModel(\r
+            nfinstid='1267',\r
+            nf_name='VNF1',\r
+            status='NOT_INSTANTIATED').save()\r
+        response = self.client.post("/api/vnflcm/v1/vnf_instances/1267/heal", data=req_data, format='json')\r
+        self.failUnlessEqual(status.HTTP_409_CONFLICT, response.status_code)\r
+        NfInstModel.objects.filter(nfinstid='1267').delete()\r
+\r
     @mock.patch.object(HealVnf, 'run')\r
     def test_heal_vnf_success(self, mock_run):\r
         req_data = {}\r
index 4fe3f84..24b33e3 100644 (file)
@@ -22,7 +22,9 @@ from rest_framework.views import APIView
 from lcm.nf.biz.heal_vnf import HealVnf\r
 from lcm.nf.serializers.heal_vnf_req import HealVnfRequestSerializer\r
 from lcm.nf.serializers.response import ProblemDetailsSerializer\r
-from lcm.pub.exceptions import NFLCMException, NFLCMExceptionNotFound\r
+from lcm.pub.exceptions import NFLCMException\r
+from lcm.pub.exceptions import NFLCMExceptionNotFound\r
+from lcm.pub.exceptions import NFLCMExceptionConflict\r
 from lcm.pub.utils.jobutil import JobUtil\r
 from lcm.pub.database.models import NfInstModel\r
 from lcm.nf.const import VNF_STATUS\r
@@ -63,6 +65,9 @@ class HealVnfView(APIView):
         if not vnf_insts.exists():\r
             raise NFLCMExceptionNotFound("VNF nf_inst_id does not exist.")\r
 \r
+        if vnf_insts[0].status != 'INSTANTIATED':\r
+            raise NFLCMExceptionConflict("VNF instantiationState is not INSTANTIATED.")\r
+\r
         NfInstModel.objects.filter(nfinstid=nf_inst_id).update(status=VNF_STATUS.HEALING)\r
         JobUtil.add_job_status(job_id, 15, 'Nf healing pre-check finish')\r
         logger.info("Nf healing pre-check finish")\r