object: update instance numa object to handle pagesize

Work-item: Enhance libvirt driver to report available
           large pages per NUMA node in the host state data

Partial-Implement: blueprint virt-driver-large-pages
Change-Id: I392bdc45aa3b6b169c1d1bfdada624a16c77c91c
This commit is contained in:
Sahid Orentino Ferdjaoui 2014-10-24 11:16:44 -04:00
parent 2dc4f8937d
commit e2bca67175
4 changed files with 27 additions and 11 deletions

View File

@ -21,18 +21,21 @@ from nova.virt import hardware
class InstanceNUMACell(base.NovaObject):
# Version 1.0: Initial version
VERSION = '1.0'
# Version 1.1: Add pagesize field
VERSION = '1.1'
fields = {
'id': fields.IntegerField(read_only=True),
'cpuset': fields.SetOfIntegersField(),
'memory': fields.IntegerField(),
'pagesize': fields.IntegerField(nullable=True),
}
class InstanceNUMATopology(base.NovaObject):
# Version 1.0: Initial version
VERSION = '1.0'
# Version 1.1: Takes into account pagesize
VERSION = '1.1'
fields = {
# NOTE(danms): The 'id' field is no longer used and should be
@ -50,16 +53,24 @@ class InstanceNUMATopology(base.NovaObject):
if topology:
cells = []
for topocell in topology.cells:
pagesize = (topocell.pagesize
and topocell.pagesize.size_kb or None)
cell = InstanceNUMACell(id=topocell.id, cpuset=topocell.cpuset,
memory=topocell.memory)
memory=topocell.memory,
pagesize=pagesize)
cells.append(cell)
return cls(cells=cells)
def topology_from_obj(self):
cells = []
for objcell in self.cells:
cell = hardware.VirtNUMATopologyCellInstance(
objcell.id, objcell.cpuset, objcell.memory)
pagesize = (
objcell.pagesize and
hardware.VirtPageSize(objcell.pagesize) or None)
cell = hardware.VirtNUMATopologyCellInstance(objcell.id,
objcell.cpuset,
objcell.memory,
pagesize=pagesize)
cells.append(cell)
return hardware.VirtNUMAInstanceTopology(cells=cells)

View File

@ -20,8 +20,10 @@ from nova.tests.objects import test_objects
from nova.virt import hardware
fake_numa_topology = hardware.VirtNUMAInstanceTopology(
cells=[hardware.VirtNUMATopologyCellInstance(0, set([1, 2]), 512),
hardware.VirtNUMATopologyCellInstance(1, set([3, 4]), 512)])
cells=[hardware.VirtNUMATopologyCellInstance(
0, set([1, 2]), 512, hardware.VirtPageSize(2048)),
hardware.VirtNUMATopologyCellInstance(
1, set([3, 4]), 512, hardware.VirtPageSize(2048))])
fake_db_topology = {
'created_at': None,
@ -55,6 +57,7 @@ class _TestInstanceNUMATopology(object):
self.assertIsInstance(obj_cell, objects.InstanceNUMACell)
self.assertEqual(topo_cell.cpuset, obj_cell.cpuset)
self.assertEqual(topo_cell.memory, obj_cell.memory)
self.assertEqual(topo_cell.pagesize.size_kb, obj_cell.pagesize)
@mock.patch('nova.db.instance_extra_get_by_instance_uuid')
def test_get_by_instance_uuid_missing(self, mock_get):

View File

@ -961,8 +961,8 @@ object_data = {
'InstanceGroupList': '1.6-c6b78f3c9d9080d33c08667e80589817',
'InstanceInfoCache': '1.5-ef64b604498bfa505a8c93747a9d8b2f',
'InstanceList': '1.10-03dd7839cd11cff75c3661c9e4227900',
'InstanceNUMACell': '1.0-17e6ee0a24cb6651d1b084efa3027bda',
'InstanceNUMATopology': '1.0-86b95d263c4c68411d44c6741b8d2bb0',
'InstanceNUMACell': '1.1-8d2a13c8360cc9ea1b68c9c6c4476857',
'InstanceNUMATopology': '1.1-86b95d263c4c68411d44c6741b8d2bb0',
'InstancePCIRequest': '1.1-e082d174f4643e5756ba098c47c1510f',
'InstancePCIRequests': '1.1-bc7c6684d8579ee49d6a3b8aef756918',
'KeyPair': '1.1-3410f51950d052d861c11946a6ae621a',
@ -1000,7 +1000,7 @@ object_relationships = {
'FloatingIP': {'FixedIP': '1.6'},
'Instance': {'InstanceFault': '1.2',
'InstanceInfoCache': '1.5',
'InstanceNUMATopology': '1.0',
'InstanceNUMATopology': '1.1',
'PciDeviceList': '1.1',
'SecurityGroupList': '1.0',
'InstancePCIRequests': '1.1'},

View File

@ -1042,7 +1042,9 @@ def instance_topology_from_instance(instance):
if dict_cells:
cells = [objects.InstanceNUMACell(id=cell['id'],
cpuset=set(cell['cpuset']),
memory=cell['memory'])
memory=cell['memory'],
pagesize=cell.get(
'pagesize'))
for cell in dict_cells]
instance_numa_topology = (
objects.InstanceNUMATopology(cells=cells))