Merge "Fix error handling in nova.cmd.baseproxy"

This commit is contained in:
Jenkins 2015-12-04 23:24:12 +00:00 committed by Gerrit Code Review
commit 4685c7e9ac
2 changed files with 13 additions and 1 deletions

View File

@ -37,7 +37,8 @@ CONF.import_opt('web', 'nova.cmd.novnc')
def exit_with_error(msg, errno=-1):
print(msg) and sys.exit(errno)
sys.stderr.write(msg + '\n')
sys.exit(errno)
def proxy(host, port):

View File

@ -65,3 +65,14 @@ class BaseProxyTestCase(test.NoDBTestCase):
web='/usr/share/spice-html5', file_only=True,
RequestHandlerClass=websocketproxy.NovaProxyRequestHandler)
mock_start.assert_called_once_with()
@mock.patch('sys.stderr.write')
@mock.patch('os.path.exists', return_value=False)
@mock.patch('sys.exit', side_effect=test.TestingException)
def test_proxy_exit_with_error(self, mock_exit, mock_exists, mock_stderr):
self.flags(ssl_only=True)
self.assertRaises(test.TestingException, baseproxy.proxy,
'0.0.0.0', '6080')
mock_stderr.assert_called_once_with(
'SSL only and self.pem not found\n')
mock_exit.assert_called_once_with(-1)