1 # Copyright 2016 ZTE 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.
16 from test_data import nsd_model, vnfd_model_dict1, vnfd_model_dict2
17 from rest_framework import status
18 from lcm.pub.utils import restcall
19 from lcm.pub.database.models import FPInstModel, NfInstModel
20 from django.test import Client
21 from django.test import TestCase
24 class TestSfc(TestCase):
26 self.client = Client()
27 FPInstModel.objects.all().delete()
28 NfInstModel.objects.all().delete()
30 nfinstid="vnf_inst_1",
31 ns_inst_id="ns_inst_1",
33 vnfd_model=json.dumps(vnfd_model_dict1)).save()
35 nfinstid="vnf_inst_2",
37 ns_inst_id="ns_inst_1",
38 vnfd_model=json.dumps(vnfd_model_dict2)).save()
43 vnffginstid="vnffg_inst_1",
47 "dest_port_range": [80, 1024],
48 "source_port_range": [80, 1024],
50 "dest_ip_range": ["192.168.1.2", "192.168.1.100"],
51 "source_ip_range": ["192.168.1.2", "192.168.1.100"],
56 sdncontrollerid="sdn_controller_1"
60 FPInstModel.objects.all().delete()
61 NfInstModel.objects.all().delete()
63 @mock.patch.object(restcall, 'call_req')
64 def test_create_port_pair_group_success(self, mock_call_req):
66 "nsinstanceid": "ns_inst_1",
67 "fpinstid": "fp_inst_1",
68 "context": json.dumps(nsd_model)
71 "/external-system/esr-thirdparty-sdnc-list/esr-thirdparty-sdnc/sdn_controller_1?depth=all":
72 [0, json.JSONEncoder().encode({
73 "thirdparty-sdnc-id": "1",
74 "esr-system-info-list": {
76 "service-url": "url_1",
77 "thirdparty-sdnc-id": "1",
83 "product-name": "bbb",
88 "/api/ztesdncdriver/v1/createportpair":
89 [0, json.JSONEncoder().encode({"id": "createportpair_id"}), '200'],
90 "/api/ztesdncdriver/v1/createportpairgroup":
91 [0, json.JSONEncoder().encode({"id": "createportpairgroup_id"}), '200'],
92 "/api/microservices/v1/services":
96 def side_effect(*args):
97 return mock_vals[args[4]]
99 mock_call_req.side_effect = side_effect
100 resp = self.client.post("/api/nslcm/v1/ns/create_port_pair_group", data)
101 rest = json.loads(FPInstModel.objects.get(fpinstid="fp_inst_1").portpairgroups)[0]
102 self.assertEqual(resp.status_code, status.HTTP_200_OK)
103 self.assertEqual("createportpairgroup_id", rest["groupid"])