def test_get_from_pool(self, rclient): cl = rapi_pool.get_rapi_client(1, "dummyhash", "cluster1", "5080", "user", "pass") rclient.assert_called_once_with("cluster1", "5080", "user", "pass") rapi_pool.put_rapi_client(cl) rclient.reset_mock() cl2 = rapi_pool.get_rapi_client(1, "dummyhash", "cluster1", "5080", "user", "pass") self.assertTrue(cl is cl2) self.assertFalse(rclient.mock_calls)
def test_changed_credentials(self, rclient): cl = rapi_pool.get_rapi_client(1, "dummyhash2", "cluster2", "5080", "user", "pass") rclient.assert_called_once_with("cluster2", "5080", "user", "pass") rapi_pool.put_rapi_client(cl) rclient.reset_mock() rapi_pool.get_rapi_client(1, "dummyhash3", "cluster2", "5080", "user", "new_pass") rclient.assert_called_once_with("cluster2", "5080", "user", "new_pass") self.assertFalse("dummyhash2" in rapi_pool._pools)
def test_changed_credentials(self, rclient): cl = rapi_pool.get_rapi_client(1, 'dummyhash2', 'cluster2', '5080', 'user', 'pass') rclient.assert_called_once_with("cluster2", "5080", "user", "pass") rapi_pool.put_rapi_client(cl) rclient.reset_mock() rapi_pool.get_rapi_client(1, 'dummyhash3', 'cluster2', '5080', 'user', 'new_pass') rclient.assert_called_once_with("cluster2", "5080", "user", "new_pass") self.assertFalse('dummyhash2' in rapi_pool._pools)
def test_get_from_pool(self, rclient): cl = rapi_pool.get_rapi_client(1, 'dummyhash', 'cluster1', '5080', 'user', 'pass') rclient.assert_called_once_with("cluster1", "5080", "user", "pass") rapi_pool.put_rapi_client(cl) rclient.reset_mock() cl2 = rapi_pool.get_rapi_client(1, 'dummyhash', 'cluster1', '5080', 'user', 'pass') self.assertTrue(cl is cl2) self.assertFalse(rclient.mock_calls)
def pooled_rapi_client(obj): if isinstance(obj, (VirtualMachine, BackendNetwork)): backend = obj.backend else: backend = obj if backend.offline: log.warning("Trying to connect with offline backend: %s", backend) raise faults.ServiceUnavailable b = backend client = get_rapi_client(b.id, b.hash, b.clustername, b.port, b.username, b.password) try: yield client finally: put_rapi_client(client)
def pooled_rapi_client(obj): if isinstance(obj, VirtualMachine): backend = obj.backend else: backend = obj if backend.offline: log.warning("Trying to connect with offline backend: %s", backend) raise faults.ServiceUnavailable b = backend client = get_rapi_client(b.id, b.hash, b.clustername, b.port, b.username, b.password) try: yield client finally: put_rapi_client(client)
def test_no_pool(self, rclient): cl = rapi_pool.get_rapi_client(1, 'dummyhash2', 'cluster2', '5080', 'user', 'pass') cl._pool = None rapi_pool.put_rapi_client(cl) self.assertTrue(cl not in rapi_pool._pools.values())
def put_client(client): put_rapi_client(client)
def test_no_pool(self, rclient): cl = rapi_pool.get_rapi_client(1, "dummyhash2", "cluster2", "5080", "user", "pass") cl._pool = None rapi_pool.put_rapi_client(cl) self.assertTrue(cl not in rapi_pool._pools.values())