Don't cache and re-use the websocket

The socket is bound to the queue name and this this removes the
ability to work with multiple queues and if the websocket it
closed it can't be easily recreated.

Change-Id: I6d05b9536111a77a54b818dcf1a9d030ad464e7f
This commit is contained in:
Dougal Matthews 2016-06-20 18:08:24 +01:00
parent d9cfd676c4
commit 5942105e2e
3 changed files with 7 additions and 14 deletions

View File

@ -148,11 +148,7 @@ class ClientWrapper(object):
def __init__(self, instance):
self._instance = instance
self._messaging_websocket = None
def messaging_websocket(self, queue_name='tripleo'):
"""Returns a websocket for the messaging service"""
if self._messaging_websocket is not None:
return self._messaging_websocket
self._messaging_websocket = WebsocketClient(self._instance, queue_name)
return self._messaging_websocket
return WebsocketClient(self._instance, queue_name)

View File

@ -40,8 +40,5 @@ class FakeClientManager(object):
class FakeClientWrapper(object):
def __init__(self):
self._messaging_websocket = mock.MagicMock()
def messaging_websocket(self, queue_name='tripleo'):
return self._messaging_websocket
return mock.MagicMock()

View File

@ -38,15 +38,15 @@ class TestPlugin(base.TestCase):
client = plugin.make_client(clientmgr)
websocket = client.messaging_websocket()
# The second access should return the same client:
self.assertIs(client.messaging_websocket(), websocket)
# The second access should not return the same client:
self.assertIsNot(client.messaging_websocket(), websocket)
plugin.make_client(clientmgr)
# And the functions should only be called when the client is created:
self.assertEqual(clientmgr.auth.get_token.call_count, 1)
self.assertEqual(clientmgr.get_endpoint_for_service_type.call_count, 1)
ws_create_connection.assert_called_once_with("ws://0.0.0.0")
self.assertEqual(clientmgr.auth.get_token.call_count, 2)
self.assertEqual(clientmgr.get_endpoint_for_service_type.call_count, 2)
ws_create_connection.assert_called_with("ws://0.0.0.0")
@mock.patch.object(plugin.WebsocketClient, "recv")
@mock.patch("websocket.create_connection")