def on_present(self, endpoints): if not self._l7_router: ing_ctl = ingress_ctl.IngressCtrlr.get_instance() self._l7_router, listener = ing_ctl.get_router_and_listener() if not self._l7_router: LOG.info("No L7 router found - do nothing") return lbaas_spec = self._get_lbaas_spec(endpoints) if self._should_ignore(endpoints, lbaas_spec): return pool_name = self._drv_lbaas.get_loadbalancer_pool_name( self._l7_router, endpoints['metadata']['namespace'], endpoints['metadata']['name']) pool = self._drv_lbaas.get_pool_by_name(pool_name, self._l7_router.project_id) if not pool: if self._get_lbaas_route_state(endpoints): self._set_lbaas_route_state(endpoints, None) LOG.debug( "L7 routing: no route defined for service " ":%s - do nothing", endpoints['metadata']['name']) else: # pool was found in L7 router LB ,verify that members are up2date lbaas_route_state = self._get_lbaas_route_state(endpoints) if not lbaas_route_state: lbaas_route_state = obj_lbaas.LBaaSRouteState() lbaas_route_state.pool = pool if self._sync_lbaas_route_members(endpoints, lbaas_route_state, lbaas_spec): self._set_lbaas_route_state(endpoints, lbaas_route_state) self._clear_route_notification(endpoints)
def _generate_route_state(self, vip, targets, project_id, subnet_id): name = 'DUMMY_NAME' drv = t_lbaas.FakeLBaaSDriver() lb = drv.ensure_loadbalancer(name, project_id, subnet_id, vip, None, 'ClusterIP') pool = drv.ensure_pool_attached_to_lb(lb, 'namespace', 'svc_name', 'HTTP') members = {} for ip, (listen_port, target_port) in targets.items(): members.setdefault((ip, listen_port, target_port), drv.ensure_member(lb, pool, subnet_id, ip, target_port, None, None)) return obj_lbaas.LBaaSRouteState(pool=pool, members=list(members.values()))
def test_on_deleted(self): endpoints = mock.sentinel.endpoints project_id = str(uuid.uuid4()) subnet_id = str(uuid.uuid4()) m_handler = mock.Mock(spec=h_ing_lbaas.IngressLoadBalancerHandler) m_handler._l7_router = t_lbaas.FakeLBaaSDriver().ensure_loadbalancer( name='L7_Router', project_id=project_id, subnet_id=subnet_id, ip='1.2.3.4', security_groups_ids=None, service_type='ClusterIP') m_handler._get_lbaas_route_state.return_value = ( obj_lbaas.LBaaSRouteState()) m_handler._remove_unused_route_members.return_value = True h_ing_lbaas.IngressLoadBalancerHandler.on_deleted(m_handler, endpoints) m_handler._get_lbaas_route_state.assert_called_once() m_handler._remove_unused_route_members.assert_called_once()