elajkat b8c65a9ec2 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
2024-10-30 10:49:41 +00:00

84 lines
2.6 KiB
Python

# All Rights Reserved 2020
#
# 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
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import copy
from oslo_utils import uuidutils
class FakeTapService:
@staticmethod
def create_tap_service(attrs=None):
"""Create a fake tap service."""
attrs = attrs or {}
tap_service_attrs = {
'id': uuidutils.generate_uuid(),
'tenant_id': uuidutils.generate_uuid(),
'name': 'test_tap_service' + uuidutils.generate_uuid(),
'status': 'ACTIVE',
}
tap_service_attrs.update(attrs)
return copy.deepcopy(tap_service_attrs)
@staticmethod
def create_tap_services(attrs=None, count=1):
"""Create multiple fake tap services."""
tap_services = []
for i in range(0, count):
if attrs is None:
attrs = {'id': 'fake_id%d' % i}
elif getattr(attrs, 'id', None) is None:
attrs['id'] = 'fake_id%d' % i
tap_services.append(FakeTapService.create_tap_service(
attrs=attrs))
return tap_services
class FakeTapFlow:
@staticmethod
def create_tap_flow(attrs=None):
"""Create a fake tap service."""
attrs = attrs or {}
tap_flow_attrs = {
'id': uuidutils.generate_uuid(),
'tenant_id': uuidutils.generate_uuid(),
'name': 'test_tap_flow' + uuidutils.generate_uuid(),
'status': 'ACTIVE',
'direction': 'BOTH',
}
tap_flow_attrs.update(attrs)
return copy.deepcopy(tap_flow_attrs)
@staticmethod
def create_tap_flows(attrs=None, count=1):
"""Create multiple fake tap flows."""
tap_flows = []
for i in range(0, count):
if attrs is None:
attrs = {
'id': 'fake_id%d' % i,
'source_port': uuidutils.generate_uuid(),
'tap_service_id': uuidutils.generate_uuid()
}
elif getattr(attrs, 'id', None) is None:
attrs['id'] = 'fake_id%d' % i
tap_flows.append(FakeTapFlow.create_tap_flow(attrs=attrs))
return tap_flows