From e17bdf969b55aa8d51d7335274b19b3d58c2ed3c Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Wed, 9 Mar 2022 12:27:30 +0100 Subject: [PATCH] NVMe-oF: Remove misleading exception from logs When disconnecting a non-replicated volume that uses the newer connection properties format we'll get some exception trace logs that could make us think that something went wrong, when in reality this is ok. Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: DEBUG oslo.privsep.daemon [-] privsep: Exception during request[95eb2bcc-e4eb-4f5b-b823-56fd7aa338c6]: Unexpected error while running command. Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: Command: blkid /dev/nvme0n2 -s TYPE -o value Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: Exit code: 2 Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: Stdout: '' Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: Stderr: '' {{(pid=988326) _process_cmd /usr/local/lib/python3.6/site-packages/oslo_privsep/daemon.py:481}} Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: Traceback (most recent call last): Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: File "/usr/local/lib/python3.6/site-packages/oslo_privsep/daemon.py", line 476, in _process_cmd Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: ret = func(*f_args, **f_kwargs) Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: File "/usr/local/lib/python3.6/site-packages/oslo_privsep/priv_context.py", line 274, in _wrap Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: return func(*args, **kwargs) Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: File "/opt/remote_brick/os_brick/privileged/rootwrap.py", line 197, in execute_root Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: return custom_execute(*cmd, shell=False, run_as_root=False, **kwargs) Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: File "/opt/remote_brick/os_brick/privileged/rootwrap.py", line 146, in custom_execute Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: on_completion=on_completion, *cmd, **kwargs) Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: File "/usr/local/lib/python3.6/site-packages/oslo_concurrency/processutils.py", line 441, in execute Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: cmd=sanitized_cmd) Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: oslo_concurrency.processutils.ProcessExecutionError: Unexpected error while running command. Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: Command: blkid /dev/nvme0n2 -s TYPE -o value Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: Exit code: 2 Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: Stdout: '' Mar 09 11:14:42 localhost.localdomain nova-compute[988198]: Stderr: '' This patch calls the command execution in a way that no longer shows such exception. Closes-Bug: #1964389 Change-Id: I1c54e1ff3026cffe49b303f01e43d1b90d0bf3bc --- os_brick/initiator/connectors/nvmeof.py | 17 +++++++---------- .../tests/initiator/connectors/test_nvmeof.py | 16 ++++++---------- .../nvmeof-hide-traceback-a968ab71352684e3.yaml | 6 ++++++ 3 files changed, 19 insertions(+), 20 deletions(-) create mode 100644 releasenotes/notes/nvmeof-hide-traceback-a968ab71352684e3.yaml diff --git a/os_brick/initiator/connectors/nvmeof.py b/os_brick/initiator/connectors/nvmeof.py index 4835ae1c4..a75228f94 100644 --- a/os_brick/initiator/connectors/nvmeof.py +++ b/os_brick/initiator/connectors/nvmeof.py @@ -847,16 +847,13 @@ class NVMeOFConnector(base.BaseLinuxConnector): raise exception.CommandExecutionFailed(e, cmd=nvme_command) def _get_fs_type(self, device_path): - cmd = ['blkid', device_path, '-s', 'TYPE', '-o', 'value'] + cmd = ('blkid', device_path, '-s', 'TYPE', '-o', 'value') LOG.debug("[!] cmd = " + str(cmd)) fs_type = None - try: - lines, err = self._execute( - *cmd, run_as_root=True, root_helper=self._root_helper) - - fs_type = lines.split('\n')[0] - except putils.ProcessExecutionError: - return None - - return fs_type + # We don't care about errors, on error lines will be '' so it's ok + lines, err = self._execute( + *cmd, run_as_root=True, root_helper=self._root_helper, + check_exit_code=False) + fs_type = lines.split('\n')[0] + return fs_type or None diff --git a/os_brick/tests/initiator/connectors/test_nvmeof.py b/os_brick/tests/initiator/connectors/test_nvmeof.py index 18faae3c9..09aa8dafd 100644 --- a/os_brick/tests/initiator/connectors/test_nvmeof.py +++ b/os_brick/tests/initiator/connectors/test_nvmeof.py @@ -991,19 +991,15 @@ class NVMeOFConnectorTestCase(test_connector.ConnectorTestCase): result = self.connector.ks_readlink(dest) self.assertEqual('', result) - @mock.patch.object(executor.Executor, '_execute') + @mock.patch.object(executor.Executor, '_execute', + return_value=('', 'There was a big error')) def test_get_fs_type_err(self, mock_execute): - mock_execute.side_effect = putils.ProcessExecutionError() result = self.connector._get_fs_type(NVME_DEVICE_PATH) self.assertIsNone(result) - cmd = ['blkid', NVME_DEVICE_PATH, '-s', 'TYPE', '-o', 'value'] - args, kwargs = mock_execute.call_args - self.assertEqual(args[0], cmd[0]) - self.assertEqual(args[1], cmd[1]) - self.assertEqual(args[2], cmd[2]) - self.assertEqual(args[3], cmd[3]) - self.assertEqual(args[4], cmd[4]) - self.assertEqual(args[5], cmd[5]) + mock_execute.assert_called_once_with( + 'blkid', NVME_DEVICE_PATH, '-s', 'TYPE', '-o', 'value', + run_as_root=True, root_helper=self.connector._root_helper, + check_exit_code=False) @mock.patch.object(nvmeof.NVMeOFConnector, '_get_nvme_devices') def test__is_nvme_available(self, mock_nvme_devices): diff --git a/releasenotes/notes/nvmeof-hide-traceback-a968ab71352684e3.yaml b/releasenotes/notes/nvmeof-hide-traceback-a968ab71352684e3.yaml new file mode 100644 index 000000000..cba54779d --- /dev/null +++ b/releasenotes/notes/nvmeof-hide-traceback-a968ab71352684e3.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + NVMe-oF connector `bug #1964389 + `_: Fixed showing + misleading traceback.