1 ##############################################################################
2 # Copyright (c) 2018 Parker Berberian, Sawyer Bergeron, and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
11 from django.test import TestCase
12 from booking.models import Booking
13 from resource_inventory.models import *
14 from account.models import *
15 from api.serializers.booking_serializer import *
16 from datetime import timedelta
17 from django.utils import timezone
18 from django.contrib.auth.models import Permission, User
26 self.host_profile_count = 0
27 self.generic_host_count = 0
28 self.host_profiles = []
29 self.generic_bundle_count = 0
30 self.booking_count = 0
33 def make_host_profile(self, lab, data):
34 hostProfile = HostProfile.objects.create(
35 host_type=data['host']['type'],
36 name=data['host']['name'],
37 description=data['host']['description']
41 for iface_data in data['interfaces']:
43 interfaceProfile = InterfaceProfile.objects.create(
44 speed=iface_data['speed'],
45 name=iface_data['name'],
48 interfaceProfile.save()
51 for disk_data in data['disks']:
53 diskProfile = DiskProfile.objects.create(
54 size=disk_data['size'],
55 media_type=disk_data['type'],
56 name=disk_data['name'],
61 cpuProfile = CpuProfile.objects.create(
62 cores=data['cpu']['cores'],
63 architecture=data['cpu']['arch'],
64 cpus=data['cpu']['cpus'],
68 ramProfile = RamProfile.objects.create(
69 amount=data['ram']['amount'],
70 channels=data['ram']['channels'],
74 hostProfile.labs.add(lab)
78 user_pberberian = User.objects.create(username="pberberian")
79 user_pberberian.save()
80 user_pberberian_prof = UserProfile.objects.create(user=user_pberberian)
81 user_pberberian_prof.save()
83 user_sbergeron = User.objects.create(username="sbergeron")
85 user_sbergeron_prof = UserProfile.objects.create(user=user_sbergeron)
86 user_sbergeron_prof.save()
87 return [user_sbergeron, user_pberberian,]
91 unh_iol = User.objects.create(username="unh_iol")
95 for i in range(1,4096):
98 # TODO: put reserved vlans here
99 iol = Lab.objects.create(
102 vlan_manager=VlanManager.objects.create(
103 vlans = json.dumps(vlans),
104 reserved_vlans = json.dumps(reserved),
105 allow_overlapping = False,
108 api_token = Lab.make_api_token(),
109 contact_email = "nfv-lab@iol.unh.edu",
110 location = "University of New Hampshire, Durham NH, 03824 USA"
115 def make_configurations(self):
117 scen1 = Scenario.objects.create(name="os-nosdn-nofeature-noha")
118 scen2 = Scenario.objects.create(name="os-odl-kvm-ha")
119 scen3 = Scenario.objects.create(name="os-nosdn-nofeature-ha")
122 fuel = Installer.objects.create(name="Fuel")
123 fuel.sup_scenarios.add(scen1)
124 fuel.sup_scenarios.add(scen3)
126 joid = Installer.objects.create(name="Joid")
127 joid.sup_scenarios.add(scen1)
128 joid.sup_scenarios.add(scen2)
130 apex = Installer.objects.create(name="Apex")
131 apex.sup_scenarios.add(scen2)
132 apex.sup_scenarios.add(scen3)
134 daisy = Installer.objects.create(name="Daisy")
135 daisy.sup_scenarios.add(scen1)
136 daisy.sup_scenarios.add(scen2)
137 daisy.sup_scenarios.add(scen3)
139 compass = Installer.objects.create(name="Compass")
140 compass.sup_scenarios.add(scen1)
141 compass.sup_scenarios.add(scen3)
145 ubuntu = Opsys.objects.create(name="Ubuntu")
146 ubuntu.sup_installers.add(compass)
147 ubuntu.sup_installers.add(joid)
149 centos = Opsys.objects.create(name="CentOs")
150 centos.sup_installers.add(apex)
151 centos.sup_installers.add(fuel)
153 suse = Opsys.objects.create(name="Suse")
154 suse.sup_installers.add(fuel)
159 compute = OPNFVRole.objects.create(name="Compute", description="Does the heavy lifting")
160 controller = OPNFVRole.objects.create(name="Controller", description="Controls everything")
161 jumphost = OPNFVRole.objects.create(name="Jumphost", description="Entry Point")
163 lab = Lab.objects.first()
164 user = UserProfile.objects.first().user
165 image = Image.objects.create(
170 host_type=HostProfile.objects.get(name="hpe")
172 image = Image.objects.create(
177 host_type=HostProfile.objects.get(name="hpe")
180 image = Image.objects.create(
185 host_type=HostProfile.objects.get(name="hpe")
187 image = Image.objects.create(
192 host_type=HostProfile.objects.get(name="arm")
195 def make_lab_hosts(self, hostcount, profile, lab, data, offset=1):
196 for i in range(hostcount):
197 name="Host_" + lab.name + "_" + profile.name + "_" + str(i + offset)
198 host = Host.objects.create(
202 labid=data[i]['labid']
204 for iface_profile in profile.interfaceprofile.all():
205 iface_data = data[i]['interfaces'][iface_profile.name]
206 Interface.objects.create(
207 mac_address=iface_data['mac'],
208 bus_address=iface_data['bus'],
209 name=iface_profile.name,
213 def make_profile_data(self):
215 returns a dictionary of data from the yaml files
216 created by inspection scripts
219 for prof in ["hpe", "arm"]: # TODO
224 "description": "some LaaS servers"
226 profile_dict['host'] = host
227 profile_dict['interfaces'] = []
228 for interface in [{"name": "eno1", "speed": 1000}, {"name": "eno2", "speed": 10000}]: # TODO
230 iface_dict["name"] = interface['name']
231 iface_dict['speed'] = interface['speed']
232 profile_dict['interfaces'].append(iface_dict)
234 profile_dict['disks'] = []
235 for disk in [{"size": 1000, "type": "ssd", "name": "sda"}]: # TODO
237 disk_dict['size'] = disk['size']
238 disk_dict['type'] = disk['type']
239 disk_dict['name'] = disk['name']
240 profile_dict['disks'].append(disk_dict)
247 profile_dict['cpu'] = cpu
253 profile_dict['ram'] = ram
255 data.append(profile_dict)
259 def get_lab_data(self, lab):
261 path = "/pharos_dashboard/data/" + lab.name + "/"
262 host_file = open(path + "hostlist.json")
263 host_structure = json.loads(host_file.read())
265 for profile in host_structure['profiles'].keys():
267 prof_path = path + profile
268 for host in host_structure['profiles'][profile]:
269 host_file = open(prof_path + "/" + host + ".yaml")
270 host_data = yaml.load(host_file.read())
272 data[profile][host] = host_data
275 def make_profiles_and_hosts(self, lab, lab_data):
276 for host_profile_name, host_data_dict in lab_data.items():
277 if len(host_data_dict) < 1:
279 host_profile = HostProfile.objects.create(
280 name=host_profile_name,
283 host_profile.labs.add(lab)
284 example_host_data = list(host_data_dict.values())[0]
286 cpu_data = example_host_data['cpu']
287 CpuProfile.objects.create(
288 cores=cpu_data['cores'],
289 architecture=cpu_data['arch'],
290 cpus=cpu_data['cpus'],
294 ram_data = example_host_data['memory']
295 RamProfile.objects.create(
296 amount=int(ram_data[:-1]),
301 disks_data = example_host_data['disk']
302 for disk_data in disks_data:
305 size=int(disk_data['size'].split('.')[0])
307 size=int(disk_data['size'].split('.')[0][:-1])
308 DiskProfile.objects.create(
311 name=disk_data['name'],
315 ifaces_data = example_host_data['interface']
316 for iface_data in ifaces_data:
317 InterfaceProfile.objects.create(
318 speed=iface_data['speed'],
319 name=iface_data['name'],
323 # all profiles created
324 for hostname, host_data in host_data_dict.items():
325 host = Host.objects.create(
328 profile=host_profile,
331 for iface_data in host_data['interface']:
332 Interface.objects.create(
333 mac_address=iface_data['mac'],
334 bus_address=iface_data['busaddr'],
335 name=iface_data['name'],
340 self.labs = self.make_labs()
341 # We should use the existing users, not creating our own
342 for lab in self.labs:
343 lab_data = self.get_lab_data(lab)
344 self.make_profiles_and_hosts(lab, lab_data)
346 # We will add opnfv info and images as they are created and supported