2015-07-28 13:55:30 |
Andrea Rosa |
description |
the _get_host_sysinfo_serial_os method try to read the machine-id file to get an UUID for the host operating system.
If the file is there but it is empty the code will raise an exception while it tries to parse the content of the file.
To reproduce the issue just add this test to the nova/tests/unit/virt/libvirt/test_driver.py
def test_get_guest_config_sysinfo_serial_os_empty_machine_id(self):
self.flags(sysinfo_serial="os", group="libvirt")
real_open = __builtin__.open
with contextlib.nested(
mock.patch.object(__builtin__, "open"),
) as (mock_open, ):
theuuid = ""
def fake_open(filename, *args, **kwargs):
if filename == "/etc/machine-id":
h = mock.MagicMock()
h.read.return_value = theuuid
h.__enter__.return_value = h
return h
return real_open(filename, *args, **kwargs)
mock_open.side_effect = fake_open
self._test_get_guest_config_sysinfo_serial(None) |
When the sysinfo_serial config parameter for the libvirt driver is set to 'os', the defined behavior is:
- return the value found in /etc/machine-id file or
- return an error if the file is not present.
There is an additional scenario where the file is present but it is empty
(https://bugs.launchpad.net/ubuntu/+source/nova/+bug/1413293) in that case we want nova to behave as if the file was missed.
At the moment the missing file and an empty file return different exceptions:
- IOError for a missing file
- IndexError for an empty file
Both of these errors are too general and don't give a big help in debugging the issue.
Please note that we do not want to fix the issue about a missing/empty machine-id file, that is something related to a bad OS installation/configuration or a bad image, the proposed fix is just to keep nova behaves consistently and giving back to the user a more clear and precise error. |
|