Merge "Silence warning when running in a container with overlayfs"

This commit is contained in:
Zuul 2024-05-11 00:38:05 +00:00 committed by Gerrit Code Review
commit e81fc02105
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``.