Revision 303bc802
b/lib/rapi/baserlib.py | ||
---|---|---|
34 | 34 |
from ganeti import http |
35 | 35 |
from ganeti import errors |
36 | 36 |
from ganeti import compat |
37 |
from ganeti import constants |
|
37 | 38 |
|
38 | 39 |
|
39 | 40 |
# Dummy value to detect unchanged parameters |
... | ... | |
382 | 383 |
""" |
383 | 384 |
return bool(self._checkIntVariable("dry-run")) |
384 | 385 |
|
385 |
def GetClient(self): |
|
386 |
def GetClient(self, query=False):
|
|
386 | 387 |
"""Wrapper for L{luxi.Client} with HTTP-specific error handling. |
387 | 388 |
|
389 |
@param query: this signifies that the client will only be used for |
|
390 |
queries; if the build-time parameter enable-split-queries is |
|
391 |
enabled, then the client will be connected to the query socket |
|
392 |
instead of the masterd socket |
|
393 |
|
|
388 | 394 |
""" |
395 |
if query and constants.ENABLE_SPLIT_QUERY: |
|
396 |
address = constants.QUERY_SOCKET |
|
397 |
else: |
|
398 |
address = None |
|
389 | 399 |
# Could be a function, pylint: disable=R0201 |
390 | 400 |
try: |
391 |
return self._client_cls() |
|
401 |
return self._client_cls(address=address)
|
|
392 | 402 |
except luxi.NoMasterError, err: |
393 | 403 |
raise http.HttpBadGateway("Can't connect to master daemon: %s" % err) |
394 | 404 |
except luxi.PermissionError: |
b/lib/rapi/testutils.py | ||
---|---|---|
294 | 294 |
""" |
295 | 295 |
return self._called |
296 | 296 |
|
297 |
def __call__(self): |
|
297 |
def __call__(self, address=None):
|
|
298 | 298 |
"""Creates an instrumented LUXI client. |
299 | 299 |
|
300 | 300 |
The LUXI client will record all method calls (use L{CalledNames} to |
... | ... | |
302 | 302 |
|
303 | 303 |
""" |
304 | 304 |
return luxi.Client(transport=compat.partial(_TestLuxiTransport, |
305 |
self.Record)) |
|
305 |
self.Record), |
|
306 |
address=address) |
|
306 | 307 |
|
307 | 308 |
|
308 | 309 |
def _TestWrapper(fn, *args, **kwargs): |
b/test/ganeti.rapi.rlib2_unittest.py | ||
---|---|---|
1 | 1 |
#!/usr/bin/python |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2010 Google Inc. |
|
4 |
# Copyright (C) 2010, 2012 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
57 | 57 |
|
58 | 58 |
|
59 | 59 |
class _FakeClient: |
60 |
def __init__(self): |
|
60 |
def __init__(self, address=None):
|
|
61 | 61 |
self._jobs = [] |
62 | 62 |
|
63 | 63 |
def GetNextSubmittedJob(self): |
... | ... | |
77 | 77 |
def GetNextClient(self): |
78 | 78 |
return self._clients.pop(0) |
79 | 79 |
|
80 |
def __call__(self): |
|
81 |
cl = self._client_cls() |
|
80 |
def __call__(self, address=None):
|
|
81 |
cl = self._client_cls(address=address)
|
|
82 | 82 |
self._clients.append(cl) |
83 | 83 |
return cl |
84 | 84 |
|
... | ... | |
103 | 103 |
|
104 | 104 |
class TestClientConnectError(unittest.TestCase): |
105 | 105 |
@staticmethod |
106 |
def _FailingClient(): |
|
106 |
def _FailingClient(address=None):
|
|
107 | 107 |
raise luxi.NoMasterError("test") |
108 | 108 |
|
109 | 109 |
def test(self): |
... | ... | |
119 | 119 |
|
120 | 120 |
class TestJobSubmitError(unittest.TestCase): |
121 | 121 |
class _SubmitErrorClient: |
122 |
def __init__(self, address=None): |
|
123 |
pass |
|
124 |
|
|
122 | 125 |
@staticmethod |
123 | 126 |
def SubmitJob(ops): |
124 | 127 |
raise errors.JobQueueFull("test") |
... | ... | |
1714 | 1717 |
|
1715 | 1718 |
class TestClusterInfo(unittest.TestCase): |
1716 | 1719 |
class _ClusterInfoClient: |
1717 |
def __init__(self): |
|
1720 |
def __init__(self, address=None):
|
|
1718 | 1721 |
self.cluster_info = None |
1719 | 1722 |
|
1720 | 1723 |
def QueryClusterInfo(self): |
Also available in: Unified diff