Skip to content

Commit 64793cf

Browse files
author
Corey Bryant
committed
xenapi/agent: Change openssl error handling
Prior to this patch, if the openssl command returned a zero exit code and wrote details to stderr, nova would raise a RuntimeError exception. This patch changes the behavior to only raise a RuntimeError exception when openssl returns a non-zero exit code. Regardless of the exit code a warning will always be logged with stderr details if stderr is not None. Note that processutils.execute will now raise a processutils.ProcessExecutionError exception for any non-zero exit code since we are passing check_exit_code=True, which we convert to a Runtime error. Thanks to Dimitri John Ledkov <[email protected]> and Eric Fried <[email protected]> for helping with this patch. Change-Id: I212ac2b5ccd93e00adb7b9fe102fcb70857c6073 Partial-Bug: #1771506 (cherry picked from commit 1da71fa)
1 parent 870e5bc commit 64793cf

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

nova/tests/unit/virt/xenapi/test_agent.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import mock
2020
from os_xenapi.client import host_agent
2121
from os_xenapi.client import XenAPI
22+
from oslo_concurrency import processutils
2223
from oslo_utils import uuidutils
2324

2425
from nova import exception
@@ -311,6 +312,19 @@ def test_set_admin_password_silently_fails(self, mock_exchange,
311312

312313
mock_add_fault.assert_called_once_with(error, mock.ANY)
313314

315+
@mock.patch('oslo_concurrency.processutils.execute')
316+
def test_run_ssl_successful(self, mock_execute):
317+
mock_execute.return_value = ('0',
318+
'*** WARNING : deprecated key derivation used.'
319+
'Using -iter or -pbkdf2 would be better.')
320+
agent.SimpleDH()._run_ssl('foo')
321+
322+
@mock.patch('oslo_concurrency.processutils.execute',
323+
side_effect=processutils.ProcessExecutionError(
324+
exit_code=1, stderr=('ERROR: Something bad happened')))
325+
def test_run_ssl_failure(self, mock_execute):
326+
self.assertRaises(RuntimeError, agent.SimpleDH()._run_ssl, 'foo')
327+
314328

315329
class UpgradeRequiredTestCase(test.NoDBTestCase):
316330
def test_less_than(self):

nova/virt/xenapi/agent.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,18 @@ def _run_ssl(self, text, decrypt=False):
422422
'pass:%s' % self._shared, '-nosalt']
423423
if decrypt:
424424
cmd.append('-d')
425-
out, err = processutils.execute(
426-
*cmd, process_input=encodeutils.safe_encode(text))
427-
if err:
428-
raise RuntimeError(_('OpenSSL error: %s') % err)
429-
return out
425+
try:
426+
out, err = processutils.execute(
427+
*cmd,
428+
process_input=encodeutils.safe_encode(text),
429+
check_exit_code=True)
430+
if err:
431+
LOG.warning("OpenSSL stderr: %s", err)
432+
return out
433+
except processutils.ProcessExecutionError as e:
434+
raise RuntimeError(
435+
_('OpenSSL errored with exit code %(exit_code)d: %(stderr)s') %
436+
{'exit_code': e.exit_code, 'stderr': e.stderr})
430437

431438
def encrypt(self, text):
432439
return self._run_ssl(text).strip('\n')

0 commit comments

Comments
 (0)