Merge "lint: Up-rev hacking"

This commit is contained in:
Zuul 2024-02-08 04:33:39 +00:00 committed by Gerrit Code Review
commit ad41371005
18 changed files with 31 additions and 26 deletions

View File

@ -168,7 +168,7 @@ class BaseAclHandler(object):
elem = fromstring(body, ACL.root_tag) elem = fromstring(body, ACL.root_tag)
acl = ACL.from_elem( acl = ACL.from_elem(
elem, True, self.req.conf.allow_no_owner) elem, True, self.req.conf.allow_no_owner)
except(XMLSyntaxError, DocumentInvalid): except (XMLSyntaxError, DocumentInvalid):
raise MalformedACLError() raise MalformedACLError()
except Exception as e: except Exception as e:
self.logger.error(e) self.logger.error(e)

View File

@ -19,8 +19,9 @@ from swift.common.utils import public
from swift.common.middleware.s3api.exception import ACLError from swift.common.middleware.s3api.exception import ACLError
from swift.common.middleware.s3api.controllers.base import Controller from swift.common.middleware.s3api.controllers.base import Controller
from swift.common.middleware.s3api.s3response import HTTPOk, S3NotImplemented,\ from swift.common.middleware.s3api.s3response import (
MalformedACLError, UnexpectedContent, MissingSecurityHeader HTTPOk, S3NotImplemented, MalformedACLError, UnexpectedContent,
MissingSecurityHeader)
from swift.common.middleware.s3api.etree import Element, SubElement, tostring from swift.common.middleware.s3api.etree import Element, SubElement, tostring
from swift.common.middleware.s3api.acl_utils import swift_acl_translate, \ from swift.common.middleware.s3api.acl_utils import swift_acl_translate, \
XMLNS_XSI XMLNS_XSI

View File

@ -18,8 +18,8 @@ from swift.common.utils import public
from swift.common.middleware.s3api.controllers.base import Controller, \ from swift.common.middleware.s3api.controllers.base import Controller, \
bucket_operation bucket_operation
from swift.common.middleware.s3api.etree import Element, tostring from swift.common.middleware.s3api.etree import Element, tostring
from swift.common.middleware.s3api.s3response import HTTPOk, S3NotImplemented,\ from swift.common.middleware.s3api.s3response import (
NoLoggingStatusForKey HTTPOk, S3NotImplemented, NoLoggingStatusForKey)
class LoggingStatusController(Controller): class LoggingStatusController(Controller):

View File

@ -1602,7 +1602,7 @@ class StaticLargeObject(object):
vrs, account, _junk = req.split_path(2, 3, True) vrs, account, _junk = req.split_path(2, 3, True)
new_env = req.environ.copy() new_env = req.environ.copy()
new_env['REQUEST_METHOD'] = 'GET' new_env['REQUEST_METHOD'] = 'GET'
del(new_env['wsgi.input']) del new_env['wsgi.input']
new_env['QUERY_STRING'] = 'multipart-manifest=get' new_env['QUERY_STRING'] = 'multipart-manifest=get'
if 'version-id' in req.params: if 'version-id' in req.params:
new_env['QUERY_STRING'] += \ new_env['QUERY_STRING'] += \

View File

@ -160,7 +160,7 @@ class BaseStoragePolicy(object):
object_ring=None, aliases='', object_ring=None, aliases='',
diskfile_module='egg:swift#replication.fs'): diskfile_module='egg:swift#replication.fs'):
# do not allow BaseStoragePolicy class to be instantiated directly # do not allow BaseStoragePolicy class to be instantiated directly
if type(self) == BaseStoragePolicy: if type(self) is BaseStoragePolicy:
raise TypeError("Can't instantiate BaseStoragePolicy directly") raise TypeError("Can't instantiate BaseStoragePolicy directly")
# policy parameter validation # policy parameter validation
try: try:

View File

@ -5568,7 +5568,7 @@ class ShardRangeList(UserList):
def __getitem__(self, index): def __getitem__(self, index):
# workaround for py3 - not needed for py2.7,py3.8 # workaround for py3 - not needed for py2.7,py3.8
result = self.data[index] result = self.data[index]
return ShardRangeList(result) if type(result) == list else result return ShardRangeList(result) if type(result) is list else result
@property @property
def lower(self): def lower(self):
@ -6365,7 +6365,7 @@ class Watchdog(object):
:param key: timeout id, as returned by start() :param key: timeout id, as returned by start()
""" """
try: try:
del(self._timeouts[key]) del self._timeouts[key]
except KeyError: except KeyError:
pass pass

View File

@ -24,7 +24,7 @@ from contextlib import closing
from eventlet import Timeout from eventlet import Timeout
from swift.obj import diskfile, replicator from swift.obj import diskfile, replicator
from swift.common.exceptions import DiskFileQuarantined, DiskFileNotExist,\ from swift.common.exceptions import DiskFileQuarantined, DiskFileNotExist, \
DiskFileDeleted, DiskFileExpired, QuarantineRequest DiskFileDeleted, DiskFileExpired, QuarantineRequest
from swift.common.daemon import Daemon from swift.common.daemon import Daemon
from swift.common.storage_policy import POLICIES from swift.common.storage_policy import POLICIES

View File

@ -3,7 +3,7 @@
# process, which may cause wedges in the gate later. # process, which may cause wedges in the gate later.
# Hacking already pins down pep8, pyflakes and flake8 # Hacking already pins down pep8, pyflakes and flake8
hacking>=2.0,<2.1.0 # Apache-2.0 hacking>=2.0,<6.2.0 # Apache-2.0
coverage>=5.0.4 # Apache-2.0 coverage>=5.0.4 # Apache-2.0
pytest>=4.6.11 # MIT pytest>=4.6.11 # MIT
pytest-cov>=2.12.1 # MIT pytest-cov>=2.12.1 # MIT

View File

@ -1381,7 +1381,7 @@ class TestManageShardRanges(unittest.TestCase):
def do_compact(user_input, options, exp_changes, exit_code): def do_compact(user_input, options, exp_changes, exit_code):
out = StringIO() out = StringIO()
err = StringIO() err = StringIO()
with mock.patch('sys.stdout', out),\ with mock.patch('sys.stdout', out), \
mock.patch('sys.stderr', err), \ mock.patch('sys.stderr', err), \
mock.patch('swift.cli.manage_shard_ranges.input', mock.patch('swift.cli.manage_shard_ranges.input',
side_effect=[user_input]): side_effect=[user_input]):

View File

@ -643,7 +643,7 @@ aliases = %s
stdout = StringIO() stdout = StringIO()
with mock.patch.object(sys, 'argv', [ with mock.patch.object(sys, 'argv', [
"prog", "object", "--swiftdir=%s" % self.swift_dir, "prog", "object", "--swiftdir=%s" % self.swift_dir,
"--validate-servers", '--policy=invalid']),\ "--validate-servers", '--policy=invalid']), \
mock.patch('sys.stdout', stdout): mock.patch('sys.stdout', stdout):
self.assertRaises(SystemExit, recon.main) self.assertRaises(SystemExit, recon.main)
self.assertIn('Invalid Storage Policy', stdout.getvalue()) self.assertIn('Invalid Storage Policy', stdout.getvalue())

View File

@ -116,7 +116,7 @@ class TestRequest(S3ApiTestCase):
'check_permission') as m_check_permission: 'check_permission') as m_check_permission:
mock_get_resp.return_value = fake_swift_resp \ mock_get_resp.return_value = fake_swift_resp \
or FakeResponse(self.s3api.conf.s3_acl) or FakeResponse(self.s3api.conf.s3_acl)
return mock_get_resp, m_check_permission,\ return mock_get_resp, m_check_permission, \
s3_req.get_response(self.s3api) s3_req.get_response(self.s3api)
def test_get_response_without_s3_acl(self): def test_get_response_without_s3_acl(self):

View File

@ -1987,7 +1987,7 @@ class TestRingBuilder(unittest.TestCase):
# test old devs but no meta # test old devs but no meta
no_meta_builder = rb no_meta_builder = rb
for dev in no_meta_builder.devs: for dev in no_meta_builder.devs:
del(dev['meta']) del dev['meta']
fake_pickle.return_value = no_meta_builder fake_pickle.return_value = no_meta_builder
pickle.load = fake_pickle pickle.load = fake_pickle
builder = ring.RingBuilder.load('fake.builder', open=fake_open) builder = ring.RingBuilder.load('fake.builder', open=fake_open)

View File

@ -129,7 +129,7 @@ class TestAuditor(unittest.TestCase):
# force code coverage for logging path # force code coverage for logging path
with mock.patch('swift.common.db_auditor.audit_location_generator', with mock.patch('swift.common.db_auditor.audit_location_generator',
fake_audit_location_generator),\ fake_audit_location_generator), \
mock.patch('time.time', mock.patch('time.time',
return_value=(test_auditor.logging_interval * 2)): return_value=(test_auditor.logging_interval * 2)):
test_auditor._one_audit_pass(0) test_auditor._one_audit_pass(0)

View File

@ -375,8 +375,8 @@ class TestInternalClient(unittest.TestCase):
user_agent = 'some_user_agent' user_agent = 'some_user_agent'
request_tries = 123 request_tries = 123
with mock.patch.object( with mock.patch.object(internal_client, 'loadapp',
internal_client, 'loadapp', return_value=app) as mock_loadapp,\ return_value=app) as mock_loadapp, \
self.assertRaises(ValueError): self.assertRaises(ValueError):
# First try with a bad arg # First try with a bad arg
internal_client.InternalClient( internal_client.InternalClient(
@ -432,8 +432,8 @@ class TestInternalClient(unittest.TestCase):
app = FakeSwift() app = FakeSwift()
user_agent = 'some_user_agent' user_agent = 'some_user_agent'
with mock.patch.object( with mock.patch.object(internal_client, 'loadapp',
internal_client, 'loadapp', return_value=app) as mock_loadapp,\ return_value=app) as mock_loadapp, \
self.assertRaises(ValueError) as cm: self.assertRaises(ValueError) as cm:
internal_client.InternalClient( internal_client.InternalClient(
conf_path, user_agent, 1, allow_modify_pipeline=True) conf_path, user_agent, 1, allow_modify_pipeline=True)
@ -775,7 +775,8 @@ class TestInternalClient(unittest.TestCase):
client = internal_client.InternalClient( client = internal_client.InternalClient(
None, "some_agent", 3, use_replication_network=False, None, "some_agent", 3, use_replication_network=False,
app=fake_app) app=fake_app)
with self.assertRaises(internal_client.UnexpectedResponse) as ctx,\ expected_error = internal_client.UnexpectedResponse
with self.assertRaises(expected_error) as ctx, \
mock.patch('swift.common.internal_client.sleep'): mock.patch('swift.common.internal_client.sleep'):
# This is obvious strange tests to expect only 400 Bad Request # This is obvious strange tests to expect only 400 Bad Request
# but this test intended to avoid extra body drain if it's # but this test intended to avoid extra body drain if it's

View File

@ -9447,7 +9447,7 @@ class TestWatchdog(unittest.TestCase):
now = time.time() now = time.time()
timeout_value = 1.0 timeout_value = 1.0
with patch('eventlet.greenthread.getcurrent', return_value=gth),\ with patch('eventlet.greenthread.getcurrent', return_value=gth), \
patch('time.time', return_value=now): patch('time.time', return_value=now):
# On first call, _next_expiration is None, it should unblock # On first call, _next_expiration is None, it should unblock
# greenthread that is blocked for ever # greenthread that is blocked for ever

View File

@ -267,7 +267,7 @@ def setup_servers(the_object_server=object_server, extra_conf=None):
{'X-Timestamp': ts, {'X-Timestamp': ts,
'x-trans-id': 'test'}) 'x-trans-id': 'test'})
resp = conn.getresponse() resp = conn.getresponse()
assert(resp.status == 201) assert resp.status == 201
# Create another account # Create another account
# used for account-to-account tests # used for account-to-account tests
ts = normalize_timestamp(time.time()) ts = normalize_timestamp(time.time())
@ -281,7 +281,7 @@ def setup_servers(the_object_server=object_server, extra_conf=None):
{'X-Timestamp': ts, {'X-Timestamp': ts,
'x-trans-id': 'test'}) 'x-trans-id': 'test'})
resp = conn.getresponse() resp = conn.getresponse()
assert(resp.status == 201) assert resp.status == 201
# Create containers, 1 per test policy # Create containers, 1 per test policy
sock = connect_tcp(('localhost', prolis.getsockname()[1])) sock = connect_tcp(('localhost', prolis.getsockname()[1]))
fd = sock.makefile('rwb') fd = sock.makefile('rwb')

View File

@ -1139,7 +1139,7 @@ class TestObjectController(BaseTestCase):
'X-Backend-Redirect-Timestamp': next(self.ts).internal} 'X-Backend-Redirect-Timestamp': next(self.ts).internal}
with mocked_http_conn(301, headers=[resp_headers]) as conn, \ with mocked_http_conn(301, headers=[resp_headers]) as conn, \
mock.patch('swift.common.utils.HASH_PATH_PREFIX', b''),\ mock.patch('swift.common.utils.HASH_PATH_PREFIX', b''), \
fake_spawn(): fake_spawn():
resp = req.get_response(self.object_controller) resp = req.get_response(self.object_controller)

View File

@ -146,6 +146,9 @@ commands = bandit -c bandit.yaml -r swift -n 5
# it's not a bug that we aren't using all of hacking, ignore: # it's not a bug that we aren't using all of hacking, ignore:
# H101: Use TODO(NAME) # H101: Use TODO(NAME)
# H202: assertRaises Exception too broad # H202: assertRaises Exception too broad
# H211/H212: Use assert{Is,IsNot}instance
# H214: Use assertIn/NotIn ...
# H216: The unittest.mock module should be used rather than ...
# H301: one import per line # H301: one import per line
# H306: imports not in alphabetical order (time, os) # H306: imports not in alphabetical order (time, os)
# H404: multi line docstring should start without a leading new line # H404: multi line docstring should start without a leading new line
@ -159,7 +162,7 @@ commands = bandit -c bandit.yaml -r swift -n 5
# Swift team needs to decide if they want to enable either of these: # Swift team needs to decide if they want to enable either of these:
# W503: line break before binary operator # W503: line break before binary operator
# W504: line break after binary operator # W504: line break after binary operator
ignore = H101,H202,H301,H306,H404,H405,H501,W503,W504,E402,E731,E741 ignore = H101,H202,H211,H212,H214,H216,H301,H306,H404,H405,H501,W503,W504,E402,E731,E741
exclude = .venv,.tox,dist,*egg exclude = .venv,.tox,dist,*egg
filename = *.py,bin/* filename = *.py,bin/*
show-source = True show-source = True