Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
Cloud:OpenStack:Newton
openstack-neutron-doc
0014-Fix-dvr-ha-router-gateway-port-binding-to-...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0014-Fix-dvr-ha-router-gateway-port-binding-to-incorrect-host.patch of Package openstack-neutron-doc
Index: neutron-9.4.2.dev21/neutron/db/l3_dvr_db.py =================================================================== --- neutron-9.4.2.dev21.orig/neutron/db/l3_dvr_db.py +++ neutron-9.4.2.dev21/neutron/db/l3_dvr_db.py @@ -52,8 +52,39 @@ router_distributed_opts = [ ] cfg.CONF.register_opts(router_distributed_opts) +class _DVRAgentInterfaceMixin(object): + def _get_gateway_port_host(self, context, router, gw_ports): + if not gw_ports.get(router.get('gw_port_id')): + return + + agent_binding = l3_sched_db.RouterL3AgentBinding + router_binding = (context.session.query(agent_binding).filter( + agent_binding.router_id.in_([router['id']])) + ).all() -class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin, + if not router_binding: + return + + return router_binding[0].l3_agent.host + + def _build_routers_list(self, context, routers, gw_ports): + routers = super(_DVRAgentInterfaceMixin, self)._build_routers_list( + context, routers, gw_ports) + + if not routers: + return [] + + for router in routers: + router['gw_port_host'] = self._get_gateway_port_host( + context, router, gw_ports) + LOG.debug("router %s gateway port host: %s", + router.get('id'), router.get('gw_port_host')) + + return routers + + +class L3_NAT_with_dvr_db_mixin(_DVRAgentInterfaceMixin, + l3_db.L3_NAT_db_mixin, l3_attrs_db.ExtraAttributesMixin): """Mixin class to enable DVR support.""" @@ -549,35 +580,6 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_ LOG.debug("Return the SNAT ports: %s", interfaces) return interfaces - def _build_routers_list(self, context, routers, gw_ports): - # Perform a single query up front for all routers - if not routers: - return [] - router_ids = [r['id'] for r in routers] - snat_binding = l3_sched_db.RouterL3AgentBinding - query = (context.session.query(snat_binding). - filter(snat_binding.router_id.in_(router_ids))).all() - bindings = dict((b.router_id, b) for b in query) - - for rtr in routers: - gw_port_id = rtr['gw_port_id'] - # Collect gw ports only if available - if gw_port_id and gw_ports.get(gw_port_id): - rtr['gw_port'] = gw_ports[gw_port_id] - if 'enable_snat' in rtr[l3.EXTERNAL_GW_INFO]: - rtr['enable_snat'] = ( - rtr[l3.EXTERNAL_GW_INFO]['enable_snat']) - - binding = bindings.get(rtr['id']) - if not binding: - rtr['gw_port_host'] = None - LOG.debug('No snat is bound to router %s', rtr['id']) - continue - - rtr['gw_port_host'] = binding.l3_agent.host - - return routers - def _process_routers(self, context, routers): routers_dict = {} snat_intfs_by_router_id = self._get_snat_sync_interfaces( Index: neutron-9.4.2.dev21/neutron/db/l3_hamode_db.py =================================================================== --- neutron-9.4.2.dev21.orig/neutron/db/l3_hamode_db.py +++ neutron-9.4.2.dev21/neutron/db/l3_hamode_db.py @@ -796,6 +796,41 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NA # Take concurrently deleted interfaces in to account pass + def _get_gateway_port_host(self, context, router, gw_ports): + if not router.get('ha'): + return super(L3_HA_NAT_db_mixin, self)._get_gateway_port_host( + context, router, gw_ports) + + gateway_port = gw_ports.get(router.get('gw_port_id')) + + if not gateway_port: + return + + gateway_port_status = gateway_port['status'] + gateway_port_binding_host = gateway_port[portbindings.HOST_ID] + + admin_ctx = context.elevated() + router_id = router['id'] + ha_bindings = self.get_l3_bindings_hosting_router_with_ha_states( + admin_ctx, router_id) + LOG.debug("HA router %(router_id)s gateway port %(gw_port_id)s " + "binding host: %(host)s, status: %(status)s", + {"router_id": router_id, + "gw_port_id": gateway_port['id'], + "host": gateway_port_binding_host, + "status": gateway_port_status}) + for ha_binding_agent, ha_binding_state in ha_bindings: + if ha_binding_state != n_const.HA_ROUTER_STATE_ACTIVE: + continue + # For create router gateway, the gateway port may not be ACTIVE + # yet, so we return 'master' host directly. + if gateway_port_status != constants.PORT_STATUS_ACTIVE: + return ha_binding_agent.host + # Do not let the original 'master' (current is backup) host, + # override the gateway port binding host. + if (gateway_port_status == constants.PORT_STATUS_ACTIVE and + ha_binding_agent.host == gateway_port_binding_host): + return ha_binding_agent.host def is_ha_router(router): """Return True if router to be handled is ha."""
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor