-
Notifications
You must be signed in to change notification settings - Fork 0
/
orchestrator_tests.py
297 lines (272 loc) · 9.59 KB
/
orchestrator_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""Anella 4.0 Orchestrator Tests"""
from start import PORT, URL_PREFIX
import json
import unittest
import requests
import random
import time
import ConfigParser
CONFIG = ConfigParser.RawConfigParser()
CONFIG.read('config.cfg')
POP_ID = int(CONFIG.get('tenor','i2cat_pop'))
BASE_URL = 'http://localhost:{0}{1}'.format(PORT, URL_PREFIX)
OVNFD_EXAMPLE = {
"name": "omupi",
"vdu":
{
"vm_image": "52f07518-3b32-4dfa-b067-2b0f53ceb0e1",
"vm_image_format": "OpenstacK_id",
"shell": "#!/bin/bash\\necho 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCTyrMs/iliz2PPAGACyGWwC7OqoIDgoStpiiXcJIAElaLiiAhlOdhCJP6okE2WzkuMf4XD80fVm/yikrjSRTVwph981KEEcAH+mRWThkoItaPqDLPh79AJfT1Ud48FQbG8MZu91X+E4ecnYQH/1bPRxiumWQLNrHmIhY8aIKv/xPCF8zZBYjG6BK/g2L22h4Ky6VI07uyzHyIk78OxUZTpQcb+jnFpJlVOZreRLc8RE6pDF17h4ZhrEmv0tvdWiubk46cbEUwOvGq9wWxFKReEQubC+7/2WNcQnkAylDxzbR9pF/RlomuwcBWSycQ8RVpmr8T1cydaBpi9cbBB2DOn alfonso@knightmare' >> /root/.ssh/authorized_keys",
"storage_amount": 6,
"flavor": "m1.medium",
"vcpus": 1
}
}
CATALOG_EXAMPLE = {
"context" : {
"runtime_params" : [
{
"name" : "wwwwww",
"desc" : "sssssss"
}
],
"name_image" : "OMPUPI40",
"tenor_url" : "http://localhost:4000",
"vm_image": "52f07518-3b32-4dfa-b067-2b0f53ceb0e1",
"vm_image_format": "openstack_id",
"flavor" : "m1.medium",
"consumer_params" : [
{
"path" : "/var/www/html/index.html",
"fields" : [
{
"required" : True,
"name" : "name",
"desc" : "Name of the consumer",
"value" : "rEpO"
},
{
"required" : True,
"name" : "picture",
"desc" : "Foto del consumer",
"value" : "https://upload.wikimedia.org/wikipedia/commons/c/ce/Documents_stacks_in_a_repository_at_The_National_Archives.jpg"
},
{
"required" : True,
"name" : "cv",
"desc" : "CV del consumer",
"value" : "Para guardar imágenes en /var/www/html/"
}
]
},
{
"path" : "/root/chequeo.txt",
"content" : "YO ESTUVE AQUI!!!!!!!!!!!!!!!!!!!!!!!!!"
}
]
}
}
ADAM_EXAMPLE = {
"context" : {
"runtime_params" : [
{
"name" : "wwwwww",
"desc" : "sssssss"
}
],
"public_network_id" : "71257860-3085-40bb-b009-5f12c688cdfb",
"name_image" : "LuNESs",
"pop_id": 21,
"vm_image_format" : "openstack_id",
"tenor_url" : "http://localhost:4000",
"vm_image" : "5d4fdb85-3e7a-4e92-be67-72214a61275d",
"flavor" : "VM.M1",
"consumer_params" : [
{
"path" : "/var/www/html/index.html",
"fields" : [
{
"required" : True,
"name" : "name",
"desc" : "Name of the consumer",
"value" : "Example deployment"
},
{
"required" : True,
"name" : "picture",
"desc" : "Consumer server Picture",
"value" : "http://vignette2.wikia.nocookie.net/creepypasta/images/2/27/Finn-El-Humano-Cuerpo-Entero-psd84986.png/revision/latest?cb=20130822044826&path-prefix=es"
},
{
"required" : True,
"name" : "cv",
"desc" : "CV del consumer",
"value" : "laksjd laksdj laksjd laks jdlkas jdlkas jd"
}
]
},
{
"path" : "/root/chequeo.txt",
"content" : "YO ESTUVE AQUI"
}
]
}
}
class OrchestratorTestCase(unittest.TestCase):
"""Full test"""
def setUp(self):
"""Initial setup"""
self._vnfs = []
self._nss = []
self._nsis = []
def test_02(self):
"""Gets NS instances"""
resp = requests.get('{0}/service/instance'.format(BASE_URL))
assert resp.status_code == 200
instances = json.loads(resp.text)
if len(instances) > 0:
assert 'service_instance_id' in instances[0]
for ins in instances:
assert ins['state'].upper() in ('RUNNING', 'DEPLOYED', 'UNKNOWN')
return instances
def start_stop(self, prv, nxt, expected):
"""Aux. method to set prv state instances to nxt asserting expected status_code"""
instances = self.test_02()
f_instances = [x for x in instances if x['state'].upper() == prv]
for ins in f_instances:
url = '{0}/service/instance/{1}'.format(BASE_URL,
ins['service_instance_id'])
resp = requests.put(url,
headers={'Content-Type': 'application/json'},
json={'state': nxt})
assert resp.status_code == expected
def test_03(self):
"""Testing start/stop"""
self.start_stop('RUNNING', 'DEPLOYED', 200)
self.start_stop('DEPLOYED', 'RUNNING', 200)
def post_vnf(self, preserve=False):
"""Posts a new VNF"""
url = '{0}/vnf'.format(BASE_URL)
resp = requests.post(url, headers={'Content-Type': 'application/json'},
json=OVNFD_EXAMPLE)
assert resp.status_code == 200
vnf_data = json.loads(resp.text)
assert 'vnf_id' in vnf_data
if not preserve:
self._vnfs.append(vnf_data['vnf_id'])
def post_ns(self, preserve=False):
"""Posts a new NS"""
vresp = requests.get('{0}/vnf'.format(BASE_URL))
assert vresp.status_code == 200
vnf_data = json.loads(vresp.text)
url = '{0}/ns'.format(BASE_URL)
resp = requests.post(url, headers={'Content-Type': 'application/json'},
json={'vnf_id': random.choice(self._vnfs),
'name': 'randomTest'})
assert resp.status_code == 200
data = json.loads(resp.text)
assert 'ns_id' in data
if not preserve:
self._nss.append(data['ns_id'])
def test_04(self):
"""Posts VNFs"""
self.post_vnf()
self.post_vnf()
def test_05(self):
"""Posts NSs"""
self.post_vnf()
self.post_vnf()
self.post_vnf()
self.post_vnf()
self.post_ns()
self.post_ns()
self.post_ns()
self.post_ns()
self.post_ns()
self.post_ns()
def instantiate_ns(self, preserve=False):
"""Instantates a NS, injects a random number
in apache index.html and waits to stack deployment to check"""
vresp = requests.get('{0}/ns'.format(BASE_URL))
presp = requests.get('{0}/pop'.format(BASE_URL))
pops = json.loads(presp.text)
nss = json.loads(vresp.text)
pop_id = POP_ID
tns = random.choice(self._nss)
ns_id = tns
random_number = random.randint(0, 10000)
body = {'pop_id': pop_id,
'callback_url': 'http://localhost:80',
'context': {
'consumer_params': [
{
'path': '/var/www/html/index.html',
'content': '{0}'.format(random_number)
}
]}
}
url = '{0}/ns/{1}'.format(BASE_URL, ns_id)
resp = requests.post(url,
headers={'Content-Type': 'application/json'},
json=body)
assert resp.status_code == 200
data = json.loads(resp.text)
assert 'service_instance_id' in data
nsid = data['service_instance_id']
assert data['state'].upper() == 'PROVISIONED'
url = '{0}/service/instance/{1}'.format(BASE_URL, nsid)
while True:
time.sleep(60)
resp = requests.get(url)
assert resp.status_code == 200
nsi = json.loads(resp.text)
if nsi['state'].upper() == 'RUNNING':
break
resp = requests.get(url)
ipaddr = None
nsi = json.loads(resp.text)
for addr in nsi['addresses']:
if addr['OS-EXT-IPS:type'] == 'floating':
ipaddr = addr['addr']
webresp = requests.get('http://{0}'.format(ipaddr))
assert random_number == int(webresp.text)
if not preserve:
self._nsis.append(nsid)
def test_06(self):
"""Posts vnf, ns and instantiates it"""
self.post_vnf(False)
self.post_ns(False)
self.instantiate_ns()
def test_07(self):
"""Posts service/instance one round mode"""
url = '{0}/service/instance'.format(BASE_URL)
resp = requests.post(url, headers={'Content-Type': 'application/json'},
json=CATALOG_EXAMPLE)
assert resp.status_code == 200
def test_08(self):
"""Posts service/instance one round mode at Adam with fixed network/pop"""
url = '{0}/service/instance'.format(BASE_URL)
resp = requests.post(url, headers={'Content-Type': 'application/json'},
json=ADAM_EXAMPLE)
assert resp.status_code == 200
def tearDown(self):
"""tearDown"""
while len(self._nsis) > 0:
nsi = self._nsis.pop()
url = '{0}/service/instance/{1}'.format(BASE_URL, nsi)
resp = requests.delete(url)
assert resp.status_code == 200
while len(self._nss) > 0:
vnf = self._nss.pop()
url = '{0}/ns/{1}'.format(BASE_URL, vnf)
resp = requests.delete(url)
assert resp.status_code == 200
while len(self._vnfs) > 0:
vnf = self._vnfs.pop()
url = '{0}/vnf/{1}'.format(BASE_URL, vnf)
resp = requests.delete(url)
assert resp.status_code == 200
if __name__ == '__main__':
unittest.main()