Per-instance serial number

Added a new ``unique`` choice to the ``[libvirt]/sysinfo_serial``
configuration which if set will result in the guest serial number
being set to ``instance.uuid`` on this host. It is also made to be
the default value of ``[libvirt]/sysinfo_serial`` config option.

Implements: blueprint per-instance-libvirt-sysinfo-serial

Change-Id: I001beb2840496f7950988acc69018244847aa888
This commit is contained in:
Kevin_Zheng 2018-11-26 11:47:33 +08:00
parent 16dda27748
commit dec5dd9286
4 changed files with 30 additions and 4 deletions

View File

@ -716,21 +716,31 @@ http://man7.org/linux/man-pages/man7/random.7.html.
'value for this config option is host-arch=machine-type. '
'For example: x86_64=machinetype1,armv7l=machinetype2'),
cfg.StrOpt('sysinfo_serial',
default='auto',
default='unique',
choices=(
('none', 'A serial number entry is not added to the guest '
'domain xml.'),
('os', 'A UUID serial number is generated from the host '
'``/etc/machine-id`` file.'),
'``/etc/machine-id`` file. This will also affect '
'existing instances on this host once they stop '
'and start again.'),
('hardware', 'A UUID for the host hardware as reported by '
'libvirt. This is typically from the host '
'SMBIOS data, unless it has been overridden '
'in ``libvirtd.conf``.'),
('auto', 'Uses the "os" source if possible, else '
'"hardware".'),
('unique', 'Uses instance UUID as the serial number. '
'This will also affect existing instances '
'on this host once they stop and start again.'),
),
help='The data source used to the populate the host "serial" '
'UUID exposed to guest in the virtual BIOS.'),
'UUID exposed to guest in the virtual BIOS. All choices '
'except ``unique`` will change the serial when migrating '
'instance to other host. Changing the choice of this '
'option will also affect existing instances on this host '
'once they stopped and started again.'
),
cfg.IntOpt('mem_stats_period_seconds',
default=10,
help='A number of seconds to memory usage statistics period. '

View File

@ -17927,6 +17927,8 @@ class TestGuestConfigSysinfoSerialOS(test.NoDBTestCase):
cfg.system_product)
self.assertEqual(version.version_string_with_package(),
cfg.system_version)
if expected_serial == 'instance_uuid':
expected_serial = instance_ref['uuid']
self.assertEqual(expected_serial,
cfg.system_serial)
self.assertEqual(instance_ref['uuid'],
@ -18025,6 +18027,10 @@ class TestGuestConfigSysinfoSerialOS(test.NoDBTestCase):
self._test_get_guest_config_sysinfo_serial(theuuid)
def test_get_guest_config_sysinfo_serial_unique(self):
self.flags(sysinfo_serial="unique", group="libvirt")
self._test_get_guest_config_sysinfo_serial('instance_uuid')
class HostStateTestCase(test.NoDBTestCase):

View File

@ -4154,7 +4154,10 @@ class LibvirtDriver(driver.ComputeDriver):
sysinfo.system_product = version.product_string()
sysinfo.system_version = version.version_string_with_package()
sysinfo.system_serial = self._sysinfo_serial_func()
if CONF.libvirt.sysinfo_serial == 'unique':
sysinfo.system_serial = instance.uuid
else:
sysinfo.system_serial = self._sysinfo_serial_func()
sysinfo.system_uuid = instance.uuid
sysinfo.system_family = "Virtual Machine"

View File

@ -0,0 +1,7 @@
---
upgrade:
- |
Added a new ``unique`` choice to the ``[libvirt]/sysinfo_serial``
configuration which if set will result in the guest serial number being
set to ``instance.uuid`` on this host. This is now the default value
of ``[libvirt]/sysinfo_serial`` config option.