From e8a3803615b0ffbe41de15101053534a149fb5d7 Mon Sep 17 00:00:00 2001 From: chenke Date: Thu, 29 Aug 2019 09:52:33 +0800 Subject: [PATCH] P4: Fix pep8 error in cyborg/api Change-Id: I46699623b99add526aff2121e60ad7e88c107da1 --- cyborg/api/controllers/base.py | 5 ++--- cyborg/api/controllers/v1/accelerators.py | 7 +------ cyborg/api/controllers/v1/deployables.py | 2 +- cyborg/api/controllers/v1/types.py | 4 ++-- tox.ini | 2 +- 5 files changed, 7 insertions(+), 13 deletions(-) diff --git a/cyborg/api/controllers/base.py b/cyborg/api/controllers/base.py index 7a1304be..d9367e4f 100644 --- a/cyborg/api/controllers/base.py +++ b/cyborg/api/controllers/base.py @@ -31,9 +31,8 @@ class APIBase(wtypes.Base): def as_dict(self): """Render this object as a dict of its fields.""" - return dict((k, getattr(self, k)) - for k in self.fields - if hasattr(self, k) and getattr(self, k) != wsme.Unset) + return {k: getattr(self, k) for k in self.fields + if hasattr(self, k) and getattr(self, k) != wsme.Unset} class CyborgController(rest.RestController): diff --git a/cyborg/api/controllers/v1/accelerators.py b/cyborg/api/controllers/v1/accelerators.py index 006915d7..88ab3003 100644 --- a/cyborg/api/controllers/v1/accelerators.py +++ b/cyborg/api/controllers/v1/accelerators.py @@ -14,7 +14,6 @@ # under the License. from oslo_log import log -import pecan from six.moves import http_client import wsme from wsme import types as wtypes @@ -23,11 +22,8 @@ from cyborg.api.controllers import base from cyborg.api.controllers import link from cyborg.api.controllers.v1 import deployables from cyborg.api.controllers.v1 import types -from cyborg.api.controllers.v1 import utils as api_utils from cyborg.api import expose -from cyborg.common import exception from cyborg.common import policy -from cyborg import objects LOG = log.getLogger(__name__) @@ -195,5 +191,4 @@ class AcceleratorsController(AcceleratorsControllerBase): :param uuid: UUID of an accelerator. """ LOG.warning("v1 APIs for accelerator objects are deprecated.") - context = pecan.request.context - obj_acc = self._resource or self._get_resource(uuid) + pass diff --git a/cyborg/api/controllers/v1/deployables.py b/cyborg/api/controllers/v1/deployables.py index c50516f2..bb8f8c8d 100644 --- a/cyborg/api/controllers/v1/deployables.py +++ b/cyborg/api/controllers/v1/deployables.py @@ -130,7 +130,7 @@ class DeployablesController(base.CyborgController): obj_dep = objects.Deployable.get(pecan.request.context, uuid) # Set attribute of the new bitstream/image information obj_dep.add_attribute(pecan.request.context, 'image_uuid', image_uuid) - # TODO (Li Liu) Trigger the program api in Agnet. + # TODO(Li Liu) Trigger the program api in Agnet. agent_api.program_fpga_with_bitstream(pecan.request.context, uuid, image_uuid) diff --git a/cyborg/api/controllers/v1/types.py b/cyborg/api/controllers/v1/types.py index 9c240de1..a5d5f5d9 100644 --- a/cyborg/api/controllers/v1/types.py +++ b/cyborg/api/controllers/v1/types.py @@ -13,9 +13,9 @@ # License for the specific language governing permissions and limitations # under the License. -import json import inspect +from oslo_serialization import jsonutils from oslo_utils import strutils from oslo_utils import uuidutils import wsme @@ -90,7 +90,7 @@ class JsonType(wtypes.UserType): @staticmethod def validate(value): try: - json.dumps(value) + jsonutils.dumps(value) except TypeError: raise exception.InvalidJsonType(value=value) else: diff --git a/tox.ini b/tox.ini index 67c0bc84..78e0d852 100644 --- a/tox.ini +++ b/tox.ini @@ -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/accelerator/,cyborg/api,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/accelerator/,cyborg/agent/,cyborg/db,dyborg/hacking/,cyborg/tests/,cyborg/image,cyborg/objects [hacking] local-check-factory = cyborg.hacking.checks.factory