def _test_create_autosnat(self, api_ver=None, autosnat=None): saw_exception = False """ Due to how the config is pulled in, we can't override the config version here and just expect it to work. """ for k, v in self.a.config.get_devices().items(): v['api_version'] = api_ver v['autosnat'] = autosnat p = 'TCP' lb = fake_objs.FakeLoadBalancer() pool = fake_objs.FakePool(p, 'ROUND_ROBIN', None) m = fake_objs.FakeListener(p, 2222, pool=pool, loadbalancer=lb) try: self.a.listener.create(None, m) except Exception as e: saw_exception = True raise e if not saw_exception: s = str(self.a.last_client.mock_calls) self.assertIn('vport.create', s) self.assertIn('autosnat=%s' % autosnat, s)
def test_stats(self): test_lb = fake_objs.FakeLoadBalancer() self.a.lb.stats(None, test_lb) self.print_mocks() s = str(self.a.last_client.mock_calls) self.assertTrue('call.slb.virtual_server.stats' in s)
def test_update_no_pool(self): m = fake_objs.FakeListener('HTTP', 8080, pool=None, loadbalancer=fake_objs.FakeLoadBalancer()) self.a.listener.create(None, m) self.assertFalse('update' in str(self.a.last_client.mock_calls))
def _test_create_default_vrid(self, api_ver=None, default_vrid=None): """ Due to how the config is pulled in, we override the config for all of the devices. """ for k, v in self.a.config.get_devices().items(): v['api_version'] = api_ver v['default_virtual_server_vrid'] = default_vrid lb = fake_objs.FakeLoadBalancer() self.a.lb.create(None, lb) create = self.a.last_client.slb.virtual_server.create create.assert_has_calls([mock.ANY]) calls = create.call_args_list if default_vrid is not None: self.assertIn('vrid=%s' % default_vrid, str(calls)) if default_vrid is None: foundVrid = any( 'vrid' in x.get('axapi_args', {}).get('virtual_server', {}) for (_, x) in calls) self.assertFalse( foundVrid, 'Expected to find no vrid in {0}'.format(str(calls)))
def test_create(self): m = fake_objs.FakeLoadBalancer() self.a.lb.create(None, m) s = str(self.a.last_client.mock_calls) self.assertTrue('call.slb.virtual_server.create' in s) self.assertTrue('fake-lb-id-001' in s) self.assertTrue('5.5.5.5' in s) self.assertTrue('UP' in s)
def test_update_down(self): m = fake_objs.FakeLoadBalancer() m.admin_state_up = False self.a.lb.update(None, m, m) s = str(self.a.last_client.mock_calls) self.assertTrue('call.slb.virtual_server.update' in s) self.assertTrue('fake-lb-id-001' in s) self.assertTrue('5.5.5.5' in s) self.assertTrue('DOWN' in s)
def test_create_vport_expressions_none(self): p = 'TCP' lb = fake_objs.FakeLoadBalancer() pool = fake_objs.FakePool(p, 'ROUND_ROBIN', None) m = fake_objs.FakeListener(p, 2222, pool=pool, loadbalancer=lb) handler = self.a.listener handler.create(None, m) s = str(self.a.last_client.mock_calls) self.assertIn("vport.create", s)
def setUp(self, **kwargs): super(TestA10Context, self).setUp(**kwargs) self.handler = self.a.pool self.ctx = self._build_openstack_context() self.m = fake_objs.FakeLoadBalancer() self.partition_key_save = self._copy_func( a10.a10_context.A10Context.get_partition_key) self.addCleanup(self._clean_import) a10.a10_context.A10Context.get_partition_key = mock.Mock() a10.a10_context.A10Context.partition_key = 'get-off-my-lawn'
def test_create(self): admin_states = [True, False] persistences = [None, 'SOURCE_IP', 'HTTP_COOKIE', 'APP_COOKIE'] protocols = ['TCP', 'UDP', 'HTTP', 'HTTPS'] lb = fake_objs.FakeLoadBalancer() for a in admin_states: for pers in persistences: for p in protocols: self.a.reset_mocks() pool = fake_objs.FakePool(p, 'ROUND_ROBIN', pers) m = fake_objs.FakeListener(p, 2222, pool=pool, loadbalancer=lb) pool.listener = m saw_exception = False try: self.a.listener.create(None, m) except a10_ex.UnsupportedFeature as e: if pers == 'APP_COOKIE': saw_exception = True else: raise e self.print_mocks() if not saw_exception: s = str(self.a.last_client.mock_calls) self.assertTrue('vport.create' in s) self.assertTrue('fake-lb-id-001' in s) self.assertTrue('fake-listen-id-001' in s) self.assertTrue('port=2222' in s) test_prot = p if p in ('HTTPS', constants.PROTOCOL_TERMINATED_HTTPS): test_prot = 'TCP' self.assertTrue(test_prot in s) if pers == 'SOURCE_IP': self.assertTrue('s_pers_name=None' not in s) pass elif pers == 'HTTP_COOKIE': self.assertTrue('s_pers=HTTP_COOKIE') self.assertTrue('c_pers_name=None' not in s) pass elif pers == 'APP_COOKIE': self.assertTrue('s_pers=APP_COOKIE') self.assertTrue('c_pers_name=None' not in s) pass else: self.assertTrue('c_pers_name=None' in s) self.assertTrue('s_pers_name=None' in s)
def test_stats_v21(self): test_lb = fake_objs.FakeLoadBalancer() test_lb.stats_v21() c = mock.MagicMock() c.client.slb.virtual_service.get = mock.Mock( return_value=test_lb.virt_service) c.client.slb.service_group.stats = mock.Mock( return_value=test_lb.serv_group) ret_val = self.a.lb._stats_v21(c, test_lb.virt_server) self.print_mocks() self.assertEqual(ret_val, test_lb.ret_stats)
def test_delete_no_db_delete_use_database_false(self): pool = fake_objs.FakePool('TCP', 'ROUND_ROBIN', None) lb = fake_objs.FakeLoadBalancer() m = fake_objs.FakeListener('TCP', 2222, pool=pool, loadbalancer=lb) binding = fake_objs.FakeCertificateBinding(listener_id=m.id) pool.listener = m bindings = [binding] get_bindings_mock = mock.Mock(return_value=bindings) self.a.listener.cert_db.get_bindings_for_listener = get_bindings_mock self.a.listener.delete(None, m) expected = self.a.listener.cert_db.delete_a10_certificate_binding.call_count self.assertEqual(expected, 0)
def test_create_vport_expressions_noname(self): get_expr_mock = mock.MagicMock() get_expr_mock.return_value = {} self.a.config.get_vport_expressions = get_expr_mock p = 'TCP' lb = fake_objs.FakeLoadBalancer() pool = fake_objs.FakePool(p, 'ROUND_ROBIN', None) m = fake_objs.FakeListener(p, 2222, pool=pool, loadbalancer=lb) m.name = None handler = self.a.listener handler.create(None, m)
def test_create_expressions_nomatch(self): self.a.config.get_virtual_server_expressions = self._get_expressions_mock expressions = self.a.config.get_virtual_server_expressions() expected = expressions.get(self.EXPR_BEGIN, {}).get("json", None) or "" m = fake_objs.FakeLoadBalancer() m.name = "mylb" handler = self.a.lb handler.create(None, m) s = str(self.a.last_client.mock_calls) self.assertIn("virtual_server.create", s) self.assertNotIn(str(expected), s)
def test_stats_v30(self): test_lb = fake_objs.FakeLoadBalancer() test_lb.stats_v30() c = mock.MagicMock() c.client.slb.virtual_server.get = mock.Mock( return_value=test_lb.virt_server) c.client.slb.service_group.stats = mock.Mock( return_value=test_lb.service_group) c.client.slb.service_group.get = mock.Mock( return_value=test_lb.members) ret_val = self.a.lb._stats_v30(c, test_lb.port_list, None) self.print_mocks() self.assertEqual(ret_val, test_lb.ret_stats_v30)
def _test_create_expressions(self, os_name, pattern, expressions=None): self.a.config.get_virtual_server_expressions = self._get_expressions_mock expressions = expressions or self.a.config.get_virtual_server_expressions( ) expected = expressions.get(pattern, {}).get("json", None) or "" m = fake_objs.FakeLoadBalancer() m.name = os_name handler = self.a.lb handler.create(None, m) s = str(self.a.last_client.mock_calls) self.assertIn("virtual_server.create", s) self.assertIn(str(expected), s)
def test_barbican_client_not_null(self, certmgr): """This tests that the barbican_client dependency is always there.""" handler = self.a.listener pool = fake_objs.FakePool(constants.PROTOCOL_TERMINATED_HTTPS, constants.LB_METHOD_ROUND_ROBIN, None) lb = fake_objs.FakeLoadBalancer() m = fake_objs.FakeListener(constants.PROTOCOL_TERMINATED_HTTPS, 2222, pool=pool, loadbalancer=lb) pool.listener = m handler.create(None, m) self.assertTrue(handler.barbican_client is not None)
def test_create_vport_defaults_global(self): expected = self.a.config.get_vport_defaults() p = 'TCP' lb = fake_objs.FakeLoadBalancer() pool = fake_objs.FakePool(p, 'ROUND_ROBIN', None) m = fake_objs.FakeListener(p, 2222, pool=pool, loadbalancer=lb) handler = self.a.listener handler.create(None, m) self.print_mocks() s = str(self.a.last_client.mock_calls) self.assertIn("vport.create", s) self.assertIn(str(expected), s)
def test_delete(self): pool = fake_objs.FakePool('HTTP', 'ROUND_ROBIN', None) lb = fake_objs.FakeLoadBalancer() m = fake_objs.FakeListener('HTTP', 2222, pool=pool, loadbalancer=lb) pool.listener = m self.a.listener.delete(None, m) self.print_mocks() s = str(self.a.last_client.mock_calls) self.assertTrue('vport.delete' in s) self.assertTrue('fake-lb-id-001' in s) self.assertTrue('fake-listen-id-001' in s) self.assertTrue('port=2222' in s) self.assertTrue('HTTP' in s)
def _test_create_expressions(self, os_name, pattern, expressions=None): self.a.config.get_vport_expressions = self._get_expressions_mock expressions = expressions or self.a.config.get_vport_expressions() expected = expressions.get(pattern, {}).get("json", {}) p = 'TCP' lb = fake_objs.FakeLoadBalancer() pool = fake_objs.FakePool(p, 'ROUND_ROBIN', None) m = fake_objs.FakeListener(p, 2222, pool=pool, loadbalancer=lb) m.name = os_name handler = self.a.listener handler.create(None, m) s = str(self.a.last_client.mock_calls) self.assertIn("vport.create", s) self.assertIn(str(expected), s)
def test_create_vport_expressions_nomatch(self): self.a.config.get_vport_expressions = self._get_expressions_mock expressions = self.a.config.get_vport_expressions() expected = expressions[self.EXPR_BEGIN].get("json", {}) p = 'TCP' lb = fake_objs.FakeLoadBalancer() pool = fake_objs.FakePool(p, 'ROUND_ROBIN', None) m = fake_objs.FakeListener(p, 2222, pool=pool, loadbalancer=lb) m.name = "insecurelistener" handler = self.a.listener handler.create(None, m) s = str(self.a.last_client.mock_calls) self.assertIn("vport.create", s) self.assertNotIn(str(expected), s)
def _test_create_ipinip(self, api_ver="3.0", ip_in_ip=False): for k, v in self.a.config.devices.items(): v['ipinip'] = ip_in_ip v['api_version'] = api_ver p = 'TCP' lb = fake_objs.FakeLoadBalancer() pool = fake_objs.FakePool(p, 'ROUND_ROBIN', None) m = fake_objs.FakeListener(p, 2222, pool=pool, loadbalancer=lb) self.a.listener.create(None, m) self.print_mocks() s = str(self.a.last_client.mock_calls) self.assertIn("vport.create", s) self.assertIn("ipinip=%s" % ip_in_ip, s)
def _tls_container_shared(self): certmgr = FakeCertManager() certmgr.certificate = "CERTDATA" certmgr.private_key = "PRIVATEKEY" certmgr.private_key_passphrase = "SECRETPASSWORD" self.a.barbican_client = certmgr handler = self.a.listener pool = fake_objs.FakePool(constants.PROTOCOL_TERMINATED_HTTPS, constants.LB_METHOD_ROUND_ROBIN, None) lb = fake_objs.FakeLoadBalancer() m = fake_objs.FakeListener(constants.PROTOCOL_TERMINATED_HTTPS, 2222, pool=pool, loadbalancer=lb) return (certmgr, m, pool, handler)
def test_create_protocol_terminated_https(self): pool = fake_objs.FakePool(constants.PROTOCOL_TERMINATED_HTTPS, constants.LB_METHOD_ROUND_ROBIN, None) lb = fake_objs.FakeLoadBalancer() m = fake_objs.FakeListener(constants.PROTOCOL_TERMINATED_HTTPS, 2222, pool=pool, loadbalancer=lb) m.default_tls_container_id = "CONTAINERID" pool.listener = m certmgr = FakeCertManager() self.a.barbican_client = certmgr self.a.listener.create(None, m) s = str(self.a.last_client.mock_calls) self.assertTrue('HTTPS' in s)
def _test_create_source_nat_pool(self, source_nat_pool): if source_nat_pool: for k, v in self.a.config.devices.items(): v['source_nat_pool'] = source_nat_pool p = 'TCP' lb = fake_objs.FakeLoadBalancer() pool = fake_objs.FakePool(p, 'ROUND_ROBIN', None) m = fake_objs.FakeListener(p, 2222, pool=pool, loadbalancer=lb) self.a.listener.create(None, m) self.print_mocks() s = str(self.a.last_client.mock_calls) self.assertIn("vport.create", s) if source_nat_pool: expected = "source_nat_pool='{0}'".format(source_nat_pool) self.assertIn(expected, s) else: self.assertIn("source_nat_pool=None", s)
def test_delete(self): pool = fake_objs.FakePool(constants.PROTOCOL_TERMINATED_HTTPS, constants.LB_METHOD_ROUND_ROBIN, None) lb = fake_objs.FakeLoadBalancer() m = fake_objs.FakeListener(constants.PROTOCOL_TERMINATED_HTTPS, 2222, pool=pool, loadbalancer=lb) pool.listener = m self.a.listener.delete(None, m) self.print_mocks() s = str(self.a.last_client.mock_calls) LOG.debug("DELETE RESULT %s" % s) self.assertTrue('vport.delete' in s) self.assertTrue('fake-lb-id-001' in s) self.assertTrue('fake-listen-id-001' in s) self.assertTrue('port=2222' in s) self.assertTrue('HTTPS' in s)
def test_update(self): pool = fake_objs.FakePool(constants.PROTOCOL_TERMINATED_HTTPS, constants.LB_METHOD_ROUND_ROBIN, None) lb = fake_objs.FakeLoadBalancer() m = fake_objs.FakeListener(constants.PROTOCOL_TERMINATED_HTTPS, 2222, pool=pool, loadbalancer=lb) certmgr = FakeCertManager() self.a.barbican_client = certmgr # self.a.listener.set_certmgr(certmgr) pool.listener = m self.a.listener.update(None, m, m) self.print_mocks() s = str(self.a.last_client.mock_calls) self.assertTrue('vport.update' in s) self.assertTrue('fake-lb-id-001' in s) self.assertTrue('fake-listen-id-001' in s) self.assertTrue('port=2222' in s) self.assertTrue('HTTPS' in s)
def setUp(self, **kwargs): super(TestA10Context, self).setUp(**kwargs) self.handler = self.a.pool self.ctx = self._build_openstack_context() self.m = fake_objs.FakeLoadBalancer()
def test_delete(self): m = fake_objs.FakeLoadBalancer() self.a.lb.delete(None, m) s = str(self.a.last_client.mock_calls) self.assertTrue('call.slb.virtual_server.delete' in s) self.assertTrue(m.id in s)
def test_delete_removes_slb(self): m = fake_objs.FakeLoadBalancer() self.a.lb.delete(None, m)
def test_refresh(self): try: self.a.lb.refresh(None, fake_objs.FakeLoadBalancer()) except a10_ex.UnsupportedFeature: pass