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.test import TestCase
11 from django.contrib.auth.models import User
13 from resource.inventory_manager import InventoryManager
14 from resource.resource_manager import ResourceManager
15 from resource.models import *
18 class InventoryManagerTestCase(TestCase):
20 def test_singleton(self):
21 instance = InventoryManager.getInstance()
22 self.assertTrue(isinstance(instance, InventoryManager))
23 self.assertTrue(instance is InventoryManager.getInstance())
27 # create lab and give it resources
28 user = User.objects.create(username="username")
29 self.lab = Lab.objects.create(
32 contact_email='someone@email.com',
33 contact_phone='dont call me'
37 hostProfile = HostProfile.objects.create(
40 description='a test profile'
42 interfaceProfile = InterfaceProfile.objects.create(
47 diskProfile = DiskProfile.objects.create(
53 cpuProfile = CpuProfile.objects.create(
55 architecture="x86_64",
59 ramProfile = RamProfile.objects.create(
65 #create GenericResourceBundle
66 genericBundle = GenericResourceBundle.objects.create()
68 self.gHost1 = GenericHost.objects.create(
70 name='generic host 1',
73 self.gHost2 = GenericHost.objects.create(
75 name='generic host 2',
79 #actual resource bundle
80 bundle = ResourceBundle.objects.create(template=genericBundle)
82 self.host1 = Host.objects.create(
91 self.host2 = Host.objects.create(
100 vlan1 = Vlan.objects.create(vlan_id=300, tagged=False)
101 vlan2 = Vlan.objects.create(vlan_id=300, tagged=False)
103 iface1 = Interface.objects.create(
104 mac_address='00:11:22:33:44:55',
105 bus_address='some bus address',
106 switch_name='switch1',
111 iface2 = Interface.objects.create(
112 mac_address='00:11:22:33:44:56',
113 bus_address='some bus address',
114 switch_name='switch1',
120 def test_acquire_host(self):
121 host = InventoryManager.getInstance().acquireHost(self.gHost1, self.lab.name)
122 self.assertNotEquals(host, None)
123 self.assertTrue(host.booked)
124 self.assertEqual(host.template, self.gHost1)
126 def test_release_host(self):
127 host = InventoryManager.getInstance().acquireHost(self.gHost1, self.lab.name)
128 self.assertTrue(host.booked)
129 InventoryManager.getInstance().releaseHost(host)
130 self.assertFalse(host.booked)
133 class ResourceManagerTestCase(TestCase):
134 def test_singleton(self):
135 instance = ResourceManager.getInstance()
136 self.assertTrue(isinstance(instance, ResourceManager))
137 self.assertTrue(instance is ResourceManager.getInstance())
141 # create lab and give it resources
142 user = User.objects.create(username="username")
143 self.lab = Lab.objects.create(
146 contact_email='someone@email.com',
147 contact_phone='dont call me'
151 hostProfile = HostProfile.objects.create(
154 description='a test profile'
156 interfaceProfile = InterfaceProfile.objects.create(
161 diskProfile = DiskProfile.objects.create(
167 cpuProfile = CpuProfile.objects.create(
169 architecture="x86_64",
173 ramProfile = RamProfile.objects.create(
179 #create GenericResourceBundle
180 genericBundle = GenericResourceBundle.objects.create()
182 self.gHost1 = GenericHost.objects.create(
183 bundle=genericBundle,
184 name='generic host 1',
187 self.gHost2 = GenericHost.objects.create(
188 bundle=genericBundle,
189 name='generic host 2',
193 #actual resource bundle
194 bundle = ResourceBundle.objects.create(template=genericBundle)
196 self.host1 = Host.objects.create(
197 template=self.gHost1,
205 self.host2 = Host.objects.create(
206 template=self.gHost2,
214 vlan1 = Vlan.objects.create(vlan_id=300, tagged=False)
215 vlan2 = Vlan.objects.create(vlan_id=300, tagged=False)
217 iface1 = Interface.objects.create(
218 mac_address='00:11:22:33:44:55',
219 bus_address='some bus address',
220 switch_name='switch1',
225 iface2 = Interface.objects.create(
226 mac_address='00:11:22:33:44:56',
227 bus_address='some bus address',
228 switch_name='switch1',
234 def test_convert_bundle(self):
235 bundle = ResourceManager.getInstance().convertResoureBundle(self.genericBundle, self.lab.name)
236 # verify bundle configuration