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)
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)
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)
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)
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)
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)
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)
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)
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)
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})
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)
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')
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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')
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')
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)
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)
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)
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)