pyupgrade changes for Python3.9+

As discussed at the Epoxy PTG meeting, run an automated
upgrade tool to make code python 3.9+ compliant.

Result of running:

$ pyupgrade --py39-plus $(git ls-files | grep ".py$")

Fixed PEP8 errors introduced by pyupgrade by running:

$ autopep8 --select=E127,E128,E501 --max-line-length 79 -r \
  --in-place neutron_taas

Also did manual updates as necessary to fix other errors
and warnings after above commands.

Inspired by Octavia and Nova [0].

[0] https://review.opendev.org/c/openstack/nova/+/896986

Change-Id: I14155656d7e233cdd0f8a30c34158465e8de325a
This commit is contained in:
elajkat 2024-10-30 10:37:58 +01:00 committed by Lajos Katona
parent 98a6569530
commit b8c65a9ec2
21 changed files with 47 additions and 51 deletions

View File

@ -32,7 +32,6 @@ disable=
global-statement, global-statement,
keyword-arg-before-vararg, keyword-arg-before-vararg,
literal-comparison, literal-comparison,
non-parent-init-called,
not-callable, not-callable,
protected-access, protected-access,
raise-missing-from, raise-missing-from,
@ -80,7 +79,6 @@ disable=
# new for python3 version of pylint # new for python3 version of pylint
consider-using-set-comprehension, consider-using-set-comprehension,
unnecessary-pass, unnecessary-pass,
useless-object-inheritance
[BASIC] [BASIC]
# Variable names can be 1 to 31 characters long, with lowercase and underscores # Variable names can be 1 to 31 characters long, with lowercase and underscores

View File

@ -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
@ -42,8 +41,8 @@ source_suffix = '.rst'
master_doc = 'index' master_doc = 'index'
# General information about the project. # General information about the project.
project = u'tap-as-a-service' project = 'tap-as-a-service'
copyright = u'2013, OpenStack Foundation' copyright = '2013, OpenStack Foundation'
# If true, '()' will be appended to :func: etc. cross-reference text. # If true, '()' will be appended to :func: etc. cross-reference text.
add_function_parentheses = True add_function_parentheses = True
@ -72,8 +71,8 @@ htmlhelp_basename = '%sdoc' % project
latex_documents = [ latex_documents = [
('index', ('index',
'doc-tap-as-a-service.tex', 'doc-tap-as-a-service.tex',
u'Tap as a Service Documentation', 'Tap as a Service Documentation',
u'OpenStack Foundation', 'manual'), 'OpenStack Foundation', 'manual'),
] ]
# Example configuration for intersphinx: refer to the Python standard library. # Example configuration for intersphinx: refer to the Python standard library.

View File

@ -34,7 +34,7 @@ OPTS = [
cfg.CONF.register_opts(OPTS) cfg.CONF.register_opts(OPTS)
class TaasAgentDriver(object, metaclass=abc.ABCMeta): class TaasAgentDriver(metaclass=abc.ABCMeta):
"""Defines stable abstract interface for TaaS Agent Driver.""" """Defines stable abstract interface for TaaS Agent Driver."""
@abc.abstractmethod @abc.abstractmethod

View File

@ -17,7 +17,7 @@ from neutron_lib import rpc as n_rpc
import oslo_messaging as messaging import oslo_messaging as messaging
class TaasPluginApiMixin(object): class TaasPluginApiMixin:
# Currently there are no Calls the Agent makes towards the Plugin. # Currently there are no Calls the Agent makes towards the Plugin.
@ -28,7 +28,7 @@ class TaasPluginApiMixin(object):
super().__init__() super().__init__()
class TaasAgentRpcCallbackMixin(object): class TaasAgentRpcCallbackMixin:
"""Mixin for Taas agent Implementations.""" """Mixin for Taas agent Implementations."""
def __init__(self): def __init__(self):

View File

@ -401,7 +401,7 @@ class OvsTaasDriver(taas_base.TaasAgentDriver):
) )
else: else:
actions = "output:%s,mod_vlan_vid:%s,output:%s" % ( actions = "output:{},mod_vlan_vid:{},output:{}".format(
str(ovs_port_id), str(taas_id), str(patch_int_tap_id) str(ovs_port_id), str(taas_id), str(patch_int_tap_id)
) )
if network_type == 'vlan': if network_type == 'vlan':

View File

@ -22,7 +22,7 @@
# - A value may be affiliated with multiple keys. # - A value may be affiliated with multiple keys.
# - A value may be affiliated with a key multiple times. # - A value may be affiliated with a key multiple times.
# #
class key_value_mgr(object): class key_value_mgr:
# #
# Initializes internal state for specified # keys # Initializes internal state for specified # keys
# #

View File

@ -30,7 +30,7 @@ import re
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
class SriovNicUtils(object): class SriovNicUtils:
# #
# Initializes internal state for specified # keys # Initializes internal state for specified # keys
# #
@ -169,7 +169,7 @@ class SriovNicUtils(object):
with open(addr_file, encoding="utf-8") as f: with open(addr_file, encoding="utf-8") as f:
mac = next(f).strip() mac = next(f).strip()
return mac return mac
except (IOError, StopIteration) as e: except (OSError, StopIteration) as e:
LOG.warning("Could not find the expected sysfs file for " LOG.warning("Could not find the expected sysfs file for "
"determining the MAC address of the PCI device " "determining the MAC address of the PCI device "
"%(addr)s. May not be a NIC. Error: %(e)s", "%(addr)s. May not be a NIC. Error: %(e)s",

View File

@ -15,7 +15,7 @@
import abc import abc
class TaasBaseDriver(object, metaclass=abc.ABCMeta): class TaasBaseDriver(metaclass=abc.ABCMeta):
def __init__(self, service_plugin): def __init__(self, service_plugin):
self.service_plugin = service_plugin self.service_plugin = service_plugin

View File

@ -19,7 +19,7 @@ from oslo_log import log
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
class ServiceDriverContext(object): class ServiceDriverContext:
"""ServiceDriverContext context base class""" """ServiceDriverContext context base class"""
def __init__(self, service_plugin, plugin_context): def __init__(self, service_plugin, plugin_context):
self._plugin = service_plugin self._plugin = service_plugin

View File

@ -21,7 +21,7 @@ import oslo_messaging as messaging
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
class TaasAgentApi(object): class TaasAgentApi:
"""RPC calls to agent APIs""" """RPC calls to agent APIs"""
def __init__(self, topic, host): def __init__(self, topic, host):

View File

@ -36,7 +36,7 @@ from oslo_utils import excutils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
class TaasCallbacks(object): class TaasCallbacks:
def __init__(self, rpc_driver, plugin): def __init__(self, rpc_driver, plugin):
super().__init__() super().__init__()

View File

@ -33,7 +33,7 @@ class TaaSDbTestCase(testlib_api.SqlTestCase):
"""Unit test for TaaS DB support.""" """Unit test for TaaS DB support."""
def setUp(self): def setUp(self):
super(TaaSDbTestCase, self).setUp() super().setUp()
self.ctx = context.get_admin_context() self.ctx = context.get_admin_context()
self.mixin = taas_db.Taas_db_Mixin() self.mixin = taas_db.Taas_db_Mixin()
self.plugin = importutils.import_object(DB_PLUGIN_KLAAS) self.plugin = importutils.import_object(DB_PLUGIN_KLAAS)

View File

@ -38,12 +38,12 @@ class TaasExtensionTestCase(test_extensions_base.ExtensionTestCase):
def setUp(self): def setUp(self):
conf_common.register_core_common_config_opts() conf_common.register_core_common_config_opts()
extensions.append_api_extensions_path(taas_extensions.__path__) extensions.append_api_extensions_path(taas_extensions.__path__)
super(TaasExtensionTestCase, self).setUp() super().setUp()
plural_mappings = {'tap_service': 'tap_services', plural_mappings = {'tap_service': 'tap_services',
'tap_flow': 'tap_flows'} 'tap_flow': 'tap_flows'}
self.setup_extension( self.setup_extension(
'%s.%s' % (taas_extensions.taas.TaasPluginBase.__module__, '{}.{}'.format(taas_extensions.taas.TaasPluginBase.__module__,
taas_extensions.taas.TaasPluginBase.__name__), taas_extensions.taas.TaasPluginBase.__name__),
taas_api.ALIAS, taas_api.ALIAS,
taas_extensions.taas.Taas, taas_extensions.taas.Taas,
'taas', 'taas',

View File

@ -34,14 +34,13 @@ _get_path = test_api_v2._get_path
class VlanFilterExtensionTestCase(test_taas_ext.TaasExtensionTestCase): class VlanFilterExtensionTestCase(test_taas_ext.TaasExtensionTestCase):
def setUp(self): def setUp(self):
super(VlanFilterExtensionTestCase, self).setUp() super().setUp()
attr_map = taas_api_def.RESOURCE_ATTRIBUTE_MAP attr_map = taas_api_def.RESOURCE_ATTRIBUTE_MAP
attr_map['tap_flows'].update( attr_map['tap_flows'].update(
vlan_filter_ext.RESOURCE_ATTRIBUTE_MAP['tap_flows']) vlan_filter_ext.RESOURCE_ATTRIBUTE_MAP['tap_flows'])
def _get_expected_tap_flow(self, data): def _get_expected_tap_flow(self, data):
ret = super(VlanFilterExtensionTestCase, ret = super()._get_expected_tap_flow(data)
self)._get_expected_tap_flow(data)
ret['tap_flow'].update( ret['tap_flow'].update(
vlan_filter=data['tap_flow'].get('vlan_filter', None)) vlan_filter=data['tap_flow'].get('vlan_filter', None))
return ret return ret

View File

@ -39,7 +39,7 @@ FAKE_TAP_FLOW = {'port': FAKE_TAP_SERVICE['port'],
class TestSriovNicTaas(base.TaasTestCase): class TestSriovNicTaas(base.TaasTestCase):
def setUp(self): def setUp(self):
super(TestSriovNicTaas, self).setUp() super().setUp()
@mock.patch.object(sriov_nic_taas, 'sriov_utils') @mock.patch.object(sriov_nic_taas, 'sriov_utils')
def test_create_tap_service(self, mock_sriov_utils): def test_create_tap_service(self, mock_sriov_utils):

View File

@ -36,7 +36,7 @@ FAKE_SRIOV_PORT = {
class TestSriovNicUtils(base.TaasTestCase): class TestSriovNicUtils(base.TaasTestCase):
def setUp(self): def setUp(self):
super(TestSriovNicUtils, self).setUp() super().setUp()
def test_get_sysfs_netdev_path_with_pf_interface(self): def test_get_sysfs_netdev_path_with_pf_interface(self):
self.assertEqual( self.assertEqual(

View File

@ -40,7 +40,7 @@ class DummyError(Exception):
class TestTaasPlugin(testlib_api.SqlTestCase): class TestTaasPlugin(testlib_api.SqlTestCase):
def setUp(self): def setUp(self):
super(TestTaasPlugin, self).setUp() super().setUp()
mock.patch.object(n_rpc, 'Connection', spec=object).start() mock.patch.object(n_rpc, 'Connection', spec=object).start()
mock.patch.object(taas_agent_api, mock.patch.object(taas_agent_api,
'TaasAgentApi', spec=object).start() 'TaasAgentApi', spec=object).start()
@ -162,8 +162,8 @@ class TestTaasPlugin(testlib_api.SqlTestCase):
self._context, ts_id_1) self._context, ts_id_1)
tap_id_assoc_2 = self._plugin.create_tap_id_association( tap_id_assoc_2 = self._plugin.create_tap_id_association(
self._context, ts_id_2) self._context, ts_id_2)
self.assertEqual(set([1, 2]), set([tap_id_assoc_1['taas_id'], self.assertEqual({1, 2}, {tap_id_assoc_1['taas_id'],
tap_id_assoc_2['taas_id']])) tap_id_assoc_2['taas_id']})
with testtools.ExpectedException(taas_exc.TapServiceLimitReached): with testtools.ExpectedException(taas_exc.TapServiceLimitReached):
self._plugin.create_tap_id_association( self._plugin.create_tap_id_association(
self._context, self._context,
@ -177,8 +177,8 @@ class TestTaasPlugin(testlib_api.SqlTestCase):
"dummyHost") "dummyHost")
tap_id_assoc_3 = self._plugin.create_tap_id_association( tap_id_assoc_3 = self._plugin.create_tap_id_association(
self._context, ts_id_3) self._context, ts_id_3)
self.assertEqual(set([1, 2]), set([tap_id_assoc_3['taas_id'], self.assertEqual({1, 2}, {tap_id_assoc_3['taas_id'],
tap_id_assoc_2['taas_id']])) tap_id_assoc_2['taas_id']})
def test_create_tap_service_wrong_tenant_id(self): def test_create_tap_service_wrong_tenant_id(self):
self._port_details['tenant_id'] = 'other-tenant' self._port_details['tenant_id'] = 'other-tenant'

View File

@ -17,7 +17,7 @@ import copy
from oslo_utils import uuidutils from oslo_utils import uuidutils
class FakeTapService(object): class FakeTapService:
@staticmethod @staticmethod
def create_tap_service(attrs=None): def create_tap_service(attrs=None):
@ -48,7 +48,7 @@ class FakeTapService(object):
return tap_services return tap_services
class FakeTapFlow(object): class FakeTapFlow:
@staticmethod @staticmethod
def create_tap_flow(attrs=None): def create_tap_flow(attrs=None):

View File

@ -54,7 +54,7 @@ class TestCreateTapFlow(test_fakes.TestNeutronClientOSCV2):
) )
def setUp(self): def setUp(self):
super(TestCreateTapFlow, self).setUp() super().setUp()
self.cmd = osc_tap_flow.CreateTapFlow(self.app, self.namespace) self.cmd = osc_tap_flow.CreateTapFlow(self.app, self.namespace)
def test_create_tap_flow(self): def test_create_tap_flow(self):
@ -117,7 +117,7 @@ class TestCreateTapFlow(test_fakes.TestNeutronClientOSCV2):
class TestListTapFlow(test_fakes.TestNeutronClientOSCV2): class TestListTapFlow(test_fakes.TestNeutronClientOSCV2):
def setUp(self): def setUp(self):
super(TestListTapFlow, self).setUp() super().setUp()
self.cmd = osc_tap_flow.ListTapFlow(self.app, self.namespace) self.cmd = osc_tap_flow.ListTapFlow(self.app, self.namespace)
def test_list_tap_flows(self): def test_list_tap_flows(self):
@ -149,7 +149,7 @@ class TestListTapFlow(test_fakes.TestNeutronClientOSCV2):
class TestDeleteTapFlow(test_fakes.TestNeutronClientOSCV2): class TestDeleteTapFlow(test_fakes.TestNeutronClientOSCV2):
def setUp(self): def setUp(self):
super(TestDeleteTapFlow, self).setUp() super().setUp()
self.app.client_manager.network = mock.Mock() self.app.client_manager.network = mock.Mock()
self.app.client_manager.network.find_tap_flow = mock.Mock( self.app.client_manager.network.find_tap_flow = mock.Mock(
side_effect=lambda name_or_id, ignore_missing: side_effect=lambda name_or_id, ignore_missing:
@ -194,7 +194,7 @@ class TestShowTapFlow(test_fakes.TestNeutronClientOSCV2):
) )
def setUp(self): def setUp(self):
super(TestShowTapFlow, self).setUp() super().setUp()
self.app.client_manager.network = mock.Mock() self.app.client_manager.network = mock.Mock()
self.app.client_manager.network.find_tap_flow = mock.Mock( self.app.client_manager.network.find_tap_flow = mock.Mock(
side_effect=lambda name_or_id, ignore_missing: side_effect=lambda name_or_id, ignore_missing:
@ -246,7 +246,7 @@ class TestUpdateTapFlow(test_fakes.TestNeutronClientOSCV2):
) )
def setUp(self): def setUp(self):
super(TestUpdateTapFlow, self).setUp() super().setUp()
self.cmd = osc_tap_flow.UpdateTapFlow(self.app, self.namespace) self.cmd = osc_tap_flow.UpdateTapFlow(self.app, self.namespace)
self.app.client_manager.network = mock.Mock() self.app.client_manager.network = mock.Mock()
self.app.client_manager.network.find_tap_flow = mock.Mock( self.app.client_manager.network.find_tap_flow = mock.Mock(

View File

@ -51,7 +51,7 @@ class TestCreateTapService(test_fakes.TestNeutronClientOSCV2):
) )
def setUp(self): def setUp(self):
super(TestCreateTapService, self).setUp() super().setUp()
self.cmd = osc_tap_service.CreateTapService(self.app, self.namespace) self.cmd = osc_tap_service.CreateTapService(self.app, self.namespace)
def test_create_tap_service(self): def test_create_tap_service(self):
@ -95,7 +95,7 @@ class TestCreateTapService(test_fakes.TestNeutronClientOSCV2):
class TestListTapService(test_fakes.TestNeutronClientOSCV2): class TestListTapService(test_fakes.TestNeutronClientOSCV2):
def setUp(self): def setUp(self):
super(TestListTapService, self).setUp() super().setUp()
self.cmd = osc_tap_service.ListTapService(self.app, self.namespace) self.cmd = osc_tap_service.ListTapService(self.app, self.namespace)
def test_list_tap_service(self): def test_list_tap_service(self):
@ -125,7 +125,7 @@ class TestListTapService(test_fakes.TestNeutronClientOSCV2):
class TestDeleteTapService(test_fakes.TestNeutronClientOSCV2): class TestDeleteTapService(test_fakes.TestNeutronClientOSCV2):
def setUp(self): def setUp(self):
super(TestDeleteTapService, self).setUp() super().setUp()
self.app.client_manager.network = mock.Mock() self.app.client_manager.network = mock.Mock()
self.app.client_manager.network.find_tap_service = mock.Mock( self.app.client_manager.network.find_tap_service = mock.Mock(
side_effect=lambda name_or_id, ignore_missing: side_effect=lambda name_or_id, ignore_missing:
@ -164,7 +164,7 @@ class TestShowTapService(test_fakes.TestNeutronClientOSCV2):
) )
def setUp(self): def setUp(self):
super(TestShowTapService, self).setUp() super().setUp()
self.app.client_manager.network = mock.Mock() self.app.client_manager.network = mock.Mock()
self.app.client_manager.network.find_tap_service = mock.Mock( self.app.client_manager.network.find_tap_service = mock.Mock(
side_effect=lambda name_or_id, ignore_missing: side_effect=lambda name_or_id, ignore_missing:
@ -212,7 +212,7 @@ class TestUpdateTapService(test_fakes.TestNeutronClientOSCV2):
) )
def setUp(self): def setUp(self):
super(TestUpdateTapService, self).setUp() super().setUp()
self.cmd = osc_tap_service.UpdateTapService(self.app, self.namespace) self.cmd = osc_tap_service.UpdateTapService(self.app, self.namespace)
self.app.client_manager.network = mock.Mock() self.app.client_manager.network = mock.Mock()
self.app.client_manager.network.find_tap_service = mock.Mock( self.app.client_manager.network.find_tap_service = mock.Mock(

View File

@ -59,9 +59,9 @@ source_suffix = '.rst'
master_doc = 'index' master_doc = 'index'
# General information about the project. # General information about the project.
project = u'tap-as-a-service' project = 'tap-as-a-service'
copyright = u'2017, Tap-as-a-service developers' copyright = '2017, Tap-as-a-service developers'
author = u'Tap-as-a-service developers' author = 'Tap-as-a-service developers'
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the
@ -247,8 +247,8 @@ latex_elements = {
# (source start file, target name, title, # (source start file, target name, title,
# author, documentclass [howto, manual, or own class]). # author, documentclass [howto, manual, or own class]).
latex_documents = [ latex_documents = [
(master_doc, 'tap-as-a-service.tex', u'tap-as-a-service Documentation', (master_doc, 'tap-as-a-service.tex', 'tap-as-a-service Documentation',
u'OpenStack', 'manual'), 'OpenStack', 'manual'),
] ]
# The name of an image file (relative to this directory) to place at the top of # The name of an image file (relative to this directory) to place at the top of
@ -277,7 +277,7 @@ latex_documents = [
# One entry per manual page. List of tuples # One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [ man_pages = [
(master_doc, 'tap-as-a-service', u'tap-as-a-service Documentation', (master_doc, 'tap-as-a-service', 'tap-as-a-service Documentation',
[author], 1) [author], 1)
] ]
@ -291,7 +291,7 @@ man_pages = [
# (source start file, target name, title, author, # (source start file, target name, title, author,
# dir menu entry, description, category) # dir menu entry, description, category)
texinfo_documents = [ texinfo_documents = [
(master_doc, 'tap-as-a-service', u'tap-as-a-service Documentation', (master_doc, 'tap-as-a-service', 'tap-as-a-service Documentation',
author, 'tap-as-a-service', 'One line description of project.', author, 'tap-as-a-service', 'One line description of project.',
'Miscellaneous'), 'Miscellaneous'),
] ]