Display error message when socket is closed
Give the user some additional information when Zaqar is down. Also, move the websocket import to the third-party import list. Change-Id: I8d4caf2ba08bceba1f014555ccd6ae3ca1a4a6c0 Closes-Bug: #1619712
This commit is contained in:
parent
7923128770
commit
12932b0cac
@ -17,11 +17,12 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import socket
|
||||||
import uuid
|
import uuid
|
||||||
import websocket
|
|
||||||
|
|
||||||
from openstackclient.common import utils
|
from openstackclient.common import utils
|
||||||
from swiftclient import client as swift_client
|
from swiftclient import client as swift_client
|
||||||
|
import websocket
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -79,7 +80,13 @@ class WebsocketClient(object):
|
|||||||
self._websocket_client_id = str(uuid.uuid4())
|
self._websocket_client_id = str(uuid.uuid4())
|
||||||
|
|
||||||
LOG.debug('Instantiating messaging websocket client: %s', endpoint)
|
LOG.debug('Instantiating messaging websocket client: %s', endpoint)
|
||||||
self._ws = websocket.create_connection(endpoint)
|
try:
|
||||||
|
self._ws = websocket.create_connection(endpoint)
|
||||||
|
except socket.error:
|
||||||
|
LOG.error("Could not establish a connection to the Zaqar "
|
||||||
|
"websocket. The command was sent but the answer "
|
||||||
|
"could not be read.")
|
||||||
|
raise
|
||||||
|
|
||||||
self.send('authenticate', extra_headers={'X-Auth-Token': token})
|
self.send('authenticate', extra_headers={'X-Auth-Token': token})
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import mock
|
import mock
|
||||||
|
import socket
|
||||||
|
|
||||||
from tripleoclient import plugin
|
from tripleoclient import plugin
|
||||||
from tripleoclient.tests import base
|
from tripleoclient.tests import base
|
||||||
@ -83,3 +84,21 @@ class TestPlugin(base.TestCase):
|
|||||||
"message": "Result for IDID",
|
"message": "Result for IDID",
|
||||||
"execution": {"id": "IDID"},
|
"execution": {"id": "IDID"},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@mock.patch("websocket.create_connection")
|
||||||
|
def test_websocket_creation_error(self, ws_create_connection):
|
||||||
|
|
||||||
|
ws_create_connection.side_effect = socket.error
|
||||||
|
|
||||||
|
clientmgr = mock.MagicMock()
|
||||||
|
clientmgr.get_endpoint_for_service_type.return_value = fakes.WS_URL
|
||||||
|
clientmgr.auth.get_token.return_value = "TOKEN"
|
||||||
|
clientmgr.auth_ref.project_id = "ID"
|
||||||
|
|
||||||
|
client = plugin.make_client(clientmgr)
|
||||||
|
|
||||||
|
msg = ("Could not establish a connection to the Zaqar websocket. The "
|
||||||
|
"command was sent but the answer could not be read.")
|
||||||
|
with mock.patch('tripleoclient.plugin.LOG') as mock_log:
|
||||||
|
self.assertRaises(socket.error, client.messaging_websocket)
|
||||||
|
mock_log.error.assert_called_once_with(msg)
|
||||||
|
Loading…
Reference in New Issue
Block a user