Add test cases of vnf notify
[vfc/nfvo/lcm.git] / lcm / v2 / tests.py
1 # Copyright 2018 ZTE Corporation.
2 #
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
6 #
7 #         http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 import unittest
16 import json
17 from django.test import Client
18 from rest_framework import status
19
20
21 class VnfGrantViewTest(unittest.TestCase):
22     def setUp(self):
23         self.client = Client()
24
25     def tearDown(self):
26         pass
27
28     def test_grant_vnf_normal(self):
29         data = {
30             "vnfInstanceId": "1",
31             "vnfLcmOpOccId": "2",
32             "vnfdId": "3",
33             "flavourId": "4",
34             "operation": "INSTANTIATE",
35             "isAutomaticInvocation": True,
36             "instantiationLevelId": "5",
37             "addResources": [
38                 {
39                     "id": "1",
40                     "type": "COMPUTE",
41                     "vduId": "2",
42                     "resourceTemplateId": "3",
43                     "resource": {
44                         "vimConnectionId": "4",
45                         "resourceProviderId": "5",
46                         "resourceId": "6",
47                         "vimLevelResourceType": "7"
48                     }
49                 }
50             ],
51             "placementConstraints": [
52                 {
53                     "affinityOrAntiAffinity": "AFFINITY",
54                     "scope": "NFVI_POP",
55                     "resource": [
56                         {
57                             "idType": "RES_MGMT",
58                             "resourceId": "1",
59                             "vimConnectionId": "2",
60                             "resourceProviderId": "3"
61                         }
62                     ]
63                 }
64             ],
65             "vimConstraints": [
66                 {
67                     "sameResourceGroup": True,
68                     "resource": [
69                         {
70                             "idType": "RES_MGMT",
71                             "resourceId": "1",
72                             "vimConnectionId": "2",
73                             "resourceProviderId": "3"
74                         }
75                     ]
76                 }
77             ],
78             "additionalParams": {},
79             "_links": {
80                 "vnfLcmOpOcc": {
81                     "href": "1"
82                 },
83                 "vnfInstance": {
84                     "href": "2"
85                 }
86             }
87         }
88         response = self.client.post("/api/nslcm/v2/grants", data=data, format='json')
89         self.assertEqual(status.HTTP_201_CREATED, response.status_code, response.content)
90         resp_data = json.loads(response.content)
91         expect_resp_data = {
92             "id": resp_data.get("id"),
93             "vnfInstanceId": "1",
94             "vnfLcmOpOccId": "2"
95         }
96         self.assertEqual(expect_resp_data, resp_data)
97
98     def test_get_notify_vnf_normal(self):
99         response = self.client.get("/api/nslcm/v2/ns/1/vnfs/1/Notify")
100         self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code, response.content)
101
102     def test_notify_vnf_normal(self):
103         data = {
104             "id": "string",
105             "notificationType": "string",
106             "subscriptionId": "string",
107             "timeStamp": "string",
108             "notificationStatus": "START",
109             "operationState": "STARTING",
110             "vnfInstanceId": "string",
111             "operation": "INSTANTIATE",
112             "isAutomaticInvocation": True,
113             "vnfLcmOpOccId": "string",
114             "affectedVnfcs": [{
115                 "vnfcInstanceId": "string",
116                 "vduId": "string",
117                 "changeType": "added",
118                 "vimId": "string",
119                 "vmId": "string",
120                 "vmName": "string"
121             }],
122             "affectedVirtualLinks": [{
123                 "vlInstanceId": "string",
124                 "vldId": "string",
125                 "changeType": "added",
126                 "networkResource": {
127                     "resourceType": "network",
128                     "resourceId": "string",
129                     "resourceName": "string"
130                 }
131             }],
132             "affectedVirtualStorages": [{}],
133             "changedInfo": {
134                 "vnfInstanceName": "string",
135                 "vnfInstanceDescription": "string",
136                 "vnfConfigurableProperties": {
137                     "additionalProp1": "string",
138                     "additionalProp2": "string",
139                     "additionalProp3": "string"
140                 },
141                 "metadata": {
142                     "additionalProp1": "string",
143                     "additionalProp2": "string",
144                     "additionalProp3": "string"
145                 },
146                 "extensions": {
147                     "additionalProp1": "string",
148                     "additionalProp2": "string",
149                     "additionalProp3": "string"
150                 },
151                 "vimConnectionInfo": [{
152                     "id": "string",
153                     "vimId": "string",
154                     "vimType": "string",
155                     "interfaceInfo": {
156                         "additionalProp1": "string",
157                         "additionalProp2": "string",
158                         "additionalProp3": "string"
159                     },
160                     "accessInfo": {
161                         "additionalProp1": "string",
162                         "additionalProp2": "string",
163                         "additionalProp3": "string"
164                     },
165                     "extra": {
166                         "additionalProp1": "string",
167                         "additionalProp2": "string",
168                         "additionalProp3": "string"
169                     }
170                 }],
171                 "vnfPkgId": "string",
172                 "vnfdId": "string",
173                 "vnfProvider": "string",
174                 "vnfProductName": "string",
175                 "vnfSoftwareVersion": "string",
176                 "vnfdVersion": "string"
177             },
178             "changedExtConnectivity": [{
179                 "id": "string",
180                 "resourceHandle": {
181                     "vimConnectionId": "string",
182                     "resourceProviderId": "string",
183                     "resourceId": "string",
184                     "vimLevelResourceType": "string"
185                 },
186                 "extLinkPorts": [{
187                     "id": "string",
188                     "resourceHandle": {
189                         "vimConnectionId": "string",
190                         "resourceProviderId": "string",
191                         "resourceId": "string",
192                         "vimLevelResourceType": "string"
193                     },
194                     "cpInstanceId": "string"
195                 }]
196             }],
197             "error": {
198                 "type": "string",
199                 "title": "string",
200                 "status": 0,
201                 "detail": "string",
202                 "instance": "string"
203             },
204             "_links": {
205                 "vnfInstance": {
206                     "href": "string"
207                 },
208                 "subscription": {
209                     "href": "string"
210                 },
211                 "vnfLcmOpOcc": {
212                     "href": "string"
213                 }
214             }
215         }
216         response = self.client.post("/api/nslcm/v2/ns/1/vnfs/2/Notify", data=data, format='json')
217         self.assertEqual(status.HTTP_204_NO_CONTENT, response.status_code, response.content)