From 9b1b8a3b6f121b5aec5ba7a8418078631adec310 Mon Sep 17 00:00:00 2001 From: Tom Weininger Date: Mon, 15 Jan 2024 12:53:21 +0100 Subject: [PATCH] pyupgrade changes for Python3.8+ (2) Result of running $ pyupgrade --py38-plus $(git ls-files | grep ".py$") This was inspired by Nova [1] Fixed PEP8 errors introduced by pyupgrade by running: $ autopep8 --select=E127,E128,E501 --max-line-length 79 -r \ --in-place octavia and manual updates. [1]: https://review.opendev.org/c/openstack/nova/+/896986 Change-Id: I4ad020fbedd8106a3a86768c25a0c4dc750ec88a --- octavia/api/app.py | 3 +-- octavia/api/common/pagination.py | 14 +++++++------- octavia/api/common/types.py | 2 +- octavia/api/drivers/amphora_driver/v2/driver.py | 8 ++++---- .../api/drivers/driver_agent/driver_listener.py | 6 +++--- octavia/api/drivers/driver_agent/driver_updater.py | 2 +- octavia/api/drivers/noop_driver/driver.py | 2 +- octavia/api/root_controller.py | 4 ++-- octavia/api/v2/types/amphora.py | 2 +- octavia/api/v2/types/availability_zone_profile.py | 3 +-- octavia/api/v2/types/availability_zones.py | 3 +-- octavia/api/v2/types/flavor_profile.py | 2 +- octavia/api/v2/types/flavors.py | 2 +- octavia/api/v2/types/health_monitor.py | 2 +- octavia/api/v2/types/l7policy.py | 2 +- octavia/api/v2/types/l7rule.py | 2 +- octavia/api/v2/types/listener.py | 6 +++--- octavia/api/v2/types/load_balancer.py | 6 +++--- octavia/api/v2/types/member.py | 4 ++-- octavia/api/v2/types/pool.py | 4 ++-- octavia/api/v2/types/quotas.py | 4 ++-- 21 files changed, 40 insertions(+), 43 deletions(-) diff --git a/octavia/api/app.py b/octavia/api/app.py index 2eb0abb62a..9ab2516ddf 100644 --- a/octavia/api/app.py +++ b/octavia/api/app.py @@ -80,8 +80,7 @@ def _wrap_app(app): audit_map_file=CONF.audit.audit_map_file, ignore_req_list=CONF.audit.ignore_req_list ) - except (EnvironmentError, OSError, - audit_middleware.PycadfAuditApiConfigError) as e: + except (OSError, audit_middleware.PycadfAuditApiConfigError) as e: raise exceptions.InputFileError( file_name=CONF.audit.audit_map_file, reason=e diff --git a/octavia/api/common/pagination.py b/octavia/api/common/pagination.py index 437ca88cb5..110a60ef7a 100644 --- a/octavia/api/common/pagination.py +++ b/octavia/api/common/pagination.py @@ -32,7 +32,7 @@ CONF = cfg.CONF LOG = logging.getLogger(__name__) -class PaginationHelper(object): +class PaginationHelper: """Class helping to interact with pagination functionality Pass this class to `db.repositories` to apply it on query @@ -149,7 +149,7 @@ class PaginationHelper(object): path_url = request.path_url links = [] if model_list: - prev_attr = ["limit={}".format(self.limit)] + prev_attr = [f"limit={self.limit}"] if self.params.get('sort'): prev_attr.append("sort={}".format(self.params.get('sort'))) if self.params.get('sort_key'): @@ -361,7 +361,7 @@ class PaginationHelper(object): attr = sa_sql.expression.case( (model_attr.isnot(None), model_attr), else_=default) - crit_attrs.append((attr == marker_values[j])) + crit_attrs.append(attr == marker_values[j]) model_attr = getattr(model, self.sort_keys[i][0]) default = PaginationHelper._get_default_column_value( @@ -372,14 +372,14 @@ class PaginationHelper(object): this_sort_dir = self.sort_keys[i][1] if this_sort_dir == constants.DESC: if self.page_reverse == "True": - crit_attrs.append((attr > marker_values[i])) + crit_attrs.append(attr > marker_values[i]) else: - crit_attrs.append((attr < marker_values[i])) + crit_attrs.append(attr < marker_values[i]) elif this_sort_dir == constants.ASC: if self.page_reverse == "True": - crit_attrs.append((attr < marker_values[i])) + crit_attrs.append(attr < marker_values[i]) else: - crit_attrs.append((attr > marker_values[i])) + crit_attrs.append(attr > marker_values[i]) else: raise exceptions.InvalidSortDirection( key=this_sort_dir) diff --git a/octavia/api/common/types.py b/octavia/api/common/types.py index ad54e49da8..56ae72fbbf 100644 --- a/octavia/api/common/types.py +++ b/octavia/api/common/types.py @@ -127,7 +127,7 @@ class BaseMeta(wtypes.BaseMeta): get_tenant_id, set_tenant_id) # This will let us know if tenant_id was explicitly set to Unset dct['_unset_tenant'] = False - return super(BaseMeta, mcs).__new__(mcs, name, bases, dct) + return super().__new__(mcs, name, bases, dct) class BaseType(wtypes.Base, metaclass=BaseMeta): diff --git a/octavia/api/drivers/amphora_driver/v2/driver.py b/octavia/api/drivers/amphora_driver/v2/driver.py index 82e2950115..6b867c44ca 100644 --- a/octavia/api/drivers/amphora_driver/v2/driver.py +++ b/octavia/api/drivers/amphora_driver/v2/driver.py @@ -473,9 +473,9 @@ class AmphoraProviderDriver(driver_base.ProviderDriver): except js_exceptions.ValidationError as e: error_object = '' if e.relative_path: - error_object = '{} '.format(e.relative_path[0]) + error_object = f'{e.relative_path[0]} ' raise exceptions.UnsupportedOptionError( - user_fault_string='{0}{1}'.format(error_object, e.message), + user_fault_string=f'{error_object}{e.message}', operator_fault_string=str(e)) except Exception as e: raise exceptions.DriverError( @@ -559,9 +559,9 @@ class AmphoraProviderDriver(driver_base.ProviderDriver): except js_exceptions.ValidationError as e: error_object = '' if e.relative_path: - error_object = '{} '.format(e.relative_path[0]) + error_object = f'{e.relative_path[0]} ' raise exceptions.UnsupportedOptionError( - user_fault_string='{0}{1}'.format(error_object, e.message), + user_fault_string=f'{error_object}{e.message}', operator_fault_string=str(e)) except Exception as e: raise exceptions.DriverError( diff --git a/octavia/api/drivers/driver_agent/driver_listener.py b/octavia/api/drivers/driver_agent/driver_listener.py index 12ffc31a17..d7513b1a86 100644 --- a/octavia/api/drivers/driver_agent/driver_listener.py +++ b/octavia/api/drivers/driver_agent/driver_listener.py @@ -62,7 +62,7 @@ class StatusRequestHandler(socketserver.BaseRequestHandler): # Send the response json_data = jsonutils.dump_as_bytes(response) - len_str = '{}\n'.format(len(json_data)).encode('utf-8') + len_str = f'{len(json_data)}\n'.encode() try: self.request.send(len_str) self.request.sendall(json_data) @@ -86,7 +86,7 @@ class StatsRequestHandler(socketserver.BaseRequestHandler): # Send the response json_data = jsonutils.dump_as_bytes(response) - len_str = '{}\n'.format(len(json_data)).encode('utf-8') + len_str = f'{len(json_data)}\n'.encode() try: self.request.send(len_str) self.request.sendall(json_data) @@ -109,7 +109,7 @@ class GetRequestHandler(socketserver.BaseRequestHandler): # Send the response json_data = jsonutils.dump_as_bytes(response) - len_str = '{}\n'.format(len(json_data)).encode('utf-8') + len_str = f'{len(json_data)}\n'.encode() try: self.request.send(len_str) self.request.sendall(json_data) diff --git a/octavia/api/drivers/driver_agent/driver_updater.py b/octavia/api/drivers/driver_agent/driver_updater.py index 83fba1c588..9f6dab0124 100644 --- a/octavia/api/drivers/driver_agent/driver_updater.py +++ b/octavia/api/drivers/driver_agent/driver_updater.py @@ -29,7 +29,7 @@ from octavia.statistics import stats_base LOG = logging.getLogger(__name__) -class DriverUpdater(object): +class DriverUpdater: def __init__(self, **kwargs): self.repos = repo.Repositories() diff --git a/octavia/api/drivers/noop_driver/driver.py b/octavia/api/drivers/noop_driver/driver.py index 61d34ce244..97180d6167 100644 --- a/octavia/api/drivers/noop_driver/driver.py +++ b/octavia/api/drivers/noop_driver/driver.py @@ -23,7 +23,7 @@ from octavia.api.drivers import utils as driver_utils LOG = logging.getLogger(__name__) -class NoopManager(object): +class NoopManager: def __init__(self): super().__init__() self.driverconfig = {} diff --git a/octavia/api/root_controller.py b/octavia/api/root_controller.py index f83470eaab..393e3a9515 100644 --- a/octavia/api/root_controller.py +++ b/octavia/api/root_controller.py @@ -27,7 +27,7 @@ CONF = cfg.CONF LOG = logging.getLogger(__name__) -class RootController(object): +class RootController: """The controller with which the pecan wsgi app should be created.""" def __init__(self): @@ -65,7 +65,7 @@ class RootController(object): host_url = pecan_request.path_url if not host_url.endswith('/'): - host_url = '{}/'.format(host_url) + host_url = f'{host_url}/' versions = [] self._add_a_version(versions, 'v2.0', 'v2', 'SUPPORTED', diff --git a/octavia/api/v2/types/amphora.py b/octavia/api/v2/types/amphora.py index d414e1046d..140e442105 100644 --- a/octavia/api/v2/types/amphora.py +++ b/octavia/api/v2/types/amphora.py @@ -47,7 +47,7 @@ class AmphoraResponse(BaseAmphoraType): @classmethod def from_data_model(cls, data_model, children=False): - amphorae = super(AmphoraResponse, cls).from_data_model( + amphorae = super().from_data_model( data_model, children=children) return amphorae diff --git a/octavia/api/v2/types/availability_zone_profile.py b/octavia/api/v2/types/availability_zone_profile.py index a423389e60..c7a3dc2ad2 100644 --- a/octavia/api/v2/types/availability_zone_profile.py +++ b/octavia/api/v2/types/availability_zone_profile.py @@ -31,8 +31,7 @@ class AvailabilityZoneProfileResponse(BaseAvailabilityZoneProfileType): @classmethod def from_data_model(cls, data_model, children=False): - availability_zone_profile = super( - AvailabilityZoneProfileResponse, cls).from_data_model( + availability_zone_profile = super().from_data_model( data_model, children=children) return availability_zone_profile diff --git a/octavia/api/v2/types/availability_zones.py b/octavia/api/v2/types/availability_zones.py index c56fe01f90..61e429355c 100644 --- a/octavia/api/v2/types/availability_zones.py +++ b/octavia/api/v2/types/availability_zones.py @@ -31,8 +31,7 @@ class AvailabilityZoneResponse(BaseAvailabilityZoneType): @classmethod def from_data_model(cls, data_model, children=False): - availability_zone = super( - AvailabilityZoneResponse, cls).from_data_model( + availability_zone = super().from_data_model( data_model, children=children) return availability_zone diff --git a/octavia/api/v2/types/flavor_profile.py b/octavia/api/v2/types/flavor_profile.py index c46508b99e..99a682449c 100644 --- a/octavia/api/v2/types/flavor_profile.py +++ b/octavia/api/v2/types/flavor_profile.py @@ -31,7 +31,7 @@ class FlavorProfileResponse(BaseFlavorProfileType): @classmethod def from_data_model(cls, data_model, children=False): - flavorprofile = super(FlavorProfileResponse, cls).from_data_model( + flavorprofile = super().from_data_model( data_model, children=children) return flavorprofile diff --git a/octavia/api/v2/types/flavors.py b/octavia/api/v2/types/flavors.py index 9da9a7ab09..d999c8271e 100644 --- a/octavia/api/v2/types/flavors.py +++ b/octavia/api/v2/types/flavors.py @@ -32,7 +32,7 @@ class FlavorResponse(BaseFlavorType): @classmethod def from_data_model(cls, data_model, children=False): - flavor = super(FlavorResponse, cls).from_data_model( + flavor = super().from_data_model( data_model, children=children) return flavor diff --git a/octavia/api/v2/types/health_monitor.py b/octavia/api/v2/types/health_monitor.py index 92a3f7150d..76723ff6f1 100644 --- a/octavia/api/v2/types/health_monitor.py +++ b/octavia/api/v2/types/health_monitor.py @@ -50,7 +50,7 @@ class HealthMonitorResponse(BaseHealthMonitorType): @classmethod def from_data_model(cls, data_model, children=False): - healthmonitor = super(HealthMonitorResponse, cls).from_data_model( + healthmonitor = super().from_data_model( data_model, children=children) if cls._full_response(): diff --git a/octavia/api/v2/types/l7policy.py b/octavia/api/v2/types/l7policy.py index 4549bd94bc..f7e1be198a 100644 --- a/octavia/api/v2/types/l7policy.py +++ b/octavia/api/v2/types/l7policy.py @@ -48,7 +48,7 @@ class L7PolicyResponse(BaseL7PolicyType): @classmethod def from_data_model(cls, data_model, children=False): - policy = super(L7PolicyResponse, cls).from_data_model( + policy = super().from_data_model( data_model, children=children) if cls._full_response(): diff --git a/octavia/api/v2/types/l7rule.py b/octavia/api/v2/types/l7rule.py index fbdddb7181..11c2015fc8 100644 --- a/octavia/api/v2/types/l7rule.py +++ b/octavia/api/v2/types/l7rule.py @@ -41,7 +41,7 @@ class L7RuleResponse(BaseL7Type): @classmethod def from_data_model(cls, data_model, children=False): - rule = super(L7RuleResponse, cls).from_data_model( + rule = super().from_data_model( data_model, children=children) return rule diff --git a/octavia/api/v2/types/listener.py b/octavia/api/v2/types/listener.py index d13df5e063..81451e48ea 100644 --- a/octavia/api/v2/types/listener.py +++ b/octavia/api/v2/types/listener.py @@ -69,7 +69,7 @@ class ListenerResponse(BaseListenerType): @classmethod def from_data_model(cls, data_model, children=False): - listener = super(ListenerResponse, cls).from_data_model( + listener = super().from_data_model( data_model, children=children) listener.sni_container_refs = [ @@ -274,7 +274,7 @@ class ListenerStatusResponse(BaseListenerType): @classmethod def from_data_model(cls, data_model, children=False): - listener = super(ListenerStatusResponse, cls).from_data_model( + listener = super().from_data_model( data_model, children=children) pool_model = pool.PoolStatusResponse @@ -297,7 +297,7 @@ class ListenerStatisticsResponse(BaseListenerType): @classmethod def from_data_model(cls, data_model, children=False): - result = super(ListenerStatisticsResponse, cls).from_data_model( + result = super().from_data_model( data_model, children=children) return result diff --git a/octavia/api/v2/types/load_balancer.py b/octavia/api/v2/types/load_balancer.py index 27129b66f0..4a1637d235 100644 --- a/octavia/api/v2/types/load_balancer.py +++ b/octavia/api/v2/types/load_balancer.py @@ -69,7 +69,7 @@ class LoadBalancerResponse(BaseLoadBalancerType): @classmethod def from_data_model(cls, data_model, children=False): - result = super(LoadBalancerResponse, cls).from_data_model( + result = super().from_data_model( data_model, children=children) if data_model.vip: result.vip_subnet_id = data_model.vip.subnet_id @@ -169,7 +169,7 @@ class LoadBalancerStatusResponse(BaseLoadBalancerType): @classmethod def from_data_model(cls, data_model, children=False): - result = super(LoadBalancerStatusResponse, cls).from_data_model( + result = super().from_data_model( data_model, children=children) listener_model = listener.ListenerStatusResponse result.listeners = [ @@ -198,7 +198,7 @@ class LoadBalancerStatisticsResponse(BaseLoadBalancerType): @classmethod def from_data_model(cls, data_model, children=False): - result = super(LoadBalancerStatisticsResponse, cls).from_data_model( + result = super().from_data_model( data_model, children=children) return result diff --git a/octavia/api/v2/types/member.py b/octavia/api/v2/types/member.py index 246a892ab1..d12e8e3f76 100644 --- a/octavia/api/v2/types/member.py +++ b/octavia/api/v2/types/member.py @@ -45,7 +45,7 @@ class MemberResponse(BaseMemberType): @classmethod def from_data_model(cls, data_model, children=False): - member = super(MemberResponse, cls).from_data_model( + member = super().from_data_model( data_model, children=children) return member @@ -142,7 +142,7 @@ class MemberStatusResponse(BaseMemberType): @classmethod def from_data_model(cls, data_model, children=False): - member = super(MemberStatusResponse, cls).from_data_model( + member = super().from_data_model( data_model, children=children) if not member.name: diff --git a/octavia/api/v2/types/pool.py b/octavia/api/v2/types/pool.py index cd1148daf7..d83478935d 100644 --- a/octavia/api/v2/types/pool.py +++ b/octavia/api/v2/types/pool.py @@ -96,7 +96,7 @@ class PoolResponse(BasePoolType): @classmethod def from_data_model(cls, data_model, children=False): - pool = super(PoolResponse, cls).from_data_model( + pool = super().from_data_model( data_model, children=children) if data_model.session_persistence: pool.session_persistence = ( @@ -240,7 +240,7 @@ class PoolStatusResponse(BasePoolType): @classmethod def from_data_model(cls, data_model, children=False): - pool = super(PoolStatusResponse, cls).from_data_model( + pool = super().from_data_model( data_model, children=children) member_model = member.MemberStatusResponse diff --git a/octavia/api/v2/types/quotas.py b/octavia/api/v2/types/quotas.py index c898de45b4..eed7234dac 100644 --- a/octavia/api/v2/types/quotas.py +++ b/octavia/api/v2/types/quotas.py @@ -56,7 +56,7 @@ class QuotaResponse(base.BaseType): @classmethod def from_data_model(cls, data_model, children=False): - quotas = super(QuotaResponse, cls).from_data_model( + quotas = super().from_data_model( data_model, children=children) quotas.quota = QuotaBase.from_data_model(data_model) return quotas @@ -83,7 +83,7 @@ class QuotaAllBase(base.BaseType): @classmethod def from_data_model(cls, data_model, children=False): - quotas = super(QuotaAllBase, cls).from_data_model( + quotas = super().from_data_model( data_model, children=children) # For backwards compatibility, remove in T quotas.load_balancer = quotas.loadbalancer