Merge "Fix wrong flake8 exception and pep8 violations"

This commit is contained in:
Jenkins 2015-12-29 22:12:50 +00:00 committed by Gerrit Code Review
commit 74f97548c9
7 changed files with 51 additions and 47 deletions

@ -24,7 +24,6 @@ import routes
from manila.api.openstack import wsgi
from manila.i18n import _
from manila.i18n import _LW
from manila import utils
from manila import wsgi as base_wsgi
LOG = log.getLogger(__name__)
@ -55,15 +54,12 @@ class ProjectMapper(APIMapper):
class APIRouter(base_wsgi.Router):
"""
Routes requests on the OpenStack API to the appropriate controller
and method.
"""
"""Routes requests on the API to the appropriate controller and method."""
ExtensionManager = None # override in subclasses
@classmethod
def factory(cls, global_config, **local_config):
"""Simple paste factory, :class:`manila.wsgi.Router` doesn't have"""
"""Simple paste factory, :class:`manila.wsgi.Router` doesn't have."""
return cls()
def __init__(self, ext_mgr=None):

@ -176,4 +176,3 @@ class APIVersionRequest(utils.ComparableMixin):
raise ValueError
return ("%(major)s.%(minor)s" %
{'major': self._ver_major, 'minor': self._ver_minor})

@ -136,9 +136,10 @@ class Request(webob.Request):
return resources.get(resource_id)
def cache_db_items(self, key, items, item_key='id'):
"""Allow API methods to store objects from a DB query to be
used by API extensions within the same API request.
"""Cache db items.
Allow API methods to store objects from a DB query to be
used by API extensions within the same API request.
An instance of this class only lives for the lifetime of a
single API request, so there's no need to implement full
cache management.
@ -146,17 +147,19 @@ class Request(webob.Request):
self.cache_resource(items, item_key, key)
def get_db_items(self, key):
"""Allow an API extension to get previously stored objects within
the same API request.
"""Get db item by key.
Allow an API extension to get previously stored objects within
the same API request.
Note that the object data will be slightly stale.
"""
return self.cached_resource(key)
def get_db_item(self, key, item_key):
"""Allow an API extension to get a previously stored object
within the same API request.
"""Get db item by key and item key.
Allow an API extension to get a previously stored object
within the same API request.
Note that the object data will be slightly stale.
"""
return self.get_db_items(key).get(item_key)
@ -261,7 +264,7 @@ class ActionDispatcher(object):
class TextDeserializer(ActionDispatcher):
"""Default request body deserialization"""
"""Default request body deserialization."""
def deserialize(self, datastring, action='default'):
return self.dispatch(datastring, action=action)
@ -284,7 +287,7 @@ class JSONDeserializer(TextDeserializer):
class DictSerializer(ActionDispatcher):
"""Default request body serialization"""
"""Default request body serialization."""
def serialize(self, data, action='default'):
return self.dispatch(data, action=action)
@ -294,7 +297,7 @@ class DictSerializer(ActionDispatcher):
class JSONDictSerializer(DictSerializer):
"""Default JSON request body serialization"""
"""Default JSON request body serialization."""
def default(self, data):
return six.b(jsonutils.dumps(data))
@ -554,7 +557,8 @@ class Resource(wsgi.Application):
support_api_request_version = True
def __init__(self, controller, action_peek=None, **deserializers):
"""
"""init method of Resource.
:param controller: object that implement methods created by routes lib
:param action_peek: dictionary of routines for peeking into an action
request body to determine the desired action
@ -730,8 +734,8 @@ class Resource(wsgi.Application):
def __call__(self, request):
"""WSGI method that controls (de)serialization and method dispatch."""
LOG.info("%(method)s %(url)s" % {"method": request.method,
"url": request.url})
LOG.info(_LI("%(method)s %(url)s") % {"method": request.method,
"url": request.url})
if self.support_api_request_version:
# Set the version of the API requested based on the header
try:
@ -1059,7 +1063,7 @@ class Controller(object):
return object.__getattribute__(self, key)
if (version_meth_dict and
key in object.__getattribute__(self, VER_METHOD_ATTR)):
key in object.__getattribute__(self, VER_METHOD_ATTR)):
return version_select
return object.__getattribute__(self, key)
@ -1194,8 +1198,8 @@ class AdminActionsMixin(object):
except (TypeError, KeyError):
raise webob.exc.HTTPBadRequest(explanation="Must specify 'status'")
if update['status'] not in self.valid_statuses:
expl = _("Invalid state. Valid states: " +
", ".join(self.valid_statuses) + ".")
expl = (_("Invalid state. Valid states: %s.") %
", ".join(self.valid_statuses))
raise webob.exc.HTTPBadRequest(explanation=expl)
return update
@ -1318,7 +1322,6 @@ class OverLimitFault(webob.exc.HTTPException):
error format.
"""
content_type = request.best_match_content_type()
metadata = {"attributes": {"overLimitFault": "code"}}
serializer = {
'application/json': JSONDictSerializer(),

@ -1,17 +0,0 @@
# Copyright 2011 OpenStack LLC.
# All Rights Reserved.
#
# 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
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# NOTE(vish): this forces the fixtures from tests/__init.py:setup() to work
from manila.tests import *

@ -37,13 +37,15 @@ class APIVersionRequestTests(test.TestCase):
def test_min_version(self):
self.assertEqual(
api_version_request.APIVersionRequest(api_version_request._MIN_API_VERSION),
api_version_request.APIVersionRequest(
api_version_request._MIN_API_VERSION),
api_version_request.min_api_version())
def test_max_api_version(self):
self.assertEqual(
api_version_request.APIVersionRequest(api_version_request._MAX_API_VERSION),
api_version_request.APIVersionRequest(
api_version_request._MAX_API_VERSION),
api_version_request.max_api_version())
@ddt.data(
@ -193,4 +195,4 @@ class APIVersionRequestTests(test.TestCase):
self.assertEqual('API Version Request '
'Major: %s, Minor: %s' % (major, minor),
request_string)
request_string)

@ -1,9 +1,22 @@
# 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
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import ddt
import inspect
import mock
import six
import webob
import inspect
from manila.api.openstack import wsgi
from manila import context
from manila import exception
@ -161,7 +174,8 @@ class JSONDictSerializerTest(test.TestCase):
expected_json = six.b('{"servers":{"a":[2,3]}}')
serializer = wsgi.JSONDictSerializer()
result = serializer.serialize(input_dict)
result = result.replace(six.b('\n'), six.b('')).replace(six.b(' '), six.b(''))
result = result.replace(six.b('\n'),
six.b('')).replace(six.b(' '), six.b(''))
self.assertEqual(expected_json, result)
@ -572,11 +586,13 @@ class ResourceTest(test.TestCase):
def extension1(req):
called.append('pre1')
resp_obj = yield
self.assertIsNone(resp_obj)
called.append('post1')
def extension2(req):
called.append('pre2')
resp_obj = yield
self.assertIsNone(resp_obj)
called.append('post2')
extensions = [extension1, extension2]
@ -699,10 +715,12 @@ class ResourceTest(test.TestCase):
def extension1(req):
resp_obj = yield
self.assertIsNone(resp_obj)
called.append(1)
def extension2(req):
resp_obj = yield
self.assertIsNone(resp_obj)
called.append(2)
ext1 = extension1(None)
@ -728,10 +746,12 @@ class ResourceTest(test.TestCase):
def extension1(req):
resp_obj = yield
self.assertIsNone(resp_obj)
called.append(1)
def extension2(req):
resp_obj = yield
self.assertIsNone(resp_obj)
called.append(2)
yield 'foo'
@ -869,6 +889,7 @@ class ValidBodyTest(test.TestCase):
body = {'foo': 'bar'}
self.assertFalse(self.controller.is_valid_body(body, 'foo'))
class AuthorizeDecoratorTest(test.TestCase):
class FakeController(wsgi.Controller):
resource_name = 'fake_resource_name'
@ -914,4 +935,4 @@ class AuthorizeDecoratorTest(test.TestCase):
with mock.patch.object(policy, 'check_policy',
mock.Mock(side_effect=exc)):
self.assertRaises(webob.exc.HTTPForbidden,
self.controller.fake_action_2, req)
self.controller.fake_action_2, req)

@ -62,7 +62,7 @@ commands = python tools/lintstack.py check
# reason: removed in hacking (https://review.openstack.org/#/c/101701/)
ignore = H904
builtins = _
exclude = .venv,.tox,dist,doc,openstack,*egg
exclude = .venv,.tox,dist,doc,*egg
[hacking]
import_exceptions =