Skip to content

Commit

Permalink
libvirt: 'video.vram' property must be an integer
Browse files Browse the repository at this point in the history
The 'vram' property of the 'video' device must be an integer else
libvirt will spit the dummy out, e.g.

  libvirt.libvirtError: XML error: cannot parse video vram '8192.0'

The division operator in Python 3 results in a float, not an integer
like in Python 2. Use the truncation division operator instead.

Change-Id: Iebf678c229da4f455459d068cafeee5f241aea1f
Signed-off-by: Stephen Finucane <[email protected]>
Closes-Bug: #1896496
(cherry picked from commit f2ca089)
  • Loading branch information
stephenfin committed Oct 12, 2020
1 parent 7baca2b commit fd7c66f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions nova/tests/unit/virt/libvirt/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -6716,7 +6716,7 @@ def test_get_guest_config_with_video_driver_vram(self):

self.assertEqual(cfg.devices[4].type, "spice")
self.assertEqual(cfg.devices[5].type, "qxl")
self.assertEqual(cfg.devices[5].vram, 64 * units.Mi / units.Ki)
self.assertEqual(cfg.devices[5].vram, 65536)

def _test_add_video_driver(self, model):
self.flags(virt_type='kvm', group='libvirt')
Expand All @@ -6727,15 +6727,19 @@ def _test_add_video_driver(self, model):

drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
guest = vconfig.LibvirtConfigGuest()
instance_ref = objects.Instance(**self.test_instance)
flavor = instance_ref.get_flavor()
flavor = objects.Flavor(
extra_specs={'hw_video:ram_max_mb': '512'})
image_meta = objects.ImageMeta.from_dict({
'properties': {'hw_video_model': model}})
'properties': {
'hw_video_model': model,
'hw_video_ram': 8,
},
})

self.assertTrue(drvr._guest_add_video_device(guest))
video = drvr._add_video_driver(guest, image_meta,
flavor)
video = drvr._add_video_driver(guest, image_meta, flavor)
self.assertEqual(model, video.type)
self.assertEqual(8192, video.vram) # should be in bytes

def test__add_video_driver(self):
self._test_add_video_driver('qxl')
Expand Down
2 changes: 1 addition & 1 deletion nova/virt/libvirt/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5522,7 +5522,7 @@ def _add_video_driver(self, guest, image_meta, flavor):
raise exception.RequestedVRamTooHigh(req_vram=video_ram,
max_vram=max_vram)
if max_vram and video_ram:
video.vram = video_ram * units.Mi / units.Ki
video.vram = video_ram * units.Mi // units.Ki
guest.add_device(video)

# NOTE(sean-k-mooney): return the video device we added
Expand Down

0 comments on commit fd7c66f

Please sign in to comment.