summaryrefslogtreecommitdiffstats
path: root/src/resource_inventory
diff options
context:
space:
mode:
authorParker Berberian <pberberian@iol.unh.edu>2018-11-20 11:19:55 -0500
committerParker Berberian <pberberian@iol.unh.edu>2018-11-26 14:07:15 -0500
commitb7c4d286ffa618be0e95b15f3883e2f6920a3fb1 (patch)
tree930e9b9282b8f50e671844b2a1e7f39dc5d6035d /src/resource_inventory
parent6a90796de1df8d74c79415c39c867ffe6cd80fd0 (diff)
Fix all flake8 errors
The flake8 command in test.sh finds no longer finds any errors. This may form a basis of a jenkins verify job as a sort of 'weak compile-time checks' The flake8 command will not complain about line length, and will not complain about django's manage.py file Change-Id: Ic47cb4fc7ada55e64485661ab6881aef475018ff Signed-off-by: Parker Berberian <pberberian@iol.unh.edu>
Diffstat (limited to 'src/resource_inventory')
-rw-r--r--src/resource_inventory/admin.py25
-rw-r--r--src/resource_inventory/models.py37
-rw-r--r--src/resource_inventory/resource_manager.py24
-rw-r--r--src/resource_inventory/tests/test_managers.py49
-rw-r--r--src/resource_inventory/tests/test_models.py109
-rw-r--r--src/resource_inventory/views.py5
6 files changed, 158 insertions, 91 deletions
diff --git a/src/resource_inventory/admin.py b/src/resource_inventory/admin.py
index 37b0c45..e063cc0 100644
--- a/src/resource_inventory/admin.py
+++ b/src/resource_inventory/admin.py
@@ -10,7 +10,30 @@
from django.contrib import admin
-from resource_inventory.models import *
+from resource_inventory.models import (
+ HostProfile,
+ InterfaceProfile,
+ DiskProfile,
+ CpuProfile,
+ RamProfile,
+ GenericResourceBundle,
+ GenericResource,
+ GenericHost,
+ GenericInterface,
+ Host,
+ Interface,
+ Network,
+ Vlan,
+ ResourceBundle,
+ Scenario,
+ Installer,
+ Opsys,
+ ConfigBundle,
+ OPNFVConfig,
+ OPNFVRole,
+ Image,
+ HostConfiguration
+)
profiles = [HostProfile, InterfaceProfile, DiskProfile, CpuProfile, RamProfile]
diff --git a/src/resource_inventory/models.py b/src/resource_inventory/models.py
index b71748e..b56317b 100644
--- a/src/resource_inventory/models.py
+++ b/src/resource_inventory/models.py
@@ -40,10 +40,14 @@ class InterfaceProfile(models.Model):
speed = models.IntegerField()
name = models.CharField(max_length=100)
host = models.ForeignKey(HostProfile, on_delete=models.DO_NOTHING, related_name='interfaceprofile')
- nic_type = models.CharField(max_length=50, choices=[
- ("onboard", "onboard"),
- ("pcie", "pcie")
- ], default="onboard")
+ nic_type = models.CharField(
+ max_length=50,
+ choices=[
+ ("onboard", "onboard"),
+ ("pcie", "pcie")
+ ],
+ default="onboard"
+ )
def __str__(self):
return self.name + " for " + str(self.host)
@@ -59,14 +63,18 @@ class DiskProfile(models.Model):
name = models.CharField(max_length=50)
host = models.ForeignKey(HostProfile, on_delete=models.DO_NOTHING, related_name='storageprofile')
rotation = models.IntegerField(default=0)
- interface = models.CharField(max_length=50, choices=[
+ interface = models.CharField(
+ max_length=50,
+ choices=[
("sata", "sata"),
("sas", "sas"),
("ssd", "ssd"),
("nvme", "nvme"),
("scsi", "scsi"),
("iscsi", "iscsi"),
- ], default="sata")
+ ],
+ default="sata"
+ )
def __str__(self):
return self.name + " for " + str(self.host)
@@ -97,7 +105,7 @@ class RamProfile(models.Model):
return str(self.amount) + "G for " + str(self.host)
-##Networking -- located here due to import order requirements
+# Networking -- located here due to import order requirements
class Network(models.Model):
id = models.AutoField(primary_key=True)
vlan_id = models.IntegerField()
@@ -106,6 +114,7 @@ class Network(models.Model):
def __str__(self):
return self.name
+
class Vlan(models.Model):
id = models.AutoField(primary_key=True)
vlan_id = models.IntegerField()
@@ -194,6 +203,7 @@ class Scenario(models.Model):
def __str__(self):
return self.name
+
class Installer(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=200)
@@ -202,6 +212,7 @@ class Installer(models.Model):
def __str__(self):
return self.name
+
class Opsys(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)
@@ -210,9 +221,10 @@ class Opsys(models.Model):
def __str__(self):
return self.name
+
class ConfigBundle(models.Model):
id = models.AutoField(primary_key=True)
- owner = models.ForeignKey(User, on_delete=models.CASCADE) #consider setting to root user?
+ owner = models.ForeignKey(User, on_delete=models.CASCADE) # consider setting to root user?
name = models.CharField(max_length=200, unique=True)
description = models.CharField(max_length=1000, default="")
bundle = models.ForeignKey(GenericResourceBundle, null=True, on_delete=models.CASCADE)
@@ -220,6 +232,7 @@ class ConfigBundle(models.Model):
def __str__(self):
return self.name
+
class OPNFVConfig(models.Model):
id = models.AutoField(primary_key=True)
installer = models.ForeignKey(Installer, on_delete=models.CASCADE)
@@ -229,6 +242,7 @@ class OPNFVConfig(models.Model):
def __str__(self):
return "OPNFV job with " + str(self.installer) + " and " + str(self.scenario)
+
class OPNFVRole(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=200)
@@ -237,6 +251,7 @@ class OPNFVRole(models.Model):
def __str__(self):
return self.name
+
class Image(models.Model):
"""
model for representing OS images / snapshots of hosts
@@ -247,12 +262,14 @@ class Image(models.Model):
name = models.CharField(max_length=200)
owner = models.ForeignKey(User, null=True, on_delete=models.SET_NULL)
public = models.BooleanField(default=True)
- host_type = models.ForeignKey(HostProfile, on_delete=models.CASCADE) #may need to change to models.SET() once images are transferrable between compatible host types
+ # may need to change host_type.on_delete to models.SET() once images are transferrable between compatible host types
+ host_type = models.ForeignKey(HostProfile, on_delete=models.CASCADE)
description = models.TextField()
def __str__(self):
return self.name
+
class HostConfiguration(models.Model):
"""
model to represent a complete configuration for a single
@@ -262,7 +279,7 @@ class HostConfiguration(models.Model):
host = models.ForeignKey(GenericHost, related_name="configuration", on_delete=models.CASCADE)
image = models.ForeignKey(Image, on_delete=models.PROTECT)
bundle = models.ForeignKey(ConfigBundle, related_name="hostConfigurations", null=True, on_delete=models.CASCADE)
- opnfvRole = models.ForeignKey(OPNFVRole, on_delete=models.PROTECT) #need protocol for phasing out a role if we are going to allow that to happen
+ opnfvRole = models.ForeignKey(OPNFVRole, on_delete=models.PROTECT)
def __str__(self):
return "config with " + str(self.host) + " and image " + str(self.image)
diff --git a/src/resource_inventory/resource_manager.py b/src/resource_inventory/resource_manager.py
index cd70867..3380990 100644
--- a/src/resource_inventory/resource_manager.py
+++ b/src/resource_inventory/resource_manager.py
@@ -8,12 +8,17 @@
##############################################################################
-from django.core.exceptions import *
from django.template.loader import render_to_string
import booking
-from dashboard.exceptions import *
-from resource_inventory.models import *
+from dashboard.exceptions import (
+ ResourceExistenceException,
+ ResourceAvailabilityException,
+ ResourceProvisioningException,
+ ModelValidationException
+)
+from resource_inventory.models import Host, HostConfiguration, ResourceBundle
+
class ResourceManager:
@@ -28,7 +33,7 @@ class ResourceManager:
ResourceManager.instance = ResourceManager()
return ResourceManager.instance
- #public interface
+ # public interface
def deleteResourceBundle(self, resourceBundle):
for host in Host.objects.filter(bundle=resourceBundle):
self.releaseHost(host)
@@ -44,13 +49,13 @@ class ResourceManager:
hosts = genericResourceBundle.getHosts()
- #current supported case: user creating new booking
- #currently unsupported: editing existing booking
+ # current supported case: user creating new booking
+ # currently unsupported: editing existing booking
physical_hosts = []
for host in hosts:
- host_config=None
+ host_config = None
if config:
host_config = HostConfiguration.objects.get(bundle=config, host=host)
try:
@@ -84,7 +89,7 @@ class ResourceManager:
for vlan in generic_interface.vlans.all():
physical_interface.config.add(vlan)
- #private interface
+ # private interface
def acquireHost(self, genericHost, labName):
host_full_set = Host.objects.filter(lab__name__exact=labName, profile=genericHost.profile)
if not host_full_set.first():
@@ -135,7 +140,7 @@ class ResourceManager:
booking_owner = booking.models.Booking.objects.get(resource=resource).owner
owner = booking_owner.username
email = booking_owner.userprofile.email_addr
- except Exception as e:
+ except Exception:
pass
details['owner'] = owner
@@ -159,7 +164,6 @@ class ResourceManager:
return pdf_nodes
-
def get_pdf_host(self, host):
host_info = {}
host_info['name'] = host.template.resource.name
diff --git a/src/resource_inventory/tests/test_managers.py b/src/resource_inventory/tests/test_managers.py
index 5a13b2e..0e7c673 100644
--- a/src/resource_inventory/tests/test_managers.py
+++ b/src/resource_inventory/tests/test_managers.py
@@ -12,7 +12,20 @@ from django.contrib.auth.models import User
from resource.inventory_manager import InventoryManager
from resource.resource_manager import ResourceManager
-from resource.models import *
+from account.models import Lab
+from resource.models import (
+ Host,
+ Vlan,
+ Interface,
+ ResourceBundle,
+ GenericHost,
+ GenericResourceBundle,
+ CpuProfile,
+ RamProfile,
+ DiskProfile,
+ HostProfile,
+ InterfaceProfile
+)
class InventoryManagerTestCase(TestCase):
@@ -39,30 +52,30 @@ class InventoryManagerTestCase(TestCase):
name='Test profile',
description='a test profile'
)
- interfaceProfile = InterfaceProfile.objects.create(
+ InterfaceProfile.objects.create(
speed=1000,
name='eno3',
host=hostProfile
)
- diskProfile = DiskProfile.objects.create(
+ DiskProfile.objects.create(
size=1000,
media_type="SSD",
name='/dev/sda',
host=hostProfile
)
- cpuProfile = CpuProfile.objects.create(
+ CpuProfile.objects.create(
cores=96,
architecture="x86_64",
cpus=2,
host=hostProfile
)
- ramProfile = RamProfile.objects.create(
+ RamProfile.objects.create(
amount=256,
channels=4,
host=hostProfile
)
- #create GenericResourceBundle
+ # create GenericResourceBundle
genericBundle = GenericResourceBundle.objects.create()
self.gHost1 = GenericHost.objects.create(
@@ -76,7 +89,7 @@ class InventoryManagerTestCase(TestCase):
profile=hostProfile
)
- #actual resource bundle
+ # actual resource bundle
bundle = ResourceBundle.objects.create(template=genericBundle)
self.host1 = Host.objects.create(
@@ -100,7 +113,7 @@ class InventoryManagerTestCase(TestCase):
vlan1 = Vlan.objects.create(vlan_id=300, tagged=False)
vlan2 = Vlan.objects.create(vlan_id=300, tagged=False)
- iface1 = Interface.objects.create(
+ Interface.objects.create(
mac_address='00:11:22:33:44:55',
bus_address='some bus address',
switch_name='switch1',
@@ -108,7 +121,7 @@ class InventoryManagerTestCase(TestCase):
config=vlan1,
host=self.host1
)
- iface2 = Interface.objects.create(
+ Interface.objects.create(
mac_address='00:11:22:33:44:56',
bus_address='some bus address',
switch_name='switch1',
@@ -153,30 +166,30 @@ class ResourceManagerTestCase(TestCase):
name='Test profile',
description='a test profile'
)
- interfaceProfile = InterfaceProfile.objects.create(
+ InterfaceProfile.objects.create(
speed=1000,
name='eno3',
host=hostProfile
)
- diskProfile = DiskProfile.objects.create(
+ DiskProfile.objects.create(
size=1000,
media_type="SSD",
name='/dev/sda',
host=hostProfile
)
- cpuProfile = CpuProfile.objects.create(
+ CpuProfile.objects.create(
cores=96,
architecture="x86_64",
cpus=2,
host=hostProfile
)
- ramProfile = RamProfile.objects.create(
+ RamProfile.objects.create(
amount=256,
channels=4,
host=hostProfile
)
- #create GenericResourceBundle
+ # create GenericResourceBundle
genericBundle = GenericResourceBundle.objects.create()
self.gHost1 = GenericHost.objects.create(
@@ -190,7 +203,7 @@ class ResourceManagerTestCase(TestCase):
profile=hostProfile
)
- #actual resource bundle
+ # actual resource bundle
bundle = ResourceBundle.objects.create(template=genericBundle)
self.host1 = Host.objects.create(
@@ -214,7 +227,7 @@ class ResourceManagerTestCase(TestCase):
vlan1 = Vlan.objects.create(vlan_id=300, tagged=False)
vlan2 = Vlan.objects.create(vlan_id=300, tagged=False)
- iface1 = Interface.objects.create(
+ Interface.objects.create(
mac_address='00:11:22:33:44:55',
bus_address='some bus address',
switch_name='switch1',
@@ -222,7 +235,7 @@ class ResourceManagerTestCase(TestCase):
config=vlan1,
host=self.host1
)
- iface2 = Interface.objects.create(
+ Interface.objects.create(
mac_address='00:11:22:33:44:56',
bus_address='some bus address',
switch_name='switch1',
@@ -232,5 +245,5 @@ class ResourceManagerTestCase(TestCase):
)
def test_convert_bundle(self):
- bundle = ResourceManager.getInstance().convertResoureBundle(self.genericBundle, self.lab.name)
+ ResourceManager.getInstance().convertResoureBundle(self.genericBundle, self.lab.name)
# verify bundle configuration
diff --git a/src/resource_inventory/tests/test_models.py b/src/resource_inventory/tests/test_models.py
index 4ddedf2..e1b2106 100644
--- a/src/resource_inventory/tests/test_models.py
+++ b/src/resource_inventory/tests/test_models.py
@@ -9,11 +9,24 @@
from django.test import TestCase
from django.contrib.auth.models import User
from account.models import Lab
-from resource_inventory.models import *
+from resource_inventory.models import (
+ Scenario,
+ Installer,
+ Opsys,
+ ConfigBundle,
+ OPNFVConfig,
+ OPNFVRole,
+ Image,
+ HostProfile,
+ GenericResourceBundle,
+ GenericResource,
+ GenericHost,
+ HostConfiguration
+)
class ConfigUtil():
- count=0
+ count = 0
@staticmethod
def makeScenario():
@@ -21,17 +34,13 @@ class ConfigUtil():
@staticmethod
def makeInstaller():
- inst = Installer.objects.create(
- name = "testInstaller"
- )
+ 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 = Opsys.objects.create(name="test Operating System")
os.sup_installers = [ConfigUtil.makeInstaller()]
return os
@@ -39,9 +48,7 @@ class ConfigUtil():
def makeConfigBundle():
user = User.objects.create(username="test_user" + str(ConfigUtil.count))
ConfigUtil.count += 1
- return ConfigBundle.objects.create(
- owner = user
- )
+ return ConfigBundle.objects.create(owner=user)
@staticmethod
def makeOPNFVConfig():
@@ -49,61 +56,60 @@ class ConfigUtil():
scenario = ConfigUtil.makeScenario()
bundle = ConfigUtil.makeConfigBundle()
return OPNFVConfig.objects.create(
- installer=installer,
- scenario=scenario,
- bundle=bundle
- )
+ installer=installer,
+ scenario=scenario,
+ bundle=bundle
+ )
@staticmethod
def makeOPNFVRole():
return OPNFVRole.objects.create(
- name="Test role",
- description="This is a test role"
- )
+ 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"
- )
+ lab_user=lab_user,
+ name="this is lab for testing",
+ contact_email="email@mail.com",
+ contact_phone="123-4567"
+ )
return Image.objects.create(
- lab_id=0,
- from_lab=lab,
- name="an image for testing",
- owner=owner
- )
-
+ lab_id=0,
+ 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"
- )
+ 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=""
- )
+ name="Generic bundle for config tests",
+ xml="",
+ owner=user,
+ description=""
+ )
resource = GenericResource.objects.create(
- bundle=bundle,
- name="a test generic resource"
- )
+ bundle=bundle,
+ name="a test generic resource"
+ )
return GenericHost.objects.create(
- profile=profile,
- resource=resource
- )
+ profile=profile,
+ resource=resource
+ )
@staticmethod
def makeHostConfiguration():
@@ -112,11 +118,11 @@ class ConfigUtil():
bundle = ConfigUtil.makeConfigBundle()
opnfvRole = ConfigUtil.makeOPNFVRole()
return HostConfiguration.objects.create(
- host=host,
- image=image,
- bundle=bundle,
- opnfvRole=opnfvRole
- )
+ host=host,
+ image=image,
+ bundle=bundle,
+ opnfvRole=opnfvRole
+ )
class ScenarioTestCase(TestCase):
@@ -124,26 +130,31 @@ 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):
diff --git a/src/resource_inventory/views.py b/src/resource_inventory/views.py
index 7e73006..2937bd7 100644
--- a/src/resource_inventory/views.py
+++ b/src/resource_inventory/views.py
@@ -8,17 +8,16 @@
##############################################################################
-from django.shortcuts import render
-from django.views import View
from django.views.generic import TemplateView
from resource_inventory.models import Host
+
class HostView(TemplateView):
template_name = "resource/hosts.html"
def get_context_data(self, **kwargs):
context = super(HostView, self).get_context_data(**kwargs)
hosts = Host.objects.filter(working=True)
- context.update({'hosts':hosts, 'title':"Hardware Resources"})
+ context.update({'hosts': hosts, 'title': "Hardware Resources"})
return context