aboutsummaryrefslogtreecommitdiffstats
path: root/src/resource_inventory/tests
diff options
context:
space:
mode:
authorJustin Choquette <jchoquette@iol.unh.edu>2023-06-08 12:46:53 -0400
committerJustin Choquette <jchoquette@iol.unh.edu>2023-07-21 13:17:51 -0400
commita09db9f287a02873c0226759f8ea444bb304cd59 (patch)
tree59e744e4b998973a808abbae2d21fbdd6201d829 /src/resource_inventory/tests
parent8ddc7e820e120f1dde4e901d3cb6f1dd3f281e65 (diff)
LaaS 3.0 Almost MVP
Change-Id: Ided9a43cf3088bb58a233dc459711c03f43e11b8 Signed-off-by: Justin Choquette <jchoquette@iol.unh.edu>
Diffstat (limited to 'src/resource_inventory/tests')
-rw-r--r--src/resource_inventory/tests/test_managers.py301
-rw-r--r--src/resource_inventory/tests/test_models.py173
2 files changed, 0 insertions, 474 deletions
diff --git a/src/resource_inventory/tests/test_managers.py b/src/resource_inventory/tests/test_managers.py
deleted file mode 100644
index 46cee5a..0000000
--- a/src/resource_inventory/tests/test_managers.py
+++ /dev/null
@@ -1,301 +0,0 @@
-##############################################################################
-# Copyright (c) 2018 Parker Berberian, 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 django.contrib.auth.models import User
-
-from resource.inventory_manager import InventoryManager
-from resource.resource_manager import ResourceManager, HostNameValidator
-from account.models import Lab
-from resource.models import (
- Host,
- Vlan,
- Interface,
- ResourceBundle,
- GenericHost,
- GenericResourceBundle,
- CpuProfile,
- RamProfile,
- DiskProfile,
- HostProfile,
- InterfaceProfile
-)
-
-
-class InventoryManagerTestCase(TestCase):
-
- def test_singleton(self):
- instance = InventoryManager.getInstance()
- self.assertTrue(isinstance(instance, InventoryManager))
- self.assertTrue(instance is InventoryManager.getInstance())
-
- def setUp(self):
- # setup
- # create lab and give it resources
- user = User.objects.create(username="username")
- self.lab = Lab.objects.create(
- lab_user=user,
- name='test lab',
- contact_email='someone@email.com',
- contact_phone='dont call me'
- )
-
- # create hostProfile
- hostProfile = HostProfile.objects.create(
- host_type=0,
- name='Test profile',
- description='a test profile'
- )
- InterfaceProfile.objects.create(
- speed=1000,
- name='eno3',
- host=hostProfile
- )
- DiskProfile.objects.create(
- size=1000,
- media_type="SSD",
- name='/dev/sda',
- host=hostProfile
- )
- CpuProfile.objects.create(
- cores=96,
- architecture="x86_64",
- cpus=2,
- host=hostProfile
- )
- RamProfile.objects.create(
- amount=256,
- channels=4,
- host=hostProfile
- )
-
- # create GenericResourceBundle
- genericBundle = GenericResourceBundle.objects.create()
-
- self.gHost1 = GenericHost.objects.create(
- bundle=genericBundle,
- name='generic host 1',
- profile=hostProfile
- )
- self.gHost2 = GenericHost.objects.create(
- bundle=genericBundle,
- name='generic host 2',
- profile=hostProfile
- )
-
- # actual resource bundle
- bundle = ResourceBundle.objects.create(template=genericBundle)
-
- self.host1 = Host.objects.create(
- template=self.gHost1,
- booked=True,
- name='host1',
- bundle=bundle,
- profile=hostProfile,
- lab=self.lab
- )
-
- self.host2 = Host.objects.create(
- template=self.gHost2,
- booked=True,
- name='host2',
- bundle=bundle,
- profile=hostProfile,
- lab=self.lab
- )
-
- vlan1 = Vlan.objects.create(vlan_id=300, tagged=False)
- vlan2 = Vlan.objects.create(vlan_id=300, tagged=False)
-
- Interface.objects.create(
- mac_address='00:11:22:33:44:55',
- bus_address='some bus address',
- switch_name='switch1',
- port_name='port10',
- config=vlan1,
- host=self.host1
- )
- Interface.objects.create(
- mac_address='00:11:22:33:44:56',
- bus_address='some bus address',
- switch_name='switch1',
- port_name='port12',
- config=vlan2,
- host=self.host2
- )
-
- def test_acquire_host(self):
- host = InventoryManager.getInstance().acquireHost(self.gHost1, self.lab.name)
- self.assertNotEquals(host, None)
- self.assertTrue(host.booked)
- self.assertEqual(host.template, self.gHost1)
-
- def test_release_host(self):
- host = InventoryManager.getInstance().acquireHost(self.gHost1, self.lab.name)
- self.assertTrue(host.booked)
- InventoryManager.getInstance().releaseHost(host)
- self.assertFalse(host.booked)
-
-
-class ResourceManagerTestCase(TestCase):
- def test_singleton(self):
- instance = ResourceManager.getInstance()
- self.assertTrue(isinstance(instance, ResourceManager))
- self.assertTrue(instance is ResourceManager.getInstance())
-
- def setUp(self):
- # setup
- # create lab and give it resources
- user = User.objects.create(username="username")
- self.lab = Lab.objects.create(
- lab_user=user,
- name='test lab',
- contact_email='someone@email.com',
- contact_phone='dont call me'
- )
-
- # create hostProfile
- hostProfile = HostProfile.objects.create(
- host_type=0,
- name='Test profile',
- description='a test profile'
- )
- InterfaceProfile.objects.create(
- speed=1000,
- name='eno3',
- host=hostProfile
- )
- DiskProfile.objects.create(
- size=1000,
- media_type="SSD",
- name='/dev/sda',
- host=hostProfile
- )
- CpuProfile.objects.create(
- cores=96,
- architecture="x86_64",
- cpus=2,
- host=hostProfile
- )
- RamProfile.objects.create(
- amount=256,
- channels=4,
- host=hostProfile
- )
-
- # create GenericResourceBundle
- genericBundle = GenericResourceBundle.objects.create()
-
- self.gHost1 = GenericHost.objects.create(
- bundle=genericBundle,
- name='generic host 1',
- profile=hostProfile
- )
- self.gHost2 = GenericHost.objects.create(
- bundle=genericBundle,
- name='generic host 2',
- profile=hostProfile
- )
-
- # actual resource bundle
- bundle = ResourceBundle.objects.create(template=genericBundle)
-
- self.host1 = Host.objects.create(
- template=self.gHost1,
- booked=True,
- name='host1',
- bundle=bundle,
- profile=hostProfile,
- lab=self.lab
- )
-
- self.host2 = Host.objects.create(
- template=self.gHost2,
- booked=True,
- name='host2',
- bundle=bundle,
- profile=hostProfile,
- lab=self.lab
- )
-
- vlan1 = Vlan.objects.create(vlan_id=300, tagged=False)
- vlan2 = Vlan.objects.create(vlan_id=300, tagged=False)
-
- Interface.objects.create(
- mac_address='00:11:22:33:44:55',
- bus_address='some bus address',
- switch_name='switch1',
- port_name='port10',
- config=vlan1,
- host=self.host1
- )
- Interface.objects.create(
- mac_address='00:11:22:33:44:56',
- bus_address='some bus address',
- switch_name='switch1',
- port_name='port12',
- config=vlan2,
- host=self.host2
- )
-
- def test_convert_bundle(self):
- ResourceManager.getInstance().convertResoureBundle(self.genericBundle, self.lab.name)
- # verify bundle configuration
-
-
-class HostNameValidatorTestCase(TestCase):
-
- def test_valid_hostnames(self):
- self.assertTrue(HostNameValidator.is_valid_hostname("localhost"))
- self.assertTrue(HostNameValidator.is_valid_hostname("Localhost"))
- self.assertTrue(HostNameValidator.is_valid_hostname("localHost"))
- self.assertTrue(HostNameValidator.is_valid_hostname("LOCALHOST"))
- self.assertTrue(HostNameValidator.is_valid_hostname("f"))
- self.assertTrue(HostNameValidator.is_valid_hostname("abc123doreyme"))
- self.assertTrue(HostNameValidator.is_valid_hostname("F9999999"))
- self.assertTrue(HostNameValidator.is_valid_hostname("my-host"))
- self.assertTrue(HostNameValidator.is_valid_hostname("My-Host"))
- self.assertTrue(HostNameValidator.is_valid_hostname("MY-HOST"))
- self.assertTrue(HostNameValidator.is_valid_hostname("a-long-name-for-my-host"))
-
- def test_invalid_hostnames(self):
- self.assertFalse(HostNameValidator.is_valid_hostname("-long-name-for-my-host"))
- self.assertFalse(HostNameValidator.is_valid_hostname("546"))
- self.assertFalse(HostNameValidator.is_valid_hostname("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
-
- def test_invalid_chars(self):
- self.assertFalse(HostNameValidator.is_valid_hostname("contains!char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains@char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains#char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains$char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains%char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains^char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains&char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains*char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains(char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains)char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains_char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains=char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains+char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains|char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains\\char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains[char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains]char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains;char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains:char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains'char"))
- self.assertFalse(HostNameValidator.is_valid_hostname('contains"char'))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains'char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains<char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains>char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains,char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains?char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains/char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains`char"))
- self.assertFalse(HostNameValidator.is_valid_hostname("contains~char"))
diff --git a/src/resource_inventory/tests/test_models.py b/src/resource_inventory/tests/test_models.py
deleted file mode 100644
index 3f2d1d8..0000000
--- a/src/resource_inventory/tests/test_models.py
+++ /dev/null
@@ -1,173 +0,0 @@
-##############################################################################
-# Copyright (c) 2018 Parker Berberian, 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 django.contrib.auth.models import User
-from account.models import Lab
-from resource_inventory.models import (
- Scenario,
- Installer,
- Opsys,
- ConfigBundle,
- OPNFVConfig,
- OPNFVRole,
- Image,
- HostProfile,
- GenericResourceBundle,
- GenericResource,
- GenericHost,
- HostConfiguration
-)
-
-
-class ConfigUtil():
- count = 0
-
- @staticmethod
- def makeScenario():
- return Scenario.objects.create(name="testScenario")
-
- @staticmethod
- def makeInstaller():
- inst = Installer.objects.create(name="testInstaller")
- inst.sup_scenarios = [ConfigUtil.makeScenario()]
- return inst
-
- @staticmethod
- def makeOpsys():
- os = Opsys.objects.create(name="test Operating System")
- os.sup_installers = [ConfigUtil.makeInstaller()]
- return os
-
- @staticmethod
- def makeConfigBundle():
- user = User.objects.create(username="test_user" + str(ConfigUtil.count))
- ConfigUtil.count += 1
- return ConfigBundle.objects.create(owner=user)
-
- @staticmethod
- def makeOPNFVConfig():
- installer = ConfigUtil.makeInstaller()
- scenario = ConfigUtil.makeScenario()
- bundle = ConfigUtil.makeConfigBundle()
- return OPNFVConfig.objects.create(
- installer=installer,
- scenario=scenario,
- bundle=bundle
- )
-
- @staticmethod
- def makeOPNFVRole():
- return OPNFVRole.objects.create(
- name="Test role",
- description="This is a test role"
- )
-
- @staticmethod
- def makeImage():
- owner = User.objects.create(username="another test user")
- lab_user = User.objects.create(username="labUserForTests")
- lab = Lab.objects.create(
- lab_user=lab_user,
- name="this is lab for testing",
- contact_email="email@mail.com",
- contact_phone="123-4567"
- )
-
- return Image.objects.create(
- cobbler_id="profile1",
- from_lab=lab,
- name="an image for testing",
- owner=owner
- )
-
- @staticmethod
- def makeGenericHost():
- profile = HostProfile.objects.create(
- host_type=0,
- name="test lab for config bundle",
- description="this is a test profile"
- )
- user = User.objects.create(username="test sample user 12")
- bundle = GenericResourceBundle.objects.create(
- name="Generic bundle for config tests",
- xml="",
- owner=user,
- description=""
- )
-
- resource = GenericResource.objects.create(
- bundle=bundle,
- name="a test generic resource"
- )
-
- return GenericHost.objects.create(
- profile=profile,
- resource=resource
- )
-
- @staticmethod
- def makeHostConfiguration():
- host = ConfigUtil.makeGenericHost()
- image = ConfigUtil.makeImage()
- bundle = ConfigUtil.makeConfigBundle()
- opnfvRole = ConfigUtil.makeOPNFVRole()
- return HostConfiguration.objects.create(
- host=host,
- image=image,
- bundle=bundle,
- opnfvRole=opnfvRole
- )
-
-
-class ScenarioTestCase(TestCase):
-
- def test_save(self):
- self.assertTrue(ConfigUtil.makeScenario())
-
-
-class InstallerTestCase(TestCase):
-
- def test_save(self):
- self.assertTrue(ConfigUtil.makeInstaller())
-
-
-class OperatingSystemTestCase(TestCase):
-
- def test_save(self):
- self.assertTrue(ConfigUtil.makeOpsys())
-
-
-class ConfigBundleTestCase(TestCase):
-
- def test_save(self):
- self.assertTrue(ConfigUtil.makeConfigBundle())
-
-
-class OPNFVConfigTestCase(TestCase):
-
- def test_save(self):
- self.assertTrue(ConfigUtil.makeOPNFVConfig())
-
-
-class OPNFVRoleTestCase(TestCase):
-
- def test_save(self):
- self.assertTrue(ConfigUtil.makeOPNFVRole())
-
-
-class HostConfigurationTestCase(TestCase):
-
- def test_save(self):
- self.assertTrue(ConfigUtil.makeHostConfiguration())
-
-
-class ImageTestCase(TestCase):
-
- def test_save(self):
- self.assertTrue(ConfigUtil.makeImage())