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``.