From 681e3776187d3ce3f7ccba8da056c007aa570232 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Fri, 10 Feb 2017 07:37:51 -0800 Subject: [PATCH] Remove straggling use of main db flavors in cellsv1 code This remaining use of the flavor query routine from the cellsv1 code still looks at the main database. This patch converts it to use the object which looks in the right place. Closes-Bug: #1663729 Change-Id: I418988ae1d72d541ace867a22b2c9267164bf61b (cherry picked from commit 6e5b1d289b68f635d369dc092eff5595fb12c331) --- nova/cells/state.py | 8 ++++---- nova/tests/unit/cells/test_cells_state_manager.py | 14 ++++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/nova/cells/state.py b/nova/cells/state.py index 3d680cec56e0..0ed5d7c83b71 100644 --- a/nova/cells/state.py +++ b/nova/cells/state.py @@ -298,12 +298,12 @@ class CellStateManager(base.Base): else: return 0 - instance_types = self.db.flavor_get_all(ctxt) + flavors = objects.FlavorList.get_all(ctxt) memory_mb_slots = frozenset( - [inst_type['memory_mb'] for inst_type in instance_types]) + [flavor.memory_mb for flavor in flavors]) disk_mb_slots = frozenset( - [(inst_type['root_gb'] + inst_type['ephemeral_gb']) * units.Ki - for inst_type in instance_types]) + [(flavor.root_gb + flavor.ephemeral_gb) * units.Ki + for flavor in flavors]) for compute_values in compute_hosts.values(): total_ram_mb_free += compute_values['free_ram_mb'] diff --git a/nova/tests/unit/cells/test_cells_state_manager.py b/nova/tests/unit/cells/test_cells_state_manager.py index d39f6f0c7454..390cb1debea8 100644 --- a/nova/tests/unit/cells/test_cells_state_manager.py +++ b/nova/tests/unit/cells/test_cells_state_manager.py @@ -112,11 +112,11 @@ def _fake_cell_get_all(context): return [] -def _fake_instance_type_all(context): +def _fake_instance_type_all(*args): def _type(mem, root, eph): - return {'root_gb': root, - 'ephemeral_gb': eph, - 'memory_mb': mem} + return objects.Flavor(root_gb=root, + ephemeral_gb=eph, + memory_mb=mem) return [_type(*fake) for fake in FAKE_ITYPES] @@ -130,7 +130,8 @@ class TestCellsStateManager(test.NoDBTestCase): _fake_compute_node_get_all) self.stub_out('nova.objects.ServiceList.get_by_binary', _fake_service_get_all_by_binary) - self.stub_out('nova.db.flavor_get_all', _fake_instance_type_all) + self.stub_out('nova.objects.FlavorList.get_all', + _fake_instance_type_all) self.stub_out('nova.db.cell_get_all', _fake_cell_get_all) def test_cells_config_not_found(self): @@ -268,7 +269,8 @@ class TestCellsStateManagerNodeDown(test.NoDBTestCase): _fake_compute_node_get_all) self.stub_out('nova.objects.ServiceList.get_by_binary', _fake_service_get_all_by_binary_nodedown) - self.stub_out('nova.db.flavor_get_all', _fake_instance_type_all) + self.stub_out('nova.objects.FlavorList.get_all', + _fake_instance_type_all) self.stub_out('nova.db.cell_get_all', _fake_cell_get_all) def test_capacity_no_reserve_nodedown(self):