diff --git a/neutron/agent/dhcp/agent.py b/neutron/agent/dhcp/agent.py index faa27fae030..790a60dee5a 100644 --- a/neutron/agent/dhcp/agent.py +++ b/neutron/agent/dhcp/agent.py @@ -161,9 +161,9 @@ class DhcpAgent(manager.Manager): # allocation pool or a port is deleted to free up an IP, this # will automatically be retried on the notification self.schedule_resync(e, network.id) - if (isinstance(e, oslo_messaging.RemoteError) - and e.exc_type == 'NetworkNotFound' - or isinstance(e, exceptions.NetworkNotFound)): + if (isinstance(e, oslo_messaging.RemoteError) and + e.exc_type == 'NetworkNotFound' or + isinstance(e, exceptions.NetworkNotFound)): LOG.debug("Network %s has been deleted.", network.id) else: LOG.exception('Unable to %(action)s dhcp for %(net_id)s.', diff --git a/neutron/agent/l3/agent.py b/neutron/agent/l3/agent.py index 946a1c6b864..d9d28a30b8d 100644 --- a/neutron/agent/l3/agent.py +++ b/neutron/agent/l3/agent.py @@ -335,8 +335,8 @@ class L3NATAgent(ha.AgentMixin, # side of it, typically because it's landing on a node that needs # to provision a router namespace because of a DVR service port # (e.g. DHCP). - if (self.conf.agent_mode == lib_const.L3_AGENT_MODE_DVR_SNAT - and router.get(lib_const.HA_INTERFACE_KEY) is not None): + if (self.conf.agent_mode == lib_const.L3_AGENT_MODE_DVR_SNAT and + router.get(lib_const.HA_INTERFACE_KEY) is not None): kwargs['state_change_callback'] = self.enqueue_state_change return dvr_edge_ha_router.DvrEdgeHaRouter(*args, **kwargs) diff --git a/neutron/agent/l3/dvr_edge_ha_router.py b/neutron/agent/l3/dvr_edge_ha_router.py index d231c6010eb..15d7a8dbaef 100644 --- a/neutron/agent/l3/dvr_edge_ha_router.py +++ b/neutron/agent/l3/dvr_edge_ha_router.py @@ -115,8 +115,7 @@ class DvrEdgeHaRouter(dvr_edge_router.DvrEdgeRouter, self._plug_external_gateway(ex_gw_port, interface_name, ns_name) def _is_this_snat_host(self): - return (self.agent_conf.agent_mode - == constants.L3_AGENT_MODE_DVR_SNAT) + return self.agent_conf.agent_mode == constants.L3_AGENT_MODE_DVR_SNAT def _dvr_internal_network_removed(self, port): super(DvrEdgeHaRouter, self)._dvr_internal_network_removed(port) diff --git a/neutron/agent/l3/router_info.py b/neutron/agent/l3/router_info.py index 372045b7105..555bd09f46b 100644 --- a/neutron/agent/l3/router_info.py +++ b/neutron/agent/l3/router_info.py @@ -772,8 +772,8 @@ class RouterInfo(object): def _delete_stale_external_devices(self, interface_name): existing_devices = self._get_existing_devices() stale_devs = [dev for dev in existing_devices - if dev.startswith(EXTERNAL_DEV_PREFIX) - and dev != interface_name] + if dev.startswith(EXTERNAL_DEV_PREFIX) and + dev != interface_name] for stale_dev in stale_devs: LOG.debug('Deleting stale external router device: %s', stale_dev) self.agent.pd.remove_gw_interface(self.router['id']) @@ -1053,8 +1053,8 @@ class RouterInfo(object): iptables = iptables_manager.get_tables(ip_version) iptables['mangle'].empty_chain('scope') iptables['filter'].empty_chain('scope') - dont_block_external = (ip_version == lib_constants.IP_VERSION_4 - and self._snat_enabled and external_port) + dont_block_external = (ip_version == lib_constants.IP_VERSION_4 and + self._snat_enabled and external_port) for device_name, mark in scopemarks.items(): # Add address scope iptables rule iptables['mangle'].add_rule( diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py index 0060d660de1..aa0fd91d177 100644 --- a/neutron/agent/linux/dhcp.py +++ b/neutron/agent/linux/dhcp.py @@ -1155,9 +1155,9 @@ class DeviceManager(object): for subnet in network.subnets: skip_subnet = ( - subnet.ip_version != ip_version - or not subnet.enable_dhcp - or subnet.gateway_ip is None) + subnet.ip_version != ip_version or + not subnet.enable_dhcp or + subnet.gateway_ip is None) if skip_subnet: continue diff --git a/neutron/agent/linux/ip_lib.py b/neutron/agent/linux/ip_lib.py index 691b2c236a7..937dcb5caff 100644 --- a/neutron/agent/linux/ip_lib.py +++ b/neutron/agent/linux/ip_lib.py @@ -274,8 +274,8 @@ class IPDevice(SubProcessBase): self.neigh = IpNeighCommand(self) def __eq__(self, other): - return (other is not None and self.name == other.name - and self.namespace == other.namespace) + return (other is not None and self.name == other.name and + self.namespace == other.namespace) def __str__(self): return self.name diff --git a/neutron/agent/metadata/agent.py b/neutron/agent/metadata/agent.py index 6d4954c86b1..ef447559509 100644 --- a/neutron/agent/metadata/agent.py +++ b/neutron/agent/metadata/agent.py @@ -280,8 +280,8 @@ class UnixDomainMetadataProxy(object): mode = self.conf.metadata_proxy_socket_mode if mode == config.DEDUCE_MODE: user = self.conf.metadata_proxy_user - if (not user or user == '0' or user == 'root' - or agent_utils.is_effective_user(user)): + if (not user or user == '0' or user == 'root' or + agent_utils.is_effective_user(user)): # user is agent effective user or root => USER_MODE mode = config.USER_MODE else: diff --git a/neutron/agent/ovsdb/impl_vsctl.py b/neutron/agent/ovsdb/impl_vsctl.py index 514f37769af..07bd212f90f 100644 --- a/neutron/agent/ovsdb/impl_vsctl.py +++ b/neutron/agent/ovsdb/impl_vsctl.py @@ -333,8 +333,8 @@ def _set_colval_args(*col_values): if isinstance(val, collections.Mapping): args += ["%s:%s%s%s" % ( col, k, op, ovsdb.py_to_val(v)) for k, v in val.items()] - elif (isinstance(val, collections.Sequence) - and not isinstance(val, six.string_types)): + elif (isinstance(val, collections.Sequence) and + not isinstance(val, six.string_types)): if len(val) == 0: args.append("%s%s%s" % (col, op, "[]")) else: diff --git a/neutron/api/extensions.py b/neutron/api/extensions.py index 8111b142612..a57033b8c0a 100644 --- a/neutron/api/extensions.py +++ b/neutron/api/extensions.py @@ -138,8 +138,8 @@ class ExtensionMiddleware(base.ConfigurableMiddleware): def __init__(self, application, ext_mgr=None): - self.ext_mgr = (ext_mgr - or ExtensionManager(get_extensions_path())) + self.ext_mgr = (ext_mgr or + ExtensionManager(get_extensions_path())) mapper = routes.Mapper() # extended resources diff --git a/neutron/api/rpc/handlers/dhcp_rpc.py b/neutron/api/rpc/handlers/dhcp_rpc.py index 20f918622b9..14269ace0e2 100644 --- a/neutron/api/rpc/handlers/dhcp_rpc.py +++ b/neutron/api/rpc/handlers/dhcp_rpc.py @@ -282,8 +282,9 @@ class DhcpRpcCallback(object): plugin = directory.get_plugin() try: old_port = plugin.get_port(context, port['id']) - if (old_port['device_id'] != constants.DEVICE_ID_RESERVED_DHCP_PORT - and old_port['device_id'] != + if (old_port['device_id'] != + constants.DEVICE_ID_RESERVED_DHCP_PORT and + old_port['device_id'] != utils.get_dhcp_agent_device_id(port['port']['network_id'], host)): raise n_exc.DhcpPortInUse(port_id=port['id']) diff --git a/neutron/common/ipv6_utils.py b/neutron/common/ipv6_utils.py index 5b13654346f..bb4f1708dc5 100644 --- a/neutron/common/ipv6_utils.py +++ b/neutron/common/ipv6_utils.py @@ -52,8 +52,8 @@ def is_enabled_and_bind_by_default(): def is_auto_address_subnet(subnet): """Check if subnet is an auto address subnet.""" modes = [const.IPV6_SLAAC, const.DHCPV6_STATELESS] - return (subnet['ipv6_address_mode'] in modes - or subnet['ipv6_ra_mode'] in modes) + return (subnet['ipv6_address_mode'] in modes or + subnet['ipv6_ra_mode'] in modes) def is_eui64_address(ip_address): diff --git a/neutron/db/allowedaddresspairs_db.py b/neutron/db/allowedaddresspairs_db.py index 1bc1bdf07c9..6b184904470 100644 --- a/neutron/db/allowedaddresspairs_db.py +++ b/neutron/db/allowedaddresspairs_db.py @@ -90,8 +90,9 @@ class AllowedAddressPairsMixin(object): return db_utils.resource_fields(res, fields) def _has_address_pairs(self, port): - return (validators.is_attr_set(port['port'][addr_apidef.ADDRESS_PAIRS]) - and port['port'][addr_apidef.ADDRESS_PAIRS] != []) + return (validators.is_attr_set( + port['port'][addr_apidef.ADDRESS_PAIRS]) and + port['port'][addr_apidef.ADDRESS_PAIRS] != []) def _check_update_has_allowed_address_pairs(self, port): """Determine if request has an allowed address pair. diff --git a/neutron/db/extradhcpopt_db.py b/neutron/db/extradhcpopt_db.py index 5829b0c83d1..bf698337429 100644 --- a/neutron/db/extradhcpopt_db.py +++ b/neutron/db/extradhcpopt_db.py @@ -82,8 +82,8 @@ class ExtraDhcpOptMixin(object): with db_api.context_manager.writer.using(context): for upd_rec in dopts: for opt in opts: - if (opt['opt_name'] == upd_rec['opt_name'] - and opt['ip_version'] == upd_rec.get( + if (opt['opt_name'] == upd_rec['opt_name'] and + opt['ip_version'] == upd_rec.get( 'ip_version', 4)): # to handle deleting of a opt from the port. if upd_rec['opt_value'] is None: diff --git a/neutron/db/ipam_backend_mixin.py b/neutron/db/ipam_backend_mixin.py index 892ae1ffe2e..1f535bf6523 100644 --- a/neutron/db/ipam_backend_mixin.py +++ b/neutron/db/ipam_backend_mixin.py @@ -765,10 +765,10 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon): old_ips = old_port.get('fixed_ips') deferred_ip_allocation = ( old_port.get('ip_allocation') == - ipalloc_apidef.IP_ALLOCATION_DEFERRED - and host and not old_host - and not old_ips - and not fixed_ips_requested) + ipalloc_apidef.IP_ALLOCATION_DEFERRED and + host and not old_host and + not old_ips and + not fixed_ips_requested) if not deferred_ip_allocation: # Check that any existing IPs are valid on the new segment new_host_requested = host and host != old_host diff --git a/neutron/db/l3_db.py b/neutron/db/l3_db.py index 78e7e650c1d..0b53fcc33bd 100644 --- a/neutron/db/l3_db.py +++ b/neutron/db/l3_db.py @@ -788,8 +788,8 @@ class L3_NAT_dbonly_mixin(l3.RouterPluginBase, if not subnet['gateway_ip']: msg = _('Subnet for router interface must have a gateway IP') raise n_exc.BadRequest(resource='router', msg=msg) - if (subnet['ip_version'] == 6 and subnet['ipv6_ra_mode'] is None - and subnet['ipv6_address_mode'] is not None): + if (subnet['ip_version'] == 6 and subnet['ipv6_ra_mode'] is None and + subnet['ipv6_address_mode'] is not None): msg = (_('IPv6 subnet %s configured to receive RAs from an ' 'external router cannot be added to Neutron Router.') % subnet['id']) diff --git a/neutron/db/l3_hamode_db.py b/neutron/db/l3_hamode_db.py index e9eacc074f9..0badefbea8e 100644 --- a/neutron/db/l3_hamode_db.py +++ b/neutron/db/l3_hamode_db.py @@ -552,8 +552,8 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin, # List agents where router is active and agent is dead # and agents where router is standby and agent is dead for binding in bindings: - if not (binding.agent.is_active - and binding.agent.admin_state_up): + if not (binding.agent.is_active and + binding.agent.admin_state_up): if binding.state == n_const.HA_ROUTER_STATE_ACTIVE: router_active_agents_dead.append(binding.agent) elif binding.state == n_const.HA_ROUTER_STATE_STANDBY: diff --git a/neutron/db/securitygroups_db.py b/neutron/db/securitygroups_db.py index 8bc6e94baf0..d09b1e65142 100644 --- a/neutron/db/securitygroups_db.py +++ b/neutron/db/securitygroups_db.py @@ -827,8 +827,9 @@ class SecurityGroupDbMixin(ext_sg.SecurityGroupPluginBase): is either [] or not is_attr_set, otherwise return False """ if (ext_sg.SECURITYGROUPS in port['port'] and - not (validators.is_attr_set(port['port'][ext_sg.SECURITYGROUPS]) - and port['port'][ext_sg.SECURITYGROUPS] != [])): + not (validators.is_attr_set( + port['port'][ext_sg.SECURITYGROUPS]) and + port['port'][ext_sg.SECURITYGROUPS] != [])): return True return False diff --git a/neutron/ipam/utils.py b/neutron/ipam/utils.py index 1c062d76bd5..c3097ab330c 100644 --- a/neutron/ipam/utils.py +++ b/neutron/ipam/utils.py @@ -23,9 +23,9 @@ def check_subnet_ip(cidr, ip_address): net = netaddr.IPNetwork(cidr) # Check that the IP is valid on subnet. This cannot be the # network or the broadcast address (which exists only in IPv4) - return (ip != net.network - and (net.version == 6 or ip != net[-1]) - and net.netmask & ip == net.network) + return (ip != net.network and + (net.version == 6 or ip != net[-1]) and + net.netmask & ip == net.network) def check_gateway_invalid_in_subnet(cidr, gateway): diff --git a/neutron/notifiers/nova.py b/neutron/notifiers/nova.py index 29d00ae0752..b3b996349b2 100644 --- a/neutron/notifiers/nova.py +++ b/neutron/notifiers/nova.py @@ -76,8 +76,9 @@ class Notifier(object): def _is_compute_port(self, port): try: - if (port['device_id'] and uuidutils.is_uuid_like(port['device_id']) - and port['device_owner'].startswith( + if (port['device_id'] and + uuidutils.is_uuid_like(port['device_id']) and + port['device_owner'].startswith( constants.DEVICE_OWNER_COMPUTE_PREFIX)): return True except (KeyError, AttributeError): @@ -116,9 +117,9 @@ class Notifier(object): # port to a new instance port without disassociate it first, an # event should be sent for original instance, that will make nova # know original instance's info, and update database for it. - if (action == 'update_floatingip' - and returned_obj['floatingip'].get('port_id') - and original_obj.get('port_id')): + if (action == 'update_floatingip' and + returned_obj['floatingip'].get('port_id') and + original_obj.get('port_id')): disassociate_returned_obj = {'floatingip': {'port_id': None}} event = self.create_port_changed_event(action, original_obj, disassociate_returned_obj) @@ -194,9 +195,9 @@ class Notifier(object): # NO_VALUE/DOWN/BUILD -> ACTIVE/ERROR. elif (previous_port_status in [sql_attr.NO_VALUE, constants.PORT_STATUS_DOWN, - constants.PORT_STATUS_BUILD] - and current_port_status in [constants.PORT_STATUS_ACTIVE, - constants.PORT_STATUS_ERROR]): + constants.PORT_STATUS_BUILD] and + current_port_status in [constants.PORT_STATUS_ACTIVE, + constants.PORT_STATUS_ERROR]): event_name = VIF_PLUGGED # All the remaining state transitions are of no interest to nova else: diff --git a/neutron/objects/qos/rule.py b/neutron/objects/qos/rule.py index 8a84f83a0d7..76d90b1afec 100644 --- a/neutron/objects/qos/rule.py +++ b/neutron/objects/qos/rule.py @@ -113,8 +113,9 @@ class QosRule(base.NeutronDbObject): # - Is a port QoS policy (not a network QoS policy) # - Is not an internal network device (e.g. router) and is a network # QoS policy and there is no port QoS policy - return (is_port_policy or ((is_router_gw or not is_network_device_port) - and is_network_policy_only)) + return (is_port_policy or + ((is_router_gw or not is_network_device_port) and + is_network_policy_only)) @base.NeutronObjectRegistry.register diff --git a/neutron/plugins/ml2/drivers/agent/_common_agent.py b/neutron/plugins/ml2/drivers/agent/_common_agent.py index cb27aabc4e7..b03ebbfb439 100644 --- a/neutron/plugins/ml2/drivers/agent/_common_agent.py +++ b/neutron/plugins/ml2/drivers/agent/_common_agent.py @@ -202,8 +202,8 @@ class CommonAgentLoop(service.Service): # Updated devices are processed the same as new ones, as their # admin_state_up may have changed. The set union prevents duplicating # work when a device is new and updated in the same polling iteration. - devices_added_updated = (set(device_info.get('added')) - | set(device_info.get('updated'))) + devices_added_updated = (set(device_info.get('added')) | + set(device_info.get('updated'))) if devices_added_updated: resync_a = self.treat_devices_added_updated(devices_added_updated) @@ -408,14 +408,15 @@ class CommonAgentLoop(service.Service): # Retry cleaning devices that may not have been cleaned properly. # And clean any that disappeared since the previous iteration. - device_info['removed'] = (previous['removed'] | previous['current'] - - current_devices) + device_info['removed'] = (previous['removed'] | + previous['current'] - + current_devices) # Retry updating devices that may not have been updated properly. # And any that were updated since the previous iteration. # Only update devices that currently exist. - device_info['updated'] = (previous['updated'] | updated_devices - & current_devices) + device_info['updated'] = (previous['updated'] | updated_devices & + current_devices) else: device_info['added'] = current_devices - previous['current'] device_info['removed'] = previous['current'] - current_devices @@ -424,9 +425,9 @@ class CommonAgentLoop(service.Service): return device_info def _device_info_has_changes(self, device_info): - return (device_info.get('added') - or device_info.get('updated') - or device_info.get('removed')) + return (device_info.get('added') or + device_info.get('updated') or + device_info.get('removed')) def daemon_loop(self): LOG.info("%s Agent RPC Daemon Started!", self.agent_type) @@ -447,8 +448,8 @@ class CommonAgentLoop(service.Service): device_info = self.scan_devices(previous=device_info, sync=sync) sync = False - if (self._device_info_has_changes(device_info) - or self.sg_agent.firewall_refresh_needed()): + if (self._device_info_has_changes(device_info) or + self.sg_agent.firewall_refresh_needed()): LOG.debug("Agent loop found changes! %s", device_info) try: sync = self.process_network_devices(device_info) diff --git a/neutron/plugins/ml2/drivers/l2pop/mech_driver.py b/neutron/plugins/ml2/drivers/l2pop/mech_driver.py index ce71001d9c7..7a97c0bdd0f 100644 --- a/neutron/plugins/ml2/drivers/l2pop/mech_driver.py +++ b/neutron/plugins/ml2/drivers/l2pop/mech_driver.py @@ -166,9 +166,9 @@ class L2populationMechanismDriver(api.MechanismDriver): agent_host) self.L2populationAgentNotify.remove_fdb_entries( self.rpc_ctx, fdb_entries) - elif (context.host != context.original_host - and context.original_status == const.PORT_STATUS_ACTIVE - and context.status == const.PORT_STATUS_DOWN): + elif (context.host != context.original_host and + context.original_status == const.PORT_STATUS_ACTIVE and + context.status == const.PORT_STATUS_DOWN): # The port has been migrated. Send notification about port # removal from old host. fdb_entries = self._get_agent_fdb( diff --git a/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py b/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py index e078b0a345a..6c5438b8f86 100644 --- a/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/linuxbridge/agent/linuxbridge_neutron_agent.py @@ -696,8 +696,8 @@ class LinuxBridgeManager(amb.CommonAgentManagerBase): test_iface = None for seg_id in moves.range(1, constants.MAX_VXLAN_VNI + 1): - if (ip_lib.device_exists(self.get_vxlan_device_name(seg_id)) - or ip_lib.vxlan_in_use(seg_id)): + if (ip_lib.device_exists(self.get_vxlan_device_name(seg_id)) or + ip_lib.vxlan_in_use(seg_id)): continue test_iface = self.ensure_vxlan(seg_id) break diff --git a/neutron/plugins/ml2/drivers/mech_sriov/agent/sriov_nic_agent.py b/neutron/plugins/ml2/drivers/mech_sriov/agent/sriov_nic_agent.py index dc179602e69..3d3dee8e7cd 100644 --- a/neutron/plugins/ml2/drivers/mech_sriov/agent/sriov_nic_agent.py +++ b/neutron/plugins/ml2/drivers/mech_sriov/agent/sriov_nic_agent.py @@ -210,9 +210,9 @@ class SriovNicSwitchAgent(object): return device_info def _device_info_has_changes(self, device_info): - return (device_info.get('added') - or device_info.get('updated') - or device_info.get('removed')) + return (device_info.get('added') or + device_info.get('updated') or + device_info.get('removed')) def process_network_devices(self, device_info): resync_a = False @@ -225,8 +225,8 @@ class SriovNicSwitchAgent(object): # Updated devices are processed the same as new ones, as their # admin_state_up may have changed. The set union prevents duplicating # work when a device is new and updated in the same polling iteration. - devices_added_updated = (set(device_info.get('added')) - | set(device_info.get('updated'))) + devices_added_updated = (set(device_info.get('added')) | + set(device_info.get('updated'))) if devices_added_updated: resync_a = self.treat_devices_added_updated(devices_added_updated) diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py index 48167a193de..180f97d0445 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py @@ -575,8 +575,8 @@ class OVSDVRNeutronAgent(object): if not self.in_distributed_mode(): return - if local_vlan_map.network_type not in (constants.TUNNEL_NETWORK_TYPES - + [n_const.TYPE_VLAN]): + if local_vlan_map.network_type not in (constants.TUNNEL_NETWORK_TYPES + + [n_const.TYPE_VLAN]): LOG.debug("DVR: Port %s is with network_type %s not supported" " for dvr plumbing", port.vif_id, local_vlan_map.network_type) diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py index 2773f01ae8b..b05346e2e03 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_neutron_agent.py @@ -351,8 +351,8 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin, if not local_vlan: continue net_uuid = local_vlan_map.get('net_uuid') - if (net_uuid and net_uuid not in self._local_vlan_hints - and local_vlan != constants.DEAD_VLAN_TAG): + if (net_uuid and net_uuid not in self._local_vlan_hints and + local_vlan != constants.DEAD_VLAN_TAG): self.available_local_vlans.remove(local_vlan) self._local_vlan_hints[local_vlan_map['net_uuid']] = \ local_vlan @@ -1367,8 +1367,8 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin, for lvm in self.vlan_manager: for port in lvm.vif_ports.values(): if ( - port.port_name in port_tags - and port_tags[port.port_name] != lvm.vlan + port.port_name in port_tags and + port_tags[port.port_name] != lvm.vlan ): LOG.info( "Port '%(port_name)s' has lost " @@ -2029,8 +2029,8 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin, devices_need_retry = (any(failed_devices.values()) or any(failed_ancillary_devices.values()) or ports_not_ready_yet) - if (self._agent_has_updates(polling_manager) or sync - or devices_need_retry): + if (self._agent_has_updates(polling_manager) or sync or + devices_need_retry): try: LOG.debug("Agent rpc_loop - iteration:%(iter_num)d - " "starting polling. Elapsed:%(elapsed).3f", @@ -2149,8 +2149,8 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin, rpc_api.client.set_max_timeout(timeout) def _check_agent_configurations(self): - if (self.enable_distributed_routing and self.enable_tunneling - and not self.l2_pop): + if (self.enable_distributed_routing and self.enable_tunneling and + not self.l2_pop): raise ValueError(_("DVR deployments for VXLAN/GRE/Geneve " "underlays require L2-pop to be enabled, " diff --git a/neutron/plugins/ml2/drivers/type_tunnel.py b/neutron/plugins/ml2/drivers/type_tunnel.py index 57c64f912e6..94742c5df43 100644 --- a/neutron/plugins/ml2/drivers/type_tunnel.py +++ b/neutron/plugins/ml2/drivers/type_tunnel.py @@ -445,8 +445,8 @@ class TunnelRpcCallbackMixin(object): host_endpoint = driver.obj.get_endpoint_by_host(host) ip_endpoint = driver.obj.get_endpoint_by_ip(tunnel_ip) - if (ip_endpoint and ip_endpoint.host is None - and host_endpoint is None): + if (ip_endpoint and ip_endpoint.host is None and + host_endpoint is None): driver.obj.delete_endpoint(ip_endpoint.ip_address) elif (ip_endpoint and ip_endpoint.host != host): LOG.info( diff --git a/neutron/services/logapi/common/db_api.py b/neutron/services/logapi/common/db_api.py index 4a855c97744..e4f0bd5e4b5 100644 --- a/neutron/services/logapi/common/db_api.py +++ b/neutron/services/logapi/common/db_api.py @@ -172,9 +172,9 @@ def get_logs_bound_port(context, port_id): project_id = port['project_id'] logs = log_object.Log.get_objects( context, project_id=project_id, enabled=True) - is_bound = lambda log: (log.resource_id in port.security_group_ids - or log.target_id == port.id - or (not log.target_id and not log.resource_id)) + is_bound = lambda log: (log.resource_id in port.security_group_ids or + log.target_id == port.id or + (not log.target_id and not log.resource_id)) return [log for log in logs if is_bound(log)] diff --git a/neutron/services/segments/plugin.py b/neutron/services/segments/plugin.py index 35e494e096f..a9f3416eadc 100644 --- a/neutron/services/segments/plugin.py +++ b/neutron/services/segments/plugin.py @@ -72,8 +72,8 @@ class Plugin(db.SegmentDbMixin, segment.SegmentPluginBase): # TODO(carl_baldwin) Make this work with service subnets when # it's a thing. - is_adjacent = (not network_db.subnets - or not network_db.subnets[0].segment_id) + is_adjacent = (not network_db.subnets or + not network_db.subnets[0].segment_id) network_res[l2adj_apidef.L2_ADJACENCY] = is_adjacent @staticmethod diff --git a/neutron/services/timestamp/timestamp_db.py b/neutron/services/timestamp/timestamp_db.py index d1dd417d15c..b824a9c2dfb 100644 --- a/neutron/services/timestamp/timestamp_db.py +++ b/neutron/services/timestamp/timestamp_db.py @@ -47,8 +47,8 @@ def _change_since_result_filter_hook(query, filters): query = query.join(standard_attr.StandardAttribute, target_model_class.standard_attr_id == standard_attr.StandardAttribute.id).filter( - standard_attr.StandardAttribute.updated_at - >= changed_since) + standard_attr.StandardAttribute.updated_at >= + changed_since) return query @@ -57,8 +57,8 @@ def _update_timestamp(session, context, instances): while objs_list: obj = objs_list.pop() - if (isinstance(obj, standard_attr.HasStandardAttributes) - and obj.standard_attr_id): + if (isinstance(obj, standard_attr.HasStandardAttributes) and + obj.standard_attr_id): obj.updated_at = timeutils.utcnow() diff --git a/neutron/tests/functional/db/test_migrations.py b/neutron/tests/functional/db/test_migrations.py index 714000f0af2..02314c7a2bb 100644 --- a/neutron/tests/functional/db/test_migrations.py +++ b/neutron/tests/functional/db/test_migrations.py @@ -153,8 +153,8 @@ class _TestModelsMigrations(test_migrations.ModelsMigrationsSync): return head_models.get_metadata() def include_object(self, object_, name, type_, reflected, compare_to): - if type_ == 'table' and (name == 'alembic_version' - or name in external.TABLES): + if type_ == 'table' and (name == 'alembic_version' or + name in external.TABLES): return False return super(_TestModelsMigrations, self).include_object( @@ -363,8 +363,9 @@ class TestModelsMigrationsMysql(testlib_api.MySQLTestCaseMixin, self.assertGreater(len(tables), 0, "No tables found. Wrong schema?") res = [table for table in tables if - insp.get_table_options(table)['mysql_engine'] != 'InnoDB' - and table != 'alembic_version'] + insp.get_table_options(table)['mysql_engine'] != + 'InnoDB' and + table != 'alembic_version'] self.assertEqual(0, len(res), "%s non InnoDB tables created" % res) diff --git a/neutron/tests/functional/test_server.py b/neutron/tests/functional/test_server.py index 43110f789d9..8adc6baefa0 100644 --- a/neutron/tests/functional/test_server.py +++ b/neutron/tests/functional/test_server.py @@ -146,8 +146,8 @@ class TestNeutronServer(base.BaseTestCase): # Wait for temp file to be created and its size reaching the expected # value expected_size = len(expected_msg) - condition = lambda: (os.path.isfile(self.temp_file) - and os.stat(self.temp_file).st_size == + condition = lambda: (os.path.isfile(self.temp_file) and + os.stat(self.temp_file).st_size == expected_size) utils.wait_until_true( diff --git a/neutron/tests/unit/agent/l3/test_agent.py b/neutron/tests/unit/agent/l3/test_agent.py index 4c8816f9e20..d7f0a6009ce 100644 --- a/neutron/tests/unit/agent/l3/test_agent.py +++ b/neutron/tests/unit/agent/l3/test_agent.py @@ -1864,8 +1864,8 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): l3_test_common.router_append_subnet( router, count=2, ip_version=6, ipv6_subnet_modes=([{'ra_mode': lib_constants.IPV6_SLAAC, - 'address_mode': lib_constants.IPV6_SLAAC}] - * 2)) + 'address_mode': lib_constants.IPV6_SLAAC}] * + 2)) self._process_router_instance_for_agent(agent, ri, router) self._assert_ri_process_enabled(ri) # Reset mocks to check for modified radvd config diff --git a/neutron/tests/unit/agent/linux/test_dhcp.py b/neutron/tests/unit/agent/linux/test_dhcp.py index cab5711800d..a0c5ad58cec 100644 --- a/neutron/tests/unit/agent/linux/test_dhcp.py +++ b/neutron/tests/unit/agent/linux/test_dhcp.py @@ -1219,8 +1219,8 @@ class TestDnsmasq(TestBase): prefix6 = '--dhcp-range=set:tag%d,%s,%s,%s%s' possible_leases = 0 for i, s in enumerate(network.subnets): - if (s.ip_version != 6 - or s.ipv6_address_mode == constants.DHCPV6_STATEFUL): + if (s.ip_version != 6 or + s.ipv6_address_mode == constants.DHCPV6_STATEFUL): if s.ip_version == 4: expected.extend([prefix % ( i, s.cidr.split('/')[0], diff --git a/neutron/tests/unit/common/test_utils.py b/neutron/tests/unit/common/test_utils.py index 97e7786f26c..cba844d940a 100644 --- a/neutron/tests/unit/common/test_utils.py +++ b/neutron/tests/unit/common/test_utils.py @@ -50,9 +50,9 @@ class _PortRange(object): @property def can_merge(self): - return (self.prev_ref - and self.possible_mask_base == self.prev_ref.possible_mask_base - and self.mask == self.prev_ref.mask) + return (self.prev_ref and + self.possible_mask_base == self.prev_ref.possible_mask_base and + self.mask == self.prev_ref.mask) def shake(self): """Try to merge ranges created earlier. diff --git a/neutron/tests/unit/db/test_db_base_plugin_v2.py b/neutron/tests/unit/db/test_db_base_plugin_v2.py index f6240cb5efb..434ea04c8af 100644 --- a/neutron/tests/unit/db/test_db_base_plugin_v2.py +++ b/neutron/tests/unit/db/test_db_base_plugin_v2.py @@ -4318,9 +4318,9 @@ class TestSubnetsV2(NeutronDbPluginV2TestCase): 'fe80::/64', ip_version=6, ipv6_ra_mode=addr_mode, ipv6_address_mode=addr_mode) - if (insert_db_reference_error or insert_address_allocated - or device_owner == constants.DEVICE_OWNER_ROUTER_SNAT - or device_owner in constants.ROUTER_INTERFACE_OWNERS): + if (insert_db_reference_error or insert_address_allocated or + device_owner == constants.DEVICE_OWNER_ROUTER_SNAT or + device_owner in constants.ROUTER_INTERFACE_OWNERS): # DVR SNAT, router interfaces and DHCP ports should not have # been updated with addresses from the new auto-address subnet self.assertEqual(1, len(port['port']['fixed_ips'])) diff --git a/neutron/tests/unit/extensions/test_extra_dhcp_opt.py b/neutron/tests/unit/extensions/test_extra_dhcp_opt.py index 60a28dbc67a..2a796914e63 100644 --- a/neutron/tests/unit/extensions/test_extra_dhcp_opt.py +++ b/neutron/tests/unit/extensions/test_extra_dhcp_opt.py @@ -63,9 +63,9 @@ class TestExtraDhcpOpt(ExtraDhcpOptDBTestCase): for opt in returned: name = opt['opt_name'] for exp in expected: - if (name == exp['opt_name'] - and opt['ip_version'] == exp.get( - 'ip_version', 4)): + if (name == exp['opt_name'] and + opt['ip_version'] == exp.get( + 'ip_version', 4)): val = exp['opt_value'] break self.assertEqual(val, opt['opt_value']) diff --git a/neutron/tests/unit/extensions/test_l3.py b/neutron/tests/unit/extensions/test_l3.py index 3cc7be22e1c..032f2aa6132 100644 --- a/neutron/tests/unit/extensions/test_l3.py +++ b/neutron/tests/unit/extensions/test_l3.py @@ -350,8 +350,9 @@ class L3NatTestCaseMixin(object): data['router']['name'] = name if admin_state_up is not None: data['router']['admin_state_up'] = admin_state_up - for arg in (('admin_state_up', 'tenant_id', 'availability_zone_hints') - + (arg_list or ())): + for arg in (('admin_state_up', 'tenant_id', + 'availability_zone_hints') + + (arg_list or ())): # Arg must be present and not empty if arg in kwargs: data['router'][arg] = kwargs[arg] diff --git a/neutron/tests/unit/extensions/test_portsecurity.py b/neutron/tests/unit/extensions/test_portsecurity.py index 3e49baef2da..b3982929216 100644 --- a/neutron/tests/unit/extensions/test_portsecurity.py +++ b/neutron/tests/unit/extensions/test_portsecurity.py @@ -136,8 +136,8 @@ class PortSecurityTestPlugin(db_base_plugin_v2.NeutronDbPluginV2, has_ip = self._ip_on_port(ret_port) # checks if security groups were updated adding/modifying # security groups, port security is set and port has ip - if (has_security_groups and (not ret_port[psec.PORTSECURITY] - or not has_ip)): + if (has_security_groups and (not ret_port[psec.PORTSECURITY] or + not has_ip)): raise psec_exc.PortSecurityAndIPRequiredForSecurityGroups() # Port security/IP was updated off. Need to check that no security diff --git a/neutron/tests/unit/extensions/test_securitygroup.py b/neutron/tests/unit/extensions/test_securitygroup.py index 6a5265eb186..a8bd399dd87 100644 --- a/neutron/tests/unit/extensions/test_securitygroup.py +++ b/neutron/tests/unit/extensions/test_securitygroup.py @@ -172,8 +172,8 @@ class SecurityGroupsTestCase(test_db_base_plugin_v2.NeutronDbPluginV2TestCase): for r in res['security_group_rules']: if (r['direction'] == 'egress' and not r['port_range_max'] and - not r['port_range_min'] and not r['protocol'] - and not r['remote_ip_prefix']): + not r['port_range_min'] and not r['protocol'] and + not r['remote_ip_prefix']): self._delete('security-group-rules', r['id']) def _assert_sg_rule_has_kvs(self, security_group_rule, expected_kvs): diff --git a/neutron/tests/unit/notifiers/test_nova.py b/neutron/tests/unit/notifiers/test_nova.py index 4319f58cd9c..f07bc77b5e0 100644 --- a/neutron/tests/unit/notifiers/test_nova.py +++ b/neutron/tests/unit/notifiers/test_nova.py @@ -117,9 +117,9 @@ class TestNovaNotify(base.BaseTestCase): elif (previous_port_status in [sql_attr.NO_VALUE, n_const.PORT_STATUS_DOWN, - n_const.PORT_STATUS_BUILD] - and current_port_status in [n_const.PORT_STATUS_ACTIVE, - n_const.PORT_STATUS_ERROR]): + n_const.PORT_STATUS_BUILD] and + current_port_status in [n_const.PORT_STATUS_ACTIVE, + n_const.PORT_STATUS_ERROR]): event_name = nova.VIF_PLUGGED else: diff --git a/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py b/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py index 95b0cdd5450..71dfca6e9d5 100644 --- a/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py +++ b/neutron/tests/unit/plugins/ml2/extensions/test_dns_integration.py @@ -170,11 +170,9 @@ class DNSIntegrationTestCase(test_plugin.Ml2PluginV2TestCase): else: self.assertFalse(dns_data_db['current_dns_domain']) records_v4 = [ip['ip_address'] for ip in port['fixed_ips'] - if netaddr.IPAddress(ip['ip_address']).version - == 4] + if netaddr.IPAddress(ip['ip_address']).version == 4] records_v6 = [ip['ip_address'] for ip in port['fixed_ips'] - if netaddr.IPAddress(ip['ip_address']).version - == 6] + if netaddr.IPAddress(ip['ip_address']).version == 6] expected = [] expected_delete = [] if records_v4: diff --git a/tox.ini b/tox.ini index 84981f6218b..9e603bba53c 100644 --- a/tox.ini +++ b/tox.ini @@ -148,8 +148,7 @@ commands = sphinx-build -W -b linkcheck doc/source doc/build/linkcheck # TODO(amotoki) check the following new rules should be fixed or ignored # E402 module level import not at top of file # E731 do not assign a lambda expression, use a def -# W503 line break before binary operator -ignore = E125,E126,E128,E129,E265,E402,E731,W503,H404,H405,N530,N534,N536 +ignore = E125,E126,E128,E129,E265,E402,E731,H404,H405,N530,N534,N536 # H106: Don't put vim configuration in source files # H203: Use assertIs(Not)None to check for None # H204: Use assert(Not)Equal to check for equality