diff options
author | fujinhua <fu.jinhua@zte.com.cn> | 2018-08-10 14:08:08 +0800 |
---|---|---|
committer | fujinhua <fu.jinhua@zte.com.cn> | 2018-08-10 14:27:20 +0800 |
commit | f574b8d4c2a830520a6f15232a88a4862ddc3b5d (patch) | |
tree | dd592d1cc3d16f291df884f95037c7318c4c992f | |
parent | 3c3dec8119189a5cedf58948ab1de1cc33be5f73 (diff) |
Add unit test for ns instantiate
Change-Id: I9423cd90fed4ea9f73a4c7e4225e7b55c0fff2ef
Issue-ID: VFC-1009
Signed-off-by: fujinhua <fu.jinhua@zte.com.cn>
-rw-r--r-- | lcm/ns/ns_instant.py | 8 | ||||
-rw-r--r-- | lcm/ns/tests/test_ns_instant.py | 26 |
2 files changed, 22 insertions, 12 deletions
diff --git a/lcm/ns/ns_instant.py b/lcm/ns/ns_instant.py index b10b9c12..698e77e2 100644 --- a/lcm/ns/ns_instant.py +++ b/lcm/ns/ns_instant.py @@ -104,7 +104,7 @@ class InstantNSService(object): vnf_params_json = json.JSONEncoder().encode(params_vnf) plan_input = { 'jobId': job_id, - 'nsInstanceId': self.req_data["nsInstanceId"], + 'nsInstanceId': self.ns_inst_id, 'object_context': dst_plan, 'object_additionalParamForNs': params_json, 'object_additionalParamForVnf': vnf_params_json @@ -191,7 +191,8 @@ class InstantNSService(object): BuildInWorkflowThread(plan_input).start() return dict(data={'jobId': job_id}, status=status.HTTP_200_OK) - def get_vnf_vim_id(self, vim_id, location_constraints, vnfdid): + @staticmethod + def get_vnf_vim_id(vim_id, location_constraints, vnfdid): for location in location_constraints: if "vnfProfileId" in location and vnfdid == location["vnfProfileId"]: return location["locationConstraints"]["vimId"] @@ -199,7 +200,8 @@ class InstantNSService(object): return vim_id raise NSLCMException("No Vim info is found for vnf(%s)." % vnfdid) - def set_vl_vim_id(self, vim_id, location_constraints, plan_dict): + @staticmethod + def set_vl_vim_id(vim_id, location_constraints, plan_dict): if "vls" not in plan_dict: logger.debug("No vl is found in nsd.") return diff --git a/lcm/ns/tests/test_ns_instant.py b/lcm/ns/tests/test_ns_instant.py index bd84c035..f4df1075 100644 --- a/lcm/ns/tests/test_ns_instant.py +++ b/lcm/ns/tests/test_ns_instant.py @@ -19,27 +19,35 @@ import mock from lcm.pub.database.models import NSInstModel from lcm.ns.ns_instant import InstantNSService +from lcm.pub.utils import restcall class TestNsInstant(TestCase): def setUp(self): self.client = Client() NSInstModel.objects.filter().delete() - self.ns_inst_id = "2" + self.url = "/api/nslcm/v1/ns/2/instantiate" + self.req_data = { + "additionalParamForNs": { + "location": "1", + "sdnControllerId": "2" + } + } NSInstModel(id="2", nspackage_id="7", nsd_id="2").save() def tearDown(self): pass @mock.patch.object(InstantNSService, 'do_biz') - def testNsInstantNormal(self, mock_do_biz): + def test_ns_instantiate_normal(self, mock_do_biz): mock_do_biz.return_value = dict(data={'jobId': "1"}, status=status.HTTP_200_OK) - data = { - "additionalParamForNs": { - "location": "1", - "sdnControllerId": "2" - } - } - resp = self.client.post("/api/nslcm/v1/ns/%s/instantiate" % self.ns_inst_id, data=data) + resp = self.client.post(self.url, data=self.req_data) self.failUnlessEqual(status.HTTP_200_OK, resp.status_code) self.assertEqual({'jobId': "1"}, resp.data) + + @mock.patch.object(restcall, 'call_req') + def test_ns_instantiate_when_fail_to_parse_nsd(self, mock_call_req): + mock_call_req.return_value = [1, "Failed to parse nsd", '500'] + resp = self.client.post(self.url, data=self.req_data) + self.assertEqual(resp.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR) + self.assertIn("error", resp.data) |