Silence warning when running in a container with overlayfs

When running in a container using overlayfs we may see the following
warning:

  WARNING os_brick.initiator.connectors.nvmeof process execution error
  in _get_host_uuid: Unexpected error while running command.
  Command: blkid overlay -s UUID -o value
  Exit code: 2
  Stdout: ''
  Stderr: '': oslo_concurrency.processutils.ProcessExecutionError:
  Unexpected error while running command.

This change fixes the issue by not running the command when the file
system source is overlay.

Closes-Bug: #2045557
Change-Id: I3abc5bee7f474a9a40d396c559a42edff86334e0
(cherry picked from commit bd07c571da)
This commit is contained in:
Mark Goddard 2023-12-04 12:51:24 +00:00
parent e29a47e0a5
commit 823cda4b8a
3 changed files with 20 additions and 3 deletions

View File

@ -819,8 +819,13 @@ class NVMeOFConnector(base.BaseLinuxConnector):
try:
lines, err = self._execute(
*cmd, run_as_root=True, root_helper=self._root_helper)
source = lines.split('\n')[0]
# In a container this could be 'overlay', which causes the blkid
# command to fail.
if source == "overlay":
return None
blkid_cmd = (
'blkid', lines.split('\n')[0], '-s', 'UUID', '-o', 'value')
'blkid', source, '-s', 'UUID', '-o', 'value')
lines, _err = self._execute(
*blkid_cmd, run_as_root=True, root_helper=self._root_helper)
return lines.split('\n')[0]

View File

@ -918,8 +918,10 @@ class NVMeOFConnectorTestCase(test_connector.ConnectorTestCase):
@mock.patch.object(nvmeof.NVMeOFConnector, '_execute', autospec=True)
def test_get_sysuuid_without_newline(self, mock_execute):
mock_execute.return_value = (
"9126E942-396D-11E7-B0B7-A81E84C186D1\n", "")
mock_execute.side_effect = [
("/dev/sda1", ""),
("9126E942-396D-11E7-B0B7-A81E84C186D1\n", "")
]
uuid = self.connector._get_host_uuid()
expected_uuid = "9126E942-396D-11E7-B0B7-A81E84C186D1"
self.assertEqual(expected_uuid, uuid)
@ -930,6 +932,12 @@ class NVMeOFConnectorTestCase(test_connector.ConnectorTestCase):
uuid = self.connector._get_host_uuid()
self.assertIsNone(uuid)
@mock.patch.object(nvmeof.NVMeOFConnector, '_execute', autospec=True)
def test_get_sysuuid_overlay(self, mock_execute):
mock_execute.return_value = ("overlay\n", "")
uuid = self.connector._get_host_uuid()
self.assertIsNone(uuid)
@mock.patch.object(utils, 'get_nvme_host_id',
return_value=SYS_UUID)
@mock.patch.object(nvmeof.NVMeOFConnector,

View File

@ -0,0 +1,4 @@
---
fixes:
- |
Fixes an warning seen when running in a container using ``overlayfs``.