def test_context_e(self): try: with a10.A10Context(self.handler, self.ctx, self.m) as c: self.empty_mocks() c raise FakeException() except FakeException: self.empty_close_mocks()
def _test_alternate_partition(self, use_alternate=False): expected = self.a.config.get_device("axadp-alt").get("shared_partition", "shared") self.m["tenant_id"] = expected if use_alternate else "get-off-my-lawn" with a10.A10Context(self.handler, self.ctx, self.m, use_alternate_partition=use_alternate) as c: c active_mock = self.a.last_client.system.partition.active self.assertEqual(use_alternate, expected in str(active_mock.mock_calls)) self.empty_close_mocks()
def stats(self, context, pool_id): tenant_id = self.neutron.pool_get_tenant_id(context, pool_id) pool = {'id': pool_id, 'tenant_id': tenant_id} with a10.A10Context(self, context, pool) as c: try: vip_id = self.neutron.vip_get_id(context, pool['id']) vip = self.neutron.vip_get(context, vip_id) name = self.meta(vip, 'vip_name', vip['id']) r = c.client.slb.virtual_server.stats(name) return { "bytes_in": r["virtual_server_stat"]["req_bytes"], "bytes_out": r["virtual_server_stat"]["resp_bytes"], "active_connections": r["virtual_server_stat"]["cur_conns"], "total_connections": r["virtual_server_stat"]["tot_conns"] } except Exception: return { "bytes_in": 0, "bytes_out": 0, "active_connections": 0, "total_connections": 0 }
def test_context(self): with a10.A10Context(self.handler, self.ctx, self.m) as c: self.empty_mocks() c self.empty_close_mocks()