Merge "NVMe-oF: Fix generation of hostnqn file"

This commit is contained in:
Zuul 2024-01-06 11:34:20 +00:00 committed by Gerrit Code Review
commit 8e960a9bcd
3 changed files with 25 additions and 9 deletions

View File

@ -50,11 +50,14 @@ def create_hostnqn() -> str:
# This is different from OSError's ENOENT, which is missing nvme
# command. This ENOENT is when nvme says there isn't an nqn.
except putils.ProcessExecutionError as e:
err_msg = e.stdout[:e.stdout.find('\n')]
show_hostnqn_subcmd_missing = (
"ERROR: Invalid sub-command".casefold() in err_msg.casefold())
if show_hostnqn_subcmd_missing:
# nvme-cli's error are all over the place, so merge the output
err_msg = e.stdout + '\n' + e.stderr
msg = err_msg.casefold()
if 'error: invalid sub-command' in msg:
LOG.debug('Version too old cannot check current hostnqn.')
elif 'hostnqn is not available' in msg:
LOG.debug('Version too old to return hostnqn from non file '
'sources')
elif e.exit_code == errno.ENOENT:
LOG.debug('No nqn could be formed from dmi or systemd.')
else:

View File

@ -64,7 +64,8 @@ class PrivNVMeTestCase(base.TestCase):
hostnqn = mock.Mock()
mock_exec.side_effect = [
putils.ProcessExecutionError(exit_code=errno.ENOENT,
stdout="totally exist sub-command"),
stdout="totally exist sub-command",
stderr=''),
(hostnqn, mock.sentinel.err)
]
@ -83,17 +84,23 @@ class PrivNVMeTestCase(base.TestCase):
mock_chmod.assert_called_once_with('/etc/nvme/hostnqn', 0o644)
self.assertEqual(stripped_hostnqn, res)
@ddt.data((231, 'error: Invalid sub-command\n', ''),
(254, '', 'hostnqn is not available -- use nvme gen-hostnqn\n'))
@ddt.unpack
@mock.patch('os.chmod')
@mock.patch.object(builtins, 'open', new_callable=mock.mock_open)
@mock.patch('os.makedirs')
@mock.patch.object(rootwrap, 'custom_execute')
def test_create_hostnqn_generate_old_nvme_cli(self, mock_exec, mock_mkdirs,
mock_open, mock_chmod):
def test_create_hostnqn_generate_old_nvme_cli(
self, exit_code, stdout, stderr, mock_exec, mock_mkdirs, mock_open,
mock_chmod):
hostnqn = mock.Mock()
mock_exec.side_effect = [
putils.ProcessExecutionError(
exit_code=231,
stdout="error: Invalid sub-command\n"),
exit_code=exit_code,
stdout=stdout,
stderr=stderr),
(hostnqn, mock.sentinel.err)
]

View File

@ -0,0 +1,6 @@
---
fixes:
- |
NVMe-oF connector `bug #2035606
<https://bugs.launchpad.net/os-brick/+bug/2035606>`_: Fixed generation of
hostnqn file on old nvme-cli versions.