aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorParker Berberian <pberberian@iol.unh.edu>2019-02-18 17:07:47 +0000
committerGerrit Code Review <gerrit@opnfv.org>2019-02-18 17:07:47 +0000
commit011026903a94944258bf8c69aeb2700c6c57b02e (patch)
tree6d0426658a4a34d1d2af879170aaaad0db65695b /src
parent0b48d9b6cb6941a9cecedc409ec0968d0b72ec62 (diff)
parent37620c753acf540e3c16364419617ebeb0388c5b (diff)
Merge "Fixed all Flake8 errors"
Diffstat (limited to 'src')
-rw-r--r--src/account/models.py4
-rw-r--r--src/api/models.py12
-rw-r--r--src/booking/quick_deployer.py12
-rw-r--r--src/dashboard/populate_db_iol.py2
-rw-r--r--src/dashboard/tasks.py3
-rw-r--r--src/workflow/booking_workflow.py4
-rw-r--r--src/workflow/models.py6
-rw-r--r--src/workflow/sw_bundle_workflow.py4
-rw-r--r--src/workflow/workflow_factory.py5
-rw-r--r--src/workflow/workflow_manager.py15
10 files changed, 34 insertions, 33 deletions
diff --git a/src/account/models.py b/src/account/models.py
index 0f8154e..4fc7c40 100644
--- a/src/account/models.py
+++ b/src/account/models.py
@@ -61,7 +61,7 @@ class VlanManager(models.Model):
new_vlan = vlans.index(1) # will throw if none available
vlans[new_vlan] = 0
allocated.append(new_vlan)
- if count is 1:
+ if count == 1:
return allocated[0]
return allocated
@@ -131,7 +131,7 @@ class VlanManager(models.Model):
vlans = set(vlans)
for vlan in vlans:
- if my_vlans[vlan] is 0:
+ if my_vlans[vlan] == 0:
raise ValueError("vlan " + str(vlan) + " is not available")
my_vlans[vlan] = 0
diff --git a/src/api/models.py b/src/api/models.py
index b14ea2f..30f0f75 100644
--- a/src/api/models.py
+++ b/src/api/models.py
@@ -42,7 +42,7 @@ class LabManagerTracker(object):
"""
try:
lab = Lab.objects.get(name=lab_name)
- except:
+ except Exception:
raise PermissionDenied("Lab not found")
if lab.api_token == token:
return LabManager(lab)
@@ -366,7 +366,7 @@ class AccessConfig(TaskConfig):
d['revoke'] = self.revoke
try:
d['context'] = json.loads(self.context)
- except:
+ except Exception:
pass
return d
@@ -753,7 +753,7 @@ class JobFactory(object):
job = None
try:
job = Job.objects.get(booking=booking)
- except:
+ except Exception:
job = Job.objects.create(status=JobStatus.NEW, booking=booking)
cls.makeHardwareConfigs(
hosts=hosts,
@@ -796,7 +796,7 @@ class JobFactory(object):
hardware_config = None
try:
hardware_config = HardwareConfig.objects.get(relation__host=host)
- except:
+ except Exception:
hardware_config = HardwareConfig()
relation = HostHardwareRelation()
@@ -839,7 +839,7 @@ class JobFactory(object):
network_config = None
try:
network_config = NetworkConfig.objects.get(relation__host=host)
- except:
+ except Exception:
network_config = NetworkConfig.objects.create()
relation = HostNetworkRelation()
@@ -878,5 +878,5 @@ class JobFactory(object):
software_relation = SoftwareRelation.objects.create(job=job, config=software_config)
software_relation.save()
return software_relation
- except:
+ except Exception:
return None
diff --git a/src/booking/quick_deployer.py b/src/booking/quick_deployer.py
index c431017..d838de9 100644
--- a/src/booking/quick_deployer.py
+++ b/src/booking/quick_deployer.py
@@ -124,7 +124,7 @@ def create_from_form(form, request):
raise InvalidHostnameException("Hostname must comply to RFC 952 and all extensions to it until this point")
# check that image os is compatible with installer
if installer in image.os.sup_installers.all():
- #if installer not here, we can omit that and not check for scenario
+ # if installer not here, we can omit that and not check for scenario
if not scenario:
raise IncompatibleScenarioForInstaller("An OPNFV Installer needs a scenario to be chosen to work properly")
if scenario not in installer.sup_scenarios.all():
@@ -137,9 +137,9 @@ def create_from_form(form, request):
raise ImageOwnershipInvalid("You are not the owner of the chosen private image")
# check if host type is available
- #ResourceManager.getInstance().acquireHost(ghost, lab.name)
+ # ResourceManager.getInstance().acquireHost(ghost, lab.name)
available_host_types = ResourceManager.getInstance().getAvailableHostTypes(lab)
- if not profile in available_host_types:
+ if profile not in available_host_types:
# TODO: handle deleting generic resource in this instance along with grb
raise HostNotAvailable("Could not book selected host due to changed availability. Try again later")
@@ -231,12 +231,8 @@ def create_from_form(form, request):
booking.pdf = ResourceManager().makePDF(booking.resource)
booking.config_bundle = cbundle
booking.save()
- print("users field:")
- print(users_field)
- print(type(users_field))
- #users_field = json.loads(users_field)
users_field = users_field[2:-2]
- if users_field: #may be empty after split, if no collaborators entered
+ if users_field: # may be empty after split, if no collaborators entered
users_field = json.loads(users_field)
for collaborator in users_field:
user = User.objects.get(id=collaborator['id'])
diff --git a/src/dashboard/populate_db_iol.py b/src/dashboard/populate_db_iol.py
index 4368520..916dd97 100644
--- a/src/dashboard/populate_db_iol.py
+++ b/src/dashboard/populate_db_iol.py
@@ -307,7 +307,7 @@ class Populator:
size = 0
try:
size = int(disk_data['size'].split('.')[0])
- except:
+ except Exception:
size = int(disk_data['size'].split('.')[0][:-1])
DiskProfile.objects.create(
size=size,
diff --git a/src/dashboard/tasks.py b/src/dashboard/tasks.py
index 837e7a1..597629f 100644
--- a/src/dashboard/tasks.py
+++ b/src/dashboard/tasks.py
@@ -11,7 +11,6 @@
from celery import shared_task
from django.utils import timezone
-from django.db.models import Q
from booking.models import Booking
from notifier.manager import NotificationHandler
from api.models import Job, JobStatus, SoftwareRelation, HostHardwareRelation, HostNetworkRelation, AccessRelation
@@ -41,7 +40,7 @@ def booking_poll():
if vlan.public:
try:
host.lab.vlan_manager.release_public_vlan(vlan.vlan_id)
- except: # will fail if we already released in this loop
+ except Exception: # will fail if we already released in this loop
pass
else:
vlans.append(vlan.vlan_id)
diff --git a/src/workflow/booking_workflow.py b/src/workflow/booking_workflow.py
index 76950b8..8be7720 100644
--- a/src/workflow/booking_workflow.py
+++ b/src/workflow/booking_workflow.py
@@ -115,7 +115,7 @@ class Booking_Resource_Select(Resource_Select):
if resource:
try:
booking.resource.template = resource
- except:
+ except Exception:
booking.resource = ResourceBundle(template=resource)
models['booking'] = booking
self.repo_put(self.repo.BOOKING_MODELS, models)
@@ -182,7 +182,7 @@ class SWConfig_Select(WorkflowStep):
chosen_bundle = booking.config_bundle
default.append(chosen_bundle.id)
bundle = chosen_bundle
- except:
+ except Exception:
if created_bundle:
default.append(created_bundle.id)
bundle = created_bundle
diff --git a/src/workflow/models.py b/src/workflow/models.py
index beaaee4..7dae279 100644
--- a/src/workflow/models.py
+++ b/src/workflow/models.py
@@ -323,8 +323,8 @@ class Repository():
SNAPSHOT_DESC = "description of the snapshot"
BOOKING_INFO_FILE = "the INFO.yaml file for this user's booking"
- #migratory elements of segmented workflow
- #each of these is the end result of a different workflow.
+ # migratory elements of segmented workflow
+ # each of these is the end result of a different workflow.
HAS_RESULT = "whether or not workflow has a result"
RESULT_KEY = "key for target index that result will be put into in parent"
RESULT = "result object from workflow"
@@ -458,7 +458,7 @@ class Repository():
try:
interface.host = interface.host
interface.save()
- except Exception as e:
+ except Exception:
return "GRB, saving interface " + str(interface) + " failed. CODE:0x0019"
else:
return "GRB, no interface set provided. CODE:0x001a"
diff --git a/src/workflow/sw_bundle_workflow.py b/src/workflow/sw_bundle_workflow.py
index 80d1b3d..fd41018 100644
--- a/src/workflow/sw_bundle_workflow.py
+++ b/src/workflow/sw_bundle_workflow.py
@@ -72,7 +72,7 @@ class Define_Software(WorkflowStep):
host_profile = host.profile
break
excluded_images = Image.objects.exclude(owner=user).exclude(public=True)
- excluded_images = excluded_images | Image.objects.exclude(host_type=host.profile)
+ excluded_images = excluded_images | Image.objects.exclude(host_type=host_profile)
lab = self.repo_get(self.repo.SELECTED_GRESOURCE_BUNDLE).lab
excluded_images = excluded_images | Image.objects.exclude(from_lab=lab)
filter_data["id_form-" + str(i) + "-image"] = []
@@ -138,7 +138,7 @@ class Define_Software(WorkflowStep):
q.filter(host_type=host.profile)
q.filter(from_lab=lab)
q.get(id=image.id) # will throw exception if image is not in q
- except:
+ except Exception:
self.metastep.set_invalid("Image " + image.name + " is not compatible with host " + host.resource.name)
role = form.cleaned_data['role']
if "jumphost" in role.name.lower():
diff --git a/src/workflow/workflow_factory.py b/src/workflow/workflow_factory.py
index 1f4a28a..f5e2ad1 100644
--- a/src/workflow/workflow_factory.py
+++ b/src/workflow/workflow_factory.py
@@ -12,7 +12,7 @@ from workflow.booking_workflow import Booking_Resource_Select, SWConfig_Select,
from workflow.resource_bundle_workflow import Define_Hardware, Define_Nets, Resource_Meta_Info
from workflow.sw_bundle_workflow import Config_Software, Define_Software, SWConf_Resource_Select
from workflow.snapshot_workflow import Select_Host_Step, Image_Meta_Step
-from workflow.models import Repository, Confirmation_Step
+from workflow.models import Confirmation_Step
import uuid
@@ -35,6 +35,7 @@ class ConfigMetaWorkflow(object):
workflow_type = 2
color = "#00ffcc"
+
class MetaStep(object):
UNTOUCHED = 0
@@ -76,6 +77,7 @@ class MetaStep(object):
def __ne__(self, other):
return self.id.int != other.id.int
+
class Workflow(object):
def __init__(self, steps, metasteps, repository):
self.repository = repository
@@ -83,6 +85,7 @@ class Workflow(object):
self.metasteps = metasteps
self.active_index = 0
+
class WorkflowFactory():
booking_steps = [
Booking_Resource_Select,
diff --git a/src/workflow/workflow_manager.py b/src/workflow/workflow_manager.py
index 1d672cf..89a9d96 100644
--- a/src/workflow/workflow_manager.py
+++ b/src/workflow/workflow_manager.py
@@ -10,10 +10,8 @@
from django.http import JsonResponse
-import random
-
from booking.models import Booking
-from workflow.workflow_factory import WorkflowFactory, MetaStep
+from workflow.workflow_factory import WorkflowFactory
from workflow.models import Repository
from resource_inventory.models import (
GenericResourceBundle,
@@ -47,10 +45,15 @@ class SessionManager():
repo.set_defaults(defaults)
repo.el[repo.HAS_RESULT] = False
repo.el[repo.SESSION_USER] = self.owner
- self.workflows.append(self.factory.create_workflow(workflow_type=workflow_type, repo = repo))
+ self.workflows.append(
+ self.factory.create_workflow(
+ workflow_type=workflow_type,
+ repo=repo
+ )
+ )
def pop_workflow(self):
- if( len(self.workflows) <= 1 ):
+ if(len(self.workflows) <= 1):
return False
if self.workflows[-1].repository.el[self.workflows[-1].repository.HAS_RESULT]:
@@ -70,7 +73,7 @@ class SessionManager():
responsejson["active"] = self.active_workflow().repository.el['active_step']
responsejson["workflow_count"] = len(self.workflows)
return JsonResponse(responsejson, safe=False)
- except Exception as e:
+ except Exception:
pass
def render(self, request, **kwargs):