Browse Source

Fix wrong flake8 exception and pep8 violations

In the tox.ini, [flake8] section, "exclude =
.venv,.tox,dist,doc,openstack,*egg". From this rule, all 'openstack'
directories are excluded. This rule is intended to exclude
manila/openstack/common code check, but this is wrong
because it also exclude checks against manila/api/openstack and
manila/tests/api/openstack. We should fix it

Change-Id: Ie820e3931e83a82c40b0d9b9d943787a5d6ec363
Closes-Bug: #1529092
houming-wang 3 years ago
parent
commit
9a74a01855

+ 2
- 6
manila/api/openstack/__init__.py View File

@@ -24,7 +24,6 @@ import routes
24 24
 from manila.api.openstack import wsgi
25 25
 from manila.i18n import _
26 26
 from manila.i18n import _LW
27
-from manila import utils
28 27
 from manila import wsgi as base_wsgi
29 28
 
30 29
 LOG = log.getLogger(__name__)
@@ -55,15 +54,12 @@ class ProjectMapper(APIMapper):
55 54
 
56 55
 
57 56
 class APIRouter(base_wsgi.Router):
58
-    """
59
-    Routes requests on the OpenStack API to the appropriate controller
60
-    and method.
61
-    """
57
+    """Routes requests on the API to the appropriate controller and method."""
62 58
     ExtensionManager = None  # override in subclasses
63 59
 
64 60
     @classmethod
65 61
     def factory(cls, global_config, **local_config):
66
-        """Simple paste factory, :class:`manila.wsgi.Router` doesn't have"""
62
+        """Simple paste factory, :class:`manila.wsgi.Router` doesn't have."""
67 63
         return cls()
68 64
 
69 65
     def __init__(self, ext_mgr=None):

+ 0
- 1
manila/api/openstack/api_version_request.py View File

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

+ 19
- 16
manila/api/openstack/wsgi.py View File

@@ -136,9 +136,10 @@ class Request(webob.Request):
136 136
         return resources.get(resource_id)
137 137
 
138 138
     def cache_db_items(self, key, items, item_key='id'):
139
-        """Allow API methods to store objects from a DB query to be
140
-        used by API extensions within the same API request.
139
+        """Cache db items.
141 140
 
141
+        Allow API methods to store objects from a DB query to be
142
+        used by API extensions within the same API request.
142 143
         An instance of this class only lives for the lifetime of a
143 144
         single API request, so there's no need to implement full
144 145
         cache management.
@@ -146,17 +147,19 @@ class Request(webob.Request):
146 147
         self.cache_resource(items, item_key, key)
147 148
 
148 149
     def get_db_items(self, key):
149
-        """Allow an API extension to get previously stored objects within
150
-        the same API request.
150
+        """Get db item by key.
151 151
 
152
+        Allow an API extension to get previously stored objects within
153
+        the same API request.
152 154
         Note that the object data will be slightly stale.
153 155
         """
154 156
         return self.cached_resource(key)
155 157
 
156 158
     def get_db_item(self, key, item_key):
157
-        """Allow an API extension to get a previously stored object
158
-        within the same API request.
159
+        """Get db item by key and item key.
159 160
 
161
+        Allow an API extension to get a previously stored object
162
+        within the same API request.
160 163
         Note that the object data will be slightly stale.
161 164
         """
162 165
         return self.get_db_items(key).get(item_key)
@@ -261,7 +264,7 @@ class ActionDispatcher(object):
261 264
 
262 265
 
263 266
 class TextDeserializer(ActionDispatcher):
264
-    """Default request body deserialization"""
267
+    """Default request body deserialization."""
265 268
 
266 269
     def deserialize(self, datastring, action='default'):
267 270
         return self.dispatch(datastring, action=action)
@@ -284,7 +287,7 @@ class JSONDeserializer(TextDeserializer):
284 287
 
285 288
 
286 289
 class DictSerializer(ActionDispatcher):
287
-    """Default request body serialization"""
290
+    """Default request body serialization."""
288 291
 
289 292
     def serialize(self, data, action='default'):
290 293
         return self.dispatch(data, action=action)
@@ -294,7 +297,7 @@ class DictSerializer(ActionDispatcher):
294 297
 
295 298
 
296 299
 class JSONDictSerializer(DictSerializer):
297
-    """Default JSON request body serialization"""
300
+    """Default JSON request body serialization."""
298 301
 
299 302
     def default(self, data):
300 303
         return six.b(jsonutils.dumps(data))
@@ -554,7 +557,8 @@ class Resource(wsgi.Application):
554 557
     support_api_request_version = True
555 558
 
556 559
     def __init__(self, controller, action_peek=None, **deserializers):
557
-        """
560
+        """init method of Resource.
561
+
558 562
         :param controller: object that implement methods created by routes lib
559 563
         :param action_peek: dictionary of routines for peeking into an action
560 564
                             request body to determine the desired action
@@ -730,8 +734,8 @@ class Resource(wsgi.Application):
730 734
     def __call__(self, request):
731 735
         """WSGI method that controls (de)serialization and method dispatch."""
732 736
 
733
-        LOG.info("%(method)s %(url)s" % {"method": request.method,
734
-                                         "url": request.url})
737
+        LOG.info(_LI("%(method)s %(url)s") % {"method": request.method,
738
+                                              "url": request.url})
735 739
         if self.support_api_request_version:
736 740
             # Set the version of the API requested based on the header
737 741
             try:
@@ -1059,7 +1063,7 @@ class Controller(object):
1059 1063
             return object.__getattribute__(self, key)
1060 1064
 
1061 1065
         if (version_meth_dict and
1062
-                    key in object.__getattribute__(self, VER_METHOD_ATTR)):
1066
+                key in object.__getattribute__(self, VER_METHOD_ATTR)):
1063 1067
             return version_select
1064 1068
 
1065 1069
         return object.__getattribute__(self, key)
@@ -1194,8 +1198,8 @@ class AdminActionsMixin(object):
1194 1198
         except (TypeError, KeyError):
1195 1199
             raise webob.exc.HTTPBadRequest(explanation="Must specify 'status'")
1196 1200
         if update['status'] not in self.valid_statuses:
1197
-            expl = _("Invalid state. Valid states: " +
1198
-                     ", ".join(self.valid_statuses) + ".")
1201
+            expl = (_("Invalid state. Valid states: %s.") %
1202
+                    ", ".join(self.valid_statuses))
1199 1203
             raise webob.exc.HTTPBadRequest(explanation=expl)
1200 1204
         return update
1201 1205
 
@@ -1318,7 +1322,6 @@ class OverLimitFault(webob.exc.HTTPException):
1318 1322
         error format.
1319 1323
         """
1320 1324
         content_type = request.best_match_content_type()
1321
-        metadata = {"attributes": {"overLimitFault": "code"}}
1322 1325
 
1323 1326
         serializer = {
1324 1327
             'application/json': JSONDictSerializer(),

+ 0
- 17
manila/tests/api/openstack/__init__.py View File

@@ -1,17 +0,0 @@
1
-# Copyright 2011 OpenStack LLC.
2
-# All Rights Reserved.
3
-#
4
-#    Licensed under the Apache License, Version 2.0 (the "License"); you may
5
-#    not use this file except in compliance with the License. You may obtain
6
-#    a copy of the License at
7
-#
8
-#         http://www.apache.org/licenses/LICENSE-2.0
9
-#
10
-#    Unless required by applicable law or agreed to in writing, software
11
-#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
-#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
-#    License for the specific language governing permissions and limitations
14
-#    under the License.
15
-
16
-# NOTE(vish): this forces the fixtures from tests/__init.py:setup() to work
17
-from manila.tests import *

+ 5
- 3
manila/tests/api/openstack/test_api_version_request.py View File

@@ -37,13 +37,15 @@ class APIVersionRequestTests(test.TestCase):
37 37
     def test_min_version(self):
38 38
 
39 39
         self.assertEqual(
40
-            api_version_request.APIVersionRequest(api_version_request._MIN_API_VERSION),
40
+            api_version_request.APIVersionRequest(
41
+                api_version_request._MIN_API_VERSION),
41 42
             api_version_request.min_api_version())
42 43
 
43 44
     def test_max_api_version(self):
44 45
 
45 46
         self.assertEqual(
46
-            api_version_request.APIVersionRequest(api_version_request._MAX_API_VERSION),
47
+            api_version_request.APIVersionRequest(
48
+                api_version_request._MAX_API_VERSION),
47 49
             api_version_request.max_api_version())
48 50
 
49 51
     @ddt.data(
@@ -193,4 +195,4 @@ class APIVersionRequestTests(test.TestCase):
193 195
 
194 196
         self.assertEqual('API Version Request '
195 197
                          'Major: %s, Minor: %s' % (major, minor),
196
-                         request_string)
198
+                         request_string)

+ 24
- 3
manila/tests/api/openstack/test_wsgi.py View File

@@ -1,9 +1,22 @@
1
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
2
+#    not use this file except in compliance with the License. You may obtain
3
+#    a copy of the License at
4
+#
5
+#         http://www.apache.org/licenses/LICENSE-2.0
6
+#
7
+#    Unless required by applicable law or agreed to in writing, software
8
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
+#    License for the specific language governing permissions and limitations
11
+#    under the License.
12
+
1 13
 import ddt
2
-import inspect
3 14
 import mock
4 15
 import six
5 16
 import webob
6 17
 
18
+import inspect
19
+
7 20
 from manila.api.openstack import wsgi
8 21
 from manila import context
9 22
 from manila import exception
@@ -161,7 +174,8 @@ class JSONDictSerializerTest(test.TestCase):
161 174
         expected_json = six.b('{"servers":{"a":[2,3]}}')
162 175
         serializer = wsgi.JSONDictSerializer()
163 176
         result = serializer.serialize(input_dict)
164
-        result = result.replace(six.b('\n'), six.b('')).replace(six.b(' '), six.b(''))
177
+        result = result.replace(six.b('\n'),
178
+                                six.b('')).replace(six.b(' '), six.b(''))
165 179
         self.assertEqual(expected_json, result)
166 180
 
167 181
 
@@ -572,11 +586,13 @@ class ResourceTest(test.TestCase):
572 586
         def extension1(req):
573 587
             called.append('pre1')
574 588
             resp_obj = yield
589
+            self.assertIsNone(resp_obj)
575 590
             called.append('post1')
576 591
 
577 592
         def extension2(req):
578 593
             called.append('pre2')
579 594
             resp_obj = yield
595
+            self.assertIsNone(resp_obj)
580 596
             called.append('post2')
581 597
 
582 598
         extensions = [extension1, extension2]
@@ -699,10 +715,12 @@ class ResourceTest(test.TestCase):
699 715
 
700 716
         def extension1(req):
701 717
             resp_obj = yield
718
+            self.assertIsNone(resp_obj)
702 719
             called.append(1)
703 720
 
704 721
         def extension2(req):
705 722
             resp_obj = yield
723
+            self.assertIsNone(resp_obj)
706 724
             called.append(2)
707 725
 
708 726
         ext1 = extension1(None)
@@ -728,10 +746,12 @@ class ResourceTest(test.TestCase):
728 746
 
729 747
         def extension1(req):
730 748
             resp_obj = yield
749
+            self.assertIsNone(resp_obj)
731 750
             called.append(1)
732 751
 
733 752
         def extension2(req):
734 753
             resp_obj = yield
754
+            self.assertIsNone(resp_obj)
735 755
             called.append(2)
736 756
             yield 'foo'
737 757
 
@@ -869,6 +889,7 @@ class ValidBodyTest(test.TestCase):
869 889
         body = {'foo': 'bar'}
870 890
         self.assertFalse(self.controller.is_valid_body(body, 'foo'))
871 891
 
892
+
872 893
 class AuthorizeDecoratorTest(test.TestCase):
873 894
     class FakeController(wsgi.Controller):
874 895
         resource_name = 'fake_resource_name'
@@ -914,4 +935,4 @@ class AuthorizeDecoratorTest(test.TestCase):
914 935
         with mock.patch.object(policy, 'check_policy',
915 936
                                mock.Mock(side_effect=exc)):
916 937
             self.assertRaises(webob.exc.HTTPForbidden,
917
-                              self.controller.fake_action_2, req)
938
+                              self.controller.fake_action_2, req)

+ 1
- 1
tox.ini View File

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

Loading…
Cancel
Save