Merge "Fix consider-iterating-dictionary pylint warnings"
This commit is contained in:
commit
4141340c4e
56 files changed
+107
-113
No files matched your search
@@ -75,13 +75,11 @@ disable=
|
||||
unspecified-encoding,
|
||||
unused-private-member,
|
||||
# "C" Coding convention violations
|
||||
consider-iterating-dictionary,
|
||||
invalid-name,
|
||||
missing-docstring,
|
||||
ungrouped-imports,
|
||||
wrong-import-order,
|
||||
consider-using-f-string,
|
||||
consider-using-dict-items,
|
||||
# "R" Refactor recommendations
|
||||
duplicate-code,
|
||||
inconsistent-return-statements,
|
||||
|
||||
@@ -215,7 +215,7 @@ class BaseOVS:
|
||||
@property
|
||||
def capabilities(self):
|
||||
_cfg = self.config
|
||||
return {k: _cfg.get(k, OVS_DEFAULT_CAPS[k]) for k in OVS_DEFAULT_CAPS}
|
||||
return {k: _cfg.get(k, v) for k, v in OVS_DEFAULT_CAPS.items()}
|
||||
|
||||
@property
|
||||
def is_hw_offload_enabled(self):
|
||||
@@ -959,7 +959,7 @@ class OVSBridge(BaseOVS):
|
||||
qos_constants.RULE_TYPE_BANDWIDTH_LIMIT)
|
||||
if not qos_queues:
|
||||
return
|
||||
if QOS_DEFAULT_QUEUE in qos_queues.keys():
|
||||
if QOS_DEFAULT_QUEUE in qos_queues:
|
||||
queue_uuid = qos_queues.pop(QOS_DEFAULT_QUEUE)
|
||||
if qos_queues:
|
||||
self._update_qos(
|
||||
@@ -1087,7 +1087,7 @@ class OVSBridge(BaseOVS):
|
||||
qos_constants.RULE_TYPE_MINIMUM_BANDWIDTH)
|
||||
if not qos_queues:
|
||||
return
|
||||
if queue_num in qos_queues.keys():
|
||||
if queue_num in qos_queues:
|
||||
qos_queues.pop(queue_num)
|
||||
if qos_queues:
|
||||
self._update_qos(
|
||||
|
||||
@@ -128,7 +128,7 @@ class QosAgentDriver(metaclass=abc.ABCMeta):
|
||||
|
||||
def _rule_type_has_ingress_direction(self, rule_type):
|
||||
supported_rule = self.SUPPORTED_RULES[rule_type]
|
||||
if qos_consts.DIRECTION not in supported_rule.keys():
|
||||
if qos_consts.DIRECTION not in supported_rule:
|
||||
return False
|
||||
return (constants.INGRESS_DIRECTION in
|
||||
supported_rule[qos_consts.DIRECTION]['type:values'])
|
||||
|
||||
@@ -416,7 +416,7 @@ class PortForwardingAgentExtension(l3_extension.L3AgentExtension):
|
||||
if ha_port:
|
||||
ri.enable_keepalived()
|
||||
self._sending_port_forwarding_fip_status(ri, fip_status)
|
||||
for fip_id in fip_status.keys():
|
||||
for fip_id in fip_status:
|
||||
self.mapping.clear_by_fip(fip_id, ri.router_id)
|
||||
|
||||
def _get_router_info(self, router_id):
|
||||
|
||||
@@ -714,9 +714,9 @@ class Dnsmasq(DhcpLocalProcess):
|
||||
else:
|
||||
merged.append(fip)
|
||||
|
||||
for subnet_id in by_subnet:
|
||||
for subnet_id, ips in by_subnet.items():
|
||||
addr6_list = ','.join([self._format_address_for_dnsmasq(ip)
|
||||
for ip in by_subnet[subnet_id]])
|
||||
for ip in ips])
|
||||
merged.append(NewFip(subnet_id=subnet_id,
|
||||
ip_address=addr6_list))
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ def convert_to_kilobits(value, base):
|
||||
bits_value = utils.bytes_to_bits(value)
|
||||
return utils.bits_to_kilobits(bits_value, base)
|
||||
unit = value[-1:]
|
||||
if unit not in UNITS.keys():
|
||||
if unit not in UNITS:
|
||||
raise InvalidUnit(unit=unit)
|
||||
val = int(value[:-1])
|
||||
if input_in_bits:
|
||||
|
||||
@@ -131,7 +131,7 @@ class SecurityGroupAgentRpc:
|
||||
device_names = [
|
||||
dev['device'] for dev in all_devices.values()]
|
||||
for device_id in device_ids:
|
||||
if (device_id not in all_devices.keys() and
|
||||
if (device_id not in all_devices and
|
||||
device_id not in device_names):
|
||||
trusted_devices.append(device_id)
|
||||
return trusted_devices
|
||||
|
||||
@@ -371,7 +371,7 @@ class PaginationEmulatedHelper(PaginationHelper):
|
||||
class PaginationNativeHelper(PaginationEmulatedHelper):
|
||||
|
||||
def update_args(self, args):
|
||||
if self.primary_key not in dict(args.get('sorts', [])).keys():
|
||||
if self.primary_key not in dict(args.get('sorts', [])):
|
||||
args.setdefault('sorts', []).append((self.primary_key, True))
|
||||
args.update({'limit': self.limit, 'marker': self.marker,
|
||||
'page_reverse': self.page_reverse})
|
||||
@@ -408,7 +408,7 @@ class SortingEmulatedHelper(SortingHelper):
|
||||
def update_fields(self, original_fields, fields_to_add):
|
||||
if not original_fields:
|
||||
return
|
||||
for key in dict(self.sort_dict).keys():
|
||||
for key in dict(self.sort_dict):
|
||||
if key not in original_fields:
|
||||
original_fields.append(key)
|
||||
fields_to_add.append(key)
|
||||
|
||||
@@ -219,7 +219,7 @@ class ExtensionMiddleware(base.ConfigurableMiddleware):
|
||||
"""Return a dict of ActionExtensionController-s by collection."""
|
||||
action_controllers = {}
|
||||
for action in ext_mgr.get_actions():
|
||||
if action.collection not in action_controllers.keys():
|
||||
if action.collection not in action_controllers:
|
||||
controller = ActionExtensionController(application)
|
||||
mapper.connect("/%s/:(id)/action.:(format)" %
|
||||
action.collection,
|
||||
@@ -238,7 +238,7 @@ class ExtensionMiddleware(base.ConfigurableMiddleware):
|
||||
"""Returns a dict of RequestExtensionController-s by collection."""
|
||||
request_ext_controllers = {}
|
||||
for req_ext in ext_mgr.get_request_extensions():
|
||||
if req_ext.key not in request_ext_controllers.keys():
|
||||
if req_ext.key not in request_ext_controllers:
|
||||
controller = RequestExtensionController(application)
|
||||
mapper.connect(req_ext.url_route + '.:(format)',
|
||||
action='process',
|
||||
|
||||
@@ -164,7 +164,7 @@ class Controller:
|
||||
to see them.
|
||||
"""
|
||||
attributes_to_exclude = []
|
||||
for attr_name in data.keys():
|
||||
for attr_name in data:
|
||||
# NOTE(haleyb): If no attribute data was found and this
|
||||
# attribute name is 'project_id', we must also check if there
|
||||
# is data for 'tenant_id'. This can happen for some of the
|
||||
|
||||
@@ -176,7 +176,7 @@ class MetadataProxyHandlerBaseSocketServer(
|
||||
resp_headers['content-encoding'] = 'gzip'
|
||||
elif (
|
||||
resp_content_magic not in CONTENT_ENCODERS.values() and
|
||||
resp_body_encoding in CONTENT_ENCODERS.keys()
|
||||
resp_body_encoding in CONTENT_ENCODERS
|
||||
):
|
||||
# content-encoding is set but content is not actually encoded,
|
||||
# this is normal for how `requests` behaves, it decodes gzip
|
||||
@@ -195,7 +195,7 @@ class MetadataProxyHandlerBaseSocketServer(
|
||||
# The content of the response is decoded depending on the
|
||||
# "Context-Enconding" header, if present. The operation is limited to
|
||||
# ("gzip", "deflate"), as is in the ``webob.response.Response`` class.
|
||||
if _res.content_encoding in CONTENT_ENCODERS.keys():
|
||||
if _res.content_encoding in CONTENT_ENCODERS:
|
||||
_res.decode_content()
|
||||
|
||||
# NOTE(ralonsoh): there should be a better way to format the HTTP
|
||||
|
||||
@@ -88,8 +88,8 @@ class ExtraGatewaysDbOnlyMixin(l3_gwmode_db.L3_NAT_dbonly_mixin):
|
||||
}
|
||||
router = payload.latest_state
|
||||
router_db = payload.metadata['router_db']
|
||||
for attr in attr_defaults.keys():
|
||||
value = router.get(attr, attr_defaults[attr])
|
||||
for attr, default_val in attr_defaults.items():
|
||||
value = router.get(attr, default_val)
|
||||
if value is not None:
|
||||
self.set_extra_attr_value(router_db, attr, value)
|
||||
|
||||
@@ -366,9 +366,9 @@ class ExtraGatewaysDbOnlyMixin(l3_gwmode_db.L3_NAT_dbonly_mixin):
|
||||
compat_gw_port_info = part_matches.pop(router_db['gw_port_id'], None)
|
||||
|
||||
# Actually remove extra gateways first.
|
||||
for extra_gw_port_id in part_matches.keys():
|
||||
for extra_gw_port_id, gw_info in part_matches.items():
|
||||
self._delete_extra_gw_port(context, router_id, extra_gw_port_id)
|
||||
removed_gateways.append(part_matches[extra_gw_port_id])
|
||||
removed_gateways.append(gw_info)
|
||||
|
||||
# If the matched gateway port ID includes the compatibility one, handle
|
||||
# its removal in a compatible way.
|
||||
@@ -550,8 +550,8 @@ class ExtraGatewaysDbOnlyMixin(l3_gwmode_db.L3_NAT_dbonly_mixin):
|
||||
format_gateway_info(rp.port)
|
||||
for rp in router_db.attached_ports
|
||||
if (rp.port.device_owner == constants.DEVICE_OWNER_ROUTER_GW and
|
||||
rp.port.id not in found_gw_port_ids.keys() and
|
||||
rp.port.id not in part_matches.keys() and
|
||||
rp.port.id not in found_gw_port_ids and
|
||||
rp.port.id not in part_matches and
|
||||
rp.port.id != router_db.gw_port_id)
|
||||
]
|
||||
self._remove_external_gateways(context, router_id, ports_to_remove, {})
|
||||
|
||||
@@ -53,8 +53,8 @@ class ServiceTypeManager:
|
||||
if svc_type in self.config))
|
||||
return list(
|
||||
chain.from_iterable(
|
||||
self.config[p].get_service_providers(filters, fields)
|
||||
for p in self.config)
|
||||
plugin.get_service_providers(filters, fields)
|
||||
for plugin in self.config.values())
|
||||
)
|
||||
|
||||
def get_default_service_provider(self, context, service_type):
|
||||
|
||||
@@ -36,14 +36,13 @@ class Flavors(api_extensions.APIExtensionDescriptor):
|
||||
apidef.RESOURCE_ATTRIBUTE_MAP,
|
||||
constants.FLAVORS)
|
||||
plugin = directory.get_plugin(constants.FLAVORS)
|
||||
for collection_name in apidef.SUB_RESOURCE_ATTRIBUTE_MAP:
|
||||
for collection_name, collection in (
|
||||
apidef.SUB_RESOURCE_ATTRIBUTE_MAP.items()):
|
||||
# Special handling needed for sub-resources with 'y' ending
|
||||
# (e.g. proxies -> proxy)
|
||||
resource_name = collection_name[:-1]
|
||||
parent = apidef.SUB_RESOURCE_ATTRIBUTE_MAP[collection_name].get(
|
||||
'parent')
|
||||
params = apidef.SUB_RESOURCE_ATTRIBUTE_MAP[collection_name].get(
|
||||
'parameters')
|
||||
parent = collection.get('parent')
|
||||
params = collection.get('parameters')
|
||||
|
||||
controller = base.create_resource(collection_name, resource_name,
|
||||
plugin, params,
|
||||
|
||||
@@ -47,12 +47,11 @@ class Local_ip(api_extensions.APIExtensionDescriptor):
|
||||
attr_map=params)
|
||||
resources = [ext]
|
||||
|
||||
for collection_name in local_ip_apidef.SUB_RESOURCE_ATTRIBUTE_MAP:
|
||||
for collection_name, collection in (
|
||||
local_ip_apidef.SUB_RESOURCE_ATTRIBUTE_MAP.items()):
|
||||
resource_name = local_ip_apidef.LOCAL_IP_ASSOCIATION
|
||||
parent = local_ip_apidef.SUB_RESOURCE_ATTRIBUTE_MAP[
|
||||
collection_name].get('parent')
|
||||
params = local_ip_apidef.SUB_RESOURCE_ATTRIBUTE_MAP[
|
||||
collection_name].get('parameters')
|
||||
parent = collection.get('parent')
|
||||
params = collection.get('parameters')
|
||||
|
||||
controller = base.create_resource(collection_name, resource_name,
|
||||
plugin, params,
|
||||
|
||||
@@ -55,12 +55,11 @@ class Qos(api_extensions.APIExtensionDescriptor):
|
||||
allow_bulk=True)
|
||||
|
||||
plugin = directory.get_plugin(constants.QOS)
|
||||
for collection_name in apidef.SUB_RESOURCE_ATTRIBUTE_MAP:
|
||||
for collection_name, collection in (
|
||||
apidef.SUB_RESOURCE_ATTRIBUTE_MAP.items()):
|
||||
resource_name = collection_name[:-1]
|
||||
parent = apidef.SUB_RESOURCE_ATTRIBUTE_MAP[
|
||||
collection_name].get('parent')
|
||||
params = apidef.SUB_RESOURCE_ATTRIBUTE_MAP[collection_name].get(
|
||||
'parameters')
|
||||
parent = collection.get('parent')
|
||||
params = collection.get('parameters')
|
||||
|
||||
controller = base.create_resource(collection_name, resource_name,
|
||||
plugin, params,
|
||||
|
||||
@@ -63,7 +63,7 @@ class QuotaSetsController(wsgi.Controller):
|
||||
self._update_extended_attributes = True
|
||||
|
||||
def _update_attributes(self):
|
||||
for quota_resource in resource_registry.get_all_resources().keys():
|
||||
for quota_resource in resource_registry.get_all_resources():
|
||||
attr_dict = EXTENDED_ATTRIBUTES_2_0[RESOURCE_COLLECTION]
|
||||
attr_dict[quota_resource] = {
|
||||
'allow_post': False,
|
||||
|
||||
@@ -80,8 +80,8 @@ class PortForwarding(base.NeutronDbObject):
|
||||
def _new_instance(self, **kwargs):
|
||||
fields_parameters = {f: getattr(self, f)
|
||||
for f in self.fields if hasattr(self, f)}
|
||||
sanitized_kwargs = {k: kwargs[k]
|
||||
for k in kwargs if k in self.fields}
|
||||
sanitized_kwargs = {k: v
|
||||
for k, v in kwargs.items() if k in self.fields}
|
||||
fields_parameters.update(sanitized_kwargs)
|
||||
return PortForwarding(**fields_parameters)
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ class QuotaController(utils.NeutronPecanController):
|
||||
|
||||
# Ensure limits for all registered resources are returned
|
||||
attr_dict = attributes.RESOURCES[self.collection]
|
||||
for quota_resource in resource_registry.get_all_resources().keys():
|
||||
for quota_resource in resource_registry.get_all_resources():
|
||||
attr_dict[quota_resource] = {
|
||||
'allow_post': False,
|
||||
'allow_put': True,
|
||||
|
||||
@@ -567,7 +567,7 @@ class SriovNicAgentConfigParser:
|
||||
"""
|
||||
dev_net_set = set(itertools.chain.from_iterable(
|
||||
self.device_mappings.values()))
|
||||
for dev_name in self.exclude_devices.keys():
|
||||
for dev_name in self.exclude_devices:
|
||||
if dev_name not in dev_net_set:
|
||||
raise ValueError(_(
|
||||
"Invalid exclude_devices: "
|
||||
|
||||
@@ -1563,8 +1563,7 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin,
|
||||
ovs_bridges.remove(integ_br)
|
||||
if self.enable_tunneling:
|
||||
ovs_bridges.remove(tun_br)
|
||||
br_names = [self.phys_brs[physical_network].br_name for
|
||||
physical_network in self.phys_brs]
|
||||
br_names = [brs.br_name for brs in self.phys_brs.values()]
|
||||
ovs_bridges.difference_update(br_names)
|
||||
# Filter list of bridges to those that have external
|
||||
# bridge-id's configured
|
||||
|
||||
@@ -653,7 +653,7 @@ class OvsdbNbOvnIdl(nb_impl_idl.OvnNbApiIdlImpl, Backend):
|
||||
# then try to schedule on all gateways with physnets connected,
|
||||
# and filter required physnet.
|
||||
available_chassis = {
|
||||
c for c in all_gw_chassis or chassis_with_physnets.keys()
|
||||
c for c in all_gw_chassis or chassis_with_physnets
|
||||
if not utils.is_gateway_chassis_invalid(
|
||||
c, all_gw_chassis, physnet, chassis_with_physnets,
|
||||
az_hints, chassis_with_azs)}
|
||||
|
||||
@@ -1042,7 +1042,7 @@ class OVNClient:
|
||||
ls = self._nb_idl.lookup(
|
||||
'Logical_Switch', utils.ovn_name(port['network_id']))
|
||||
for lb in ls.load_balancer:
|
||||
for ext_id in lb.external_ids.keys():
|
||||
for ext_id in lb.external_ids:
|
||||
if ext_id.startswith(ovn_const.LB_EXT_IDS_POOL_PREFIX):
|
||||
members = lb.external_ids[ext_id]
|
||||
if not members:
|
||||
@@ -1083,7 +1083,7 @@ class OVNClient:
|
||||
continue
|
||||
|
||||
# Find out IP addresses and subnets of configured members.
|
||||
for ext_id in lb.external_ids.keys():
|
||||
for ext_id in lb.external_ids:
|
||||
if not ext_id.startswith(ovn_const.LB_EXT_IDS_POOL_PREFIX):
|
||||
continue
|
||||
members = lb.external_ids[ext_id]
|
||||
|
||||
@@ -516,17 +516,17 @@ class OvnNbSynchronizer(db_sync_base.BaseOvnDbSynchronizer):
|
||||
fip_dict[protocol] = fip_dict_proto
|
||||
if fip_id not in db_mapped_pfs:
|
||||
db_mapped_pfs[fip_id] = fip_dict
|
||||
for fip_id in db_mapped_pfs:
|
||||
for fip_id, db_pfs_fip_id in db_mapped_pfs.items():
|
||||
ovn_pfs_fip_id = ovn_pfs.get(fip_id, {})
|
||||
# check for cases when ovn has lbs for protocols that are not in
|
||||
# neutron db
|
||||
if len(db_mapped_pfs[fip_id]) != len(ovn_pfs_fip_id):
|
||||
if len(db_pfs_fip_id) != len(ovn_pfs_fip_id):
|
||||
to_add_or_update.add(fip_id)
|
||||
continue
|
||||
# check that vips in each protocol are an exact match
|
||||
for protocol in db_mapped_pfs[fip_id]:
|
||||
for protocol in db_pfs_fip_id:
|
||||
ovn_fip_dict_proto = ovn_pfs_fip_id.get(protocol)
|
||||
if db_mapped_pfs[fip_id][protocol] != ovn_fip_dict_proto:
|
||||
if db_pfs_fip_id[protocol] != ovn_fip_dict_proto:
|
||||
to_add_or_update.add(fip_id)
|
||||
|
||||
# remove pf entries that exist in ovn lb but have no fip in
|
||||
@@ -1127,7 +1127,7 @@ class OvnNbSynchronizer(db_sync_base.BaseOvnDbSynchronizer):
|
||||
self.core_plugin.delete_port(ctx, port['id'])
|
||||
db_ports.pop(port['id'], None)
|
||||
port = metadata_ports[0]
|
||||
if port['id'] in db_ports.keys():
|
||||
if port['id'] in db_ports:
|
||||
LOG.warning('Metadata port %s for network %s found in '
|
||||
'Neutron but not in OVN NB DB',
|
||||
port['id'], net['id'])
|
||||
|
||||
@@ -1416,7 +1416,7 @@ class Ml2Plugin(db_base_plugin_v2.NeutronDbPluginV2,
|
||||
net_id: driver_context.NetworkContext(
|
||||
self, context, nets_by_netid[net_id],
|
||||
segments=segments_by_netid[net_id])
|
||||
for net_id in nets_by_netid.keys()
|
||||
for net_id in nets_by_netid
|
||||
}
|
||||
return netctxs_by_netid
|
||||
|
||||
|
||||
+2
-2
@@ -149,8 +149,8 @@ def _build_subattr_match_rule(attr_name, attr, action, target):
|
||||
# typing for API attributes
|
||||
# Expect a dict as type descriptor
|
||||
validate = attr['validate']
|
||||
key = [k for k in validate.keys() if (k.startswith('type:dict') or
|
||||
k.startswith('type:list_of_dict'))]
|
||||
key = [k for k in validate if (k.startswith('type:dict') or
|
||||
k.startswith('type:list_of_dict'))]
|
||||
if not key:
|
||||
LOG.warning("Unable to find data type descriptor for attribute %s",
|
||||
attr_name)
|
||||
|
||||
@@ -81,7 +81,7 @@ class QuotaEngine:
|
||||
|
||||
requested_resources = set(deltas.keys())
|
||||
all_resources = resource_registry.get_all_resources()
|
||||
managed_resources = {res for res in all_resources.keys()
|
||||
managed_resources = {res for res in all_resources
|
||||
if res in requested_resources}
|
||||
# Make sure we accounted for all of them...
|
||||
unknown_resources = requested_resources - managed_resources
|
||||
|
||||
@@ -116,10 +116,10 @@ class tracked_resources:
|
||||
@functools.wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
registry = ResourceRegistry.get_instance()
|
||||
for resource_name in self._tracked_resources:
|
||||
for resource_name, t_resource in self._tracked_resources.items():
|
||||
registry.set_tracked_resource(
|
||||
resource_name,
|
||||
self._tracked_resources[resource_name],
|
||||
t_resource,
|
||||
self._override)
|
||||
return f(*args, **kwargs)
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ def get_rpc_method(resource_type, rpc_method_key):
|
||||
raise NotImplementedError()
|
||||
|
||||
for rpc_method in RPC_RESOURCES_METHOD_MAP[resource_type]:
|
||||
if rpc_method_key in rpc_method.keys():
|
||||
if rpc_method_key in rpc_method:
|
||||
return list(rpc_method.values())[0]
|
||||
|
||||
raise NotImplementedError()
|
||||
|
||||
@@ -339,7 +339,7 @@ class MeteringAgent(MeteringPluginRpc, manager.Manager):
|
||||
for router in routers:
|
||||
labels = router[constants.METERING_LABEL_KEY]
|
||||
for label in labels:
|
||||
if label['id'] in self.metering_labels.keys():
|
||||
if label['id'] in self.metering_labels:
|
||||
del self.metering_labels[label['id']]
|
||||
|
||||
return self._invoke_driver(context, routers,
|
||||
|
||||
@@ -89,7 +89,7 @@ class PlacementReportPlugin(service_base.ServicePluginBase):
|
||||
hypervisors = {
|
||||
device: agent['host']
|
||||
for device
|
||||
in configurations['resource_provider_bandwidths'].keys()
|
||||
in configurations['resource_provider_bandwidths']
|
||||
}
|
||||
|
||||
log_msg = (
|
||||
|
||||
@@ -676,7 +676,7 @@ class PortForwardingPlugin(fip_pf.PortForwardingPluginBase):
|
||||
def _validate_filter_for_port_forwarding(self, request_filter):
|
||||
if not request_filter:
|
||||
return
|
||||
for filter_member_key in request_filter.keys():
|
||||
for filter_member_key in request_filter:
|
||||
if filter_member_key in pf.FIELDS_NOT_SUPPORT_FILTER:
|
||||
raise pf_exc.PortForwardingNotSupportFilterField(
|
||||
filter=filter_member_key)
|
||||
|
||||
@@ -268,7 +268,7 @@ class Host(fixtures.Fixture):
|
||||
str(self.env_desc.network_range[-2]))).address)
|
||||
|
||||
def get_bridge(self):
|
||||
if "ovs" in self.agents.keys():
|
||||
if "ovs" in self.agents:
|
||||
return self.ovs_agent.br_int
|
||||
|
||||
def disconnect(self):
|
||||
|
||||
@@ -771,7 +771,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase):
|
||||
router.ns_name,
|
||||
ip_version=constants.IP_VERSION_4, )
|
||||
|
||||
actual_routes = [{key: route[key] for key in expected_route.keys()}
|
||||
actual_routes = [{key: route[key] for key in expected_route}
|
||||
for route in updated_route]
|
||||
self.assertIn(expected_route, actual_routes)
|
||||
|
||||
@@ -779,7 +779,7 @@ class L3AgentTestFramework(base.BaseSudoTestCase):
|
||||
updated_route = ip_lib.list_ip_routes(
|
||||
router.ns_name,
|
||||
ip_version=constants.IP_VERSION_4)
|
||||
routes_actual = [{key: route[key] for key in expected_route.keys()}
|
||||
routes_actual = [{key: route[key] for key in expected_route}
|
||||
for route in updated_route]
|
||||
for entry in routes_actual:
|
||||
if entry['via']:
|
||||
|
||||
@@ -227,7 +227,7 @@ class TestDvrRouter(DvrRouterTestFramework, framework.L3AgentTestFramework):
|
||||
snat_bound_fip=True, enable_gw=False)
|
||||
|
||||
def _check_routes(self, expected_routes, actual_routes):
|
||||
actual_routes = [{key: route[key] for key in expected_routes[0].keys()}
|
||||
actual_routes = [{key: route[key] for key in expected_routes[0]}
|
||||
for route in actual_routes]
|
||||
self.assertEqual(expected_routes, actual_routes)
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ class IpLibTestFramework(functional_base.BaseSudoTestCase):
|
||||
class IpLibTestCase(IpLibTestFramework):
|
||||
|
||||
def _check_routes(self, expected_routes, actual_routes):
|
||||
actual_routes = [{key: route[key] for key in expected_routes[0].keys()}
|
||||
actual_routes = [{key: route[key] for key in expected_routes[0]}
|
||||
for route in actual_routes]
|
||||
self.assertEqual(expected_routes, actual_routes)
|
||||
|
||||
|
||||
@@ -125,12 +125,11 @@ class FakeExtension(api_extensions.ExtensionDescriptor):
|
||||
collection_name, controller, attr_map=params)
|
||||
resources.append(resource)
|
||||
|
||||
for collection_name in self.SUB_RESOURCE_ATTRIBUTE_MAP:
|
||||
for collection_name, coll_data in (
|
||||
self.SUB_RESOURCE_ATTRIBUTE_MAP.items()):
|
||||
resource_name = collection_name[:-1]
|
||||
parent = self.SUB_RESOURCE_ATTRIBUTE_MAP[collection_name].get(
|
||||
'parent')
|
||||
params = self.SUB_RESOURCE_ATTRIBUTE_MAP[collection_name].get(
|
||||
'parameters')
|
||||
parent = coll_data.get('parent')
|
||||
params = coll_data.get('parameters')
|
||||
|
||||
controller = base.create_resource(collection_name, resource_name,
|
||||
fake_plugin, params,
|
||||
|
||||
+4
-4
@@ -962,15 +962,15 @@ class TestOvnNbSync(base.TestOVNFunctionalBase):
|
||||
external_ids=external_ids,
|
||||
options={'foo': 'bar'}))
|
||||
|
||||
for port_id in self.lport_dhcpv4_disabled:
|
||||
for port_id, opts in self.lport_dhcpv4_disabled.items():
|
||||
txn.add(self.nb_api.set_lswitch_port(
|
||||
port_id, if_exists=True,
|
||||
dhcpv4_options=[self.lport_dhcpv4_disabled[port_id]]))
|
||||
dhcpv4_options=[opts]))
|
||||
|
||||
for port_id in self.lport_dhcpv6_disabled:
|
||||
for port_id, opts in self.lport_dhcpv6_disabled.items():
|
||||
txn.add(self.nb_api.set_lswitch_port(
|
||||
port_id, if_exists=True,
|
||||
dhcpv6_options=[self.lport_dhcpv6_disabled[port_id]]))
|
||||
dhcpv6_options=[opts]))
|
||||
|
||||
# Delete the first DNS record and clear the second row records
|
||||
i = 0
|
||||
|
||||
@@ -532,8 +532,8 @@ class RouteTestCase(functional_base.BaseSudoTestCase):
|
||||
|
||||
for mp in rta_multipath:
|
||||
mp['gateway'] = linux_utils.get_attr(mp, 'RTA_GATEWAY')
|
||||
for key in to_check:
|
||||
if to_check[key] != mp[key]:
|
||||
for key, expected in to_check.items():
|
||||
if expected != mp[key]:
|
||||
break
|
||||
else:
|
||||
break
|
||||
|
||||
+4
-2
@@ -104,8 +104,10 @@ class OVSDBHandlerTestCase(base.OVSAgentTestFramework):
|
||||
'removed': [],
|
||||
'modified': []
|
||||
}
|
||||
for event_type in filtered_events:
|
||||
for dev in events[event_type]:
|
||||
for event_type, event_devs in events.items():
|
||||
if event_type not in filtered_events:
|
||||
continue
|
||||
for dev in event_devs:
|
||||
iface_id = agent.int_br.portid_from_external_ids(
|
||||
dev.get('external_ids', []))
|
||||
is_for_this_test = (
|
||||
|
||||
@@ -275,7 +275,7 @@ class ConntrackHelperMappingTestCase(base.BaseTestCase):
|
||||
self.assertEqual(
|
||||
new_conntrack_helper1,
|
||||
managed_cths[self.conntrack_helper1.id])
|
||||
for router_id in self.mapping._router_conntrack_helper_mapping.keys():
|
||||
for router_id in self.mapping._router_conntrack_helper_mapping:
|
||||
self.assertIn(router_id, [self.router1, self.router2])
|
||||
self.assertEqual(
|
||||
len([self.router1, self.router2]),
|
||||
|
||||
@@ -320,10 +320,10 @@ class ResourceTestCase(base.BaseTestCase):
|
||||
resource = webtest.TestApp(
|
||||
wsgi_resource.Resource(controller,
|
||||
action_status=action_status))
|
||||
for action in action_status:
|
||||
for action, status in action_status.items():
|
||||
environ = {'wsgiorg.routing_args': (None, {'action': action})}
|
||||
res = resource.get('', extra_environ=environ)
|
||||
self.assertEqual(action_status[action], res.status_int)
|
||||
self.assertEqual(status, res.status_int)
|
||||
|
||||
def _test_error_log_level(self, expected_webob_exc, expect_log_info=False,
|
||||
use_fault_map=True, exc_raised=None):
|
||||
|
||||
@@ -127,7 +127,7 @@ class MeteringPluginDbTestCase(
|
||||
|
||||
resource_prefix_map = {
|
||||
k.replace('_', '-'): "/metering"
|
||||
for k in metering_apidef.RESOURCE_ATTRIBUTE_MAP.keys()
|
||||
for k in metering_apidef.RESOURCE_ATTRIBUTE_MAP
|
||||
}
|
||||
|
||||
def setUp(self, plugin=None):
|
||||
|
||||
@@ -190,7 +190,7 @@ class TestDbBasePluginIpam(test_db_base.NeutronDbPluginV2TestCase):
|
||||
mocks['ipam']._ipam_deallocate_ips(mock.ANY, mocks['driver'],
|
||||
mock.ANY, ips)
|
||||
|
||||
get_calls = [mock.call(data[ip][1]) for ip in data]
|
||||
get_calls = [mock.call(ip_data[1]) for ip_data in data.values()]
|
||||
mocks['driver'].get_subnet.assert_has_calls(get_calls, any_order=True)
|
||||
|
||||
ip_calls = [mock.call(ip) for ip in data]
|
||||
@@ -299,7 +299,7 @@ class TestDbBasePluginIpam(test_db_base.NeutronDbPluginV2TestCase):
|
||||
|
||||
mocks['ipam']._ipam_allocate_ips(
|
||||
mock.ANY, mocks['driver'], mocks['port'], ips)
|
||||
get_calls = [mock.call([data[ip][1]]) for ip in data]
|
||||
get_calls = [mock.call([ip_data[1]]) for ip_data in data.values()]
|
||||
mocks['driver'].get_allocator.assert_has_calls(
|
||||
get_calls, any_order=True)
|
||||
|
||||
|
||||
@@ -533,9 +533,8 @@ class ExtGwModeSepTestCase(ExtGwModeIntTestCase):
|
||||
def setUp(self, plugin=None):
|
||||
# Store l3 resource attribute map as it will be updated
|
||||
self._l3_attribute_map_bk = {}
|
||||
for item in l3_apidef.RESOURCE_ATTRIBUTE_MAP:
|
||||
self._l3_attribute_map_bk[item] = (
|
||||
l3_apidef.RESOURCE_ATTRIBUTE_MAP[item].copy())
|
||||
for item, attrs in l3_apidef.RESOURCE_ATTRIBUTE_MAP.items():
|
||||
self._l3_attribute_map_bk[item] = attrs.copy()
|
||||
plugin = plugin or (
|
||||
'neutron.tests.unit.extensions.test_l3.TestNoL3NatPlugin')
|
||||
# the L3 service plugin
|
||||
|
||||
@@ -199,8 +199,8 @@ class TestDefaultSecurityGroupRules(
|
||||
def test_create_default_security_group_rule_with_unmasked_prefix(self):
|
||||
addr = {'10.1.2.3': {'mask': '32', 'ethertype': 'IPv4'},
|
||||
'fe80::2677:3ff:fe7d:4c': {'mask': '128', 'ethertype': 'IPv6'}}
|
||||
for remote_ip_prefix in addr:
|
||||
ethertype = addr[remote_ip_prefix]['ethertype']
|
||||
for remote_ip_prefix, addr_info in addr.items():
|
||||
ethertype = addr_info['ethertype']
|
||||
rule = self._build_default_security_group_rule(
|
||||
'ingress',
|
||||
const.PROTO_NAME_TCP,
|
||||
@@ -213,7 +213,7 @@ class TestDefaultSecurityGroupRules(
|
||||
res_sg = self.deserialize(self.fmt, res)
|
||||
prefix = res_sg['default_security_group_rule']['remote_ip_prefix']
|
||||
self.assertEqual('{}/{}'.format(
|
||||
remote_ip_prefix, addr[remote_ip_prefix]['mask']), prefix)
|
||||
remote_ip_prefix, addr_info['mask']), prefix)
|
||||
|
||||
def test_create_default_security_group_rule_tcp_protocol_as_number(self):
|
||||
protocol = const.PROTO_NUM_TCP # TCP
|
||||
|
||||
@@ -658,10 +658,10 @@ class TestSecurityGroups(SecurityGroupDBTestCase):
|
||||
description = 'my webservers'
|
||||
addr = {'10.1.2.3': {'mask': '32', 'ethertype': 'IPv4'},
|
||||
'fe80::2677:3ff:fe7d:4c': {'mask': '128', 'ethertype': 'IPv6'}}
|
||||
for ip in addr:
|
||||
for ip, ip_info in addr.items():
|
||||
with self.security_group(name, description) as sg:
|
||||
sg_id = sg['security_group']['id']
|
||||
ethertype = addr[ip]['ethertype']
|
||||
ethertype = ip_info['ethertype']
|
||||
remote_ip_prefix = ip
|
||||
rule = self._build_security_group_rule(
|
||||
sg_id,
|
||||
@@ -675,7 +675,7 @@ class TestSecurityGroups(SecurityGroupDBTestCase):
|
||||
self.assertEqual(webob.exc.HTTPCreated.code, res.status_int)
|
||||
res_sg = self.deserialize(self.fmt, res)
|
||||
prefix = res_sg['security_group_rule']['remote_ip_prefix']
|
||||
self.assertEqual('{}/{}'.format(ip, addr[ip]['mask']), prefix)
|
||||
self.assertEqual('{}/{}'.format(ip, ip_info['mask']), prefix)
|
||||
|
||||
def test_create_security_group_rule_tcp_protocol_as_number(self):
|
||||
name = 'webservers'
|
||||
|
||||
@@ -51,8 +51,8 @@ class SubnetOnboardTestsBase:
|
||||
pool_data = {'project_id': project_id, 'shared': shared, 'name': name,
|
||||
'address_scope_id': address_scope_id,
|
||||
'prefixes': prefixes, 'is_default': is_default_pool}
|
||||
for key in kwargs:
|
||||
pool_data[key] = kwargs[key]
|
||||
for key, value in kwargs.items():
|
||||
pool_data[key] = value
|
||||
|
||||
with db_api.CONTEXT_WRITER.using(self.context):
|
||||
yield self.driver.create_subnetpool(self.context,
|
||||
|
||||
@@ -56,8 +56,8 @@ class SubnetpoolPrefixOpsTestBase:
|
||||
pool_data = {'project_id': project_id, 'shared': shared, 'name': name,
|
||||
'address_scope_id': address_scope_id,
|
||||
'prefixes': prefixes, 'is_default': is_default_pool}
|
||||
for key in kwargs:
|
||||
pool_data[key] = kwargs[key]
|
||||
for key, value in kwargs.items():
|
||||
pool_data[key] = value
|
||||
|
||||
with db_api.CONTEXT_WRITER.using(self.context):
|
||||
yield self.driver.create_subnetpool(self.context,
|
||||
|
||||
@@ -295,7 +295,7 @@ class FakeResource(dict):
|
||||
setattr(self, name, method)
|
||||
|
||||
def __repr__(self):
|
||||
reprkeys = sorted(k for k in self.__dict__.keys() if k[0] != '_' and
|
||||
reprkeys = sorted(k for k in self.__dict__ if k[0] != '_' and
|
||||
k != 'manager')
|
||||
info = ", ".join(f"{k}={getattr(self, k)}" for k in reprkeys)
|
||||
return f"<{self.__class__.__name__} {info}>"
|
||||
|
||||
@@ -581,7 +581,7 @@ def get_value(generator, version):
|
||||
def remove_timestamps_from_fields(obj_fields, cls_fields):
|
||||
obj_fields_result = obj_fields.copy()
|
||||
for ts_field in TIMESTAMP_FIELDS:
|
||||
if ts_field in cls_fields.keys() and cls_fields[ts_field].nullable:
|
||||
if ts_field in cls_fields and cls_fields[ts_field].nullable:
|
||||
obj_fields_result.pop(ts_field)
|
||||
return obj_fields_result
|
||||
|
||||
|
||||
@@ -410,7 +410,7 @@ class NetworkSegmentRangeDbObjectTestCase(obj_test_base.BaseDbObjectTestCase,
|
||||
def test_delete_expired_default_network_segment_ranges(self):
|
||||
start_time = n_utils.datetime_to_ts(timeutils.utcnow())
|
||||
num_ranges = 5
|
||||
for network_type in network_segment_range.models_map.keys():
|
||||
for network_type in network_segment_range.models_map:
|
||||
for idx in range(num_ranges):
|
||||
try:
|
||||
obj = self._create_network_segment_range(
|
||||
@@ -427,7 +427,7 @@ class NetworkSegmentRangeDbObjectTestCase(obj_test_base.BaseDbObjectTestCase,
|
||||
|
||||
def test_new_default(self):
|
||||
start_time = n_utils.datetime_to_ts(timeutils.utcnow())
|
||||
for network_type in network_segment_range.models_map.keys():
|
||||
for network_type in network_segment_range.models_map:
|
||||
physical_network = ('foo' if network_type == constants.TYPE_VLAN
|
||||
else None)
|
||||
ranges = network_segment_range.NetworkSegmentRange.get_objects(
|
||||
|
||||
@@ -48,7 +48,7 @@ class LoggerMechanismDriver(api.MechanismDriver):
|
||||
added_keys = set(curr_item.keys()) - set(og_item.keys())
|
||||
output = f"{method_name}:\n"
|
||||
|
||||
for k in curr_item.keys():
|
||||
for k in curr_item:
|
||||
if k in og_item and og_item[k] != curr_item[k]:
|
||||
output += "key[{}], {} -> {}\n".format(
|
||||
k, og_item[k], curr_item[k])
|
||||
|
||||
@@ -1435,8 +1435,8 @@ class TestOvnSbSyncML2(test_mech_driver.OVNMechanismDriverTestCase):
|
||||
len(hostname_with_physnets),
|
||||
ovn_driver.update_segment_host_mapping.call_count)
|
||||
update_segment_host_mapping_calls = [mock.call(
|
||||
host, hostname_with_physnets[host])
|
||||
for host in hostname_with_physnets]
|
||||
host, physnets)
|
||||
for host, physnets in hostname_with_physnets.items()]
|
||||
ovn_driver.update_segment_host_mapping.assert_has_calls(
|
||||
update_segment_host_mapping_calls, any_order=True)
|
||||
|
||||
|
||||
@@ -4780,7 +4780,7 @@ class TestOVNMechanismDriverDHCPOptions(OVNMechanismDriverTestCase):
|
||||
'v6_snet_id_1': {'options': {}},
|
||||
'v6_snet_id_3': {'options': {
|
||||
ovn_const.DHCPV6_STATELESS_OPT: 'true'}}}
|
||||
return [fake_rows[row] for row in fake_rows if row in subnets]
|
||||
return [v for k, v in fake_rows.items() if k in subnets]
|
||||
|
||||
self.mech_driver.nb_ovn.get_subnets_dhcp_options.side_effect = fake
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ class TestMeteringPlugin(test_db_base_plugin_v2.NeutronDbPluginV2TestCase,
|
||||
|
||||
resource_prefix_map = {
|
||||
k.replace('_', '-'): "/metering"
|
||||
for k in metering_apidef.RESOURCE_ATTRIBUTE_MAP.keys()
|
||||
for k in metering_apidef.RESOURCE_ATTRIBUTE_MAP
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
@@ -561,7 +561,7 @@ class TestMeteringPluginL3AgentScheduler(
|
||||
|
||||
resource_prefix_map = {
|
||||
k.replace('_', '-'): "/metering"
|
||||
for k in metering_apidef.RESOURCE_ATTRIBUTE_MAP.keys()
|
||||
for k in metering_apidef.RESOURCE_ATTRIBUTE_MAP
|
||||
}
|
||||
|
||||
def setUp(self, plugin_str=None, service_plugins=None, scheduler=None):
|
||||
|
||||
Reference in new issue
Block a user