Matteo Scandolo | c41467a | 2016-05-02 18:15:57 -0700 | [diff] [blame] | 1 | import dredd_hooks as hooks |
| 2 | import sys |
| 3 | |
| 4 | # HELPERS |
| 5 | # NOTE move in separated module |
| 6 | import os |
| 7 | import sys |
| 8 | sys.path.append("/opt/xos") |
| 9 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings") |
| 10 | import django |
| 11 | from core.models import * |
Scott Baker | 16d4ac3 | 2016-06-13 11:48:41 -0700 | [diff] [blame] | 12 | from services.volt.models import * |
| 13 | from services.vsg.models import * |
Matteo Scandolo | c41467a | 2016-05-02 18:15:57 -0700 | [diff] [blame] | 14 | from services.vtr.models import * |
| 15 | import urllib2 |
| 16 | import json |
Matteo Scandolo | d9f92a7 | 2016-05-05 15:44:13 -0700 | [diff] [blame] | 17 | from django.utils import timezone |
Matteo Scandolo | c41467a | 2016-05-02 18:15:57 -0700 | [diff] [blame] | 18 | django.setup() |
| 19 | |
| 20 | |
| 21 | def doLogin(username, password): |
| 22 | url = "http://127.0.0.1:8000/xoslib/login?username=%s&password=%s" % (username, password) |
| 23 | res = urllib2.urlopen(url).read() |
| 24 | parsed = json.loads(res) |
| 25 | return {'token': parsed['xoscsrftoken'], 'sessionid': parsed['xossessionid']} |
| 26 | |
| 27 | |
| 28 | def cleanDB(): |
| 29 | # deleting all subscribers |
| 30 | for s in CordSubscriberRoot.objects.all(): |
| 31 | s.delete(purge=True) |
| 32 | |
| 33 | # deleting all slices |
| 34 | for s in Slice.objects.all(): |
| 35 | s.delete(purge=True) |
| 36 | |
| 37 | # deleting all Services |
| 38 | for s in Service.objects.all(): |
| 39 | s.delete(purge=True) |
| 40 | |
| 41 | # deleting all Tenants |
| 42 | for s in Tenant.objects.all(): |
| 43 | s.delete(purge=True) |
| 44 | |
| 45 | # deleting all Networks |
| 46 | for s in Network.objects.all(): |
| 47 | s.delete(purge=True) |
| 48 | |
| 49 | # deleting all NetworkTemplates |
| 50 | for s in NetworkTemplate.objects.all(): |
| 51 | s.delete(purge=True) |
| 52 | |
| 53 | for s in NetworkSlice.objects.all(): |
| 54 | s.delete(purge=True) |
| 55 | |
| 56 | for s in AddressPool.objects.all(): |
| 57 | s.delete(purge=True) |
| 58 | |
| 59 | for s in Flavor.objects.all(): |
| 60 | s.delete(purge=True) |
| 61 | |
| 62 | for s in Image.objects.all(): |
| 63 | s.delete(purge=True) |
| 64 | |
| 65 | # print 'DB Cleaned' |
| 66 | |
| 67 | |
| 68 | def createTestSubscriber(): |
| 69 | |
| 70 | cleanDB() |
| 71 | createFlavors() |
| 72 | |
| 73 | # load user |
| 74 | user = User.objects.get(email="padmin@vicci.org") |
| 75 | |
| 76 | # network template |
| 77 | private_template = NetworkTemplate() |
| 78 | private_template.name = 'Private Network' |
| 79 | private_template.save() |
| 80 | |
| 81 | # creating the test subscriber |
| 82 | subscriber = CordSubscriberRoot(name='Test Subscriber 1', id=1) |
Matteo Scandolo | d9f92a7 | 2016-05-05 15:44:13 -0700 | [diff] [blame] | 83 | subscriber.created = timezone.now() |
Matteo Scandolo | c41467a | 2016-05-02 18:15:57 -0700 | [diff] [blame] | 84 | subscriber.save() |
| 85 | |
| 86 | # vRouter service |
| 87 | vrouter_service = VRouterService() |
| 88 | vrouter_service.name = 'service_vrouter' |
| 89 | vrouter_service.save() |
| 90 | |
| 91 | # address pools |
| 92 | ap_vsg = AddressPool() |
| 93 | ap_vsg.service = vrouter_service |
| 94 | ap_vsg.name = 'addresses_vsg' |
| 95 | ap_vsg.addresses = '10.168.0.0' |
| 96 | ap_vsg.gateway_ip = '10.168.0.1' |
| 97 | ap_vsg.gateway_mac = '02:42:0a:a8:00:01' |
| 98 | ap_vsg.save() |
| 99 | |
| 100 | # print 'vRouter created' |
| 101 | |
| 102 | # Site |
| 103 | site = Site.objects.get(name='MySite') |
| 104 | |
| 105 | # vSG service |
| 106 | vsg_service = VSGService() |
| 107 | vsg_service.name = 'service_vsg' |
| 108 | |
| 109 | # vSG slice |
| 110 | vsg_slice = Slice(id=2) |
| 111 | vsg_slice.name = site.login_base + "_testVsg" |
| 112 | vsg_slice.service = vsg_service.id |
| 113 | vsg_slice.site = site |
| 114 | vsg_slice.caller = user |
| 115 | |
| 116 | vsg_slice.save() |
| 117 | |
| 118 | vsg_service.save() |
| 119 | |
| 120 | # volt service |
| 121 | volt_service = VOLTService() |
| 122 | volt_service.name = 'service_volt' |
| 123 | volt_service.save() |
| 124 | |
| 125 | # cvpe image |
| 126 | createImage('ubuntu-vcpe4') |
| 127 | |
| 128 | # vcpe slice |
| 129 | vcpe_slice = Slice(id=3) |
| 130 | vcpe_slice.name = site.login_base + "_testVcpe" |
| 131 | vcpe_slice.service = Service.objects.get(kind='vCPE') |
| 132 | vcpe_slice.site = site |
| 133 | vcpe_slice.caller = user |
| 134 | vcpe_slice.save() |
| 135 | |
| 136 | # print 'vcpe_slice created' |
| 137 | |
| 138 | # create a lan network |
Matteo Scandolo | d9f92a7 | 2016-05-05 15:44:13 -0700 | [diff] [blame] | 139 | lan_net = Network(id=1) |
Matteo Scandolo | c41467a | 2016-05-02 18:15:57 -0700 | [diff] [blame] | 140 | lan_net.name = 'lan_network' |
| 141 | lan_net.owner = vcpe_slice |
| 142 | lan_net.template = private_template |
| 143 | lan_net.save() |
| 144 | |
| 145 | # print 'lan_network created' |
| 146 | |
| 147 | # add relation between vcpe slice and lan network |
| 148 | vcpe_network = NetworkSlice() |
| 149 | vcpe_network.network = lan_net |
| 150 | vcpe_network.slice = vcpe_slice |
| 151 | vcpe_network.save() |
| 152 | |
| 153 | # print 'vcpe network relation added' |
| 154 | |
| 155 | # vbng service |
| 156 | vbng_service = VBNGService() |
| 157 | vbng_service.name = 'service_vbng' |
| 158 | vbng_service.save() |
| 159 | |
| 160 | # print 'vbng_service creater' |
| 161 | |
| 162 | # volt tenant |
| 163 | vt = VOLTTenant(subscriber=subscriber.id, id=1) |
| 164 | vt.s_tag = "222" |
| 165 | vt.c_tag = "432" |
| 166 | vt.provider_service_id = volt_service.id |
| 167 | vt.caller = user |
| 168 | vt.save() |
| 169 | |
| 170 | # print "Subscriber Created" |
| 171 | |
| 172 | |
| 173 | def deleteTruckrolls(): |
| 174 | for s in VTRTenant.objects.all(): |
| 175 | s.delete(purge=True) |
| 176 | |
| 177 | |
| 178 | def setUpTruckroll(): |
| 179 | service_vtr = VTRService() |
| 180 | service_vtr.name = 'service_vtr' |
| 181 | service_vtr.save() |
| 182 | |
| 183 | |
| 184 | def createTruckroll(): |
| 185 | setUpTruckroll() |
| 186 | tn = VTRTenant(id=1) |
Matteo Scandolo | d9f92a7 | 2016-05-05 15:44:13 -0700 | [diff] [blame] | 187 | tn.created = timezone.now() |
Matteo Scandolo | c41467a | 2016-05-02 18:15:57 -0700 | [diff] [blame] | 188 | tn.save() |
| 189 | |
| 190 | |
| 191 | def createFlavors(): |
| 192 | small = Flavor(id=1) |
| 193 | small.name = "m1.small" |
Matteo Scandolo | d9f92a7 | 2016-05-05 15:44:13 -0700 | [diff] [blame] | 194 | small.created = timezone.now() |
Matteo Scandolo | c41467a | 2016-05-02 18:15:57 -0700 | [diff] [blame] | 195 | small.save() |
| 196 | |
| 197 | medium = Flavor(id=2) |
| 198 | medium.name = "m1.medium" |
Matteo Scandolo | d9f92a7 | 2016-05-05 15:44:13 -0700 | [diff] [blame] | 199 | medium.created = timezone.now() |
Matteo Scandolo | c41467a | 2016-05-02 18:15:57 -0700 | [diff] [blame] | 200 | medium.save() |
| 201 | |
| 202 | large = Flavor(id=3) |
| 203 | large.name = "m1.large" |
Matteo Scandolo | d9f92a7 | 2016-05-05 15:44:13 -0700 | [diff] [blame] | 204 | large.created = timezone.now() |
Matteo Scandolo | c41467a | 2016-05-02 18:15:57 -0700 | [diff] [blame] | 205 | large.save() |
| 206 | |
| 207 | |
| 208 | def createSlice(): |
| 209 | site = Site.objects.get(name='MySite') |
| 210 | user = User.objects.get(email="padmin@vicci.org") |
| 211 | |
| 212 | sl = Slice(id=1) |
Matteo Scandolo | d9f92a7 | 2016-05-05 15:44:13 -0700 | [diff] [blame] | 213 | sl.created = timezone.now() |
Matteo Scandolo | c41467a | 2016-05-02 18:15:57 -0700 | [diff] [blame] | 214 | sl.name = site.login_base + "_testSlice" |
| 215 | sl.site = site |
| 216 | sl.caller = user |
| 217 | sl.save() |
| 218 | return sl |
| 219 | |
| 220 | |
| 221 | def createDeployment(): |
| 222 | deployment = Deployment(id=1) |
Matteo Scandolo | d9f92a7 | 2016-05-05 15:44:13 -0700 | [diff] [blame] | 223 | deployment.created = timezone.now() |
Matteo Scandolo | c41467a | 2016-05-02 18:15:57 -0700 | [diff] [blame] | 224 | deployment.name = 'MyTestDeployment' |
| 225 | deployment.save() |
| 226 | return deployment |
| 227 | |
| 228 | |
| 229 | def createImage(name): |
| 230 | img = Image(id=1) |
| 231 | img.name = name |
Matteo Scandolo | d9f92a7 | 2016-05-05 15:44:13 -0700 | [diff] [blame] | 232 | img.created = timezone.now() |
Matteo Scandolo | c41467a | 2016-05-02 18:15:57 -0700 | [diff] [blame] | 233 | img.disk_format = 'QCOW2' |
| 234 | img.kind = 'vm' |
| 235 | img.save() |
| 236 | return img |
| 237 | |
| 238 | |
| 239 | def createNode(deployment): |
| 240 | site = Site.objects.get(name='MySite') |
| 241 | |
| 242 | site_deployment = SiteDeployment(id=1) |
| 243 | site_deployment.site = site |
Matteo Scandolo | d9f92a7 | 2016-05-05 15:44:13 -0700 | [diff] [blame] | 244 | site_deployment.created = timezone.now() |
Matteo Scandolo | c41467a | 2016-05-02 18:15:57 -0700 | [diff] [blame] | 245 | site_deployment.deployment = deployment |
| 246 | site_deployment.save() |
| 247 | |
| 248 | node = Node(id=1) |
| 249 | node.name = 'test-node' |
Matteo Scandolo | d9f92a7 | 2016-05-05 15:44:13 -0700 | [diff] [blame] | 250 | node.created = timezone.now() |
Matteo Scandolo | c41467a | 2016-05-02 18:15:57 -0700 | [diff] [blame] | 251 | node.site = site |
| 252 | node.site_deployment = site_deployment |
| 253 | node.save() |
| 254 | return node |
| 255 | |
| 256 | |
| 257 | def setupInstance(): |
| 258 | deployment = createDeployment() |
| 259 | sl = createSlice() |
| 260 | node = createNode(deployment) |
| 261 | img = createImage('test-image') |
Matteo Scandolo | d9f92a7 | 2016-05-05 15:44:13 -0700 | [diff] [blame] | 262 | # print {'image': img.id, 'deployment': deployment.id, 'slice': sl.id} |
Matteo Scandolo | c41467a | 2016-05-02 18:15:57 -0700 | [diff] [blame] | 263 | return {'image': img, 'deployment': deployment, 'slice': sl} |
| 264 | |
| 265 | |
| 266 | def createInstance(): |
| 267 | requirements = setupInstance() |
| 268 | user = User.objects.get(email="padmin@vicci.org") |
| 269 | |
| 270 | instance = Instance(id=1) |
| 271 | instance.name = 'test-instance' |
Matteo Scandolo | d9f92a7 | 2016-05-05 15:44:13 -0700 | [diff] [blame] | 272 | instance.created = timezone.now() |
Matteo Scandolo | c41467a | 2016-05-02 18:15:57 -0700 | [diff] [blame] | 273 | instance.node = Node.objects.all()[0] |
| 274 | instance.image = requirements['image'] |
| 275 | instance.slice = requirements['slice'] |
| 276 | instance.deployment = requirements['deployment'] |
| 277 | instance.caller = user |
| 278 | instance.save() |
| 279 | |
Matteo Scandolo | d9f92a7 | 2016-05-05 15:44:13 -0700 | [diff] [blame] | 280 | |
Matteo Scandolo | f2ec12b | 2016-05-16 10:31:32 -0700 | [diff] [blame] | 281 | def createService(): |
| 282 | service = Service(id=1) |
| 283 | service.name = 'test-service' |
| 284 | service.save() |
| 285 | |
Matteo Scandolo | d9f92a7 | 2016-05-05 15:44:13 -0700 | [diff] [blame] | 286 | # setupInstance() |
| 287 | # depl = createDeployment() |
Matteo Scandolo | f2ec12b | 2016-05-16 10:31:32 -0700 | [diff] [blame] | 288 | # createTestSubscriber() |
Matteo Scandolo | c41467a | 2016-05-02 18:15:57 -0700 | [diff] [blame] | 289 | # createInstance() |
Matteo Scandolo | d9f92a7 | 2016-05-05 15:44:13 -0700 | [diff] [blame] | 290 | # createSlice() |
| 291 | # createNode(depl) |
| 292 | # createImage('test-image') |
| 293 | # createFlavors() |
| 294 | # createTruckroll() |
Matteo Scandolo | f2ec12b | 2016-05-16 10:31:32 -0700 | [diff] [blame] | 295 | # setUpTruckroll() |
| 296 | createService() |