def ensure_l7_rule(self, loadbalancer, l7_policy, compare_type, type, value): l7_rule = obj_lbaas.LBaaSL7Rule(compare_type=compare_type, l7policy_id=l7_policy.id, type=type, value=value) return self._ensure_provisioned(loadbalancer, l7_rule, self._create_l7_rule, self._find_l7_rule)
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_lbaas = mock.Mock(spec=drv_base.LBaaSDriver) l7_policy = obj_lbaas.LBaaSL7Policy( id='00EE9E11-91C2-41CF-8FD4-7970579E6666', name='myname', listener_id='00EE9E11-91C2-41CF-8FD4-7970579E5C45', redirect_pool_id='00EE9E11-91C2-41CF-8FD4-7970579E5C46', project_id='00EE9E11-91C2-41CF-8FD4-7970579E5C46') route_state = obj_route.RouteState(l7_policy=l7_policy) route = { 'metadata': { 'namespace': 'namespace', 'name': 'name' }, 'spec': { 'host': 'new.www.test.com', 'path': '/nice_path', 'to': { 'name': 'target_service' } } } route_spec = obj_route.RouteSpec(host='www.test.com', path=None, to_service='target_service') ret_p_l7_rule = obj_lbaas.LBaaSL7Rule( id='55559E11-91C2-41CF-8FD4-7970579E5C44', compare_type=OCP_ROUTE_PATH_COMP_TYPE, l7policy_id='55559E11-91C2-41CF-8FD4-7970579E5C45', type='PATH', value='/nice_path') m_handler._drv_lbaas.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, ret_p_l7_rule) m_handler._drv_lbaas.ensure_l7_rule.assert_called_once_with( m_handler._l7_router, route_state.l7_policy, OCP_ROUTE_PATH_COMP_TYPE, 'PATH', route['spec']['path'])
def test_find_l7_rule_not_found(self): lbaas = self.useFixture(k_fix.MockLBaaSClient()).client cls = d_lbaasv2.LBaaSv2Driver m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver) l7_rule = obj_lbaas.LBaaSL7Rule( compare_type='EQUAL_TO', l7policy_id='D4F35594-27EB-4F4C-930C-31DD40F53B77', type='HOST_NAME', value='www.test.com') resp = {'rules': []} lbaas.list_lbaas_l7rules.return_value = resp ret = cls._find_l7_rule(m_driver, l7_rule) lbaas.list_lbaas_l7rules.assert_called_once_with( l7_rule.l7policy_id, type=l7_rule.type, value=l7_rule.value, compare_type=l7_rule.compare_type) self.assertIsNone(ret)
def test_sync_path_l7_rule_route_spec_not_sync(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_lbaas = mock.Mock(spec=drv_base.LBaaSDriver) old_p_l7_rule = obj_lbaas.LBaaSL7Rule( id='00EE9E11-91C2-41CF-8FD4-7970579E5C44', compare_type=OCP_ROUTE_PATH_COMP_TYPE, l7policy_id='00EE9E11-91C2-41CF-8FD4-7970579E5C45', type='PATH', value='/cur_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': 'new_path', 'to': { 'name': 'target_service' } } } route_spec = obj_route.RouteSpec(host='www.test.com', path='/not_cur_path', to_service='target_service') m_handler._drv_lbaas.update_l7_rule.return_value = None h_route.OcpRouteHandler._sync_path_l7_rule(m_handler, route, route_spec, route_state) self.assertEqual(route_state.p_l7_rule.value, route['spec']['path']) self.assertEqual(route_spec.path, route['spec']['path'])
def test_sync_host_l7_rule_new_host(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_lbaas = mock.Mock(spec=drv_base.LBaaSDriver) h_l7_rule = obj_lbaas.LBaaSL7Rule( 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': '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') m_handler._drv_lbaas.ensure_l7_rule.return_value = h_l7_rule h_route.OcpRouteHandler._sync_host_l7_rule(m_handler, route, route_spec, route_state) self.assertEqual(route_state.h_l7_rule.value, route['spec']['host'])
def test_find_l7_rule(self): lbaas = self.useFixture(k_fix.MockLBaaSClient()).client cls = d_lbaasv2.LBaaSv2Driver m_driver = mock.Mock(spec=d_lbaasv2.LBaaSv2Driver) l7_rule = obj_lbaas.LBaaSL7Rule( compare_type='EQUAL_TO', l7policy_id='D4F35594-27EB-4F4C-930C-31DD40F53B77', type='HOST_NAME', value='www.test.com') l7_rule_id = '3A70CEC0-392D-4BC1-A27C-06E63A0FD54F' resp = {'rules': [{'id': l7_rule_id}]} lbaas.list_lbaas_l7rules.return_value = resp ret = cls._find_l7_rule(m_driver, l7_rule) lbaas.list_lbaas_l7rules.assert_called_once_with( l7_rule.l7policy_id, type=l7_rule.type, value=l7_rule.value, compare_type=l7_rule.compare_type) for attr in l7_rule.obj_fields: self.assertEqual(getattr(l7_rule, attr), getattr(ret, attr)) self.assertEqual(l7_rule_id, ret.id)