示例#1
0
 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)
示例#2
0
 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)
示例#3
0
 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)
示例#4
0
 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)
示例#5
0
文件: models.py 项目: cstavr/synnefo
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)
示例#6
0
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)
示例#7
0
 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())
示例#8
0
文件: models.py 项目: cstavr/synnefo
 def put_client(client):
         put_rapi_client(client)
示例#9
0
 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())
示例#10
0
 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())
示例#11
0
 def put_client(client):
     put_rapi_client(client)