def setUp(self): super(BaseTestEdgeLbaasV2, self).setUp() self.context = context.get_admin_context() callbacks = mock.Mock() callbacks.plugin = mock.Mock() self.edge_driver = vcns_driver.VcnsDriver(callbacks) self.lbv2_driver = mock.Mock() self.core_plugin = mock.Mock() base_mgr.LoadbalancerBaseManager._lbv2_driver = self.lbv2_driver base_mgr.LoadbalancerBaseManager._core_plugin = self.core_plugin self._patch_lb_plugin(self.lbv2_driver, self._tested_entity) self.lb = lb_models.LoadBalancer(LB_ID, LB_TENANT_ID, 'lb-name', '', 'some-subnet', 'port-id', LB_VIP) self.listener = lb_models.Listener(LISTENER_ID, LB_TENANT_ID, 'l-name', '', None, LB_ID, 'HTTP', protocol_port=80, loadbalancer=self.lb) self.sess_persist = lb_models.SessionPersistence(type='HTTP_COOKIE') self.pool = lb_models.Pool(POOL_ID, LB_TENANT_ID, 'pool-name', '', None, 'HTTP', 'ROUND_ROBIN', loadbalancer_id=LB_ID, listener=self.listener, listeners=[self.listener], loadbalancer=self.lb, session_persistence=self.sess_persist) self.listener.default_pool = self.pool self.member = lb_models.Member(MEMBER_ID, LB_TENANT_ID, POOL_ID, MEMBER_ADDRESS, 80, 1, pool=self.pool) self.hm = lb_models.HealthMonitor(HM_ID, LB_TENANT_ID, 'PING', 3, 3, 1, pool=self.pool) self.l7policy = lb_models.L7Policy(L7POL_ID, LB_TENANT_ID, name='policy-test', description='policy-desc', listener_id=LISTENER_ID, action='REJECT', listener=self.listener, position=1) self.l7rule1 = lb_models.L7Rule(L7RULE_ID1, LB_TENANT_ID, l7policy_id=L7POL_ID, compare_type='EQUAL_TO', invert=False, type='HEADER', key='key1', value='val1', policy=self.l7policy) self.l7rule2 = lb_models.L7Rule(L7RULE_ID2, LB_TENANT_ID, l7policy_id=L7POL_ID, compare_type='STARTS_WITH', invert=True, type='PATH', value='/images', policy=self.l7policy)
def _create_fake_models(self, children=True, graph=False): # This id is used for all the entities. id = 'test_id' lb = data_models.LoadBalancer(id=id) if not children: return lb sni_container = data_models.SNI(listener_id=id) listener = data_models.Listener(id=id, loadbalancer=lb, sni_containers=[sni_container]) pool = data_models.Pool(id=id, loadbalancer=lb) member = data_models.Member(id=id, pool=pool) hm = data_models.HealthMonitor(id=id, pool=pool) sp = data_models.SessionPersistence(pool_id=pool.id, pool=pool) l7policy = data_models.L7Policy( id=id, listener=listener, listener_id=listener.id, action=constants.L7_POLICY_ACTION_REDIRECT_TO_POOL) l7rule = data_models.L7Rule( id=id, policy=l7policy, type=constants.L7_RULE_TYPE_PATH, compare_type=constants.L7_RULE_COMPARE_TYPE_STARTS_WITH, value='/api') lb.listeners = [listener] lb.pools = [pool] if graph: r_pool = data_models.Pool(id=id, loadbalancer=lb) r_member = data_models.Member(id=id, pool=r_pool) r_pool.members = [r_member] l7policy.redirect_pool = r_pool l7policy.redirect_pool_id = r_pool.id lb.pools.append(r_pool) else: l7policy.redirect_pool = pool l7policy.redirect_pool_id = pool.id listener.default_pool = pool listener.l7_policies = [l7policy] l7policy.rules = [l7rule] pool.members = [member] pool.session_persistence = sp pool.healthmonitor = hm return lb