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 ##############################################################################
10 from django.contrib.auth.models import User
14 from account.models import UserProfile, Lab, LabStatus, VlanManager, PublicNetwork
15 from resource_inventory.models import (
30 class BookingContextData(object):
31 def prepopulate(self, *args, **kwargs):
32 self.loginuser = instantiate_user(False, username=kwargs.get("login_username", "newtestuser"), password="testpassword")
33 instantiate_userprofile(self.loginuser, True)
35 lab_user = kwargs.get("lab_user", instantiate_user(True))
36 self.lab = instantiate_lab(lab_user)
38 self.host_profile = make_hostprofile_set(self.lab)
39 self.scenario = instantiate_scenario()
40 self.installer = instantiate_installer([self.scenario])
41 os = instantiate_os([self.installer])
42 self.image = instantiate_image(self.lab, 1, self.loginuser, os, self.host_profile)
43 self.host = instantiate_host(self.host_profile, self.lab)
44 self.role = instantiate_opnfvrole()
45 self.pubnet = instantiate_publicnet(10, self.lab)
48 def instantiate_user(is_superuser,
50 password="testpassword",
51 email="default_email@user.com"
53 user = User.objects.create_user(username=username, email=email, password=password)
54 user.is_superuser = is_superuser
61 def instantiate_userprofile(user=None, can_book_multiple=False):
63 user = instantiate_user(True, 'test_user', 'test_pass', 'test_user@test_site.org')
64 userprofile = UserProfile()
65 userprofile.user = user
66 userprofile.booking_privledge = can_book_multiple
73 def instantiate_vlanmanager(vlans=None,
75 allow_overlapping=False,
78 vlanmanager = VlanManager()
81 for vlan in range(0, 4095):
82 vlans.append(vlan % 2)
83 vlanmanager.vlans = json.dumps(vlans)
84 if not reserved_vlans:
86 for vlan in range(0, 4095):
87 reserved_vlans.append(0)
88 vlanmanager.reserved_vlans = json.dumps(vlans)
89 vlanmanager.block_size = block_size
90 vlanmanager.allow_overlapping = allow_overlapping
97 def instantiate_lab(user=None,
98 name="Test Lab Instance",
103 vlan_manager = instantiate_vlanmanager()
106 user = instantiate_user(True, 'test_user', 'test_pass', 'test_user@test_site.org')
111 lab.contact_email = 'test_lab@test_site.org'
112 lab.contact_phone = '603 123 4567'
114 lab.vlan_manager = vlan_manager
115 lab.description = 'test lab instantiation'
116 lab.api_token = '12345678'
124 resource_inventory instantiation section for permenant resources
128 def make_hostprofile_set(lab, name="test_hostprofile"):
129 hostprof = instantiate_hostprofile(lab, name=name)
130 instantiate_diskprofile(hostprof, 500, name=name)
131 instantiate_cpuprofile(hostprof)
132 instantiate_interfaceprofile(hostprof, name=name)
133 instantiate_ramprofile(hostprof)
138 def instantiate_hostprofile(lab,
140 name="test hostprofile instance"
142 hostprof = HostProfile()
143 hostprof.host_type = host_type
145 hostprof.description = 'test hostprofile instance'
147 hostprof.labs.add(lab)
154 def instantiate_ramprofile(host,
157 ramprof = RamProfile()
159 ramprof.amount = amount
160 ramprof.channels = channels
166 def instantiate_diskprofile(hostprofile,
169 name="test diskprofile",
173 diskprof = DiskProfile()
176 diskprof.media_type = media_type
177 diskprof.host = hostprofile
178 diskprof.rotation = rotation
179 diskprof.interface = interface
186 def instantiate_cpuprofile(hostprofile,
188 architecture="x86_64",
191 cpuprof = CpuProfile()
192 cpuprof.cores = cores
193 cpuprof.architecture = architecture
195 cpuprof.host = hostprofile
203 def instantiate_interfaceprofile(hostprofile,
205 name="test interface profile",
208 intprof = InterfaceProfile()
209 intprof.host = hostprofile
211 intprof.speed = speed
212 intprof.nic_type = nic_type
219 def instantiate_image(lab,
225 name="default image",
226 description="default image"
230 image.lab_id = lab_id
232 image.host_type = host_profile
233 image.public = public
235 image.description = description
242 def instantiate_scenario(name="test scenario"):
243 scenario = Scenario()
249 def instantiate_installer(supported_scenarios,
250 name="test installer"
252 installer = Installer()
253 installer.name = name
255 for scenario in supported_scenarios:
256 installer.sup_scenarios.add(scenario)
262 def instantiate_os(supported_installers,
263 name="test operating system",
268 for installer in supported_installers:
269 os.sup_installers.add(installer)
274 def instantiate_host(host_profile,
287 host.profile = host_profile
290 host.working = working
292 host.template = template
302 def instantiate_opnfvrole(name="Jumphost",
303 description="test opnfvrole"):
306 role.description = description
312 def instantiate_publicnet(vlan,
317 pubnet = PublicNetwork()
321 pubnet.gateway = gateway