Change in vdsm[master]: stomp: make sure that we are connected before sending data
piotr.kliczewski at gmail.com
piotr.kliczewski at gmail.com
Thu Mar 10 09:31:46 UTC 2016
Piotr Kliczewski has uploaded a new change for review.
Change subject: stomp: make sure that we are connected before sending data
......................................................................
stomp: make sure that we are connected before sending data
There could be a situation that we send data before we receive
CONNECTED frame. When the frame arrives it is assumed be a response and
the test fails due to lack of data. To fix this issue we would retry to
send message waiting on confirmation that we are connected.
Change-Id: I08c914170d2dfa6f8d74c5e712a97b5e34b0fd77
Signed-off-by: pkliczewski <piotr.kliczewski at gmail.com>
---
M lib/yajsonrpc/__init__.py
M lib/yajsonrpc/stomp.py
M tests/stompAsyncClientTests.py
3 files changed, 18 insertions(+), 4 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/78/54578/1
diff --git a/lib/yajsonrpc/__init__.py b/lib/yajsonrpc/__init__.py
index a5e42b8..4b36d5e 100644
--- a/lib/yajsonrpc/__init__.py
+++ b/lib/yajsonrpc/__init__.py
@@ -22,7 +22,8 @@
from vdsm.compat import json
from vdsm.password import protect_passwords, unprotect_passwords
-from vdsm.utils import monotonic_time, traceback
+from vdsm.utils import monotonic_time, retry, traceback
+from yajsonrpc.stomp import NotConnected
__all__ = ["betterAsyncore", "stompreactor", "stomp"]
@@ -352,7 +353,8 @@
def call_async(self, *reqs):
call = JsonRpcCall()
- self.call_cb(call.callback, *reqs)
+ func = partial(self.call_cb, call.callback, *reqs)
+ retry(func, NotConnected, tries=5)
return call
def call_cb(self, cb, *reqs):
@@ -367,8 +369,12 @@
raise ValueError("Request id already in use %s", rid)
self._runningRequests[rid] = ctx
-
- self._transport.send(ctx.encode())
+ try:
+ self._transport.send(ctx.encode())
+ except:
+ with self._lock:
+ del self._runningRequests[rid]
+ raise
# All notifications
if ctx.isDone():
diff --git a/lib/yajsonrpc/stomp.py b/lib/yajsonrpc/stomp.py
index cd1ca06..da914cf 100644
--- a/lib/yajsonrpc/stomp.py
+++ b/lib/yajsonrpc/stomp.py
@@ -428,6 +428,10 @@
self.connection.close()
+class NotConnected(Exception):
+ pass
+
+
class AsyncClient(object):
log = logging.getLogger("yajsonrpc.protocols.stomp.AsyncClient")
@@ -506,6 +510,9 @@
raise StompError(frame)
def send(self, destination, data="", headers=None):
+ if not self._connected:
+ raise NotConnected()
+
final_headers = {"destination": destination}
if headers is not None:
final_headers.update(headers)
diff --git a/tests/stompAsyncClientTests.py b/tests/stompAsyncClientTests.py
index 4ffc327..a3fc76e 100644
--- a/tests/stompAsyncClientTests.py
+++ b/tests/stompAsyncClientTests.py
@@ -76,6 +76,7 @@
def test_send(self):
client = AsyncClient()
+ client._connected = True
data = ('{"jsonrpc":"2.0","method":"Host.getAllVmStats","params":{},'
'"id":"e8a936a6-d886-4cfa-97b9-2d54209053ff"}')
headers = {Headers.REPLY_TO: 'jms.topic.vdsm_responses',
--
To view, visit https://gerrit.ovirt.org/54578
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I08c914170d2dfa6f8d74c5e712a97b5e34b0fd77
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Piotr Kliczewski <piotr.kliczewski at gmail.com>
More information about the vdsm-patches
mailing list