From e2bca67175199feda6ba0df2020236a2be188d35 Mon Sep 17 00:00:00 2001 From: Sahid Orentino Ferdjaoui Date: Fri, 24 Oct 2014 11:16:44 -0400 Subject: [PATCH] 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 --- nova/objects/instance_numa_topology.py | 21 ++++++++++++++----- .../objects/test_instance_numa_topology.py | 7 +++++-- nova/tests/objects/test_objects.py | 6 +++--- nova/virt/hardware.py | 4 +++- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/nova/objects/instance_numa_topology.py b/nova/objects/instance_numa_topology.py index 0754282d01c7..fbd60a800cd0 100644 --- a/nova/objects/instance_numa_topology.py +++ b/nova/objects/instance_numa_topology.py @@ -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) diff --git a/nova/tests/objects/test_instance_numa_topology.py b/nova/tests/objects/test_instance_numa_topology.py index c55756ad6005..1f9f3b40fec9 100644 --- a/nova/tests/objects/test_instance_numa_topology.py +++ b/nova/tests/objects/test_instance_numa_topology.py @@ -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): diff --git a/nova/tests/objects/test_objects.py b/nova/tests/objects/test_objects.py index ca926af2f92c..c26996f52e0b 100644 --- a/nova/tests/objects/test_objects.py +++ b/nova/tests/objects/test_objects.py @@ -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'}, diff --git a/nova/virt/hardware.py b/nova/virt/hardware.py index 37dd4e68adaa..31683cca2c0f 100644 --- a/nova/virt/hardware.py +++ b/nova/virt/hardware.py @@ -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))