objects: Remove legacy '_to_dict' functions

These were made unnecessary in Kilo (commit bb3202f859) and no longer
have any callers outside of tests. It's time for them to go.

Part of blueprint numa-aware-vswitches

Change-Id: I5d7d02f94033dad83df5b60690cad76f7bc73039
This commit is contained in:
Stephen Finucane 2018-01-24 13:43:39 +00:00
parent 1fb782a6de
commit b44cb82bf8
7 changed files with 14 additions and 119 deletions

View File

@ -82,15 +82,6 @@ class InstanceNUMACell(base.NovaObject,
def __len__(self):
return len(self.cpuset)
def _to_dict(self):
# NOTE(sahid): Used as legacy, could be renamed in
# _legacy_to_dict_ to the future to avoid confusing.
return {'cpus': hardware.format_cpu_spec(self.cpuset,
allow_ranges=False),
'mem': {'total': self.memory},
'id': self.id,
'pagesize': self.pagesize}
@classmethod
def _from_dict(cls, data_dict):
# NOTE(sahid): Used as legacy, could be renamed in
@ -218,11 +209,6 @@ class InstanceNUMATopology(base.NovaObject,
"""Defined so that boolean testing works the same as for lists."""
return len(self.cells)
def _to_dict(self):
# NOTE(sahid): Used as legacy, could be renamed in _legacy_to_dict_
# in the future to avoid confusing.
return {'cells': [cell._to_dict() for cell in self.cells]}
@classmethod
def _from_dict(cls, data_dict):
# NOTE(sahid): Used as legacy, could be renamed in _legacy_from_dict_

View File

@ -22,6 +22,9 @@ from nova.virt import hardware
def all_things_equal(obj_a, obj_b):
if obj_b is None:
return False
for name in obj_a.fields:
set_a = obj_a.obj_attr_is_set(name)
set_b = obj_b.obj_attr_is_set(name)
@ -114,16 +117,6 @@ class NUMACell(base.NovaObject):
pin_siblings.update(sib)
self.unpin_cpus(pin_siblings)
def _to_dict(self):
return {
'id': self.id,
'cpus': hardware.format_cpu_spec(
self.cpuset, allow_ranges=False),
'mem': {
'total': self.memory,
'used': self.memory_usage},
'cpu_usage': self.cpu_usage}
@classmethod
def _from_dict(cls, data_dict):
cpuset = hardware.parse_cpu_spec(
@ -202,7 +195,13 @@ class NUMATopology(base.NovaObject):
fields = {
'cells': fields.ListOfObjectsField('NUMACell'),
}
}
def __eq__(self, other):
return all_things_equal(self, other)
def __ne__(self, other):
return not (self == other)
@property
def has_threads(self):
@ -237,10 +236,6 @@ class NUMATopology(base.NovaObject):
"""Defined so that boolean testing works the same as for lists."""
return len(self.cells)
def _to_dict(self):
# TODO(sahid): needs to be removed.
return {'cells': [cell._to_dict() for cell in self.cells]}
@classmethod
def _from_dict(cls, data_dict):
return cls(cells=[
@ -257,15 +252,3 @@ class NUMATopologyLimits(base.NovaObject):
'cpu_allocation_ratio': fields.FloatField(),
'ram_allocation_ratio': fields.FloatField(),
}
def to_dict_legacy(self, host_topology):
cells = []
for cell in host_topology.cells:
cells.append(
{'cpus': hardware.format_cpu_spec(
cell.cpuset, allow_ranges=False),
'mem': {'total': cell.memory,
'limit': cell.memory * self.ram_allocation_ratio},
'cpu_limit': len(cell.cpuset) * self.cpu_allocation_ratio,
'id': cell.id})
return {'cells': cells}

View File

@ -13,7 +13,6 @@
import copy
import mock
from oslo_serialization import jsonutils
from oslo_versionedobjects import base as ovo_base
from nova import exception
@ -33,8 +32,6 @@ fake_obj_numa_topology = objects.InstanceNUMATopology(
id=1, cpuset=set([3, 4]), memory=512, pagesize=2048)
])
fake_numa_topology = fake_obj_numa_topology._to_dict()
fake_db_topology = {
'created_at': None,
'updated_at': None,
@ -45,9 +42,6 @@ fake_db_topology = {
'numa_topology': fake_obj_numa_topology._to_json()
}
fake_old_db_topology = dict(fake_db_topology) # copy
fake_old_db_topology['numa_topology'] = jsonutils.dumps(fake_numa_topology)
def get_fake_obj_numa_topology(context):
fake_obj_numa_topology_cpy = fake_obj_numa_topology.obj_clone()
@ -81,11 +75,6 @@ class _TestInstanceNUMATopology(object):
mock_get.return_value = fake_db_topology
self._test_get_by_instance_uuid()
@mock.patch('nova.db.instance_extra_get_by_instance_uuid')
def test_get_by_instance_uuid_old(self, mock_get):
mock_get.return_value = fake_old_db_topology
self._test_get_by_instance_uuid()
@mock.patch('nova.db.instance_extra_get_by_instance_uuid')
def test_get_by_instance_uuid_missing(self, mock_get):
mock_get.return_value = None

View File

@ -32,28 +32,6 @@ fake_obj_numa = objects.NUMATopology(
class _TestNUMA(object):
def test_convert_wipe(self):
d1 = fake_obj_numa._to_dict()
d2 = objects.NUMATopology.obj_from_primitive(d1)._to_dict()
self.assertEqual(d1, d2)
def test_to_legacy_limits(self):
limits = objects.NUMATopologyLimits(
cpu_allocation_ratio=16,
ram_allocation_ratio=2)
host_topo = objects.NUMATopology(cells=[
objects.NUMACell(id=0, cpuset=set([1, 2]), memory=1024)
])
old_style = {'cells': [
{'mem': {'total': 1024,
'limit': 2048.0},
'id': 0,
'cpus': '1,2',
'cpu_limit': 32.0}]}
self.assertEqual(old_style, limits.to_dict_legacy(host_topo))
def test_free_cpus(self):
obj = objects.NUMATopology(cells=[
objects.NUMACell(

View File

@ -38,7 +38,6 @@ from nova.scheduler import host_manager
from nova import test
from nova.tests import fixtures
from nova.tests.unit import fake_instance
from nova.tests.unit import matchers
from nova.tests.unit.scheduler import fakes
from nova.tests import uuidsentinel as uuids
@ -589,11 +588,6 @@ class HostManagerTestCase(test.NoDBTestCase):
# 3071GB
self.assertEqual(host_states_map[('host3', 'node3')].free_disk_mb,
3145728)
self.assertThat(
objects.NUMATopology.obj_from_db_obj(
host_states_map[('host3', 'node3')].numa_topology
)._to_dict(),
matchers.DictMatches(fakes.NUMA_TOPOLOGY._to_dict()))
self.assertEqual(host_states_map[('host4', 'node4')].free_ram_mb,
8192)
# 8191GB

View File

@ -14909,19 +14909,7 @@ class LibvirtConnTestCase(test.NoDBTestCase,
[(4, 1024 * i), (2048, i)])
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
expected_topo_dict = {'cells': [
{'cpus': '0,1', 'cpu_usage': 0,
'mem': {'total': 256, 'used': 0},
'id': 0},
{'cpus': '3', 'cpu_usage': 0,
'mem': {'total': 256, 'used': 0},
'id': 1},
{'cpus': '', 'cpu_usage': 0,
'mem': {'total': 256, 'used': 0},
'id': 2},
{'cpus': '', 'cpu_usage': 0,
'mem': {'total': 256, 'used': 0},
'id': 3}]}
with test.nested(
mock.patch.object(host.Host, "get_capabilities",
return_value=caps),
@ -14932,9 +14920,6 @@ class LibvirtConnTestCase(test.NoDBTestCase,
return_value=set([0, 1, 2, 3, 6])),
):
got_topo = drvr._get_host_numa_topology()
got_topo_dict = got_topo._to_dict()
self.assertThat(
expected_topo_dict, matchers.DictMatches(got_topo_dict))
if mempages:
# cells 0
@ -14951,7 +14936,6 @@ class LibvirtConnTestCase(test.NoDBTestCase,
self.assertEqual([], got_topo.cells[0].mempages)
self.assertEqual([], got_topo.cells[1].mempages)
self.assertEqual(expected_topo_dict, got_topo_dict)
self.assertEqual(set([]), got_topo.cells[0].pinned_cpus)
self.assertEqual(set([]), got_topo.cells[1].pinned_cpus)
self.assertEqual(set([]), got_topo.cells[2].pinned_cpus)
@ -17543,10 +17527,9 @@ class HostStateTestCase(test.NoDBTestCase):
self.assertEqual(stats["disk_available_least"], 80)
self.assertEqual(jsonutils.loads(stats["pci_passthrough_devices"]),
HostStateTestCase.pci_devices)
self.assertThat(objects.NUMATopology.obj_from_db_obj(
stats['numa_topology'])._to_dict(),
matchers.DictMatches(
HostStateTestCase.numa_topology._to_dict()))
self.assertEqual(objects.NUMATopology.obj_from_db_obj(
stats['numa_topology']),
HostStateTestCase.numa_topology)
class TestUpdateProviderTree(test.NoDBTestCase):

View File

@ -1913,15 +1913,6 @@ class HelperMethodsTestCase(test.NoDBTestCase):
self.assertIsInstance(res, objects.NUMATopology)
self._check_usage(res)
def test_dicts_instance_json_old(self):
host = {'numa_topology': self.hosttopo}
instance = {'numa_topology':
jsonutils.dumps(self.instancetopo._to_dict())}
res = hw.get_host_numa_usage_from_instance(host, instance)
self.assertIsInstance(res, objects.NUMATopology)
self._check_usage(res)
def test_dicts_host_json(self):
host = {'numa_topology': self.hosttopo._to_json()}
instance = {'numa_topology': self.instancetopo}
@ -1930,15 +1921,6 @@ class HelperMethodsTestCase(test.NoDBTestCase):
self.assertIsInstance(res, six.string_types)
self._check_usage(objects.NUMATopology.obj_from_db_obj(res))
def test_dicts_host_json_old(self):
host = {'numa_topology': jsonutils.dumps(
self.hosttopo._to_dict())}
instance = {'numa_topology': self.instancetopo}
res = hw.get_host_numa_usage_from_instance(host, instance)
self.assertIsInstance(res, six.string_types)
self._check_usage(objects.NUMATopology.obj_from_db_obj(res))
def test_object_host_instance_json(self):
host = objects.ComputeNode(numa_topology=self.hosttopo._to_json())
instance = {'numa_topology': self.instancetopo._to_json()}