aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortianxing <15210838572@139.com>2018-09-13 10:45:52 +0800
committerTian Xing <15210838572@139.com>2018-09-17 00:54:20 +0000
commitc1fe81ad4d177358243407ca9feabea8cfbec1aa (patch)
treeb448a25065039ee13d9e77bc385972ec8b3ddd55
parentdbfe80a42cb1dd4724834c612556ac3a0f23e59f (diff)
update tests of test_ns_heal
Change-Id: I62fe02b403eda35824a2075f4c9479a07ad7b752 Issue-ID: VFC-1116 Signed-off-by: tianxing <15210838572@139.com>
-rw-r--r--lcm/ns/tests/test_ns_heal.py88
1 files changed, 85 insertions, 3 deletions
diff --git a/lcm/ns/tests/test_ns_heal.py b/lcm/ns/tests/test_ns_heal.py
index 72d51f96..0707ebe1 100644
--- a/lcm/ns/tests/test_ns_heal.py
+++ b/lcm/ns/tests/test_ns_heal.py
@@ -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 = {}