def testMethodReturnsNullAndServerReturnsTrue(self, use_ssl): ssl_ctx = self.ssl_ctx if use_ssl else None bridge = _DummyBridge() with constructClient(self.log, bridge, ssl_ctx) as clientFactory: with self._client(clientFactory) as client: res = self._callTimeout(client, "ping", [], CALL_ID) self.assertEqual(res, True)
def _create_client(self): bridge = _Bridge() ssl = True with constructClient(self.log, bridge, ssl) as clientFactory: json_client = clientFactory() try: yield _MockedClient(json_client, CALL_TIMEOUT, False) finally: json_client.close()
def testMethodCallArgDict(self, use_ssl): data = dummyTextGenerator(1024) ssl_ctx = self.ssl_ctx if use_ssl else None bridge = _DummyBridge() with constructClient(self.log, bridge, ssl_ctx) as clientFactory: with self._client(clientFactory) as client: self.assertEqual(self._callTimeout(client, "echo", {'text': data}, CALL_ID), data)
def _create_client(self): bridge = _Bridge() with generate_key_cert_pair() as key_cert_pair: key_file, cert_file = key_cert_pair ssl_ctx = create_ssl_context(key_file, cert_file) with constructClient(self.log, bridge, ssl_ctx) as clientFactory: json_client = clientFactory() try: yield _MockedClient(json_client, CALL_TIMEOUT, False) finally: json_client.close()
def testFullExecutor(self, use_ssl): ssl_ctx = self.ssl_ctx if use_ssl else None bridge = _DummyBridge() with constructClient(self.log, bridge, ssl_ctx) 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 testSlowMethod(self, use_ssl): ssl_ctx = self.ssl_ctx if use_ssl else None bridge = _DummyBridge() with constructClient(self.log, bridge, ssl_ctx) 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 testMethodBadParameters(self, use_ssl): # Without a schema the server returns an internal error ssl_ctx = self.ssl_ctx if use_ssl else None bridge = _DummyBridge() with constructClient(self.log, bridge, ssl_ctx) 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 testMethodMissingMethod(self, use_ssl): missing_method = "I_DO_NOT_EXIST :(" ssl_ctx = self.ssl_ctx if use_ssl else None bridge = _DummyBridge() with constructClient(self.log, bridge, ssl_ctx) 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.msg)
def testClientSubscribe(self, use_ssl): ssl_ctx = self.ssl_ctx if use_ssl else None bridge = _DummyBridge() with constructClient(self.log, bridge, ssl_ctx) 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 testClientNotify(self, use_ssl): ssl_ctx = self.ssl_ctx if use_ssl else None bridge = _DummyBridge() with constructClient(self.log, bridge, ssl_ctx) 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)