Skip to content

Commit

Permalink
libvirt: avoid setting the memnodes where when it's not a supported o…
Browse files Browse the repository at this point in the history
…ption

The current version of Libvirt in the gate doesn't support a memnode element
in the numa tune configuration. When requesting guest topology the instance
is crashing. Not setting the numa tune memnodes option when libvirt version
is less than the required minimum.

Change-Id: I99d0bb64bd6d698f2d5ce978cb3778bbad8eec91
Closes-Bug: #1415333
  • Loading branch information
vladikr committed Feb 2, 2015
1 parent 2ff5573 commit cf3a126
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
21 changes: 21 additions & 0 deletions nova/tests/unit/virt/libvirt/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,27 @@ def test_get_guest_memory_backing_config_mempages_none(self):
self.assertIsNone(self._test_get_guest_memory_backing_config(
'not_empty', 'not_empty', 'not_empty'))

def test_get_guest_numa_tune_memnodes(self):
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
guest_cpu_numa_config = objects.InstanceNUMATopology(cells=[
objects.InstanceNUMACell(
id=1, cpuset=set([0, 1]),
memory=1024, pagesize=2048)])
memnodes = [vconfig.LibvirtConfigGuestNUMATuneMemNode()]
with mock.patch.object(host.Host, 'has_min_version',
return_value=True):
self.assertIsNotNone(drvr._get_guest_numa_tune_memnodes(
guest_cpu_numa_config, memnodes))
self.assertEqual(guest_cpu_numa_config.cells[0].id,
memnodes[0].cellid)

def test_get_guest_numa_tune_memnodes_none(self):
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True)
with mock.patch.object(host.Host, 'has_min_version',
return_value=False):
self.assertIsNone(drvr._get_guest_numa_tune_memnodes(
'something', 'something'))

@mock.patch.object(objects.Flavor, 'get_by_id')
def test_get_guest_config_numa_host_instance_fit_w_cpu_pinset(self,
mock_flavor):
Expand Down
24 changes: 19 additions & 5 deletions nova/virt/libvirt/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ def repr_method(self):
MIN_LIBVIRT_FSFREEZE_VERSION = (1, 2, 5)
# libvirt mempage size report
MIN_LIBVIRT_MEMPAGES_VERSION = (1, 2, 8)
# libvirt memory allocation policy for each guest NUMA node
MIN_LIBVIRT_MEMNODE_VERSION = (1, 2, 7)

# Hyper-V paravirtualized time source
MIN_LIBVIRT_HYPERV_TIMER_VERSION = (1, 2, 2)
Expand Down Expand Up @@ -3481,14 +3483,14 @@ def _get_guest_numa_config(self, instance_numa_topology, flavor,
guest_cpu_tune.vcpupin.sort(key=operator.attrgetter("id"))

guest_numa_tune.memory = numa_mem
guest_numa_tune.memnodes = numa_memnodes

# normalize cell.id
for i, (cell, memnode) in enumerate(
zip(guest_cpu_numa_config.cells,
guest_numa_tune.memnodes)):
for i, cell in enumerate(guest_cpu_numa_config.cells):
cell.id = i
memnode.cellid = i

guest_numa_tune.memnodes = self._get_guest_numa_tune_memnodes(
guest_cpu_numa_config,
numa_memnodes)

return GuestNumaConfig(None, guest_cpu_tune,
guest_cpu_numa_config,
Expand All @@ -3497,6 +3499,18 @@ def _get_guest_numa_config(self, instance_numa_topology, flavor,
return GuestNumaConfig(allowed_cpus, None,
guest_cpu_numa_config, None)

def _get_guest_numa_tune_memnodes(self, guest_cpu_numa_config,
numa_memnodes):
if not self._host.has_min_version(MIN_LIBVIRT_MEMNODE_VERSION):
return

# normalize cell.id
for (cell, memnode) in zip(guest_cpu_numa_config.cells,
numa_memnodes):
memnode.cellid = cell.id

return numa_memnodes

def _get_guest_os_type(self, virt_type):
"""Returns the guest OS type based on virt type."""
if virt_type == "lxc":
Expand Down

0 comments on commit cf3a126

Please sign in to comment.