Change in vdsm[master]: events: verify data before sending
piotr.kliczewski at gmail.com
piotr.kliczewski at gmail.com
Tue Apr 12 12:11:16 UTC 2016
Piotr Kliczewski has uploaded a new change for review.
Change subject: events: verify data before sending
......................................................................
events: verify data before sending
We want to check whether event contents aligns with the schema before
sending it to the engine.
Change-Id: Ifc854517d04db830e685edc47e6b7e1055c8d89c
Signed-off-by: pkliczewski <piotr.kliczewski at gmail.com>
---
M lib/vdsm/rpc/Bridge.py
M lib/vdsm/rpc/bindingjsonrpc.py
M lib/yajsonrpc/__init__.py
M tests/integration/jsonRpcHelper.py
M tests/stompTests.py
M vdsm/clientIF.py
6 files changed, 31 insertions(+), 11 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/29/56029/1
diff --git a/lib/vdsm/rpc/Bridge.py b/lib/vdsm/rpc/Bridge.py
index 3c5d65e..c69a971 100644
--- a/lib/vdsm/rpc/Bridge.py
+++ b/lib/vdsm/rpc/Bridge.py
@@ -65,12 +65,19 @@
paths.append(vdsmapi.find_schema('vdsm-api-gluster'))
self._schema = vdsmapi.Schema(paths)
+ self._event_schema = vdsmapi.Schema(
+ [vdsmapi.find_schema('vdsm-events')])
+
self._threadLocal = threading.local()
self.log = logging.getLogger('DynamicBridge')
def register_server_address(self, server_address):
self._threadLocal.server = server_address
+ @property
+ def event_schema(self):
+ return self._event_schema
+
def unregister_server_address(self):
self._threadLocal.server = None
diff --git a/lib/vdsm/rpc/bindingjsonrpc.py b/lib/vdsm/rpc/bindingjsonrpc.py
index d1c4d07..936b8e9 100644
--- a/lib/vdsm/rpc/bindingjsonrpc.py
+++ b/lib/vdsm/rpc/bindingjsonrpc.py
@@ -39,7 +39,7 @@
workers_count=_THREADS,
max_tasks=_TASKS,
scheduler=scheduler)
-
+ self._bridge = bridge
self._server = JsonRpcServer(bridge, timeout, self._executor.dispatch)
self._reactor = StompReactor(subs)
self.startReactor()
@@ -54,6 +54,10 @@
def reactor(self):
return self._reactor
+ @property
+ def bridge(self):
+ return self._bridge
+
def start(self):
self._executor.start()
diff --git a/lib/yajsonrpc/__init__.py b/lib/yajsonrpc/__init__.py
index 9aa011d..526a052 100644
--- a/lib/yajsonrpc/__init__.py
+++ b/lib/yajsonrpc/__init__.py
@@ -193,12 +193,14 @@
"""
log = logging.getLogger("jsonrpc.Notification")
- def __init__(self, event_id, cb):
+ def __init__(self, event_id, cb, bridge):
self._event_id = event_id
self._cb = cb
+ self._bridge = bridge
def emit(self, **kwargs):
self._add_notify_time(kwargs)
+ self._bridge.event_schema.verify_event_params(self._event_id, kwargs)
notification = json.dumps({'jsonrpc': '2.0',
'method': self._event_id,
'params': kwargs})
diff --git a/tests/integration/jsonRpcHelper.py b/tests/integration/jsonRpcHelper.py
index ab5bdf5..05b47a7 100644
--- a/tests/integration/jsonRpcHelper.py
+++ b/tests/integration/jsonRpcHelper.py
@@ -73,6 +73,7 @@
notification = Notification(
event_id,
self._send_notification,
+ self.json_binding.bridge
)
notification.emit(**kwargs)
diff --git a/tests/stompTests.py b/tests/stompTests.py
index 02b86e9..45007f6 100644
--- a/tests/stompTests.py
+++ b/tests/stompTests.py
@@ -41,8 +41,15 @@
_USE_SSL = [[True], [False]]
+class Schema(object):
+
+ def verify_event_params(self, sub_id, args):
+ pass
+
+
class _SampleBridge(object):
cif = None
+ event_schema = Schema()
def echo(self, text):
return text
diff --git a/vdsm/clientIF.py b/vdsm/clientIF.py
index fc4b5b4..ca368b0 100644
--- a/vdsm/clientIF.py
+++ b/vdsm/clientIF.py
@@ -154,20 +154,19 @@
event_id and a dictionary as event body. Before sending
there is notify_time added on top level to the dictionary.
"""
- notification = Notification(
- event_id,
- self._send_notification,
- )
- notification.emit(**kwargs)
-
- def _send_notification(self, message):
try:
- self.bindings['jsonrpc'].reactor.server.send(
- message, config.get('addresses', 'event_queue'))
+ notification = Notification(
+ event_id, self._send_notification,
+ self.bindings['jsonrpc'].bridge)
+ notification.emit(**kwargs)
except KeyError:
self.log.warning("Attempt to send an event when jsonrpc binding"
" not available")
+ def _send_notification(self, message):
+ self.bindings['jsonrpc'].reactor.server.send(
+ message, config.get('addresses', 'event_queue'))
+
def contEIOVms(self, sdUUID, isDomainStateValid):
# This method is called everytime the onDomainStateChange
# event is emitted, this event is emitted even when a domain goes
--
To view, visit https://gerrit.ovirt.org/56029
To unsubscribe, visit https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifc854517d04db830e685edc47e6b7e1055c8d89c
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