Example #1
0
 def testMethodReturnsNullAndServerReturnsTrue(self, ssl):
     bridge = _DummyBridge()
     with constructClient(self.log, bridge, ssl) as clientFactory:
         with self._client(clientFactory) as client:
             res = self._callTimeout(client, "ping", [],
                                     CALL_ID)
             self.assertEqual(res, True)
Example #2
0
    def testMethodCallArgDict(self, ssl):
        data = dummyTextGenerator(1024)

        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                self.assertEqual(self._callTimeout(client, "echo",
                                 {'text': data}, CALL_ID), data)
Example #3
0
    def testSlowMethod(self, ssl):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                with self.assertRaises(JsonRpcErrorBase) as cm:
                    self._callTimeout(client, "slow_response", [], CALL_ID)

                self.assertEqual(cm.exception.code,
                                 JsonRpcNoResponseError().code)
Example #4
0
    def testMethodCallArgList(self, ssl):
        data = dummyTextGenerator(1024)

        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                self.log.info("Calling 'echo'")
                self.assertEqual(
                    self._callTimeout(client, "echo", (data, ), CALL_ID), data)
Example #5
0
    def testMethodCallArgDict(self, ssl):
        data = dummyTextGenerator(1024)

        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                self.assertEqual(
                    self._callTimeout(client, "echo", {'text': data}, CALL_ID),
                    data)
Example #6
0
    def testFullExecutor(self, ssl):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                with self.assertRaises(JsonRpcErrorBase) as cm:
                    self._callTimeout(client, "no_method", [], CALL_ID)

                self.assertEqual(cm.exception.code,
                                 JsonRpcInternalError().code)
Example #7
0
    def testMethodCallArgList(self, ssl):
        data = dummyTextGenerator(1024)

        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                self.log.info("Calling 'echo'")
                self.assertEqual(self._callTimeout(client, "echo",
                                                   (data,), CALL_ID), data)
Example #8
0
    def testSlowMethod(self, ssl):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                with self.assertRaises(JsonRpcErrorBase) as cm:
                    self._callTimeout(client, "slow_response", [], CALL_ID)

                self.assertEqual(cm.exception.code,
                                 JsonRpcNoResponseError().code)
Example #9
0
    def testFullExecutor(self, ssl):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                with self.assertRaises(JsonRpcErrorBase) as cm:
                    self._callTimeout(client, "no_method", [], CALL_ID)

                self.assertEqual(cm.exception.code,
                                 JsonRpcInternalError().code)
Example #10
0
    def testMethodBadParameters(self, ssl):
        # Without a schema the server returns an internal error

        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                with self.assertRaises(JsonRpcErrorBase) as cm:
                    self._callTimeout(client, "echo", [], CALL_ID)

                self.assertEqual(cm.exception.code,
                                 JsonRpcInternalError().code)
Example #11
0
 def testMethodReturnsNullAndServerReturnsTrue(self, ssl, type):
     bridge = _DummyBridge()
     with constructClient(self.log, bridge, ssl, type) as clientFactory:
         with self._client(clientFactory) as client:
             if type == "xml":
                 response = client.send("ping", ())
                 # for xml empty response is not allowed by design
                 self.assertTrue("None unless allow_none is enabled" in response)
             else:
                 res = self._callTimeout(client, "ping", [], CALL_ID)
                 self.assertEquals(res, True)
Example #12
0
    def testClientNotify(self, ssl):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                def callback(client, event, params):
                    self.assertEqual(event, 'vdsm.event')
                    self.assertEqual(params['content'], True)

                client.registerEventCallback(callback)
                client.notify('vdsm.event', 'jms.topic.test',
                              bridge.event_schema, {'content': True})
Example #13
0
    def testMethodCallArgDict(self, ssl, type):
        data = dummyTextGenerator(1024)

        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl, type) as clientFactory:
            with self._client(clientFactory) as client:
                if type == "xml":
                    response = client.send("echo", (data,))
                    self.assertEquals(response, data)
                else:
                    self.assertEquals(self._callTimeout(client, "echo", {"text": data}, CALL_ID), data)
Example #14
0
    def testClientNotify(self, ssl):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:

                def callback(client, event, params):
                    self.assertEqual(event, 'vdsm.event')
                    self.assertEqual(params['content'], True)

                client.registerEventCallback(callback)
                client.notify('vdsm.event', 'jms.topic.test',
                              bridge.event_schema, {'content': True})
Example #15
0
    def testDoubleResponse(self, ssl):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:

                def callback(client, event, params):
                    self.assertEqual(event, 'vdsm.double_response')
                    self.assertEqual(params['content'], True)

                client.registerEventCallback(callback)
                res = self._callTimeout(client, "double_response", [], CALL_ID)
                self.assertEqual(res, 'sent')
Example #16
0
    def testMethodBadParameters(self, ssl):
        # Without a schema the server returns an internal error

        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                with self.assertRaises(JsonRpcErrorBase) as cm:
                    self._callTimeout(client, "echo", [],
                                      CALL_ID)

                self.assertEqual(cm.exception.code,
                                 JsonRpcInternalError().code)
Example #17
0
 def testMethodReturnsNullAndServerReturnsTrue(self, ssl, type):
     bridge = _DummyBridge()
     with constructClient(self.log, bridge, ssl, type) as clientFactory:
         with self._client(clientFactory) as client:
             if type == "xml":
                 response = client.send("ping", ())
                 # for xml empty response is not allowed by design
                 self.assertTrue(
                     "None unless allow_none is enabled" in response)
             else:
                 res = self._callTimeout(client, "ping", [], CALL_ID)
                 self.assertEquals(res, True)
Example #18
0
    def testMethodMissingMethod(self, ssl, type):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl, type) as clientFactory:
            with self._client(clientFactory) as client:
                if type == "xml":
                    response = client.send("I.DO.NOT.EXIST :(", ())
                    self.assertTrue('"I.DO.NOT.EXIST :(" is not supported' in response)
                else:
                    with self.assertRaises(JsonRpcError) as cm:
                        self._callTimeout(client, "I.DO.NOT.EXIST :(", [], CALL_ID)

                    self.assertEquals(cm.exception.code, JsonRpcMethodNotFoundError().code)
Example #19
0
    def testFullExecutor(self, ssl, type):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl, type) as clientFactory:
            with self._client(clientFactory) as client:
                if type == "xml":
                    # TODO start using executor for xmlrpc
                    pass
                else:
                    with self.assertRaises(JsonRpcError) as cm:
                        self._callTimeout(client, "no_method", [], CALL_ID)

                    self.assertEquals(cm.exception.code, JsonRpcInternalError().code)
Example #20
0
    def testSlowMethod(self, ssl, type):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl, type) as clientFactory:
            with self._client(clientFactory) as client:
                if type == "xml":
                    # we do not provide timeout for xmlrpc
                    pass
                else:
                    with self.assertRaises(JsonRpcError) as cm:
                        self._callTimeout(client, "slow_response", [], CALL_ID)

                    self.assertEquals(cm.exception.code, JsonRpcNoResponseError().code)
Example #21
0
    def testDoubleResponse(self, ssl):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                def callback(client, event, params):
                    self.assertEqual(event, 'vdsm.double_response')
                    self.assertEqual(params['content'], True)

                client.registerEventCallback(callback)
                res = self._callTimeout(client, "double_response", [],
                                        CALL_ID)
                self.assertEqual(res, 'sent')
Example #22
0
    def testMethodCallArgDict(self, ssl, type):
        data = dummyTextGenerator(1024)

        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl, type) as clientFactory:
            with self._client(clientFactory) as client:
                if type == "xml":
                        response = client.send("echo", (data,))
                        self.assertEquals(response, data)
                else:
                    self.assertEquals(self._callTimeout(client, "echo",
                                      {'text': data}, CALL_ID), data)
Example #23
0
    def testFullExecutor(self, ssl, type):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl, type) as clientFactory:
            with self._client(clientFactory) as client:
                if type == "xml":
                    # TODO start using executor for xmlrpc
                    pass
                else:
                    with self.assertRaises(JsonRpcError) as cm:
                        self._callTimeout(client, "no_method", [], CALL_ID)

                    self.assertEquals(cm.exception.code,
                                      JsonRpcInternalError().code)
Example #24
0
    def testMethodMissingMethod(self, ssl):
        missing_method = "I_DO_NOT_EXIST :("

        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                with self.assertRaises(JsonRpcErrorBase) as cm:
                    self._callTimeout(client, missing_method, [], CALL_ID)

                self.assertEqual(
                    cm.exception.code,
                    JsonRpcMethodNotFoundError(method=missing_method).code)
                self.assertIn(missing_method, cm.exception.message)
Example #25
0
    def testSlowMethod(self, ssl, type):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl, type) as clientFactory:
            with self._client(clientFactory) as client:
                if type == "xml":
                    # we do not provide timeout for xmlrpc
                    pass
                else:
                    with self.assertRaises(JsonRpcError) as cm:
                        self._callTimeout(client, "slow_response", [], CALL_ID)

                    self.assertEquals(cm.exception.code,
                                      JsonRpcNoResponseError().code)
Example #26
0
    def testMethodCallArgList(self, ssl, type):
        data = dummyTextGenerator(1024)

        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl, type) as clientFactory:
            with self._client(clientFactory) as client:
                self.log.info("Calling 'echo'")
                if type == "xml":
                    response = client.send("echo", (data,))
                    self.assertEquals(response, data)
                else:
                    self.assertEquals(self._callTimeout(client, "echo",
                                      (data,), CALL_ID,
                                      CALL_TIMEOUT), data)
Example #27
0
    def testMethodCallArgList(self, ssl, type):
        data = dummyTextGenerator(1024)

        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl, type) as clientFactory:
            with self._client(clientFactory) as client:
                self.log.info("Calling 'echo'")
                if type == "xml":
                    response = client.send("echo", (data, ))
                    self.assertEquals(response, data)
                else:
                    self.assertEquals(
                        self._callTimeout(client, "echo", (data, ), CALL_ID,
                                          CALL_TIMEOUT), data)
Example #28
0
    def testMethodBadParameters(self, ssl, type):
        # Without a schema the server returns an internal error

        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl, type) as clientFactory:
            with self._client(clientFactory) as client:
                if type == "xml":
                    response = client.send("echo", ())
                    self.assertTrue("echo() takes exactly 2 arguments" in response)
                else:
                    with self.assertRaises(JsonRpcError) as cm:
                        self._callTimeout(client, "echo", [], CALL_ID)

                    self.assertEquals(cm.exception.code, JsonRpcInternalError().code)
Example #29
0
    def testMethodMissingMethod(self, ssl):
        missing_method = "I_DO_NOT_EXIST :("

        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                with self.assertRaises(JsonRpcErrorBase) as cm:
                    self._callTimeout(client, missing_method, [],
                                      CALL_ID)

                self.assertEqual(
                    cm.exception.code,
                    JsonRpcMethodNotFoundError(method=missing_method).code)
                self.assertIn(missing_method, cm.exception.message)
Example #30
0
    def testMethodMissingMethod(self, ssl, type):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl, type) as clientFactory:
            with self._client(clientFactory) as client:
                if type == "xml":
                    response = client.send("I.DO.NOT.EXIST :(", ())
                    self.assertTrue("\"I.DO.NOT.EXIST :(\" is not supported"
                                    in response)
                else:
                    with self.assertRaises(JsonRpcError) as cm:
                        self._callTimeout(client, "I.DO.NOT.EXIST :(", [],
                                          CALL_ID)

                    self.assertEquals(cm.exception.code,
                                      JsonRpcMethodNotFoundError().code)
Example #31
0
    def testDoubleResponse(self, ssl, type):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl, type) as clientFactory:
            with self._client(clientFactory) as client:
                if type == "xml":
                    # ignore notifications for xmlrpc
                    pass
                else:
                    def callback(client, event, params):
                        self.assertEqual(event, 'vdsm.double_response')
                        self.assertEqual(params['content'], True)

                    client.registerEventCallback(callback)
                    res = self._callTimeout(client, "double_response", [],
                                            CALL_ID)
                    self.assertEqual(res, 'sent')
Example #32
0
    def testDoubleResponse(self, ssl, type):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl, type) as clientFactory:
            with self._client(clientFactory) as client:
                if type == "xml":
                    # ignore notifications for xmlrpc
                    pass
                else:
                    def callback(client, event, params):
                        self.assertEquals(event, 'vdsm.double_response')
                        self.assertEquals(params['content'], True)

                    client.registerEventCallback(callback)
                    res = self._callTimeout(client, "double_response", [],
                                            CALL_ID)
                    self.assertEquals(res, 'sent')
Example #33
0
    def testMethodBadParameters(self, ssl, type):
        # Without a schema the server returns an internal error

        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl, type) as clientFactory:
            with self._client(clientFactory) as client:
                if type == "xml":
                    response = client.send("echo", ())
                    self.assertTrue(
                        "echo() takes exactly 2 arguments" in response)
                else:
                    with self.assertRaises(JsonRpcError) as cm:
                        self._callTimeout(client, "echo", [], CALL_ID)

                    self.assertEquals(cm.exception.code,
                                      JsonRpcInternalError().code)
Example #34
0
    def testClientSubscribe(self, ssl):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                event_queue = queue.Queue()
                sub = client.subscribe(EVENT_TOPIC, event_queue)

                res = self._callTimeout(client, "send_event", [], CALL_ID)
                self.assertEqual(res, 'sent')
                client.unsubscribe(sub)

                events = self._collect_events(event_queue)
                self.assertEqual(len(events), 1)

                event, event_params = events[0]
                self.assertEqual(event, '|vdsm|test_event|')
                self.assertEqual(event_params['content'], True)
Example #35
0
    def testMethodMissingMethod(self, ssl, type):
        missing_method = "I_DO_NOT_EXIST :("

        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl, type) as clientFactory:
            with self._client(clientFactory) as client:
                if type == "xml":
                    response = client.send(missing_method, ())
                    self.assertIn(missing_method, response)
                else:
                    with self.assertRaises(JsonRpcError) as cm:
                        self._callTimeout(client, missing_method, [], CALL_ID)

                    self.assertEquals(
                        cm.exception.code,
                        JsonRpcMethodNotFoundError(missing_method).code)
                    self.assertIn(missing_method, cm.exception.message)
Example #36
0
    def testMethodMissingMethod(self, ssl, type):
        missing_method = "I_DO_NOT_EXIST :("

        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl, type) as clientFactory:
            with self._client(clientFactory) as client:
                if type == "xml":
                    response = client.send(missing_method, ())
                    self.assertIn(missing_method, response)
                else:
                    with self.assertRaises(JsonRpcError) as cm:
                        self._callTimeout(client, missing_method, [],
                                          CALL_ID)

                    self.assertEquals(
                        cm.exception.code,
                        JsonRpcMethodNotFoundError(missing_method).code)
                    self.assertIn(missing_method, cm.exception.message)
Example #37
0
    def testClientSubscribe(self, ssl):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                event_queue = queue.Queue()
                sub = client.subscribe(EVENT_TOPIC, event_queue)

                res = self._callTimeout(client, "send_event", [],
                                        CALL_ID)
                self.assertEqual(res, 'sent')
                client.unsubscribe(sub)

                events = self._collect_events(event_queue)
                self.assertEqual(len(events), 1)

                event, event_params = events[0]
                self.assertEqual(event, '|vdsm|test_event|')
                self.assertEqual(event_params['content'], True)
Example #38
0
    def testClientNotify(self, ssl):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                event_queue = queue.Queue()
                custom_topic = 'custom.topic'
                sub = client.subscribe(custom_topic, event_queue)

                client.notify('vdsm.event', custom_topic,
                              bridge.event_schema, {'content': True})

                # Waiting for event before unsubscribing, to make sure,
                # it will be received
                event, event_params = self._get_with_timeout(event_queue)
                self.assertEqual(event, 'vdsm.event')
                self.assertEqual(event_params['content'], True)

                client.unsubscribe(sub)
                events = self._collect_events(event_queue)
                self.assertEqual(len(events), 0)
Example #39
0
    def testClientNotify(self, ssl):
        bridge = _DummyBridge()
        with constructClient(self.log, bridge, ssl) as clientFactory:
            with self._client(clientFactory) as client:
                event_queue = queue.Queue()
                custom_topic = 'custom.topic'
                sub = client.subscribe(custom_topic, event_queue)

                client.notify('vdsm.event', custom_topic, bridge.event_schema,
                              {'content': True})

                # Waiting for event before unsubscribing, to make sure,
                # it will be received
                event, event_params = self._get_with_timeout(event_queue)
                self.assertEqual(event, 'vdsm.event')
                self.assertEqual(event_params['content'], True)

                client.unsubscribe(sub)
                events = self._collect_events(event_queue)
                self.assertEqual(len(events), 0)
Example #40
0
 def testMethodReturnsNullAndServerReturnsTrue(self, ssl):
     bridge = _DummyBridge()
     with constructClient(self.log, bridge, ssl) as clientFactory:
         with self._client(clientFactory) as client:
             res = self._callTimeout(client, "ping", [], CALL_ID)
             self.assertEqual(res, True)