P6: Fix pep8 error in cyborg/agent and cyborg/db

Change-Id: I3b30cc6388ceb9f771c09007c696d8ea69608860
This commit is contained in:
chenke 2019-08-29 14:59:38 +08:00
parent de4efde491
commit 369abe8dd0
6 changed files with 35 additions and 29 deletions

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
@ -21,9 +20,9 @@ from oslo_service import periodic_task
from cyborg.accelerator.drivers.fpga.base import FPGADriver
from cyborg.agent.resource_tracker import ResourceTracker
from cyborg.agent.rpcapi import AgentAPI
from cyborg.image.api import API as ImageAPI
from cyborg.conductor import rpcapi as cond_api
from cyborg.conf import CONF
from cyborg.image.api import API as ImageAPI
LOG = logging.getLogger(__name__)
@ -53,8 +52,8 @@ class AgentManager(periodic_task.PeriodicTasks):
pass
def fpga_program(self, context, deployable_uuid, image_uuid):
""" Program a FPGA regoin, image can be a url or local file"""
# TODO (Shaohe Feng) Get image from glance.
"""Program a FPGA region, image can be a url or local file"""
# TODO(Shaohe Feng) Get image from glance.
# And add claim and rollback logical.
path = self._download_bitstream(context, image_uuid)
dep = self.cond_api.deployable_get(context, deployable_uuid)
@ -63,7 +62,7 @@ class AgentManager(periodic_task.PeriodicTasks):
def fpga_program_v2(self, context, controlpath_id,
bitstream_uuid, driver_name):
# TODO Use tempfile module?
# TODO() Use tempfile module?
download_path = "/tmp/" + bitstream_uuid + ".gbs"
self.image_api.download(context,
bitstream_uuid,
@ -74,7 +73,7 @@ class AgentManager(periodic_task.PeriodicTasks):
os.remove(download_path)
def _download_bitstream(self, context, bitstream_uuid):
"""download the bistream
"""Download the bistream
:param context: the context
:param bistream_uuid: v4 uuid of the bitstream to reprogram
@ -88,5 +87,5 @@ class AgentManager(periodic_task.PeriodicTasks):
@periodic_task.periodic_task(run_immediately=True)
def update_available_resource(self, context, startup=True):
"""update all kinds of accelerator resources from their drivers."""
"""Update all kinds of accelerator resources from their drivers."""
self._rt.update_usage(context)

View File

@ -44,9 +44,9 @@ class ResourceTracker(object):
self.acc_drivers = []
self._initialize_drivers()
def _initialize_drivers(self, enabled_drivers=[]):
"""
Load accelerator drivers.
def _initialize_drivers(self, enabled_drivers=None):
"""Load accelerator drivers.
:return: [nvidia_gpu_driver_obj, intel_fpga_driver_obj]
"""
acc_drivers = []

View File

@ -20,8 +20,8 @@ import oslo_messaging as messaging
from cyborg.common import constants
from cyborg.common import rpc
from cyborg.objects import base as objects_base
from cyborg import objects
from cyborg.objects import base as objects_base
from oslo_log import log
@ -65,7 +65,7 @@ class AgentAPI(object):
dpl_get = objects.Deployable.get(context, deployable_uuid)
if not dpl_get:
# TODO (Li Liu) throw an exception here
# TODO(Li Liu) throw an exception here
return 0
cctxt = self.client.prepare(server=dpl_get.host, version=version)

View File

@ -15,8 +15,8 @@
"""SQLAlchemy storage backend."""
import threading
import copy
import threading
import uuid
from oslo_db import api as oslo_db_api
@ -27,17 +27,15 @@ from oslo_log import log
from oslo_utils import strutils
from oslo_utils import timeutils
from oslo_utils import uuidutils
from sqlalchemy.orm import load_only
from sqlalchemy import and_
from sqlalchemy import or_
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.sql import func
from sqlalchemy.orm import load_only
from cyborg.common import exception
from cyborg.common.i18n import _
from cyborg.db import api
from cyborg.db.sqlalchemy import models
from sqlalchemy import or_
from sqlalchemy import and_
_CONTEXT = threading.local()
LOG = log.getLogger(__name__)
@ -198,7 +196,7 @@ class Connection(api.Connection):
return _paginate_query(context, models.AttachHandle, query_prefix,
limit, marker, sort_key, sort_dir)
def _exact_filter(self, model, query, filters, legal_keys=[]):
def _exact_filter(self, model, query, filters, legal_keys=None):
"""Applies exact match filtering to a deployable query.
Returns the updated query. Modifies filters argument to remove
filters consumed.
@ -211,6 +209,8 @@ class Connection(api.Connection):
:param legal_keys: list of keys to apply exact filtering to
"""
if legal_keys is None:
legal_keys = []
filter_dict = {}
# Walk through all the keys
@ -955,7 +955,7 @@ class Connection(api.Connection):
def quota_reserve(self, context, resources, deltas, expire,
until_refresh, max_age, project_id=None,
is_allocated_reserve=False):
""" Create reservation record in DB according to params"""
"""Create reservation record in DB according to params"""
with _session_for_write() as session:
if project_id is None:
project_id = context.project_id

View File

@ -19,13 +19,18 @@ from oslo_db import options as db_options
from oslo_db.sqlalchemy import models
from oslo_utils import timeutils
import six.moves.urllib.parse as urlparse
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, String, Integer, Boolean, Enum, ForeignKey, \
Index
from sqlalchemy import Text
from sqlalchemy import schema
from sqlalchemy import Boolean
from sqlalchemy import Column
from sqlalchemy import DateTime
from sqlalchemy import Enum
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import ForeignKey
from sqlalchemy import Index
from sqlalchemy import Integer
from sqlalchemy import orm
from sqlalchemy import schema
from sqlalchemy import String
from sqlalchemy import Text
from cyborg.common import constants
from cyborg.common import paths
@ -114,7 +119,7 @@ class Deployable(Base):
driver_name = Column(String(100), nullable=True)
bitstream_id = Column(String(36), nullable=True)
# TODO Add programming_in_progress field
# TODO() Add programming_in_progress field
class Attribute(Base):
@ -131,7 +136,8 @@ class Attribute(Base):
class ControlpathID(Base):
"""Identifier for the Device when driver reporting to agent, IDs is
needed especially when multiple PFs exist in one Devices."""
needed especially when multiple PFs exist in one Devices.
"""
__tablename__ = 'controlpath_ids'
@ -189,7 +195,8 @@ class DeviceProfile(Base):
class ExtArq(Base):
"""ExtArq is the abbreviation of ExtendedAcceleratorRequest, it represents
extended nova requests for attach related operations."""
extended nova requests for attach related operations.
"""
__tablename__ = 'extended_accelerator_requests'
__table_args__ = (

View File

@ -107,7 +107,7 @@ show-source = True
ignore = E123,E125,H405
builtins = _
enable-extensions = H106,H203,H904
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,*sqlalchemy/alembic/versions/*,demo/,releasenotes,cyborg/agent/,cyborg/db,dyborg/hacking/,cyborg/tests/,cyborg/image,cyborg/objects
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,*sqlalchemy/alembic/versions/*,demo/,releasenotes,cyborg/hacking/,cyborg/tests/,cyborg/image,cyborg/objects
[hacking]
local-check-factory = cyborg.hacking.checks.factory