1 # Copyright (C) 2018 Verizon. All Rights Reserved
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.
17 from django.test import TestCase, Client
18 from rest_framework import status
20 from lcm.pub.database.models import VNFLcmOpOccModel
23 class TestVNFLcmOpOccs(TestCase):
25 self.client = Client()
26 self.vnf_lcm_op_occ_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
27 VNFLcmOpOccModel.objects.all().delete()
28 self.test_single_vnf_lcm_op = {
29 "id": "99442b18-a5c7-11e8-998c-bf1755941f16",
30 "operationState": "STARTING",
31 "stateEnteredTime": "2018-07-09",
32 "startTime": "2018-07-09",
33 "vnfInstanceId": "cd552c9c-ab6f-11e8-b354-236c32aa91a1",
36 "isAutomaticInvocation": False,
37 "operationParams": {},
38 "isCancelPending": False,
41 "resourceChanges": None,
43 "changedExtConnectivity": None,
51 self.test_vnflcmop_with_exclude_default = [{
52 "id": "99442b18-a5c7-11e8-998c-bf1755941f16",
53 "operationState": "STARTING",
54 "stateEnteredTime": "2018-07-09",
55 "startTime": "2018-07-09",
56 "vnfInstanceId": "cd552c9c-ab6f-11e8-b354-236c32aa91a1",
59 "isAutomaticInvocation": False,
60 "isCancelPending": False,
70 self.test_multiple_vnf_lcm_op = [{
71 "id": "a6b9415c-ab99-11e8-9d37-dbb5e0378955",
72 "operationState": "STARTING",
73 "stateEnteredTime": "2018-07-09",
74 "startTime": "2018-07-09",
75 "vnfInstanceId": "cd552c9c-ab6f-11e8-b354-236c32aa91a1",
77 "operation": "INSTANTIATE",
78 "isAutomaticInvocation": False,
79 "operationParams": {},
80 "isCancelPending": False,
83 "resourceChanges": None,
85 "changedExtConnectivity": None,
93 self.test_multiple_vnf_lcm_op.append(
94 self.test_single_vnf_lcm_op)
99 def test_get_vnflcmopoccs(self):
100 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
101 vnf_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
102 VNFLcmOpOccModel(id=lcm_op_id, operation_state="STARTING",
103 state_entered_time="2018-07-09", start_time="2018-07-09",
104 vnf_instance_id=vnf_instance_id,
105 grant_id=None, operation="SCALE", is_automatic_invocation=False,
106 operation_params='{}', is_cancel_pending=False, cancel_mode=None,
107 error=None, resource_changes=None, changed_ext_connectivity=None,
108 links=json.dumps({"self": {"href": "demo"}, "vnfInstance": "demo"})).save()
109 response = self.client.get("/api/vnflcm/v1/vnf_lcm_op_occs", format='json')
110 self.assertEqual(response.status_code, status.HTTP_200_OK)
111 self.assertEqual([self.test_single_vnf_lcm_op], response.data)
113 def test_get_vnflcmopoccs_with_id_not_exist(self):
114 response = self.client.get("/api/vnflcm/v1/vnf_lcm_op_occs?id=dummy", format='json')
115 self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
118 "detail": "LCM Operation Occurances do not exist"
120 self.assertEqual(expected_data, response.data)
122 def test_get_vnflcmopoccs_with_filters(self):
123 lcm_op_id = "a6b9415c-ab99-11e8-9d37-dbb5e0378955"
124 vnf_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
125 VNFLcmOpOccModel(id=lcm_op_id, operation_state="STARTING",
126 state_entered_time="2018-07-09", start_time="2018-07-09",
127 vnf_instance_id=vnf_instance_id,
128 grant_id=None, operation="INSTANTIATE", is_automatic_invocation=False,
129 operation_params='{}', is_cancel_pending=False, cancel_mode=None,
130 error=None, resource_changes=None, changed_ext_connectivity=None,
131 links=json.dumps({"self": {"href": "demo"}, "vnfInstance": "demo"})).save()
133 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
134 VNFLcmOpOccModel(id=lcm_op_id, operation_state="STARTING",
135 state_entered_time="2018-07-09", start_time="2018-07-09",
136 vnf_instance_id=vnf_instance_id,
137 grant_id=None, operation="SCALE", is_automatic_invocation=False,
138 operation_params='{}', is_cancel_pending=False, cancel_mode=None,
139 error=None, resource_changes=None, changed_ext_connectivity=None,
140 links=json.dumps({"self": {"href": "demo"}, "vnfInstance": "demo"})).save()
141 response = self.client.get("/api/vnflcm/v1/vnf_lcm_op_occs", format='json')
142 self.assertEqual(response.status_code, status.HTTP_200_OK)
143 self.assertEqual(self.test_multiple_vnf_lcm_op, response.data)
145 response = self.client.get("/api/vnflcm/v1/vnf_lcm_op_occs?operation=SCALE", format='json')
146 self.assertEqual(response.status_code, status.HTTP_200_OK)
147 self.assertEqual([self.test_single_vnf_lcm_op], response.data)
149 response = self.client.get("/api/vnflcm/v1/vnf_lcm_op_occs?vnfInstanceId=%s" % vnf_instance_id, format='json')
150 self.assertEqual(response.status_code, status.HTTP_200_OK)
151 self.assertEqual(self.test_multiple_vnf_lcm_op, response.data)
153 def test_get_vnflcmopoccs_with_extra_flags(self):
154 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
155 vnf_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
156 VNFLcmOpOccModel(id=lcm_op_id, operation_state="STARTING",
157 state_entered_time="2018-07-09", start_time="2018-07-09",
158 vnf_instance_id=vnf_instance_id,
159 grant_id=None, operation="SCALE", is_automatic_invocation=False,
160 operation_params='{}', is_cancel_pending=False, cancel_mode=None,
161 error=None, resource_changes=None, changed_ext_connectivity=None,
162 links=json.dumps({"self": {"href": "demo"}, "vnfInstance": "demo"})).save()
163 response = self.client.get("/api/vnflcm/v1/vnf_lcm_op_occs?exclude_default", format='json')
164 self.assertEqual(response.status_code, status.HTTP_200_OK)
165 self.assertEqual(self.test_vnflcmop_with_exclude_default, response.data)
167 def test_get_vnflcmopocc_with_id(self):
168 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
169 vnf_instance_id = "cd552c9c-ab6f-11e8-b354-236c32aa91a1"
170 VNFLcmOpOccModel(id=lcm_op_id, operation_state="STARTING",
171 state_entered_time="2018-07-09", start_time="2018-07-09",
172 vnf_instance_id=vnf_instance_id,
173 grant_id=None, operation="SCALE", is_automatic_invocation=False,
174 operation_params='{}', is_cancel_pending=False, cancel_mode=None,
175 error=None, resource_changes=None, changed_ext_connectivity=None,
176 links=json.dumps({"self": {"href": "demo"}, "vnfInstance": "demo"})).save()
177 response = self.client.get("/api/vnflcm/v1/vnf_lcm_op_occs/" + lcm_op_id, format='json')
178 self.assertEqual(response.status_code, status.HTTP_200_OK)
179 self.assertEqual(self.test_single_vnf_lcm_op, response.data)
181 def test_single_vnflcmopocc_with_unknown_id(self):
182 lcm_op_id = "99442b18-a5c7-11e8-998c-bf1755941f16"
183 response = self.client.get("/api/vnflcm/v1/vnf_lcm_op_occs/" + lcm_op_id, format='json')
184 self.assertEqual(response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
187 "detail": "LCM Operation Occurance does not exist"
189 self.assertEqual(expected_data, response.data)