Exemplo n.º 1
0
    def test_sync_path_l7_rule(self):
        m_handler = mock.Mock(spec=h_route.OcpRouteHandler)
        m_handler._l7_router = obj_lbaas.LBaaSLoadBalancer(
            id='00EE9E11-91C2-41CF-8FD4-7970579E5C4C',
            project_id='TEST_PROJECT')
        m_handler._drv_l7_router = mock.Mock(
            spec=d_l7_rtr.LBaaSv2L7RouterDriver)

        old_p_l7_rule = obj_route.RouteL7Rule(
            id='00EE9E11-91C2-41CF-8FD4-7970579E5C44',
            compare_type='EQUAL_TO',
            l7policy_id='00EE9E11-91C2-41CF-8FD4-7970579E5C45',
            type='PATH',
            value='/nice_path/')

        route_state = obj_route.RouteState(p_l7_rule=old_p_l7_rule)

        route = {
            'metadata': {
                'namespace': 'namespace',
                'name': 'name'
            },
            'spec': {
                'host': 'new.www.test.com',
                'path': 'mypath',
                'to': {
                    'name': 'target_service'
                }
            }
        }

        route_spec = obj_route.RouteSpec(host='www.test.com',
                                         path='mypath',
                                         to_service='target_service')

        ret_p_l7_rule = obj_route.RouteL7Rule(
            id='55559E11-91C2-41CF-8FD4-7970579E5C44',
            compare_type='EQUAL_TO',
            l7policy_id='55559E11-91C2-41CF-8FD4-7970579E5C45',
            type='PATH',
            value='/nice_path/')

        m_handler._drv_l7_router.ensure_l7_rule.return_value = ret_p_l7_rule
        h_route.OcpRouteHandler._sync_path_l7_rule(m_handler, route,
                                                   route_spec, route_state)
        self.assertEqual(route_state.p_l7_rule, old_p_l7_rule)
Exemplo n.º 2
0
    def test_sync_host_l7_rule_already_exist(self):
        m_handler = mock.Mock(spec=h_route.OcpRouteHandler)
        m_handler._l7_router = obj_lbaas.LBaaSLoadBalancer(
            id='00EE9E11-91C2-41CF-8FD4-7970579E5C4C',
            project_id='TEST_PROJECT')
        m_handler._drv_l7_router = mock.Mock(
            spec=d_l7_rtr.LBaaSv2L7RouterDriver)
        h_l7_rule = obj_route.RouteL7Rule(
            id='00EE9E11-91C2-41CF-8FD4-7970579E5C44',
            compare_type='EQUAL_TO',
            l7policy_id='00EE9E11-91C2-41CF-8FD4-7970579E5C45',
            type='HOST',
            value='www.example.com')

        route_state = obj_route.RouteState(h_l7_rule=h_l7_rule)
        route = {
            'metadata': {
                'namespace': 'namespace',
                'name': 'name'
            },
            'spec': {
                'host': 'www.test.com',
                'path': 'mypath',
                'to': {
                    'name': 'target_service'
                }
            }
        }

        route_spec = obj_route.RouteSpec(host='www.test.com',
                                         path='mypath',
                                         to_service='target_service')

        h_route.OcpRouteHandler._sync_host_l7_rule(m_handler, route,
                                                   route_spec, route_state)
        self.assertEqual(route_state.h_l7_rule, h_l7_rule)