From dec5dd9286e0d218d3f7658879369b5d4a529a65 Mon Sep 17 00:00:00 2001 From: Kevin_Zheng Date: Mon, 26 Nov 2018 11:47:33 +0800 Subject: [PATCH] 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 --- nova/conf/libvirt.py | 16 +++++++++++++--- nova/tests/unit/virt/libvirt/test_driver.py | 6 ++++++ nova/virt/libvirt/driver.py | 5 ++++- .../per-instance-serial-f2e597cb05d1b09e.yaml | 7 +++++++ 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/per-instance-serial-f2e597cb05d1b09e.yaml diff --git a/nova/conf/libvirt.py b/nova/conf/libvirt.py index 3f368f9aa89d..4d87ea616a75 100644 --- a/nova/conf/libvirt.py +++ b/nova/conf/libvirt.py @@ -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. ' diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 84d05a55c280..12c3e82f86bb 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -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): diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index e762b27b8c25..0d18bc5663ad 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -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" diff --git a/releasenotes/notes/per-instance-serial-f2e597cb05d1b09e.yaml b/releasenotes/notes/per-instance-serial-f2e597cb05d1b09e.yaml new file mode 100644 index 000000000000..66ac2f4bab8a --- /dev/null +++ b/releasenotes/notes/per-instance-serial-f2e597cb05d1b09e.yaml @@ -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.