update tests of test_ns_heal 65/66265/5
authortianxing <15210838572@139.com>
Thu, 13 Sep 2018 02:45:52 +0000 (10:45 +0800)
committerTian Xing <15210838572@139.com>
Mon, 17 Sep 2018 00:54:20 +0000 (00:54 +0000)
Change-Id: I62fe02b403eda35824a2075f4c9479a07ad7b752
Issue-ID: VFC-1116
Signed-off-by: tianxing <15210838572@139.com>
lcm/ns/tests/test_ns_heal.py

index 72d51f9..0707ebe 100644 (file)
@@ -75,6 +75,7 @@ class TestHealNsViews(TestCase):
 
     @mock.patch.object(NSHealService, 'run')
     def test_heal_vnf_url(self, mock_run):
+
         data = {
             "healVnfData": {
                 "vnfInstanceId": self.nf_inst_id,
@@ -83,6 +84,35 @@ class TestHealNsViews(TestCase):
                     "action": "restartvm",
                     "actionvminfo": {
                         "vmid": "33",
+                        "vduid": "",
+                        "vmname": "xgw-smp11"
+                    }
+                }
+            }
+        }
+
+        response = self.client.post("/api/nslcm/v1/ns/%s/heal" % self.ns_inst_id, data=data)
+        self.assertEqual(status.HTTP_202_ACCEPTED, response.status_code, response.data)
+        self.assertIsNotNone(response.data)
+        self.assertIn("jobId", response.data)
+        self.assertNotIn("error", response.data)
+
+        response = self.client.delete("/api/nslcm/v1/ns/%s" % self.ns_inst_id)
+        self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code)
+
+    # add healNsData
+    @mock.patch.object(NSHealService, 'run')
+    def test_heal_ns_url(self, mock_run):
+
+        data = {
+            "healNsData": {
+                "vnfInstanceId": self.nf_inst_id,
+                "cause": "",
+                "additionalParams": {
+                    "action": "vmreset",
+                    "actionvminfo": {
+                        "vmid": "33",
+                        "vduid": "",
                         "vmname": "xgw-smp11"
                     }
                 }
@@ -101,7 +131,7 @@ class TestHealNsViews(TestCase):
     @mock.patch.object(NFHealService, 'start')
     @mock.patch.object(NSHealService, 'wait_job_finish')
     @mock.patch.object(NSHealService, 'update_job')
-    def test_ns_manual_scale_thread(self, mock_start, mock_wait, mock_update):
+    def test_heal_vnf_thread(self, mock_start, mock_wait, mock_update):
 
         data = {
             "healVnfData": {
@@ -111,6 +141,31 @@ class TestHealNsViews(TestCase):
                     "action": "restartvm",
                     "actionvminfo": {
                         "vmid": "33",
+                        "vduid": "",
+                        "vmname": "xgw-smp11"
+                    }
+                }
+            }
+        }
+
+        NSHealService(self.ns_inst_id, data, self.job_id).run()
+        self.assertEqual(NSInstModel.objects.get(id=self.ns_inst_id).status, NS_INST_STATUS.HEALING)
+
+    # add healNsData
+    @mock.patch.object(NFHealService, 'start')
+    @mock.patch.object(NSHealService, 'wait_job_finish')
+    @mock.patch.object(NSHealService, 'update_job')
+    def test_heal_ns_thread(self, mock_start, mock_wait, mock_update):
+
+        data = {
+            "healNsData": {
+                "vnfInstanceId": self.nf_inst_id,
+                "cause": "",
+                "additionalParams": {
+                    "action": "vmreset",
+                    "actionvminfo": {
+                        "vmid": "33",
+                        "vduid": "",
                         "vmname": "xgw-smp11"
                     }
                 }
@@ -121,7 +176,7 @@ class TestHealNsViews(TestCase):
         self.assertEqual(NSInstModel.objects.get(id=self.ns_inst_id).status, NS_INST_STATUS.HEALING)
 
     @mock.patch.object(NSHealService, "start")
-    def test_ns_heal_non_existing_ns(self, mock_start):
+    def test_heal_vnf_non_existing_ns(self, mock_start):
         mock_start.side_effect = NSLCMException("NS Not Found")
 
         ns_inst_id = "2"
@@ -145,8 +200,35 @@ class TestHealNsViews(TestCase):
         self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
         self.assertIn("error", response.data)
 
+    # add healNsData
+    @mock.patch.object(NSHealService, "start")
+    def test_heal_ns_heal_non_existing_ns(self, mock_start):
+        mock_start.side_effect = NSLCMException("NS Not Found")
+
+        ns_inst_id = "2"
+
+        data = {
+            "healNsData": {
+                "vnfInstanceId": self.nf_inst_id,
+                "cause": "",
+                "additionalParams": {
+                    "action": "vmreset",
+                    "actionvminfo": {
+                        "vmid": "33",
+                        "vduid": "",
+                        "vmname": "xgw-smp11"
+                    }
+                }
+            }
+        }
+
+        response = self.client.post("/api/nslcm/v1/ns/%s/heal" % ns_inst_id, data=data)
+        self.assertEqual(response.data["error"], "NS Not Found")
+        self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
+        self.assertIn("error", response.data)
+
     @mock.patch.object(NSHealService, "start")
-    def test_ns_heal_empty_post(self, mock_start):
+    def test_heal_vnf_empty_post(self, mock_start):
         mock_start.side_effect = NSLCMException("healVnfData parameter does not exist or value is incorrect.")
 
         data = {}