Merge "Handle FileNotFoundError on get_system_uuid()"

This commit is contained in:
Zuul 2023-01-25 17:40:42 +00:00 committed by Gerrit Code Review
commit 655fcc41b3
2 changed files with 11 additions and 1 deletions

View File

@ -87,7 +87,7 @@ def get_system_uuid() -> str:
out, err = rootwrap.custom_execute('dmidecode', '-ssystem-uuid')
if not out:
LOG.warning('dmidecode returned empty system-uuid')
except putils.ProcessExecutionError as e:
except (putils.ProcessExecutionError, FileNotFoundError) as e:
LOG.debug("Unable to locate dmidecode. For Cinder RSD Backend,"
" please make sure it is installed: %s", e)
out = ""

View File

@ -166,3 +166,13 @@ class PrivNVMeTestCase(base.TestCase):
mock_open.assert_called_once_with('/sys/class/dmi/id/product_uuid',
'r')
mock_exec.assert_called_once_with('dmidecode', '-ssystem-uuid')
@mock.patch.object(builtins, 'open', side_effect=Exception)
@mock.patch.object(rootwrap, 'custom_execute',
side_effect=FileNotFoundError)
def test_get_system_uuid_dmidecode_missing(self, mock_exec, mock_open):
res = privsep_nvme.get_system_uuid()
self.assertEqual('', res)
mock_open.assert_called_once_with('/sys/class/dmi/id/product_uuid',
'r')
mock_exec.assert_called_once_with('dmidecode', '-ssystem-uuid')