示例#1
0
    def _sync_route_members_impl(self, m_get_drv_lbaas, m_get_drv_project,
                                 m_get_drv_subnets, subnet_id, project_id,
                                 endpoints, state, spec):
        m_drv_lbaas = mock.Mock(wraps=t_lbaas.FakeLBaaSDriver())
        m_drv_project = mock.Mock()
        m_drv_project.get_project.return_value = project_id
        m_drv_subnets = mock.Mock()
        m_drv_subnets.get_subnets.return_value = {
            subnet_id: mock.sentinel.subnet
        }
        m_get_drv_lbaas.return_value = m_drv_lbaas
        m_get_drv_project.return_value = m_drv_project
        m_get_drv_subnets.return_value = m_drv_subnets

        handler = h_ing_lbaas.IngressLoadBalancerHandler()

        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')

        with mock.patch.object(handler, '_get_pod_subnet') as m_get_pod_subnet:
            m_get_pod_subnet.return_value = subnet_id
            handler._sync_lbaas_route_members(endpoints, state, spec)

        observed_targets = sorted((str(member.ip), (member.port, member.port))
                                  for member in state.members)
        return observed_targets
示例#2
0
    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()))
示例#3
0
    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()