diff options
author | Zuul <zuul@review.opendev.org> | 2019-06-04 06:36:11 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2019-06-04 06:36:11 +0000 |
commit | ed4a1ece0486a283d311b389fa8c0908564a71ce (patch) | |
tree | 191d6cd65db29b88aff0e119ea6ce3c09c6de799 | |
parent | 7feadd492f19a37b015d4ce62893cf27a0716033 (diff) | |
parent | 64793cf6f77c5ba7c9ea51662d936c7545ffce8c (diff) | |
download | nova-ed4a1ece0486a283d311b389fa8c0908564a71ce.tar.gz |
Merge "xenapi/agent: Change openssl error handling" into stable/stein
-rw-r--r-- | nova/tests/unit/virt/xenapi/test_agent.py | 14 | ||||
-rw-r--r-- | nova/virt/xenapi/agent.py | 17 |
2 files changed, 26 insertions, 5 deletions
diff --git a/nova/tests/unit/virt/xenapi/test_agent.py b/nova/tests/unit/virt/xenapi/test_agent.py index 8c77445c22..2848fc2882 100644 --- a/nova/tests/unit/virt/xenapi/test_agent.py +++ b/nova/tests/unit/virt/xenapi/test_agent.py @@ -19,6 +19,7 @@ import time import mock from os_xenapi.client import host_agent from os_xenapi.client import XenAPI +from oslo_concurrency import processutils from oslo_utils import uuidutils from nova import exception @@ -311,6 +312,19 @@ class SetAdminPasswordTestCase(AgentTestCaseBase): mock_add_fault.assert_called_once_with(error, mock.ANY) + @mock.patch('oslo_concurrency.processutils.execute') + def test_run_ssl_successful(self, mock_execute): + mock_execute.return_value = ('0', + '*** WARNING : deprecated key derivation used.' + 'Using -iter or -pbkdf2 would be better.') + agent.SimpleDH()._run_ssl('foo') + + @mock.patch('oslo_concurrency.processutils.execute', + side_effect=processutils.ProcessExecutionError( + exit_code=1, stderr=('ERROR: Something bad happened'))) + def test_run_ssl_failure(self, mock_execute): + self.assertRaises(RuntimeError, agent.SimpleDH()._run_ssl, 'foo') + class UpgradeRequiredTestCase(test.NoDBTestCase): def test_less_than(self): diff --git a/nova/virt/xenapi/agent.py b/nova/virt/xenapi/agent.py index d5f060af5d..e763cc2cfd 100644 --- a/nova/virt/xenapi/agent.py +++ b/nova/virt/xenapi/agent.py @@ -422,11 +422,18 @@ class SimpleDH(object): 'pass:%s' % self._shared, '-nosalt'] if decrypt: cmd.append('-d') - out, err = processutils.execute( - *cmd, process_input=encodeutils.safe_encode(text)) - if err: - raise RuntimeError(_('OpenSSL error: %s') % err) - return out + try: + out, err = processutils.execute( + *cmd, + process_input=encodeutils.safe_encode(text), + check_exit_code=True) + if err: + LOG.warning("OpenSSL stderr: %s", err) + return out + except processutils.ProcessExecutionError as e: + raise RuntimeError( + _('OpenSSL errored with exit code %(exit_code)d: %(stderr)s') % + {'exit_code': e.exit_code, 'stderr': e.stderr}) def encrypt(self, text): return self._run_ssl(text).strip('\n') |