Run pyupgrade to clean up Python 2 syntaxes

Update all .py source files by
 $ pyupgrade --py3-only $(git ls-files | grep ".py$")
to modernize the code according to Python 3 syntaxes.

Also add the pyupgrade hook to pre-commit to avoid merging additional
Python 2 syntaxes.

Change-Id: I2adc97da3ef11ee18e30ed92e9ca5992d384fdb1
This commit is contained in:
Takashi Kajinami 2024-10-19 23:23:10 +09:00
parent ee6e7766d0
commit 822f3bd94b
20 changed files with 83 additions and 81 deletions

View File

@ -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,17 +19,21 @@ 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'] args: ['-x', 'tests']
- repo: https://github.com/PyCQA/doc8 - repo: https://github.com/PyCQA/doc8
rev: v1.1.1 rev: v1.1.2
hooks: hooks:
- id: doc8 - id: doc8
- repo: https://github.com/asottile/pyupgrade
rev: v3.18.0
hooks:
- id: pyupgrade
args: [--py3-only]

View File

@ -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");

View File

@ -40,7 +40,7 @@ class EventletBackdoorConfigValueError(Exception):
msg = (_('Invalid backdoor_port configuration %(range)s: %(ex)s. ' msg = (_('Invalid backdoor_port configuration %(range)s: %(ex)s. '
'%(help)s') % '%(help)s') %
{'range': port_range, 'ex': ex, 'help': help_msg}) {'range': port_range, 'ex': ex, 'help': help_msg})
super(EventletBackdoorConfigValueError, self).__init__(msg) super().__init__(msg)
self.port_range = port_range self.port_range = port_range
@ -50,7 +50,7 @@ def _dont_use_this():
def _dump_frame(f, frame_chapter): def _dump_frame(f, frame_chapter):
co = f.f_code co = f.f_code
print(" %s Frame: %s" % (frame_chapter, co.co_name)) print(" {} Frame: {}".format(frame_chapter, co.co_name))
print(" File: %s" % (co.co_filename)) print(" File: %s" % (co.co_filename))
print(" Captured at line number: %s" % (f.f_lineno)) print(" Captured at line number: %s" % (f.f_lineno))
co_locals = set(co.co_varnames) co_locals = set(co.co_varnames)
@ -64,7 +64,8 @@ def _dump_frame(f, frame_chapter):
if set_locals: if set_locals:
print(" %s set local variables:" % (len(set_locals))) print(" %s set local variables:" % (len(set_locals)))
for var_name in sorted(set_locals.keys()): for var_name in sorted(set_locals.keys()):
print(" %s => %r" % (var_name, f.f_locals[var_name])) print(" {} => {!r}".format(
var_name, f.f_locals[var_name]))
else: else:
print(" 0 set local variables.") print(" 0 set local variables.")
if not_set: if not_set:
@ -80,7 +81,7 @@ def _dump_frame(f, frame_chapter):
def _detailed_dump_frames(f, thread_index): def _detailed_dump_frames(f, thread_index):
i = 0 i = 0
while f is not None: while f is not None:
_dump_frame(f, "%s.%s" % (thread_index, i + 1)) _dump_frame(f, "{}.{}".format(thread_index, i + 1))
f = f.f_back f = f.f_back
i += 1 i += 1
@ -164,7 +165,7 @@ def _listen(host, start_port, end_port):
while True: while True:
try: try:
return _listen_func(host, try_port) return _listen_func(host, try_port)
except socket.error as exc: except OSError as exc:
if (exc.errno != errno.EADDRINUSE or if (exc.errno != errno.EADDRINUSE or
try_port >= end_port): try_port >= end_port):
raise raise
@ -174,7 +175,7 @@ def _listen(host, start_port, end_port):
def _try_open_unix_domain_socket(socket_path): def _try_open_unix_domain_socket(socket_path):
try: try:
return eventlet.listen(socket_path, socket.AF_UNIX) return eventlet.listen(socket_path, socket.AF_UNIX)
except socket.error as e: except OSError as e:
if e.errno != errno.EADDRINUSE: if e.errno != errno.EADDRINUSE:
# NOTE(harlowja): Some other non-address in use error # NOTE(harlowja): Some other non-address in use error
# occurred, since we aren't handling those, re-raise # occurred, since we aren't handling those, re-raise

View File

@ -76,7 +76,7 @@ def _safe_wrapper(f, kind, func_name):
return func return func
class LoopingCallBase(object): class LoopingCallBase:
_KIND = _("Unknown looping call") _KIND = _("Unknown looping call")
_RUN_ONLY_ONE_MESSAGE = _("A looping call can only run one function" _RUN_ONLY_ONE_MESSAGE = _("A looping call can only run one function"
@ -315,7 +315,7 @@ class BackOffLoopingCall(LoopingCallBase):
" only run one function at a time") " only run one function at a time")
def __init__(self, f=None, *args, **kw): def __init__(self, f=None, *args, **kw):
super(BackOffLoopingCall, self).__init__(f=f, *args, **kw) super().__init__(f=f, *args, **kw)
self._error_time = 0 self._error_time = 0
self._interval = 1 self._interval = 1
@ -355,7 +355,7 @@ class BackOffLoopingCall(LoopingCallBase):
return self._start(_idle_for, initial_delay=initial_delay) return self._start(_idle_for, initial_delay=initial_delay)
class RetryDecorator(object): class RetryDecorator:
"""Decorator for retrying a function upon suggested exceptions. """Decorator for retrying a function upon suggested exceptions.
The decorated function is retried for the given number of times, and the The decorated function is retried for the given number of times, and the

View File

@ -125,7 +125,7 @@ class _PeriodicTasksMeta(type):
def __init__(cls, names, bases, dict_): def __init__(cls, names, bases, dict_):
"""Metaclass that allows us to collect decorated periodic tasks.""" """Metaclass that allows us to collect decorated periodic tasks."""
super(_PeriodicTasksMeta, cls).__init__(names, bases, dict_) super().__init__(names, bases, dict_)
# NOTE(sirp): if the attribute is not present then we must be the base # NOTE(sirp): if the attribute is not present then we must be the base
# class, so, go ahead an initialize it. If the attribute is present, # class, so, go ahead an initialize it. If the attribute is present,
@ -170,7 +170,7 @@ def _nearest_boundary(last_run, spacing):
class PeriodicTasks(metaclass=_PeriodicTasksMeta): class PeriodicTasks(metaclass=_PeriodicTasksMeta):
def __init__(self, conf): def __init__(self, conf):
super(PeriodicTasks, self).__init__() super().__init__()
self.conf = conf self.conf = conf
self.conf.register_opts(_options.periodic_opts) self.conf.register_opts(_options.periodic_opts)
self._periodic_last_run = {} self._periodic_last_run = {}

View File

@ -120,7 +120,7 @@ class Singleton(type):
def __call__(cls, *args, **kwargs): def __call__(cls, *args, **kwargs):
with lockutils.lock('singleton_lock', semaphores=cls._semaphores): with lockutils.lock('singleton_lock', semaphores=cls._semaphores):
if cls not in cls._instances: if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__( cls._instances[cls] = super().__call__(
*args, **kwargs) *args, **kwargs)
return cls._instances[cls] return cls._instances[cls]
@ -128,20 +128,20 @@ class Singleton(type):
class SignalHandler(metaclass=Singleton): class SignalHandler(metaclass=Singleton):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(SignalHandler, self).__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.__setup_signal_interruption() self.__setup_signal_interruption()
# Map all signal names to signal integer values and create a # Map all signal names to signal integer values and create a
# reverse mapping (for easier + quick lookup). # reverse mapping (for easier + quick lookup).
self._ignore_signals = ('SIG_DFL', 'SIG_IGN') self._ignore_signals = ('SIG_DFL', 'SIG_IGN')
self._signals_by_name = dict((name, getattr(signal, name)) self._signals_by_name = {name: getattr(signal, name)
for name in dir(signal) for name in dir(signal)
if name.startswith("SIG") and if name.startswith("SIG") and
name not in self._ignore_signals) name not in self._ignore_signals}
self.signals_to_name = dict( self.signals_to_name = {
(sigval, name) sigval: name
for (name, sigval) in self._signals_by_name.items()) for (name, sigval) in self._signals_by_name.items()}
self._signal_handlers = collections.defaultdict(list) self._signal_handlers = collections.defaultdict(list)
self.clear() self.clear()
@ -193,7 +193,7 @@ class SignalHandler(metaclass=Singleton):
interrupted_frame.filename == self.__hub_module_file) or interrupted_frame.filename == self.__hub_module_file) or
(interrupted_frame.function == 'do_sleep' and (interrupted_frame.function == 'do_sleep' and
interrupted_frame.filename == __file__)): interrupted_frame.filename == __file__)):
raise IOError(errno.EINTR, 'Interrupted') raise OSError(errno.EINTR, 'Interrupted')
def __setup_signal_interruption(self): def __setup_signal_interruption(self):
"""Set up to do the Right Thing with signals during poll() and sleep(). """Set up to do the Right Thing with signals during poll() and sleep().
@ -227,7 +227,7 @@ class SignalHandler(metaclass=Singleton):
def sleep_wrapper(seconds): def sleep_wrapper(seconds):
try: try:
return do_sleep(time_sleep, seconds) return do_sleep(time_sleep, seconds)
except (IOError, InterruptedError) as err: except (OSError, InterruptedError) as err:
if err.errno != errno.EINTR: if err.errno != errno.EINTR:
raise raise
@ -244,7 +244,7 @@ class SignalHandler(metaclass=Singleton):
return sig_name in self._signals_by_name return sig_name in self._signals_by_name
class Launcher(object): class Launcher:
"""Launch one or more services and wait for them to complete.""" """Launch one or more services and wait for them to complete."""
def __init__(self, conf, restart_method='reload'): def __init__(self, conf, restart_method='reload'):
@ -311,7 +311,7 @@ class Launcher(object):
class SignalExit(SystemExit): class SignalExit(SystemExit):
def __init__(self, signo, exccode=1): def __init__(self, signo, exccode=1):
super(SignalExit, self).__init__(exccode) super().__init__(exccode)
self.signo = signo self.signo = signo
@ -323,7 +323,7 @@ class ServiceLauncher(Launcher):
:param conf: an instance of ConfigOpts :param conf: an instance of ConfigOpts
:param restart_method: passed to super :param restart_method: passed to super
""" """
super(ServiceLauncher, self).__init__( super().__init__(
conf, restart_method=restart_method) conf, restart_method=restart_method)
self.signal_handler = SignalHandler() self.signal_handler = SignalHandler()
@ -364,7 +364,7 @@ class ServiceLauncher(Launcher):
self.conf.log_opt_values(LOG, logging.DEBUG) self.conf.log_opt_values(LOG, logging.DEBUG)
try: try:
super(ServiceLauncher, self).wait() super().wait()
except SignalExit as exc: except SignalExit as exc:
signame = self.signal_handler.signals_to_name[exc.signo] signame = self.signal_handler.signals_to_name[exc.signo]
LOG.info('Caught %s, handling', signame) LOG.info('Caught %s, handling', signame)
@ -391,11 +391,11 @@ class ServiceLauncher(Launcher):
break break
self.restart() self.restart()
super(ServiceLauncher, self).wait() super().wait()
return status return status
class ServiceWrapper(object): class ServiceWrapper:
def __init__(self, service, workers): def __init__(self, service, workers):
self.service = service self.service = service
self.workers = workers self.workers = workers
@ -403,7 +403,7 @@ class ServiceWrapper(object):
self.forktimes = [] self.forktimes = []
class ProcessLauncher(object): class ProcessLauncher:
"""Launch a service with a given number of workers.""" """Launch a service with a given number of workers."""
def __init__(self, conf, wait_interval=0.01, restart_method='reload'): def __init__(self, conf, wait_interval=0.01, restart_method='reload'):
@ -672,8 +672,8 @@ class ProcessLauncher(object):
elif self.restart_method == 'mutate': elif self.restart_method == 'mutate':
self.conf.mutate_config_files() self.conf.mutate_config_files()
child_signal = signal.SIGHUP child_signal = signal.SIGHUP
for service in set( for service in {
[wrap.service for wrap in self.children.values()]): wrap.service for wrap in self.children.values()}:
service.reset() service.reset()
for pid in self.children: for pid in self.children:
@ -697,8 +697,8 @@ class ProcessLauncher(object):
self.running = False self.running = False
LOG.debug("Stop services.") LOG.debug("Stop services.")
for service in set( for service in {
[wrap.service for wrap in self.children.values()]): wrap.service for wrap in self.children.values()}:
service.stop() service.stop()
LOG.debug("Killing children.") LOG.debug("Killing children.")
@ -741,7 +741,7 @@ class Service(ServiceBase):
self.tg.wait() self.tg.wait()
class Services(object): class Services:
def __init__(self, restart_method='reload'): def __init__(self, restart_method='reload'):
if restart_method not in _LAUNCHER_RESTART_METHODS: if restart_method not in _LAUNCHER_RESTART_METHODS:

View File

@ -43,7 +43,7 @@ def _sd_notify(unset_env, msg):
sock.sendall(msg) sock.sendall(msg)
if unset_env: if unset_env:
del os.environ['NOTIFY_SOCKET'] del os.environ['NOTIFY_SOCKET']
except EnvironmentError: except OSError:
LOG.debug("Systemd notification failed", exc_info=True) LOG.debug("Systemd notification failed", exc_info=True)

View File

@ -23,7 +23,7 @@ from oslo_service import sslutils
class ServiceBaseTestCase(test_base.BaseTestCase): class ServiceBaseTestCase(test_base.BaseTestCase):
def setUp(self): def setUp(self):
super(ServiceBaseTestCase, self).setUp() super().setUp()
self.conf_fixture = self.useFixture(config.Config()) self.conf_fixture = self.useFixture(config.Config())
self.conf_fixture.register_opts(_options.eventlet_backdoor_opts) self.conf_fixture.register_opts(_options.eventlet_backdoor_opts)
self.conf_fixture.register_opts(_options.service_opts) self.conf_fixture.register_opts(_options.service_opts)

View File

@ -1,4 +1,3 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may # 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 # not use this file except in compliance with the License. You may obtain
# a copy of the License at # a copy of the License at

View File

@ -20,7 +20,7 @@ from oslo_service import loopingcall
class FixtureTestCase(test_base.BaseTestCase): class FixtureTestCase(test_base.BaseTestCase):
def setUp(self): def setUp(self):
super(FixtureTestCase, self).setUp() super().setUp()
self.sleepfx = self.useFixture(fixture.SleepFixture()) self.sleepfx = self.useFixture(fixture.SleepFixture())
def test_sleep_fixture(self): def test_sleep_fixture(self):

View File

@ -25,7 +25,7 @@ from oslo_service import loopingcall
class LoopingCallTestCase(test_base.BaseTestCase): class LoopingCallTestCase(test_base.BaseTestCase):
def setUp(self): def setUp(self):
super(LoopingCallTestCase, self).setUp() super().setUp()
self.num_runs = 0 self.num_runs = 0
def test_return_true(self): def test_return_true(self):
@ -159,7 +159,7 @@ class LoopingCallTestCase(test_base.BaseTestCase):
class DynamicLoopingCallTestCase(test_base.BaseTestCase): class DynamicLoopingCallTestCase(test_base.BaseTestCase):
def setUp(self): def setUp(self):
super(DynamicLoopingCallTestCase, self).setUp() super().setUp()
self.num_runs = 0 self.num_runs = 0
def test_return_true(self): def test_return_true(self):

View File

@ -41,7 +41,7 @@ class PeriodicTasksTestCase(base.ServiceBaseTestCase):
# the periodic task decorator # the periodic task decorator
class AService(periodic_task.PeriodicTasks): class AService(periodic_task.PeriodicTasks):
def __init__(self, conf): def __init__(self, conf):
super(AService, self).__init__(conf) super().__init__(conf)
self.called = {'doit': 0, 'urg': 0, 'ticks': 0, 'tocks': 0} self.called = {'doit': 0, 'urg': 0, 'ticks': 0, 'tocks': 0}
@periodic_task.periodic_task @periodic_task.periodic_task
@ -134,7 +134,7 @@ class PeriodicTasksTestCase(base.ServiceBaseTestCase):
# the periodic task decorator # the periodic task decorator
class AService(periodic_task.PeriodicTasks): class AService(periodic_task.PeriodicTasks):
def __init__(self, conf): def __init__(self, conf):
super(AService, self).__init__(conf) super().__init__(conf)
self.called = {'ticks': 0} self.called = {'ticks': 0}
@periodic_task.periodic_task(spacing=test_spacing) @periodic_task.periodic_task(spacing=test_spacing)
@ -155,7 +155,7 @@ class PeriodicTasksTestCase(base.ServiceBaseTestCase):
class AService(periodic_task.PeriodicTasks): class AService(periodic_task.PeriodicTasks):
def __init__(self, conf): def __init__(self, conf):
super(AService, self).__init__(conf) super().__init__(conf)
self.called = {'urg': 0, } self.called = {'urg': 0, }
@periodic_task.periodic_task @periodic_task.periodic_task
@ -174,7 +174,7 @@ class PeriodicTasksTestCase(base.ServiceBaseTestCase):
def test_name(self): def test_name(self):
class AService(periodic_task.PeriodicTasks): class AService(periodic_task.PeriodicTasks):
def __init__(self, conf): def __init__(self, conf):
super(AService, self).__init__(conf) super().__init__(conf)
@periodic_task.periodic_task(name='better-name') @periodic_task.periodic_task(name='better-name')
def tick(self, context): def tick(self, context):
@ -234,7 +234,7 @@ class ManagerMetaTestCase(base.ServiceBaseTestCase):
class ManagerTestCase(base.ServiceBaseTestCase): class ManagerTestCase(base.ServiceBaseTestCase):
"""Tests the periodic tasks portion of the manager class.""" """Tests the periodic tasks portion of the manager class."""
def setUp(self): def setUp(self):
super(ManagerTestCase, self).setUp() super().setUp()
def test_periodic_tasks_with_idle(self): def test_periodic_tasks_with_idle(self):
class Manager(periodic_task.PeriodicTasks): class Manager(periodic_task.PeriodicTasks):

View File

@ -52,18 +52,18 @@ class ServiceManagerTestCase(test_base.BaseTestCase):
class ServiceWithTimer(service.Service): class ServiceWithTimer(service.Service):
def __init__(self, ready_event=None): def __init__(self, ready_event=None):
super(ServiceWithTimer, self).__init__() super().__init__()
self.ready_event = ready_event self.ready_event = ready_event
def start(self): def start(self):
super(ServiceWithTimer, self).start() super().start()
self.timer_fired = 0 self.timer_fired = 0
self.tg.add_timer(1, self.timer_expired) self.tg.add_timer(1, self.timer_expired)
def wait(self): def wait(self):
if self.ready_event: if self.ready_event:
self.ready_event.set() self.ready_event.set()
super(ServiceWithTimer, self).wait() super().wait()
def timer_expired(self): def timer_expired(self):
self.timer_fired = self.timer_fired + 1 self.timer_fired = self.timer_fired + 1
@ -71,7 +71,7 @@ class ServiceWithTimer(service.Service):
class ServiceCrashOnStart(ServiceWithTimer): class ServiceCrashOnStart(ServiceWithTimer):
def start(self): def start(self):
super(ServiceCrashOnStart, self).start() super().start()
raise ValueError raise ValueError
@ -123,7 +123,7 @@ class ServiceTestBase(base.ServiceBaseTestCase):
time.sleep(.1) time.sleep(.1)
def setUp(self): def setUp(self):
super(ServiceTestBase, self).setUp() super().setUp()
# NOTE(markmc): ConfigOpts.log_opt_values() uses CONF.config-file # NOTE(markmc): ConfigOpts.log_opt_values() uses CONF.config-file
self.conf(args=[], default_config_files=[]) self.conf(args=[], default_config_files=[])
self.addCleanup(self.conf.reset) self.addCleanup(self.conf.reset)
@ -335,7 +335,7 @@ class ServiceRestartTest(ServiceTestBase):
class _Service(service.Service): class _Service(service.Service):
def __init__(self): def __init__(self):
super(_Service, self).__init__() super().__init__()
self.init = event.Event() self.init = event.Event()
self.cleaned_up = False self.cleaned_up = False
@ -344,7 +344,7 @@ class _Service(service.Service):
def stop(self): def stop(self):
self.cleaned_up = True self.cleaned_up = True
super(_Service, self).stop() super().stop()
class LauncherTest(base.ServiceBaseTestCase): class LauncherTest(base.ServiceBaseTestCase):
@ -418,7 +418,7 @@ class LauncherTest(base.ServiceBaseTestCase):
initialize_if_enabled_mock.return_value = None initialize_if_enabled_mock.return_value = None
launcher = service.Launcher(self.conf) launcher = service.Launcher(self.conf)
class FooService(object): class FooService:
def __init__(self): def __init__(self):
pass pass
serv = FooService() serv = FooService()
@ -552,7 +552,7 @@ class ProcessLauncherTest(base.ServiceBaseTestCase):
pipe_mock.return_value = [None, None] pipe_mock.return_value = [None, None]
launcher = service.ProcessLauncher(self.conf) launcher = service.ProcessLauncher(self.conf)
class FooService(object): class FooService:
def __init__(self): def __init__(self):
pass pass
serv = FooService() serv = FooService()
@ -593,7 +593,7 @@ class ProcessLauncherTest(base.ServiceBaseTestCase):
class GracefulShutdownTestService(service.Service): class GracefulShutdownTestService(service.Service):
def __init__(self): def __init__(self):
super(GracefulShutdownTestService, self).__init__() super().__init__()
self.finished_task = event.Event() self.finished_task = event.Event()
def start(self, sleep_amount): def start(self, sleep_amount):
@ -628,7 +628,7 @@ class ServiceTest(test_base.BaseTestCase):
class EventletServerProcessLauncherTest(base.ServiceBaseTestCase): class EventletServerProcessLauncherTest(base.ServiceBaseTestCase):
def setUp(self): def setUp(self):
super(EventletServerProcessLauncherTest, self).setUp() super().setUp()
self.conf(args=[], default_config_files=[]) self.conf(args=[], default_config_files=[])
self.addCleanup(self.conf.reset) self.addCleanup(self.conf.reset)
self.workers = 3 self.workers = 3
@ -708,5 +708,5 @@ class EventletServerProcessLauncherTest(base.ServiceBaseTestCase):
class EventletServerServiceLauncherTest(EventletServerProcessLauncherTest): class EventletServerServiceLauncherTest(EventletServerProcessLauncherTest):
def setUp(self): def setUp(self):
super(EventletServerServiceLauncherTest, self).setUp() super().setUp()
self.workers = 1 self.workers = 1

View File

@ -33,7 +33,7 @@ class SslutilsTestCase(base.ServiceBaseTestCase):
"""Test cases for sslutils.""" """Test cases for sslutils."""
def setUp(self): def setUp(self):
super(SslutilsTestCase, self).setUp() super().setUp()
self.cert_file_name = os.path.join(SSL_CERT_DIR, 'certificate.crt') self.cert_file_name = os.path.join(SSL_CERT_DIR, 'certificate.crt')
self.key_file_name = os.path.join(SSL_CERT_DIR, 'privatekey.key') self.key_file_name = os.path.join(SSL_CERT_DIR, 'privatekey.key')
self.ca_file_name = os.path.join(SSL_CERT_DIR, 'ca.crt') self.ca_file_name = os.path.join(SSL_CERT_DIR, 'ca.crt')

View File

@ -27,14 +27,14 @@ class SystemdTestCase(test_base.BaseTestCase):
def test__abstractify(self): def test__abstractify(self):
sock_name = '@fake_socket' sock_name = '@fake_socket'
res = systemd._abstractify(sock_name) res = systemd._abstractify(sock_name)
self.assertEqual('\0{0}'.format(sock_name[1:]), res) self.assertEqual('\0{}'.format(sock_name[1:]), res)
@mock.patch.object(os, 'getenv', return_value='@fake_socket') @mock.patch.object(os, 'getenv', return_value='@fake_socket')
def _test__sd_notify(self, getenv_mock, unset_env=False): def _test__sd_notify(self, getenv_mock, unset_env=False):
self.ready = False self.ready = False
self.closed = False self.closed = False
class FakeSocket(object): class FakeSocket:
def __init__(self, family, type): def __init__(self, family, type):
pass pass

View File

@ -29,7 +29,7 @@ from oslo_service import threadgroup
class ThreadGroupTestCase(test_base.BaseTestCase): class ThreadGroupTestCase(test_base.BaseTestCase):
"""Test cases for thread group.""" """Test cases for thread group."""
def setUp(self): def setUp(self):
super(ThreadGroupTestCase, self).setUp() super().setUp()
self.tg = threadgroup.ThreadGroup() self.tg = threadgroup.ThreadGroup()
self.addCleanup(self.tg.stop) self.addCleanup(self.tg.stop)

View File

@ -45,7 +45,7 @@ class WsgiTestCase(base.ServiceBaseTestCase):
"""Base class for WSGI tests.""" """Base class for WSGI tests."""
def setUp(self): def setUp(self):
super(WsgiTestCase, self).setUp() super().setUp()
self.conf(args=[], default_config_files=[]) self.conf(args=[], default_config_files=[])
@ -53,7 +53,7 @@ class TestLoaderNothingExists(WsgiTestCase):
"""Loader tests where os.path.exists always returns False.""" """Loader tests where os.path.exists always returns False."""
def setUp(self): def setUp(self):
super(TestLoaderNothingExists, self).setUp() super().setUp()
mock_patcher = mock.patch.object(os.path, 'exists', mock_patcher = mock.patch.object(os.path, 'exists',
lambda _: False) lambda _: False)
mock_patcher.start() mock_patcher.start()
@ -86,7 +86,7 @@ document_root = /tmp
""" """
def setUp(self): def setUp(self):
super(TestLoaderNormalFilesystem, self).setUp() super().setUp()
self.paste_config = tempfile.NamedTemporaryFile(mode="w+t") self.paste_config = tempfile.NamedTemporaryFile(mode="w+t")
self.paste_config.write(self._paste_config.lstrip()) self.paste_config.write(self._paste_config.lstrip())
self.paste_config.seek(0) self.paste_config.seek(0)
@ -111,14 +111,14 @@ document_root = /tmp
def tearDown(self): def tearDown(self):
self.paste_config.close() self.paste_config.close()
super(TestLoaderNormalFilesystem, self).tearDown() super().tearDown()
class TestWSGIServer(WsgiTestCase): class TestWSGIServer(WsgiTestCase):
"""WSGI server tests.""" """WSGI server tests."""
def setUp(self): def setUp(self):
super(TestWSGIServer, self).setUp() super().setUp()
def test_no_app(self): def test_no_app(self):
server = wsgi.Server(self.conf, "test_app", None) server = wsgi.Server(self.conf, "test_app", None)
@ -287,7 +287,7 @@ class TestWSGIServerWithSSL(WsgiTestCase):
"""WSGI server with SSL tests.""" """WSGI server with SSL tests."""
def setUp(self): def setUp(self):
super(TestWSGIServerWithSSL, self).setUp() super().setUp()
cert_file_name = os.path.join(SSL_CERT_DIR, 'certificate.crt') cert_file_name = os.path.join(SSL_CERT_DIR, 'certificate.crt')
key_file_name = os.path.join(SSL_CERT_DIR, 'privatekey.key') key_file_name = os.path.join(SSL_CERT_DIR, 'privatekey.key')
eventlet.monkey_patch(os=False, thread=False) eventlet.monkey_patch(os=False, thread=False)

View File

@ -35,7 +35,7 @@ def _on_thread_done(_greenthread, group, thread):
group.thread_done(thread) group.thread_done(thread)
class Thread(object): class Thread:
"""Wrapper around a greenthread. """Wrapper around a greenthread.
Holds a reference to the :class:`ThreadGroup`. The Thread will notify Holds a reference to the :class:`ThreadGroup`. The Thread will notify
@ -72,7 +72,7 @@ class Thread(object):
self.thread.cancel(*throw_args) self.thread.cancel(*throw_args)
class ThreadGroup(object): class ThreadGroup:
"""A group of greenthreads and timers. """A group of greenthreads and timers.
The point of the ThreadGroup class is to: The point of the ThreadGroup class is to:

View File

@ -139,7 +139,7 @@ class Server(service.ServiceBase):
try: try:
sock = eventlet.listen(bind_addr, family, backlog=backlog) sock = eventlet.listen(bind_addr, family, backlog=backlog)
except EnvironmentError: except OSError:
LOG.error("Could not bind to %(host)s:%(port)s", LOG.error("Could not bind to %(host)s:%(port)s",
{'host': host, 'port': port}) {'host': host, 'port': port})
raise raise
@ -245,7 +245,7 @@ class Request(webob.Request):
pass pass
class Router(object): class Router:
"""WSGI middleware that maps incoming requests to WSGI apps.""" """WSGI middleware that maps incoming requests to WSGI apps."""
def __init__(self, mapper): def __init__(self, mapper):
@ -305,17 +305,17 @@ class Router(object):
class ConfigNotFound(Exception): class ConfigNotFound(Exception):
def __init__(self, path): def __init__(self, path):
msg = _('Could not find config at %(path)s') % {'path': path} msg = _('Could not find config at %(path)s') % {'path': path}
super(ConfigNotFound, self).__init__(msg) super().__init__(msg)
class PasteAppNotFound(Exception): class PasteAppNotFound(Exception):
def __init__(self, name, path): def __init__(self, name, path):
msg = (_("Could not load paste app '%(name)s' from %(path)s") % msg = (_("Could not load paste app '%(name)s' from %(path)s") %
{'name': name, 'path': path}) {'name': name, 'path': path})
super(PasteAppNotFound, self).__init__(msg) super().__init__(msg)
class Loader(object): class Loader:
"""Used to load WSGI applications from paste configurations.""" """Used to load WSGI applications from paste configurations."""
def __init__(self, conf): def __init__(self, conf):

View File

@ -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");