From: Michal 'vorner' Vaner Date: Tue, 21 May 2013 14:15:09 +0000 (+0200) Subject: [2930] Sending notifications, python part X-Git-Tag: bind10-1.2.0beta1-release~431^2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=143264e9d77c446e9f5d9f2611198bb73de82243;p=thirdparty%2Fkea.git [2930] Sending notifications, python part --- diff --git a/src/lib/python/isc/config/ccsession.py b/src/lib/python/isc/config/ccsession.py index e801309547..8b824b8370 100644 --- a/src/lib/python/isc/config/ccsession.py +++ b/src/lib/python/isc/config/ccsession.py @@ -539,6 +539,28 @@ class ModuleCCSession(ConfigData): raise RPCError(code, value) return value + def notify(self, notification_group, event_name, params=None): + """ + Send a notification about an event to a group of recipients. + + Params: + - notification_group: This indirectly specifies which recipients get + the notification. Only the ones that register callback for the same + gorup get it. + - event_name: The name of the notification. + - params: Additional description of the event. + Return: Nothing + """ + notification = [event_name] + if params is not None: + notification.append(params) + self._session.group_sendmsg({'notification': notification}, + CC_GROUP_NOTIFICATION_PREFIX + + notification_group, + instance=CC_INSTANCE_WILDCARD, + to=CC_TO_WILDCARD, + want_answer=False) + class UIModuleCCSession(MultiConfigData): """This class is used in a configuration user interface. It contains specific functions for getting, displaying, and sending diff --git a/src/lib/python/isc/config/tests/ccsession_test.py b/src/lib/python/isc/config/tests/ccsession_test.py index 2a2d79071a..f7d014d6e9 100644 --- a/src/lib/python/isc/config/tests/ccsession_test.py +++ b/src/lib/python/isc/config/tests/ccsession_test.py @@ -350,6 +350,18 @@ class TestModuleCCSession(unittest.TestCase): self.assertRaises(RPCRecipientMissing, self.rpc_check, {"result": [-1, "Error"]}) + def test_notify(self): + """ + Test the sent notification has the right format. + """ + fake_session = FakeModuleCCSession() + mccs = self.create_session("spec1.spec", None, None, fake_session) + mccs.notify("group", "event", {"param": True}) + self.assertEqual([ + ["notifications/group", "*", {"notification": ["event", { + "param": True + }]}, False]], fake_session.message_queue) + def my_config_handler_ok(self, new_config): return isc.config.ccsession.create_answer(0)