diff options
author | Parker Berberian <pberberian@iol.unh.edu> | 2018-10-10 16:06:47 -0400 |
---|---|---|
committer | Parker Berberian <pberberian@iol.unh.edu> | 2018-10-15 13:16:11 -0400 |
commit | 1f3a770d2547848590f39e9d9b9bdffeb94eec14 (patch) | |
tree | 97222e5facd1a242d951c38482315057b5790d51 /src/api/tests | |
parent | 6d4019e59eda897384e9c00d1daf8b2ce87d128f (diff) |
Lab as a Service 2.0
See changes here:
https://wiki.opnfv.org/display/INF/Pharos+Laas
Change-Id: I59ada5f98e70a28d7f8c14eab3239597e236ca26
Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
Signed-off-by: Parker Berberian <pberberian@iol.unh.edu>
Diffstat (limited to 'src/api/tests')
-rw-r--r-- | src/api/tests/__init__.py | 8 | ||||
-rw-r--r-- | src/api/tests/test_serializers.py | 213 |
2 files changed, 221 insertions, 0 deletions
diff --git a/src/api/tests/__init__.py b/src/api/tests/__init__.py new file mode 100644 index 0000000..fe2a32d --- /dev/null +++ b/src/api/tests/__init__.py @@ -0,0 +1,8 @@ +############################################################################## +# Copyright (c) 2016 Parker Berberian and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +##############################################################################
\ No newline at end of file diff --git a/src/api/tests/test_serializers.py b/src/api/tests/test_serializers.py new file mode 100644 index 0000000..c49010c --- /dev/null +++ b/src/api/tests/test_serializers.py @@ -0,0 +1,213 @@ +############################################################################## +# Copyright (c) 2018 Sawyer Bergeron and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +from django.test import TestCase +from booking.models import Booking +from resource_inventory.models import * +from account.models import Lab +from api.serializers.booking_serializer import * +from datetime import timedelta +from django.utils import timezone +from django.contrib.auth.models import Permission, User + + +class BookingSerializerTestCase(TestCase): + + count = 0 + + def makeHostConfigurations(self, hosts, config): + lab_user = User.objects.create(username="asfasdfasdf") + owner = User.objects.create(username="asfasdfasdffffff") + lab = Lab.objects.create( + lab_user=lab_user, + name="TestLab123123", + contact_email="mail@email.com", + contact_phone="" + ) + jumphost=True + for host in hosts: + image = Image.objects.create( + lab_id=12, + from_lab=lab, + name="this is a test image", + owner=owner + ) + name = "jumphost" + if not jumphost: + name = "compute" + role = OPNFVRole.objects.create( + name=name, + description="stuff" + ) + + HostConfiguration.objects.create( + host=host, + image=image, + bundle=config, + opnfvRole=role + ) + jumphost=False + + + def setUp(self): + self.serializer = BookingField() + lab_user = User.objects.create(username="lab user") + lab = Lab.objects.create(name="test lab", lab_user=lab_user) + # create hostProfile + hostProfile = HostProfile.objects.create( + host_type=0, + name='Test profile', + description='a test profile' + ) + interfaceProfile = InterfaceProfile.objects.create( + speed=1000, + name='eno3', + host=hostProfile + ) + diskProfile = DiskProfile.objects.create( + size=1000, + media_type="SSD", + name='/dev/sda', + host=hostProfile + ) + cpuProfile = CpuProfile.objects.create( + cores=96, + architecture="x86_64", + cpus=2, + host=hostProfile + ) + ramProfile = RamProfile.objects.create( + amount=256, + channels=4, + host=hostProfile + ) + + #create GenericResourceBundle + genericBundle = GenericResourceBundle.objects.create() + + gres1 = GenericResource.objects.create( + bundle=genericBundle, + name='generic resource ' + str(self.count) + ) + self.count += 1 + gHost1 = GenericHost.objects.create( + resource=gres1, + profile=hostProfile + ) + + gres2 = GenericResource.objects.create( + bundle=genericBundle, + name='generic resource ' + str(self.count) + ) + self.count += 1 + gHost2 = GenericHost.objects.create( + resource=gres2, + profile=hostProfile + ) + user1 = User.objects.create(username='user1') + + add_booking_perm = Permission.objects.get(codename='add_booking') + user1.user_permissions.add(add_booking_perm) + + user1 = User.objects.get(pk=user1.id) + + conf = ConfigBundle.objects.create(owner=user1, name="test conf") + self.makeHostConfigurations([gHost1, gHost2], conf) + + #actual resource bundle + bundle = ResourceBundle.objects.create( + template = genericBundle + ) + + host1 = Host.objects.create( + template=gHost1, + booked=True, + name='host1', + bundle=bundle, + profile=hostProfile, + lab=lab + ) + + host2 = Host.objects.create( + template=gHost2, + booked=True, + name='host2', + bundle=bundle, + profile=hostProfile, + lab=lab + ) + + vlan1 = Vlan.objects.create(vlan_id=300, tagged=False) + vlan2 = Vlan.objects.create(vlan_id=300, tagged=False) + + iface1 = Interface.objects.create( + mac_address='00:11:22:33:44:55', + bus_address='some bus address', + switch_name='switch1', + port_name='port10', + host=host1 + ) + + iface1.config = [vlan1] + + iface2 = Interface.objects.create( + mac_address='00:11:22:33:44:56', + bus_address='some bus address', + switch_name='switch1', + port_name='port12', + host=host2 + ) + + iface2.config = [vlan2] + + # finally, can create booking + self.booking = Booking.objects.create( + owner=user1, + start = timezone.now(), + end = timezone.now() + timedelta(weeks=1), + purpose='Testing', + resource=bundle, + config_bundle=conf + ) + + serialized_booking = {} + + host1 = {} + host1['hostname'] = 'host1' + host1['image'] = {} # TODO: Images + host1['deploy_image'] = True + host2 = {} + host2['hostname'] = 'host2' + host2['image'] = {} # TODO: Images + host2['deploy_image'] = True + + serialized_booking['hosts'] = [host1, host2] + + net = {} + net['name'] = 'network_name' + net['vlan_id'] = 300 + netHost1 = {} + netHost1['hostname'] = 'host1' + netHost1['tagged'] = False + netHost1['interface'] = 0 + netHost2 = {} + netHost2['hostname'] = 'host2' + netHost2['tagged'] = False + netHost2['interface'] = 0 + net['hosts'] = [netHost1, netHost2] + + serialized_booking['networking'] = [net] + serialized_booking['jumphost'] = 'host1' + + self.serialized_booking = serialized_booking + + def test_to_representation(self): + keys = ['hosts', 'networking', 'jumphost'] + serialized_form = self.serializer.to_representation(self.booking) + for key in keys: + self.assertEquals(serialized_form[key], self.serialized_booking) |