From b603093307295f47b0e45055ec21b29ac25b8660 Mon Sep 17 00:00:00 2001 From: Brian Haley Date: Tue, 9 Aug 2022 13:17:54 -0400 Subject: [PATCH] Fix some pylint indentation warnings Running with a stricter .pylintrc generates a lot of C0330 warnings (hanging/continued indentation). Fix the ones in neutron/objects. Trivialfix Change-Id: I5e885e2b2a09d48197de30d8c6de5d74c10f5987 --- neutron/objects/agent.py | 22 +++++++++---------- neutron/objects/base.py | 5 ++--- neutron/objects/l3agent.py | 17 +++++++------- neutron/objects/network_segment_range.py | 8 +++---- .../port/extensions/allowedaddresspairs.py | 2 +- .../objects/port/extensions/extra_dhcp_opt.py | 10 ++++----- neutron/objects/ports.py | 6 ++--- neutron/objects/qos/binding.py | 2 +- neutron/objects/qos/policy.py | 4 ++-- neutron/objects/qos/qos_policy_validator.py | 8 +++---- neutron/objects/qos/rule_type.py | 4 ++-- neutron/objects/quota.py | 7 +++--- neutron/objects/rbac_db.py | 16 +++++++------- neutron/objects/subnet.py | 13 +++++------ 14 files changed, 58 insertions(+), 66 deletions(-) diff --git a/neutron/objects/agent.py b/neutron/objects/agent.py index e28fe691ffd..62b7daea14b 100644 --- a/neutron/objects/agent.py +++ b/neutron/objects/agent.py @@ -106,9 +106,9 @@ class Agent(base.NeutronDbObject): rb_model.RouterL3AgentBinding.router_id ).label('count')).outerjoin( rb_model.RouterL3AgentBinding).group_by( - agent_model.Agent, - rb_model.RouterL3AgentBinding - .l3_agent_id).order_by('count') + agent_model.Agent, + rb_model.RouterL3AgentBinding + .l3_agent_id).order_by('count') res = query.filter(agent_model.Agent.id.in_(agent_ids)).first() agent_obj = cls._load_object(context, res[0]) return agent_obj @@ -117,12 +117,11 @@ class Agent(base.NeutronDbObject): def get_l3_agents_ordered_by_num_routers(cls, context, agent_ids): with cls.db_context_reader(context): query = (context.session.query(agent_model.Agent, func.count( - rb_model.RouterL3AgentBinding.router_id) - .label('count')). - outerjoin(rb_model.RouterL3AgentBinding). - group_by(agent_model.Agent). - filter(agent_model.Agent.id.in_(agent_ids)). - order_by('count')) + rb_model.RouterL3AgentBinding.router_id).label('count')). + outerjoin(rb_model.RouterL3AgentBinding). + group_by(agent_model.Agent). + filter(agent_model.Agent.id.in_(agent_ids)). + order_by('count')) return [cls._load_object(context, record[0]) for record in query] @classmethod @@ -157,10 +156,9 @@ class Agent(base.NeutronDbObject): @db_api.CONTEXT_READER def get_agents_by_availability_zones_and_agent_type( cls, context, agent_type, availability_zones): - query = context.session.query( - agent_model.Agent).filter_by( + query = context.session.query(agent_model.Agent).filter_by( agent_type=agent_type).group_by( - agent_model.Agent.availability_zone) + agent_model.Agent.availability_zone) query = query.filter( agent_model.Agent.availability_zone.in_(availability_zones)).all() agents = [cls._load_object(context, record) for record in query] diff --git a/neutron/objects/base.py b/neutron/objects/base.py index c84d2c3874a..69bb350aeeb 100644 --- a/neutron/objects/base.py +++ b/neutron/objects/base.py @@ -868,7 +868,7 @@ class NeutronDbObject(NeutronObject, metaclass=DeclarativeObject): parent=clsname, child=objclass.__name__) if len(foreign_keys.keys()) > 1: raise o_exc.NeutronSyntheticFieldMultipleForeignKeys( - field=field) + field=field) synthetic_field_db_name = ( self.fields_need_translation.get(field, field)) @@ -981,5 +981,4 @@ class NeutronDbObject(NeutronObject, metaclass=DeclarativeObject): cls.validate_filters(**kwargs) # Succeed if at least a single object matches; no need to fetch more return bool(obj_db_api.count( - cls, context, query_limit=1, **cls.modify_fields_to_db(kwargs)) - ) + cls, context, query_limit=1, **cls.modify_fields_to_db(kwargs))) diff --git a/neutron/objects/l3agent.py b/neutron/objects/l3agent.py index fdfaa089e2e..0bcae0a31d6 100644 --- a/neutron/objects/l3agent.py +++ b/neutron/objects/l3agent.py @@ -36,7 +36,7 @@ class RouterL3AgentBinding(base.NeutronDbObject): 'router_id': common_types.UUIDField(), 'l3_agent_id': common_types.UUIDField(), 'binding_index': obj_fields.IntegerField( - default=l3agent.LOWEST_BINDING_INDEX), + default=l3agent.LOWEST_BINDING_INDEX), } # TODO(ihrachys) return OVO objects not models @@ -52,16 +52,15 @@ class RouterL3AgentBinding(base.NeutronDbObject): @classmethod @db_api.CONTEXT_READER def get_down_router_bindings(cls, context, cutoff): - query = (context.session.query( - l3agent.RouterL3AgentBinding). + query = (context.session.query(l3agent.RouterL3AgentBinding). join(agent_model.Agent). filter(agent_model.Agent.heartbeat_timestamp < cutoff, - agent_model.Agent.admin_state_up).outerjoin( - l3_attrs.RouterExtraAttributes, - l3_attrs.RouterExtraAttributes.router_id == - l3agent.RouterL3AgentBinding.router_id).filter( - l3_attrs.RouterExtraAttributes.ha.in_([sql.false(), - sql.null()]))) + agent_model.Agent.admin_state_up).outerjoin( + l3_attrs.RouterExtraAttributes, + l3_attrs.RouterExtraAttributes.router_id == + l3agent.RouterL3AgentBinding.router_id).filter( + l3_attrs.RouterExtraAttributes.ha.in_( + [sql.false(), sql.null()]))) bindings = [cls._load_object(context, db_obj) for db_obj in query.all()] return bindings diff --git a/neutron/objects/network_segment_range.py b/neutron/objects/network_segment_range.py index d0e369ce5e7..fd66a5e8058 100644 --- a/neutron/objects/network_segment_range.py +++ b/neutron/objects/network_segment_range.py @@ -119,8 +119,7 @@ class NetworkSegmentRange(base.NeutronDbObject): query = self.obj_context.session.query(alloc_segmentation_id) query = query.filter(and_( alloc_segmentation_id >= self.minimum, - alloc_segmentation_id <= self.maximum), - not_(allocated)) + alloc_segmentation_id <= self.maximum), not_(allocated)) if self.network_type == constants.TYPE_VLAN: alloc_available = query.filter( model.physical_network == self.physical_network).all() @@ -141,9 +140,8 @@ class NetworkSegmentRange(base.NeutronDbObject): self.physical_network, segments_model.NetworkSegment.segmentation_id >= self.minimum, segments_model.NetworkSegment.segmentation_id <= self.maximum)) - .filter( - segments_model.NetworkSegment.network_id == - models_v2.Network.id)).all() + .filter(segments_model.NetworkSegment.network_id == + models_v2.Network.id)).all() return dict(alloc_used) @classmethod diff --git a/neutron/objects/port/extensions/allowedaddresspairs.py b/neutron/objects/port/extensions/allowedaddresspairs.py index f3a77830b46..aabf8747774 100644 --- a/neutron/objects/port/extensions/allowedaddresspairs.py +++ b/neutron/objects/port/extensions/allowedaddresspairs.py @@ -67,7 +67,7 @@ class AllowedAddressPair(base.NeutronDbObject): def get_allowed_address_pairs_for_ports(cls, context, port_ids): with db_api.CONTEXT_READER.using(context): query = context.session.query(models.AllowedAddressPair).filter( - models.AllowedAddressPair.port_id.in_(port_ids)) + models.AllowedAddressPair.port_id.in_(port_ids)) pairs = [cls._load_object(context, db_obj) for db_obj in query.all()] return pairs diff --git a/neutron/objects/port/extensions/extra_dhcp_opt.py b/neutron/objects/port/extensions/extra_dhcp_opt.py index fe6a7422f8d..297c0b4ccfb 100644 --- a/neutron/objects/port/extensions/extra_dhcp_opt.py +++ b/neutron/objects/port/extensions/extra_dhcp_opt.py @@ -25,11 +25,11 @@ class ExtraDhcpOpt(base.NeutronDbObject): db_model = models.ExtraDhcpOpt fields = { - 'id': common_types.UUIDField(), - 'port_id': common_types.UUIDField(), - 'opt_name': obj_fields.StringField(), - 'opt_value': obj_fields.StringField(), - 'ip_version': obj_fields.IntegerField(), + 'id': common_types.UUIDField(), + 'port_id': common_types.UUIDField(), + 'opt_name': obj_fields.StringField(), + 'opt_value': obj_fields.StringField(), + 'ip_version': obj_fields.IntegerField(), } fields_no_update = ['port_id'] diff --git a/neutron/objects/ports.py b/neutron/objects/ports.py index b69dac17563..eab254ce41b 100644 --- a/neutron/objects/ports.py +++ b/neutron/objects/ports.py @@ -223,12 +223,12 @@ class IPAllocation(base.NeutronDbObject): alloc_db = (context.session.query(models_v2.IPAllocation). filter_by(subnet_id=subnet_id).join(models_v2.Port). filter(~models_v2.Port.device_owner. - in_(device_owner)).first()) + in_(device_owner)).first()) else: alloc_db = (context.session.query(models_v2.IPAllocation). filter_by(subnet_id=subnet_id).join(models_v2.Port). filter(models_v2.Port.device_owner. - in_(device_owner)).first()) + in_(device_owner)).first()) if exclude and alloc_db: return super(IPAllocation, cls)._load_object(context, alloc_db) if alloc_db: @@ -723,7 +723,7 @@ class Port(base.NeutronDbObject): """Return ports with fixed IPs in a subnet""" return context.session.query(models_v2.Port).filter( models_v2.IPAllocation.port_id == models_v2.Port.id).filter( - models_v2.IPAllocation.subnet_id == subnet_id).all() + models_v2.IPAllocation.subnet_id == subnet_id).all() @classmethod def get_port_from_mac_and_pci_slot(cls, context, device_mac, diff --git a/neutron/objects/qos/binding.py b/neutron/objects/qos/binding.py index 8cf0c926664..ef302f10af6 100644 --- a/neutron/objects/qos/binding.py +++ b/neutron/objects/qos/binding.py @@ -67,7 +67,7 @@ class QosPolicyPortBinding(base.NeutronDbObject, _QosPolicyBindingMixin): else: query = query.filter(~exists().where( cls.db_model.port_id == models_v2.Port.id)).filter( - models_v2.Port.network_id == network_id) + models_v2.Port.network_id == network_id) return query.all() diff --git a/neutron/objects/qos/policy.py b/neutron/objects/qos/policy.py index 9dcd255fe08..955e1ef93c2 100644 --- a/neutron/objects/qos/policy.py +++ b/neutron/objects/qos/policy.py @@ -342,11 +342,11 @@ class QosPolicy(rbac_db.NeutronRbacObject): @classmethod def _get_bound_project_ids(cls, session, binding_db, bound_db, - binding_db_id_column, policy_id): + binding_db_id_column, policy_id): return list(itertools.chain.from_iterable( session.query(bound_db.project_id).join( binding_db, bound_db.id == binding_db_id_column).filter( - binding_db.policy_id == policy_id).all())) + binding_db.policy_id == policy_id).all())) @classmethod def get_bound_project_ids(cls, context, policy_id): diff --git a/neutron/objects/qos/qos_policy_validator.py b/neutron/objects/qos/qos_policy_validator.py index 3eedf4a1478..b7acfadb0d8 100644 --- a/neutron/objects/qos/qos_policy_validator.py +++ b/neutron/objects/qos/qos_policy_validator.py @@ -87,10 +87,10 @@ def check_min_pps_rule_conflict(policy, rule_obj): # Check if we are mixing directionless and direction-oriented QoS # minimum packet rate rules if getattr(rule_obj, "direction", None) and ( - (rule_obj.direction == n_consts.ANY_DIRECTION and - rule.direction in n_consts.VALID_DIRECTIONS) or - (rule_obj.direction in n_consts.VALID_DIRECTIONS and - rule.direction == n_consts.ANY_DIRECTION)): + (rule_obj.direction == n_consts.ANY_DIRECTION and + rule.direction in n_consts.VALID_DIRECTIONS) or + (rule_obj.direction in n_consts.VALID_DIRECTIONS and + rule.direction == n_consts.ANY_DIRECTION)): raise qos_exc.QoSRuleParameterConflict( rule_value=rule_obj.direction, policy_id=policy["id"], diff --git a/neutron/objects/qos/rule_type.py b/neutron/objects/qos/rule_type.py index a4a90b98925..c8d44b43fe1 100644 --- a/neutron/objects/qos/rule_type.py +++ b/neutron/objects/qos/rule_type.py @@ -53,7 +53,7 @@ class QosRuleType(base.NeutronObject): drivers_obj = [QosRuleTypeDriver( name=driver['name'], supported_parameters=driver['supported_parameters']) - for driver in drivers] + for driver in drivers] return cls(type=rule_type_name, drivers=drivers_obj) @@ -67,7 +67,7 @@ class QosRuleType(base.NeutronObject): rule_types = directory.get_plugin( alias=constants.QOS).supported_rule_types( - all_supported=all_supported, all_rules=all_rules) + all_supported=all_supported, all_rules=all_rules) return [cls(type=type_) for type_ in rule_types] # we don't receive context because we don't need db access at all diff --git a/neutron/objects/quota.py b/neutron/objects/quota.py index 9602add28cb..3ae157c6e06 100644 --- a/neutron/objects/quota.py +++ b/neutron/objects/quota.py @@ -93,8 +93,7 @@ class Reservation(base.NeutronDbObject): models.Reservation.expiration, sql.func.cast( sql.func.sum(models.ResourceDelta.amount), - sqltypes.Integer)).join( - models.Reservation) + sqltypes.Integer)).join(models.Reservation) if expired: exp_expr = (models.Reservation.expiration < now) else: @@ -103,8 +102,8 @@ class Reservation(base.NeutronDbObject): models.Reservation.project_id == project_id, models.ResourceDelta.resource.in_(resources), exp_expr)).group_by( - models.ResourceDelta.resource, - models.Reservation.expiration) + models.ResourceDelta.resource, + models.Reservation.expiration) return dict((resource, total_reserved) for (resource, exp, total_reserved) in resv_query) diff --git a/neutron/objects/rbac_db.py b/neutron/objects/rbac_db.py index f3d3ad8505a..4270f9a381e 100644 --- a/neutron/objects/rbac_db.py +++ b/neutron/objects/rbac_db.py @@ -69,10 +69,10 @@ class RbacNeutronDbObjectMixin(rbac_db_mixin.RbacPluginMixin, # session rbac_db_model = rbac_db_cls.db_model return (db_utils.model_query(context, rbac_db_model).filter( - and_(rbac_db_model.object_id == obj_id, - rbac_db_model.action == models.ACCESS_SHARED, - rbac_db_model.target_project.in_( - ['*', project_id]))).count() != 0) + and_(rbac_db_model.object_id == obj_id, + rbac_db_model.action == models.ACCESS_SHARED, + rbac_db_model.target_project.in_( + ['*', project_id]))).count() != 0) @classmethod def is_shared_with_project(cls, context, obj_id, project_id): @@ -100,9 +100,9 @@ class RbacNeutronDbObjectMixin(rbac_db_mixin.RbacPluginMixin, rbac_db_model = cls.rbac_db_cls.db_model return set(itertools.chain.from_iterable(context.session.query( rbac_db_model.target_project).filter( - and_(rbac_db_model.object_id == obj_id, - rbac_db_model.action == models.ACCESS_SHARED, - rbac_db_model.target_project != '*')))) + and_(rbac_db_model.object_id == obj_id, + rbac_db_model.action == models.ACCESS_SHARED, + rbac_db_model.target_project != '*')))) @classmethod @db_api.CONTEXT_READER @@ -132,7 +132,7 @@ class RbacNeutronDbObjectMixin(rbac_db_mixin.RbacPluginMixin, # for the wildcard we need to query all of the rbac entries to # see if any allow the object sharing other_target_projects = cls._get_projects_with_shared_access_to_db_obj( - ctx_admin, obj_id) + ctx_admin, obj_id) if not bound_project_ids.issubset(other_target_projects): raise_policy_in_use() diff --git a/neutron/objects/subnet.py b/neutron/objects/subnet.py index 3a17687bca2..13bd482749f 100644 --- a/neutron/objects/subnet.py +++ b/neutron/objects/subnet.py @@ -251,13 +251,12 @@ class Subnet(base.NeutronDbObject): object_data = db_obj.get('dns_publish_fixed_ip', None) else: object_data = SubnetDNSPublishFixedIP.get_objects( - self.obj_context, - subnet_id=self.id) + self.obj_context, + subnet_id=self.id) dns_publish_fixed_ip = False if object_data: - dns_publish_fixed_ip = object_data.get( - 'dns_publish_fixed_ip') + dns_publish_fixed_ip = object_data.get('dns_publish_fixed_ip') setattr(self, 'dns_publish_fixed_ip', dns_publish_fixed_ip) self.obj_reset_changes(['dns_publish_fixed_ip']) @@ -358,7 +357,7 @@ class Subnet(base.NeutronDbObject): @classmethod def _query_filter_by_fixed_ips_segment(cls, query, fixed_ips, - allow_multiple_segments=False): + allow_multiple_segments=False): """Excludes subnets not on the same segment as fixed_ips :raises: FixedIpsSubnetsNotOnSameSegment @@ -509,8 +508,8 @@ class Subnet(base.NeutronDbObject): if ignored_service_type: service_type_model = SubnetServiceType.db_model query = query.filter(~exists().where(and_( - cls.db_model.id == service_type_model.subnet_id, - service_type_model.service_type == ignored_service_type))) + cls.db_model.id == service_type_model.subnet_id, + service_type_model.service_type == ignored_service_type))) # (zigo): When a subnet is created, at this point in the code, # its service_types aren't populated in the subnet_service_types