def test_create_loadbalancer_failed(self, mlb):
        loadbalancer = data_models.LoadBalancer(id='1')

        self.assertIn(loadbalancer.id, self.mgr.instance_mapping)
        self.driver_mock.loadbalancer.create.side_effect = Exception
        mlb.return_value = loadbalancer
        self.mgr.create_loadbalancer(mock.Mock(), loadbalancer.to_dict(),
                                     'devdriver')
        self.driver_mock.loadbalancer.create.assert_called_once_with(
            loadbalancer)
        self.update_statuses.assert_called_once_with(loadbalancer, error=True)
Example #2
0
 def test_update_pool(self, mpool):
     loadbalancer = data_models.LoadBalancer(id='1')
     listener = data_models.Listener(id=1,
                                     loadbalancer_id='1',
                                     loadbalancer=loadbalancer)
     pool = data_models.Pool(id='1', listener=listener, protocol='HTTPS')
     old_pool = data_models.Pool(id='1', listener=listener, protocol='HTTP')
     mpool.side_effect = [pool, old_pool]
     self.mgr.update_pool(mock.Mock(), old_pool.to_dict(), pool.to_dict())
     self.driver_mock.pool.update.assert_called_once_with(old_pool, pool)
     self.update_statuses.assert_called_once_with(pool)
Example #3
0
 def test_create_monitor(self, mmonitor):
     loadbalancer = data_models.LoadBalancer(id='1')
     listener = data_models.Listener(id=1,
                                     loadbalancer_id='1',
                                     loadbalancer=loadbalancer)
     pool = data_models.Pool(id='1', listener=listener, protocol='HTTPS')
     monitor = data_models.HealthMonitor(id='1', pool=pool)
     mmonitor.return_value = monitor
     self.mgr.create_healthmonitor(mock.Mock(), monitor.to_dict())
     self.driver_mock.healthmonitor.create.assert_called_once_with(monitor)
     self.update_statuses.assert_called_once_with(monitor)
Example #4
0
    def test_create_pool(self, mpool):
        loadbalancer = data_models.LoadBalancer(id='1')
        listener = data_models.Listener(id=1,
                                        loadbalancer_id='1',
                                        loadbalancer=loadbalancer)
        pool = data_models.Pool(id='1', listener=listener)

        mpool.return_value = pool
        self.mgr.create_pool(mock.Mock(), pool.to_dict())
        self.driver_mock.pool.create.assert_called_once_with(pool)
        self.update_statuses.assert_called_once_with(pool)
Example #5
0
    def test_create_listener(self, mlistener):
        loadbalancer = data_models.LoadBalancer(id='1')
        listener = data_models.Listener(id=1,
                                        loadbalancer_id='1',
                                        loadbalancer=loadbalancer)

        self.assertIn(loadbalancer.id, self.mgr.instance_mapping)
        mlistener.return_value = listener
        self.mgr.create_listener(mock.Mock(), listener.to_dict())
        self.driver_mock.listener.create.assert_called_once_with(listener)
        self.update_statuses.assert_called_once_with(listener)
 def test_update_monitor(self, mmonitor):
     loadbalancer = data_models.LoadBalancer(id='1')
     pool = data_models.Pool(id='1', loadbalancer=loadbalancer,
                             protocol='HTTPS')
     monitor = data_models.HealthMonitor(id='1', pool=pool, delay=1)
     old_monitor = data_models.HealthMonitor(id='1', pool=pool, delay=2)
     mmonitor.side_effect = [monitor, old_monitor]
     self.mgr.update_healthmonitor(mock.Mock(), old_monitor.to_dict(),
                                   monitor.to_dict())
     self.driver_mock.healthmonitor.update.assert_called_once_with(
         old_monitor, monitor)
     self.update_statuses.assert_called_once_with(monitor)
 def test_update_member(self, mmember):
     loadbalancer = data_models.LoadBalancer(id='1')
     pool = data_models.Pool(id='1', loadbalancer=loadbalancer,
                             protocol='HTTPS')
     member = data_models.Member(id='1', pool=pool, weight=1)
     old_member = data_models.Member(id='1', pool=pool, weight=2)
     mmember.side_effect = [member, old_member]
     self.mgr.update_member(mock.Mock(), old_member.to_dict(),
                            member.to_dict())
     self.driver_mock.member.update.assert_called_once_with(old_member,
                                                            member)
     self.update_statuses.assert_called_once_with(member)
Example #8
0
 def test_create_member_failed(self, mmember):
     loadbalancer = data_models.LoadBalancer(id='1')
     listener = data_models.Listener(id=1,
                                     loadbalancer_id='1',
                                     loadbalancer=loadbalancer)
     pool = data_models.Pool(id='1', listener=listener, protocol='HTTPS')
     member = data_models.Member(id='1', pool=pool)
     mmember.return_value = member
     self.driver_mock.member.create.side_effect = Exception
     self.mgr.create_member(mock.Mock(), member.to_dict())
     self.driver_mock.member.create.assert_called_once_with(member)
     self.update_statuses.assert_called_once_with(member, error=True)
Example #9
0
    def test_create_pool_failed(self, mpool):
        loadbalancer = data_models.LoadBalancer(id='1')
        listener = data_models.Listener(id=1,
                                        loadbalancer_id='1',
                                        loadbalancer=loadbalancer)
        pool = data_models.Pool(id='1', listener=listener)

        mpool.return_value = pool
        self.driver_mock.pool.create.side_effect = Exception
        self.mgr.create_pool(mock.Mock(), pool)
        self.driver_mock.pool.create.assert_called_once_with(pool)
        self.update_statuses.assert_called_once_with(pool, error=True)
 def _create_fake_models(self):
     id = 'name-001'
     lb = data_models.LoadBalancer(id=id)
     listener = data_models.Listener(id=id, loadbalancer=lb)
     pool = data_models.Pool(id=id, listener=listener)
     member = data_models.Member(id=id, pool=pool)
     hm = data_models.HealthMonitor(id=id, pool=pool)
     lb.listeners = [listener]
     listener.default_pool = pool
     pool.members = [member]
     pool.healthmonitor = hm
     return lb
    def setUp(self):
        super(BaseTestEdgeLbaasV2, self).setUp()

        self.context = context.get_admin_context()
        self.edge_driver = lb_driver_v2.EdgeLoadbalancerDriverV2()

        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._patch_nsxlib_lb_clients(self.core_plugin)

        self.lb = lb_models.LoadBalancer(LB_ID, LB_TENANT_ID, 'lb1', '',
                                         'some-subnet', 'port-id', LB_VIP)
        self.listener = lb_models.Listener(LISTENER_ID, LB_TENANT_ID,
                                           'listener1', 'Dummy', None, LB_ID,
                                           'HTTP', protocol_port=80,
                                           loadbalancer=self.lb)
        self.https_listener = lb_models.Listener(
            LISTENER_ID, LB_TENANT_ID, 'listener1', '', None, LB_ID,
            'HTTPS', protocol_port=443, loadbalancer=self.lb)
        self.terminated_https_listener = lb_models.Listener(
            LISTENER_ID, LB_TENANT_ID, 'listener1', '', None, LB_ID,
            'TERMINATED_HTTPS', protocol_port=443, loadbalancer=self.lb)
        self.pool = lb_models.Pool(POOL_ID, LB_TENANT_ID, 'pool1', '',
                                   None, 'HTTP', 'ROUND_ROBIN',
                                   loadbalancer_id=LB_ID,
                                   listener=self.listener,
                                   listeners=[self.listener],
                                   loadbalancer=self.lb)
        self.member = lb_models.Member(MEMBER_ID, LB_TENANT_ID, POOL_ID,
                                       MEMBER_ADDRESS, 80, 1, pool=self.pool,
                                       name='member1')
        self.hm = lb_models.HealthMonitor(HM_ID, LB_TENANT_ID, 'PING', 3, 3,
                                          1, pool=self.pool, name='hm1')
        self.l7policy = lb_models.L7Policy(L7POLICY_ID, LB_TENANT_ID,
                                           name='policy-test',
                                           description='policy-desc',
                                           listener_id=LISTENER_ID,
                                           action='REDIRECT_TO_POOL',
                                           redirect_pool_id=POOL_ID,
                                           listener=self.listener,
                                           position=1)
        self.l7rule = lb_models.L7Rule(L7RULE_ID, LB_TENANT_ID,
                                       l7policy_id=L7POLICY_ID,
                                       compare_type='EQUAL_TO',
                                       invert=False,
                                       type='HEADER',
                                       key='key1',
                                       value='val1',
                                       policy=self.l7policy)
    def test_reload_loadbalancer_driver_not_found(self):
        lb = data_models.LoadBalancer(id='1').to_dict()
        lb['provider'] = {'device_driver': 'unknowndriver'}
        self.rpc_mock.get_loadbalancer.return_value = lb
        lb_id = 'new_id'
        self.assertNotIn(lb_id, self.mgr.instance_mapping)

        self.mgr._reload_loadbalancer(lb_id)

        self.assertTrue(self.log.error.called)
        self.assertFalse(self.driver_mock.deploy_instance.called)
        self.assertNotIn(lb_id, self.mgr.instance_mapping)
        self.assertFalse(self.rpc_mock.loadbalancer_deployed.called)
    def test_update_statuses_loadbalancer(self):
        self.update_statuses_patcher.stop()
        lb = data_models.LoadBalancer(id='1')
        self.mgr._update_statuses(lb)
        self.rpc_mock.update_status.assert_called_once_with(
            'loadbalancer', lb.id, provisioning_status=constants.ACTIVE,
            operating_status=lb_const.ONLINE)

        self.rpc_mock.update_status.reset_mock()
        self.mgr._update_statuses(lb, error=True)
        self.rpc_mock.update_status.assert_called_once_with(
            'loadbalancer', lb.id, provisioning_status=constants.ERROR,
            operating_status=lb_const.OFFLINE)
 def test_update_listener_failed(self, mlistener):
     loadbalancer = data_models.LoadBalancer(id='1')
     old_listener = data_models.Listener(id=1, loadbalancer_id='1',
                                         loadbalancer=loadbalancer,
                                         protocol_port=80)
     listener = data_models.Listener(id=1, loadbalancer_id='1',
                                     loadbalancer=loadbalancer,
                                     protocol_port=81)
     mlistener.side_effect = [listener, old_listener]
     self.driver_mock.listener.update.side_effect = Exception
     self.mgr.update_listener(mock.Mock(), old_listener, listener)
     self.driver_mock.listener.update.assert_called_once_with(old_listener,
                                                              listener)
     self.update_statuses.assert_called_once_with(listener, error=True)
 def _build_mock_data_models(self):
     host_route = data_models.HostRoute(destination='0.0.0.0/0',
                                        nexthop='192.0.0.1')
     subnet = data_models.Subnet(cidr='10.0.0.1/24',
                                 gateway_ip='10.0.0.2',
                                 host_routes=[host_route])
     fixed_ip = data_models.IPAllocation(ip_address='10.0.0.1')
     setattr(fixed_ip, 'subnet', subnet)
     port = data_models.Port(id='port1', network_id='network1',
                             mac_address='12-34-56-78-9A-BC',
                             fixed_ips=[fixed_ip])
     self.lb = data_models.LoadBalancer(id='lb1', listeners=[],
                                        vip_port=port,
                                        vip_address='10.0.0.1')
    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.EdgeLoadbalancerBaseManager._lbv2_driver = self.lbv2_driver
        base_mgr.EdgeLoadbalancerBaseManager._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.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])
        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)
Example #17
0
 def test_get_ready_devices(self):
     with self.loadbalancer() as loadbalancer:
         lb_id = loadbalancer['loadbalancer']['id']
         self.plugin_instance.db.update_loadbalancer_provisioning_status(
             context.get_admin_context(),
             loadbalancer['loadbalancer']['id'])
         with mock.patch(
                 'neutron_lbaas.agent_scheduler.LbaasAgentSchedulerDbMixin.'
                 'list_loadbalancers_on_lbaas_agent') as mock_agent_lbs:
             mock_agent_lbs.return_value = [
                 data_models.LoadBalancer(id=lb_id)
             ]
             ready = self.callbacks.get_ready_devices(
                 context.get_admin_context(), )
             self.assertEqual([lb_id], ready)
    def test_reload_loadbalancer(self):
        lb = data_models.LoadBalancer(id='1').to_dict()
        lb['provider'] = {'device_driver': 'devdriver'}
        self.rpc_mock.get_loadbalancer.return_value = lb
        lb_id = 'new_id'
        self.assertNotIn(lb_id, self.mgr.instance_mapping)

        self.mgr._reload_loadbalancer(lb_id)

        calls = self.driver_mock.deploy_instance.call_args_list
        self.assertEqual(1, len(calls))
        called_lb = calls[0][0][0]
        self.assertEqual(lb['id'], called_lb.id)
        self.assertIn(lb['id'], self.mgr.instance_mapping)
        self.rpc_mock.loadbalancer_deployed.assert_called_once_with(lb_id)
 def _create_fake_models(self):
     # This id is used for all the entities.
     id = 'test_id'
     lb = data_models.LoadBalancer(id=id)
     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, listener=listener)
     member = data_models.Member(id=id, pool=pool)
     hm = data_models.HealthMonitor(id=id, pool=pool)
     lb.listeners = [listener]
     listener.default_pool = pool
     pool.members = [member]
     pool.healthmonitor = hm
     return lb
    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
    def test_reload_loadbalancer_exception_on_driver(self):
        lb = data_models.LoadBalancer(id='3').to_dict()
        lb['provider'] = {'device_driver': 'devdriver'}
        self.rpc_mock.get_loadbalancer.return_value = lb
        self.driver_mock.deploy_instance.side_effect = Exception
        lb_id = 'new_id'
        self.assertNotIn(lb_id, self.mgr.instance_mapping)

        self.mgr._reload_loadbalancer(lb_id)

        calls = self.driver_mock.deploy_instance.call_args_list
        self.assertEqual(1, len(calls))
        called_lb = calls[0][0][0]
        self.assertEqual(lb['id'], called_lb.id)
        self.assertNotIn(lb['id'], self.mgr.instance_mapping)
        self.assertFalse(self.rpc_mock.loadbalancer_deployed.called)
        self.assertTrue(self.log.exception.called)
        self.assertTrue(self.mgr.needs_resync)
Example #22
0
    def _get_faked_model(obj):
        lb = data_models.LoadBalancer(id='test_lb')
        if obj == 'lbaas/loadbalancer':
            return lb

        pool = data_models.Pool(id='test_pool_id', loadbalancer=lb)
        if obj == 'lbaas/pool':
            return pool

        listener = data_models.Listener(id='test_listener_id', loadbalancer=lb)
        if obj == 'lbaas/listener':
            return listener

        member = data_models.Member(id='test_member_id', pool=pool)
        if obj == 'lbaas/member':
            return member

        hm = data_models.HealthMonitor(id='test_health_monitor_id', pool=pool)

        return hm
    def test_refresh(self, lb_from_dict):
        rpc_return = {'id': self.in_lb.id}
        self.driver.plugin_rpc.get_loadbalancer.return_value = rpc_return
        from_dict_return = data_models.LoadBalancer(id=self.in_lb.id)
        lb_from_dict.return_value = from_dict_return
        self.driver.deploy_instance.return_value = True
        self.driver.exists.return_value = True
        self.lb_manager.refresh(self.in_lb)
        self.driver.plugin_rpc.get_loadbalancer.assert_called_once_with(
            self.in_lb.id)
        lb_from_dict.assert_called_once_with(rpc_return)
        self.driver.deploy_instance.assert_called_once_with(from_dict_return)
        self.assertFalse(self.driver.exists.called)
        self.assertFalse(self.driver.undeploy_instance.called)

        self.driver.reset_mock()
        lb_from_dict.reset_mock()
        self.driver.deploy_instance.return_value = False
        self.driver.exists.return_value = False
        self.lb_manager.refresh(self.in_lb)
        self.driver.plugin_rpc.get_loadbalancer.assert_called_once_with(
            self.in_lb.id)
        lb_from_dict.assert_called_once_with(rpc_return)
        self.driver.deploy_instance.assert_called_once_with(from_dict_return)
        self.driver.exists.assert_called_once_with(self.in_lb.id)
        self.assertFalse(self.driver.undeploy_instance.called)

        self.driver.reset_mock()
        lb_from_dict.reset_mock()
        self.driver.deploy_instance.return_value = False
        self.driver.exists.return_value = True
        self.lb_manager.refresh(self.in_lb)
        self.driver.plugin_rpc.get_loadbalancer.assert_called_once_with(
            self.in_lb.id)
        lb_from_dict.assert_called_once_with(rpc_return)
        self.driver.deploy_instance.assert_called_once_with(from_dict_return)
        self.driver.exists.assert_called_once_with(from_dict_return.id)
        self.driver.undeploy_instance.assert_called_once_with(self.in_lb.id)
Example #24
0
 def test_get_ready_devices_inactive_loadbalancer(self):
     with self.loadbalancer() as loadbalancer:
         lb_id = loadbalancer['loadbalancer']['id']
         self.plugin_instance.db.update_loadbalancer_provisioning_status(
             context.get_admin_context(),
             loadbalancer['loadbalancer']['id'])
         # set the loadbalancer inactive need to use plugin directly since
         # status is not tenant mutable
         self.plugin_instance.db.update_loadbalancer(
             context.get_admin_context(),
             loadbalancer['loadbalancer']['id'],
             {'loadbalancer': {
                 'provisioning_status': constants.INACTIVE
             }})
         with mock.patch(
                 'neutron_lbaas.agent_scheduler.LbaasAgentSchedulerDbMixin.'
                 'list_loadbalancers_on_lbaas_agent') as mock_agent_lbs:
             mock_agent_lbs.return_value = [
                 data_models.LoadBalancer(id=lb_id)
             ]
             ready = self.callbacks.get_ready_devices(
                 context.get_admin_context(), )
             self.assertEqual([loadbalancer['loadbalancer']['id']], ready)
    def test_update_statuses_healthmonitor(self):
        self.update_statuses_patcher.stop()
        hm = data_models.HealthMonitor(id='1')
        pool = data_models.Pool(id='1', healthmonitor=hm)
        hm.pool = pool
        listener = data_models.Listener(id='1', default_pool=pool)
        lb = data_models.LoadBalancer(id='1', listeners=[listener])
        listener.loadbalancer = lb
        pool.loadbalancer = lb
        self.mgr._update_statuses(hm)
        self.assertEqual(2, self.rpc_mock.update_status.call_count)
        calls = [
            mock.call('healthmonitor',
                      hm.id,
                      provisioning_status=constants.ACTIVE,
                      operating_status=None),
            mock.call('loadbalancer',
                      lb.id,
                      provisioning_status=constants.ACTIVE,
                      operating_status=None)
        ]
        self.rpc_mock.update_status.assert_has_calls(calls)

        self.rpc_mock.update_status.reset_mock()
        self.mgr._update_statuses(hm, error=True)
        self.assertEqual(2, self.rpc_mock.update_status.call_count)
        calls = [
            mock.call('healthmonitor',
                      hm.id,
                      provisioning_status=constants.ERROR,
                      operating_status=None),
            mock.call('loadbalancer',
                      lb.id,
                      provisioning_status=constants.ACTIVE,
                      operating_status=None)
        ]
        self.rpc_mock.update_status.assert_has_calls(calls)
    def test_update_statuses_member(self):
        self.update_statuses_patcher.stop()
        member = data_models.Member(id='1')
        pool = data_models.Pool(id='1', members=[member])
        member.pool = pool
        listener = data_models.Listener(id='1', default_pool=pool)
        lb = data_models.LoadBalancer(id='1', listeners=[listener])
        listener.loadbalancer = lb
        pool.loadbalancer = lb
        self.mgr._update_statuses(member)
        self.assertEqual(2, self.rpc_mock.update_status.call_count)
        calls = [
            mock.call('member',
                      member.id,
                      provisioning_status=constants.ACTIVE,
                      operating_status=lb_const.ONLINE),
            mock.call('loadbalancer',
                      lb.id,
                      provisioning_status=constants.ACTIVE,
                      operating_status=None)
        ]
        self.rpc_mock.update_status.assert_has_calls(calls)

        self.rpc_mock.update_status.reset_mock()
        self.mgr._update_statuses(member, error=True)
        self.assertEqual(2, self.rpc_mock.update_status.call_count)
        calls = [
            mock.call('member',
                      member.id,
                      provisioning_status=constants.ERROR,
                      operating_status=lb_const.OFFLINE),
            mock.call('loadbalancer',
                      lb.id,
                      provisioning_status=constants.ACTIVE,
                      operating_status=None)
        ]
        self.rpc_mock.update_status.assert_has_calls(calls)
 def test_update(self):
     old_lb = data_models.LoadBalancer(id='lb0')
     self.lb_manager.refresh = mock.Mock()
     self.lb_manager.update(old_lb, self.in_lb)
     self.lb_manager.refresh.assert_called_once_with(self.in_lb)
 def setUp(self):
     super(BaseTestLoadBalancerManager, self).setUp()
     self.in_lb = data_models.LoadBalancer(id='lb1', listeners=[])
    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)