blob: 6779014d3de31f6781dbc5ebc3a07c552b34daa7 [file] [log] [blame]
Matteo Scandoloa6658422016-04-06 14:44:56 -07001import dredd_hooks as hooks
2import sys
Matteo Scandoloa6658422016-04-06 14:44:56 -07003
teone7d1c1272016-04-07 13:43:33 -04004# HELPERS
Matteo Scandoloc916b5e2016-04-07 14:38:54 -07005# NOTE move in separated module
6import os
7import sys
8sys.path.append("/opt/xos")
9os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
10import django
11from core.models import *
12from services.cord.models import *
Matteo Scandolo336dda12016-04-07 16:36:23 -070013from services.vtr.models import *
Matteo Scandoloaf4c2382016-04-08 14:22:39 -070014import urllib2
15import json
Matteo Scandoloc916b5e2016-04-07 14:38:54 -070016django.setup()
Matteo Scandoloa6658422016-04-06 14:44:56 -070017
Matteo Scandoloc916b5e2016-04-07 14:38:54 -070018
Matteo Scandoloaf4c2382016-04-08 14:22:39 -070019def doLogin(username, password):
20 url = "http://127.0.0.1:8000/xoslib/login?username=%s&password=%s" % (username, password)
21 res = urllib2.urlopen(url).read()
22 parsed = json.loads(res)
23 return {'token': parsed['xoscsrftoken'], 'sessionid': parsed['xossessionid']}
24
25
Matteo Scandoloc916b5e2016-04-07 14:38:54 -070026def cleanDB():
27 # deleting all subscribers
28 for s in CordSubscriberRoot.objects.all():
29 s.delete(purge=True)
30
31 # deleting all slices
32 for s in Slice.objects.all():
33 s.delete(purge=True)
34
35 # deleting all Services
36 for s in Service.objects.all():
37 s.delete(purge=True)
38
39 # deleting all Tenants
40 for s in Tenant.objects.all():
41 s.delete(purge=True)
42
43 # deleting all Networks
44 for s in Network.objects.all():
45 s.delete(purge=True)
46
47 # deleting all NetworkTemplates
48 for s in NetworkTemplate.objects.all():
49 s.delete(purge=True)
50
51 for s in NetworkSlice.objects.all():
52 s.delete(purge=True)
53
Matteo Scandolof2bb5592016-04-11 09:59:23 -070054 # print 'DB Cleaned'
Matteo Scandoloaf4c2382016-04-08 14:22:39 -070055
Matteo Scandoloc916b5e2016-04-07 14:38:54 -070056
57def createTestSubscriber():
58
59 cleanDB()
60
61 # load user
62 user = User.objects.get(email="padmin@vicci.org")
63
64 # network template
65 private_template = NetworkTemplate()
66 private_template.name = 'Private Network'
67 private_template.save()
68
69 # creating the test subscriber
70 subscriber = CordSubscriberRoot(name='Test Subscriber 1', id=1)
71 subscriber.save()
72
73 # Site
74 site = Site.objects.get(name='MySite')
75
76 # vSG service
77 vsg_service = VSGService()
78 vsg_service.name = 'service_vsg'
79
80 # vSG slice
81 vsg_slice = Slice()
82 vsg_slice.name = site.login_base + "_testVsg"
83 vsg_slice.service = vsg_service.id
84 vsg_slice.site = site
85 vsg_slice.caller = user
86
87 vsg_slice.save()
88
89 vsg_service.save()
90
91 # volt service
92 volt_service = VOLTService()
93 volt_service.name = 'service_volt'
94 volt_service.save()
95
96 # vcpe slice
97 vcpe_slice = Slice()
98 vcpe_slice.name = site.login_base + "_testVcpe"
99 vcpe_slice.service = Service.objects.get(kind='vCPE')
100 vcpe_slice.site = site
101 vcpe_slice.caller = user
102 vcpe_slice.save()
103
Matteo Scandolof2bb5592016-04-11 09:59:23 -0700104 # print 'vcpe_slice created'
Matteo Scandoloc916b5e2016-04-07 14:38:54 -0700105
106 # create a lan network
107 lan_net = Network()
108 lan_net.name = 'lan_network'
109 lan_net.owner = vcpe_slice
110 lan_net.template = private_template
111 lan_net.save()
112
Matteo Scandolof2bb5592016-04-11 09:59:23 -0700113 # print 'lan_network created'
Matteo Scandoloc916b5e2016-04-07 14:38:54 -0700114
115 # add relation between vcpe slice and lan network
116 vcpe_network = NetworkSlice()
117 vcpe_network.network = lan_net
118 vcpe_network.slice = vcpe_slice
119 vcpe_network.save()
120
Matteo Scandolof2bb5592016-04-11 09:59:23 -0700121 # print 'vcpe network relation added'
Matteo Scandoloc916b5e2016-04-07 14:38:54 -0700122
123 # vbng service
124 vbng_service = VBNGService()
125 vbng_service.name = 'service_vbng'
126 vbng_service.save()
127
Matteo Scandolof2bb5592016-04-11 09:59:23 -0700128 # print 'vbng_service creater'
Matteo Scandolob94d7ab2016-04-08 16:38:15 -0700129
Matteo Scandoloc916b5e2016-04-07 14:38:54 -0700130 # volt tenant
131 vt = VOLTTenant(subscriber=subscriber.id, id=1)
132 vt.s_tag = "222"
133 vt.c_tag = "432"
134 vt.provider_service_id = volt_service.id
135 vt.caller = user
136 vt.save()
137
Matteo Scandolof2bb5592016-04-11 09:59:23 -0700138 # print "Subscriber Created"
Matteo Scandoloc916b5e2016-04-07 14:38:54 -0700139
Matteo Scandoloa6658422016-04-06 14:44:56 -0700140
Matteo Scandolo336dda12016-04-07 16:36:23 -0700141def deleteTruckrolls():
142 for s in VTRTenant.objects.all():
143 s.delete(purge=True)
144
145
146def setUpTruckroll():
147 service_vtr = VTRService()
148 service_vtr.name = 'service_vtr'
149 service_vtr.save()
150
151
152def createTruckroll():
153 setUpTruckroll()
154 tn = VTRTenant(id=1)
155 tn.save()
156
157
Matteo Scandolob94d7ab2016-04-08 16:38:15 -0700158@hooks.before_all
159def my_before_all_hook(transactions):
Matteo Scandolof2bb5592016-04-11 09:59:23 -0700160 # print "-------------------------------- Before All Hook --------------------------------"
Matteo Scandolob94d7ab2016-04-08 16:38:15 -0700161 cleanDB()
162
163
Matteo Scandoloa6658422016-04-06 14:44:56 -0700164@hooks.before_each
165def my_before_each_hook(transaction):
Matteo Scandolof2bb5592016-04-11 09:59:23 -0700166 # print "-------------------------------- Before Each Hook --------------------------------"
Matteo Scandoloaf4c2382016-04-08 14:22:39 -0700167 auth = doLogin('padmin@vicci.org', 'letmein')
168 transaction['request']['headers']['X-CSRFToken'] = auth['token']
169 transaction['request']['headers']['Cookie'] = "xossessionid=%s; xoscsrftoken=%s" % (auth['sessionid'], auth['token'])
Matteo Scandoloc916b5e2016-04-07 14:38:54 -0700170 createTestSubscriber()
Matteo Scandoloa6658422016-04-06 14:44:56 -0700171 sys.stdout.flush()
172
173
174@hooks.before("Truckroll > Truckroll Collection > Create a Truckroll")
Matteo Scandolo336dda12016-04-07 16:36:23 -0700175def test1(transaction):
176 setUpTruckroll()
Matteo Scandoloa6658422016-04-06 14:44:56 -0700177
178
179@hooks.before("Truckroll > Truckroll Detail > View a Truckroll Detail")
Matteo Scandolo336dda12016-04-07 16:36:23 -0700180def test2(transaction):
181 deleteTruckrolls()
182 createTruckroll()
Matteo Scandoloa6658422016-04-06 14:44:56 -0700183
184
185@hooks.before("Truckroll > Truckroll Detail > Delete a Truckroll Detail")
Matteo Scandolo336dda12016-04-07 16:36:23 -0700186def test3(transaction):
187 deleteTruckrolls()
188 createTruckroll()
Matteo Scandoloa6658422016-04-06 14:44:56 -0700189
190
191@hooks.before("vOLT > vOLT Collection > Create a vOLT")
Matteo Scandolo336dda12016-04-07 16:36:23 -0700192def test4(transaction):
Matteo Scandoloaf4c2382016-04-08 14:22:39 -0700193 # transaction['skip'] = True
194 VOLTTenant.objects.get(kind='vOLT').delete()