From e5f1cd3c1e4ff0b46932bd1ad858974d4c930881 Mon Sep 17 00:00:00 2001 From: LuyaoZhong Date: Sun, 29 Sep 2019 08:54:41 +0000 Subject: [PATCH] make virtual pmem feature compatible with python3 convert floating-point number to integer when generating vpmem xml. Co-Authored-By: Eric Fried Change-Id: I6e94150820bf31a8404ef257db2b64b0d2ee9763 Closes-Bug: 1845905 (cherry picked from commit 6d5fdb4ef4dc3e5f40298e751d966ca54b2ae902) --- nova/tests/unit/virt/libvirt/test_driver.py | 42 +++++++++++++++++++++ nova/virt/libvirt/driver.py | 4 +- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index b4439a91d83d..02d44490efdd 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -25207,3 +25207,45 @@ class LibvirtPMEMNamespaceTests(test.NoDBTestCase): drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) self.assertRaises(exception.VPMEMCleanupFailed, drvr._cleanup_vpmems, vpmems) + + def test_guest_add_vpmems_int_values(self): + """Ensures XML is generated with integer size/align values. + + See bug #1845905. + """ + guest = vconfig.LibvirtConfigGuest() + guest.virt_type = 'kvm' + guest.name = 'name' + guest.uuid = 'uuid' + guest.memory = 1024 + vpmems = [self.vpmem_0] + drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) + drvr._guest_add_vpmems(guest, vpmems) + expected = ''' + + uuid + name + 1024 + 4193280 + 1 + + None + + + + + /dev/dax0.0 + 2048 + + + + 4192256 + 0 + + + + + ''' + self.assertXmlEqual(expected, guest.to_xml()) diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 5a891f3a51b1..d5e039636bf0 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -5778,8 +5778,8 @@ class LibvirtDriver(driver.ComputeDriver): guest.max_memory_size = guest.memory guest.max_memory_slots = 0 for vpmem in vpmems: - size_kb = vpmem.size / units.Ki - align_kb = vpmem.align / units.Ki + size_kb = vpmem.size // units.Ki + align_kb = vpmem.align // units.Ki vpmem_config = vconfig.LibvirtConfigGuestVPMEM( devpath=vpmem.devpath, size_kb=size_kb, align_kb=align_kb)