From 823cda4b8a2102281facfcd666514fc6147d770a Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Mon, 4 Dec 2023 12:51:24 +0000 Subject: [PATCH] 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 bd07c571da7a3f78dbdec68af638b7e16181848d) --- os_brick/initiator/connectors/nvmeof.py | 7 ++++++- os_brick/tests/initiator/connectors/test_nvmeof.py | 12 ++++++++++-- .../fix-host-uuid-warning-3814b7e47bde8010.yaml | 4 ++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/fix-host-uuid-warning-3814b7e47bde8010.yaml diff --git a/os_brick/initiator/connectors/nvmeof.py b/os_brick/initiator/connectors/nvmeof.py index ee13c36d5..a140a7295 100644 --- a/os_brick/initiator/connectors/nvmeof.py +++ b/os_brick/initiator/connectors/nvmeof.py @@ -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] diff --git a/os_brick/tests/initiator/connectors/test_nvmeof.py b/os_brick/tests/initiator/connectors/test_nvmeof.py index 95156ee4b..07512ce63 100644 --- a/os_brick/tests/initiator/connectors/test_nvmeof.py +++ b/os_brick/tests/initiator/connectors/test_nvmeof.py @@ -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, diff --git a/releasenotes/notes/fix-host-uuid-warning-3814b7e47bde8010.yaml b/releasenotes/notes/fix-host-uuid-warning-3814b7e47bde8010.yaml new file mode 100644 index 000000000..863fd3714 --- /dev/null +++ b/releasenotes/notes/fix-host-uuid-warning-3814b7e47bde8010.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + Fixes an warning seen when running in a container using ``overlayfs``.