Merge "Run pyupgrade to clean up Python 2 syntaxes"
This commit is contained in:
commit
20f6fb1b6e
@ -1,6 +1,6 @@
|
|||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v4.5.0
|
rev: v5.0.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
# Replaces or checks mixed line ending
|
# Replaces or checks mixed line ending
|
||||||
@ -19,12 +19,17 @@ repos:
|
|||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
files: .*\.(yaml|yml)$
|
files: .*\.(yaml|yml)$
|
||||||
- repo: https://opendev.org/openstack/hacking
|
- repo: https://opendev.org/openstack/hacking
|
||||||
rev: 6.1.0
|
rev: 7.0.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: hacking
|
- id: hacking
|
||||||
additional_dependencies: []
|
additional_dependencies: []
|
||||||
- repo: https://github.com/PyCQA/bandit
|
- repo: https://github.com/PyCQA/bandit
|
||||||
rev: 1.7.6
|
rev: 1.7.10
|
||||||
hooks:
|
hooks:
|
||||||
- id: bandit
|
- id: bandit
|
||||||
args: ['-x', 'tests', '-s', 'B311,B404,B603,B606']
|
args: ['-x', 'tests', '-s', 'B311,B404,B603,B606']
|
||||||
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
|
rev: v3.18.0
|
||||||
|
hooks:
|
||||||
|
- id: pyupgrade
|
||||||
|
args: [--py3-only]
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright (C) 2020 Red Hat, Inc.
|
# Copyright (C) 2020 Red Hat, Inc.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -47,7 +47,7 @@ class LockFixture(fixtures.Fixture):
|
|||||||
self.mgr = lockutils.lock(name, lock_file_prefix, True)
|
self.mgr = lockutils.lock(name, lock_file_prefix, True)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(LockFixture, self).setUp()
|
super().setUp()
|
||||||
self.addCleanup(self.mgr.__exit__, None, None, None)
|
self.addCleanup(self.mgr.__exit__, None, None, None)
|
||||||
self.lock = self.mgr.__enter__()
|
self.lock = self.mgr.__enter__()
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ class ExternalLockFixture(fixtures.Fixture):
|
|||||||
.. versionadded:: 0.3
|
.. versionadded:: 0.3
|
||||||
"""
|
"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ExternalLockFixture, self).setUp()
|
super().setUp()
|
||||||
temp_dir = self.useFixture(fixtures.TempDir())
|
temp_dir = self.useFixture(fixtures.TempDir())
|
||||||
conf = self.useFixture(config.Config(lockutils.CONF)).config
|
conf = self.useFixture(config.Config(lockutils.CONF)).config
|
||||||
conf(lock_path=temp_dir.path, group='oslo_concurrency')
|
conf(lock_path=temp_dir.path, group='oslo_concurrency')
|
||||||
|
@ -104,7 +104,7 @@ class ReaderWriterLock(fasteners.ReaderWriterLock):
|
|||||||
InterProcessLock = fasteners.InterProcessLock
|
InterProcessLock = fasteners.InterProcessLock
|
||||||
|
|
||||||
|
|
||||||
class FairLocks(object):
|
class FairLocks:
|
||||||
"""A garbage collected container of fair locks.
|
"""A garbage collected container of fair locks.
|
||||||
|
|
||||||
With a fair lock, contending lockers will get the lock in the order in
|
With a fair lock, contending lockers will get the lock in the order in
|
||||||
@ -147,7 +147,7 @@ def internal_fair_lock(name):
|
|||||||
return _fair_locks.get(name)
|
return _fair_locks.get(name)
|
||||||
|
|
||||||
|
|
||||||
class Semaphores(object):
|
class Semaphores:
|
||||||
"""A garbage collected container of semaphores.
|
"""A garbage collected container of semaphores.
|
||||||
|
|
||||||
This collection internally uses a weak value dictionary so that when a
|
This collection internally uses a weak value dictionary so that when a
|
||||||
@ -192,7 +192,7 @@ def _get_lock_path(name, lock_file_prefix, lock_path=None):
|
|||||||
name = name.replace(os.sep, '_')
|
name = name.replace(os.sep, '_')
|
||||||
if lock_file_prefix:
|
if lock_file_prefix:
|
||||||
sep = '' if lock_file_prefix.endswith('-') else '-'
|
sep = '' if lock_file_prefix.endswith('-') else '-'
|
||||||
name = '%s%s%s' % (lock_file_prefix, sep, name)
|
name = '{}{}{}'.format(lock_file_prefix, sep, name)
|
||||||
|
|
||||||
local_lock_path = lock_path or CONF.oslo_concurrency.lock_path
|
local_lock_path = lock_path or CONF.oslo_concurrency.lock_path
|
||||||
|
|
||||||
|
@ -70,18 +70,18 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class InvalidArgumentError(Exception):
|
class InvalidArgumentError(Exception):
|
||||||
def __init__(self, message=None):
|
def __init__(self, message=None):
|
||||||
super(InvalidArgumentError, self).__init__(message)
|
super().__init__(message)
|
||||||
|
|
||||||
|
|
||||||
class UnknownArgumentError(Exception):
|
class UnknownArgumentError(Exception):
|
||||||
def __init__(self, message=None):
|
def __init__(self, message=None):
|
||||||
super(UnknownArgumentError, self).__init__(message)
|
super().__init__(message)
|
||||||
|
|
||||||
|
|
||||||
class ProcessExecutionError(Exception):
|
class ProcessExecutionError(Exception):
|
||||||
def __init__(self, stdout=None, stderr=None, exit_code=None, cmd=None,
|
def __init__(self, stdout=None, stderr=None, exit_code=None, cmd=None,
|
||||||
description=None):
|
description=None):
|
||||||
super(ProcessExecutionError, self).__init__(
|
super().__init__(
|
||||||
stdout, stderr, exit_code, cmd, description)
|
stdout, stderr, exit_code, cmd, description)
|
||||||
self.exit_code = exit_code
|
self.exit_code = exit_code
|
||||||
self.stderr = stderr
|
self.stderr = stderr
|
||||||
@ -112,7 +112,7 @@ class ProcessExecutionError(Exception):
|
|||||||
|
|
||||||
class NoRootWrapSpecified(Exception):
|
class NoRootWrapSpecified(Exception):
|
||||||
def __init__(self, message=None):
|
def __init__(self, message=None):
|
||||||
super(NoRootWrapSpecified, self).__init__(message)
|
super().__init__(message)
|
||||||
|
|
||||||
|
|
||||||
def _subprocess_setup(on_preexec_fn):
|
def _subprocess_setup(on_preexec_fn):
|
||||||
@ -146,7 +146,7 @@ LOG_FINAL_ERROR = LogErrors.FINAL
|
|||||||
LOG_DEFAULT_ERROR = LogErrors.DEFAULT
|
LOG_DEFAULT_ERROR = LogErrors.DEFAULT
|
||||||
|
|
||||||
|
|
||||||
class ProcessLimits(object):
|
class ProcessLimits:
|
||||||
"""Resource limits on a process.
|
"""Resource limits on a process.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
@ -192,7 +192,7 @@ class ProcessLimits(object):
|
|||||||
for limit in self._LIMITS:
|
for limit in self._LIMITS:
|
||||||
val = getattr(self, limit)
|
val = getattr(self, limit)
|
||||||
if val is not None:
|
if val is not None:
|
||||||
args.append("%s=%s" % (self._LIMITS[limit], val))
|
args.append("{}={}".format(self._LIMITS[limit], val))
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ def lock_files(handles_dir, out_queue):
|
|||||||
lock_file(handle)
|
lock_file(handle)
|
||||||
count += 1
|
count += 1
|
||||||
unlock_file(handle)
|
unlock_file(handle)
|
||||||
except IOError:
|
except OSError:
|
||||||
os._exit(2)
|
os._exit(2)
|
||||||
finally:
|
finally:
|
||||||
handle.close()
|
handle.close()
|
||||||
@ -78,7 +78,7 @@ def lock_files(handles_dir, out_queue):
|
|||||||
class LockTestCase(test_base.BaseTestCase):
|
class LockTestCase(test_base.BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(LockTestCase, self).setUp()
|
super().setUp()
|
||||||
self.config = self.useFixture(config.Config(lockutils.CONF)).config
|
self.config = self.useFixture(config.Config(lockutils.CONF)).config
|
||||||
|
|
||||||
def test_synchronized_wrapped_function_metadata(self):
|
def test_synchronized_wrapped_function_metadata(self):
|
||||||
@ -363,7 +363,7 @@ class LockTestCase(test_base.BaseTestCase):
|
|||||||
|
|
||||||
class FileBasedLockingTestCase(test_base.BaseTestCase):
|
class FileBasedLockingTestCase(test_base.BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(FileBasedLockingTestCase, self).setUp()
|
super().setUp()
|
||||||
self.lock_dir = tempfile.mkdtemp()
|
self.lock_dir = tempfile.mkdtemp()
|
||||||
|
|
||||||
def test_lock_file_exists(self):
|
def test_lock_file_exists(self):
|
||||||
@ -399,7 +399,7 @@ class FileBasedLockingTestCase(test_base.BaseTestCase):
|
|||||||
lock1.trylock()
|
lock1.trylock()
|
||||||
lock1.unlock()
|
lock1.unlock()
|
||||||
time.sleep(0)
|
time.sleep(0)
|
||||||
except IOError:
|
except OSError:
|
||||||
# This is what we expect to happen
|
# This is what we expect to happen
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@ -415,7 +415,7 @@ class FileBasedLockingTestCase(test_base.BaseTestCase):
|
|||||||
try:
|
try:
|
||||||
lock2.trylock()
|
lock2.trylock()
|
||||||
have_lock = True
|
have_lock = True
|
||||||
except IOError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
# NOTE(bnemec): This is racy, but I don't want to add any
|
# NOTE(bnemec): This is racy, but I don't want to add any
|
||||||
@ -557,7 +557,7 @@ class FileBasedLockingTestCase(test_base.BaseTestCase):
|
|||||||
class LockutilsModuleTestCase(test_base.BaseTestCase):
|
class LockutilsModuleTestCase(test_base.BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(LockutilsModuleTestCase, self).setUp()
|
super().setUp()
|
||||||
self.old_env = os.environ.get('OSLO_LOCK_PATH')
|
self.old_env = os.environ.get('OSLO_LOCK_PATH')
|
||||||
if self.old_env is not None:
|
if self.old_env is not None:
|
||||||
del os.environ['OSLO_LOCK_PATH']
|
del os.environ['OSLO_LOCK_PATH']
|
||||||
@ -565,7 +565,7 @@ class LockutilsModuleTestCase(test_base.BaseTestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
if self.old_env is not None:
|
if self.old_env is not None:
|
||||||
os.environ['OSLO_LOCK_PATH'] = self.old_env
|
os.environ['OSLO_LOCK_PATH'] = self.old_env
|
||||||
super(LockutilsModuleTestCase, self).tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
def test_main(self):
|
def test_main(self):
|
||||||
script = '\n'.join([
|
script = '\n'.join([
|
||||||
@ -597,7 +597,7 @@ class LockutilsModuleTestCase(test_base.BaseTestCase):
|
|||||||
class TestLockFixture(test_base.BaseTestCase):
|
class TestLockFixture(test_base.BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestLockFixture, self).setUp()
|
super().setUp()
|
||||||
self.config = self.useFixture(config.Config(lockutils.CONF)).config
|
self.config = self.useFixture(config.Config(lockutils.CONF)).config
|
||||||
self.tempdir = tempfile.mkdtemp()
|
self.tempdir = tempfile.mkdtemp()
|
||||||
|
|
||||||
@ -606,7 +606,7 @@ class TestLockFixture(test_base.BaseTestCase):
|
|||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self._check_in_lock()
|
self._check_in_lock()
|
||||||
super(TestLockFixture, self).tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
def test_lock_fixture(self):
|
def test_lock_fixture(self):
|
||||||
# Setup lock fixture to test that teardown is inside the lock
|
# Setup lock fixture to test that teardown is inside the lock
|
||||||
@ -619,7 +619,7 @@ class TestLockFixture(test_base.BaseTestCase):
|
|||||||
class TestGetLockPath(test_base.BaseTestCase):
|
class TestGetLockPath(test_base.BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestGetLockPath, self).setUp()
|
super().setUp()
|
||||||
self.conf = self.useFixture(config.Config(lockutils.CONF)).conf
|
self.conf = self.useFixture(config.Config(lockutils.CONF)).conf
|
||||||
|
|
||||||
def test_get_default(self):
|
def test_get_default(self):
|
||||||
|
@ -89,7 +89,7 @@ class UtilsTest(test_base.BaseTestCase):
|
|||||||
on_completion_callback = mock.Mock()
|
on_completion_callback = mock.Mock()
|
||||||
|
|
||||||
def fake_communicate(*args, timeout=None):
|
def fake_communicate(*args, timeout=None):
|
||||||
raise IOError("Broken pipe")
|
raise OSError("Broken pipe")
|
||||||
|
|
||||||
mock_comm.side_effect = fake_communicate
|
mock_comm.side_effect = fake_communicate
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ class UtilsTest(test_base.BaseTestCase):
|
|||||||
mock_comm.return_value = None
|
mock_comm.return_value = None
|
||||||
mock_tpool.execute.return_value = mock_comm.return_value
|
mock_tpool.execute.return_value = mock_comm.return_value
|
||||||
|
|
||||||
fake_pinput = 'fake pinput'.encode('utf-8')
|
fake_pinput = b'fake pinput'
|
||||||
|
|
||||||
with mock.patch.object(processutils, 'eventlet_patched',
|
with mock.patch.object(processutils, 'eventlet_patched',
|
||||||
use_eventlet):
|
use_eventlet):
|
||||||
@ -240,7 +240,7 @@ exit 1
|
|||||||
tmpfilename, tmpfilename2, attempts=10,
|
tmpfilename, tmpfilename2, attempts=10,
|
||||||
process_input=b'foo',
|
process_input=b'foo',
|
||||||
delay_on_retry=False)
|
delay_on_retry=False)
|
||||||
fp = open(tmpfilename2, 'r')
|
fp = open(tmpfilename2)
|
||||||
runs = fp.read()
|
runs = fp.read()
|
||||||
fp.close()
|
fp.close()
|
||||||
self.assertNotEqual('failure', 'stdin did not '
|
self.assertNotEqual('failure', 'stdin did not '
|
||||||
@ -320,7 +320,7 @@ grep foo
|
|||||||
# This test and the one below ensures that when communicate raises
|
# This test and the one below ensures that when communicate raises
|
||||||
# an OSError, we do the right thing(s)
|
# an OSError, we do the right thing(s)
|
||||||
def test_exception_on_communicate_error(self):
|
def test_exception_on_communicate_error(self):
|
||||||
mock = self.useFixture(fixtures.MockPatch(
|
mock_comm = self.useFixture(fixtures.MockPatch(
|
||||||
'subprocess.Popen.communicate',
|
'subprocess.Popen.communicate',
|
||||||
side_effect=OSError(errno.EAGAIN, 'fake-test')))
|
side_effect=OSError(errno.EAGAIN, 'fake-test')))
|
||||||
|
|
||||||
@ -330,10 +330,10 @@ grep foo
|
|||||||
'false',
|
'false',
|
||||||
check_exit_code=False)
|
check_exit_code=False)
|
||||||
|
|
||||||
self.assertEqual(1, mock.mock.call_count)
|
self.assertEqual(1, mock_comm.mock.call_count)
|
||||||
|
|
||||||
def test_retry_on_communicate_error(self):
|
def test_retry_on_communicate_error(self):
|
||||||
mock = self.useFixture(fixtures.MockPatch(
|
mock_comm = self.useFixture(fixtures.MockPatch(
|
||||||
'subprocess.Popen.communicate',
|
'subprocess.Popen.communicate',
|
||||||
side_effect=OSError(errno.EAGAIN, 'fake-test')))
|
side_effect=OSError(errno.EAGAIN, 'fake-test')))
|
||||||
|
|
||||||
@ -344,11 +344,11 @@ grep foo
|
|||||||
check_exit_code=False,
|
check_exit_code=False,
|
||||||
attempts=5)
|
attempts=5)
|
||||||
|
|
||||||
self.assertEqual(5, mock.mock.call_count)
|
self.assertEqual(5, mock_comm.mock.call_count)
|
||||||
|
|
||||||
def _test_and_check_logging_communicate_errors(self, log_errors=None,
|
def _test_and_check_logging_communicate_errors(self, log_errors=None,
|
||||||
attempts=None):
|
attempts=None):
|
||||||
mock = self.useFixture(fixtures.MockPatch(
|
mock_comm = self.useFixture(fixtures.MockPatch(
|
||||||
'subprocess.Popen.communicate',
|
'subprocess.Popen.communicate',
|
||||||
side_effect=OSError(errno.EAGAIN, 'fake-test')))
|
side_effect=OSError(errno.EAGAIN, 'fake-test')))
|
||||||
|
|
||||||
@ -367,7 +367,8 @@ grep foo
|
|||||||
'false',
|
'false',
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
self.assertEqual(attempts if attempts else 1, mock.mock.call_count)
|
self.assertEqual(attempts if attempts else 1,
|
||||||
|
mock_comm.mock.call_count)
|
||||||
self.assertIn('Got an OSError', fixture.output)
|
self.assertIn('Got an OSError', fixture.output)
|
||||||
self.assertIn('errno: %d' % errno.EAGAIN, fixture.output)
|
self.assertIn('errno: %d' % errno.EAGAIN, fixture.output)
|
||||||
self.assertIn("'/usr/bin/env false'", fixture.output)
|
self.assertIn("'/usr/bin/env false'", fixture.output)
|
||||||
@ -530,7 +531,7 @@ grep foo
|
|||||||
|
|
||||||
class ProcessExecutionErrorLoggingTest(test_base.BaseTestCase):
|
class ProcessExecutionErrorLoggingTest(test_base.BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(ProcessExecutionErrorLoggingTest, self).setUp()
|
super().setUp()
|
||||||
self.tmpfilename = self.create_tempfiles(
|
self.tmpfilename = self.create_tempfiles(
|
||||||
[["process_execution_error_logging_test",
|
[["process_execution_error_logging_test",
|
||||||
PROCESS_EXECUTION_ERROR_LOGGING_TEST]],
|
PROCESS_EXECUTION_ERROR_LOGGING_TEST]],
|
||||||
@ -624,7 +625,7 @@ class TryCmdTestCase(test_base.BaseTestCase):
|
|||||||
self.assertEqual('', e)
|
self.assertEqual('', e)
|
||||||
|
|
||||||
|
|
||||||
class FakeSshChannel(object):
|
class FakeSshChannel:
|
||||||
def __init__(self, rc):
|
def __init__(self, rc):
|
||||||
self.rc = rc
|
self.rc = rc
|
||||||
|
|
||||||
@ -637,7 +638,7 @@ class FakeSshStream(io.BytesIO):
|
|||||||
self.channel = FakeSshChannel(rc)
|
self.channel = FakeSshChannel(rc)
|
||||||
|
|
||||||
|
|
||||||
class FakeSshConnection(object):
|
class FakeSshConnection:
|
||||||
def __init__(self, rc, out=b'stdout', err=b'stderr'):
|
def __init__(self, rc, out=b'stdout', err=b'stderr'):
|
||||||
self.rc = rc
|
self.rc = rc
|
||||||
self.out = out
|
self.out = out
|
||||||
|
@ -64,7 +64,7 @@ def watch(logger, action, level=logging.DEBUG, after=5.0):
|
|||||||
watch.start()
|
watch.start()
|
||||||
|
|
||||||
def log():
|
def log():
|
||||||
msg = "%s not completed after %0.3fs" % (action, watch.elapsed())
|
msg = "{} not completed after {:0.3f}s".format(action, watch.elapsed())
|
||||||
logger.log(level, msg)
|
logger.log(level, msg)
|
||||||
|
|
||||||
timer = threading.Timer(after, log)
|
timer = threading.Timer(after, log)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
# You may obtain a copy of the License at
|
# You may obtain a copy of the License at
|
||||||
|
Loading…
Reference in New Issue
Block a user