From dbc5dfad8f63cedeb55cd4229a35b6092c6c3b66 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Thu, 4 Apr 2019 15:54:04 +0100 Subject: [PATCH] db: Remove cell APIs These are no longer needed. We can't actually remove the 'cells' table yet (that has to wait another release or two) but a TODO is added to ensure this eventually happens. The 'CellExists' and 'CellNotFound' exceptions, which were only raised by these APIs, are removed. Part of blueprint remove-cells-v1 Change-Id: Ibc402b446c9b92ce03a1dd98f41ec6cf5db20642 Signed-off-by: Stephen Finucane --- nova/db/api.py | 27 --------- nova/db/sqlalchemy/api.py | 45 -------------- nova/db/sqlalchemy/models.py | 3 + nova/exception.py | 8 --- nova/tests/unit/db/test_db_api.py | 98 ------------------------------- 5 files changed, 3 insertions(+), 178 deletions(-) diff --git a/nova/db/api.py b/nova/db/api.py index 8475935ad7..2188859165 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -1521,33 +1521,6 @@ def pci_device_update(context, node_id, address, value): return IMPL.pci_device_update(context, node_id, address, value) -################### - -def cell_create(context, values): - """Create a new child Cell entry.""" - return IMPL.cell_create(context, values) - - -def cell_update(context, cell_name, values): - """Update a child Cell entry.""" - return IMPL.cell_update(context, cell_name, values) - - -def cell_delete(context, cell_name): - """Delete a child Cell.""" - return IMPL.cell_delete(context, cell_name) - - -def cell_get(context, cell_name): - """Get a specific child Cell.""" - return IMPL.cell_get(context, cell_name) - - -def cell_get_all(context): - """Get all child Cells.""" - return IMPL.cell_get_all(context) - - #################### diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index ea4b7d6884..bff9e0b7c2 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -4577,51 +4577,6 @@ def console_get(context, console_id, instance_uuid=None): return result -################## - - -@pick_context_manager_writer -def cell_create(context, values): - cell = models.Cell() - cell.update(values) - try: - cell.save(context.session) - except db_exc.DBDuplicateEntry: - raise exception.CellExists(name=values['name']) - return cell - - -def _cell_get_by_name_query(context, cell_name): - return model_query(context, models.Cell).filter_by(name=cell_name) - - -@pick_context_manager_writer -def cell_update(context, cell_name, values): - cell_query = _cell_get_by_name_query(context, cell_name) - if not cell_query.update(values): - raise exception.CellNotFound(cell_name=cell_name) - cell = cell_query.first() - return cell - - -@pick_context_manager_writer -def cell_delete(context, cell_name): - return _cell_get_by_name_query(context, cell_name).soft_delete() - - -@pick_context_manager_reader -def cell_get(context, cell_name): - result = _cell_get_by_name_query(context, cell_name).first() - if not result: - raise exception.CellNotFound(cell_name=cell_name) - return result - - -@pick_context_manager_reader -def cell_get_all(context): - return model_query(context, models.Cell, read_deleted="no").all() - - ######################## # User-provided metadata diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index e7b65de3c1..8701711973 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -340,6 +340,7 @@ class Instance(BASE, NovaBase, models.SoftDeleteMixin): # OpenStack compute cell name. This will only be set at the top of # the cells tree and it'll be a full cell name such as 'api!hop1!hop2' + # TODO(stephenfin): Remove this cell_name = Column(String(255)) # NOTE(pumaranikar): internal_id attribute is no longer used (bug 1441242) @@ -1088,6 +1089,8 @@ class InstanceTypeExtraSpecs(BASE, NovaBase, models.SoftDeleteMixin): 'InstanceTypeExtraSpecs.deleted == 0)') +# TODO(stephenfin): Remove this in the U release or later, once we're sure we +# won't want it back (it's for cells v1, so we won't) class Cell(BASE, NovaBase, models.SoftDeleteMixin): """Represents parent and child cells of this cell. Cells can have multiple parents and children, so there could be any number diff --git a/nova/exception.py b/nova/exception.py index da83ced09d..f80417065e 100644 --- a/nova/exception.py +++ b/nova/exception.py @@ -1277,14 +1277,6 @@ class FlavorExtraSpecUpdateCreateFailed(NovaException): "after %(retries)d retries.") -class CellNotFound(NotFound): - msg_fmt = _("Cell %(cell_name)s doesn't exist.") - - -class CellExists(NovaException): - msg_fmt = _("Cell with name %(name)s already exists.") - - class CellTimeout(NotFound): msg_fmt = _("Timeout waiting for response from cell") diff --git a/nova/tests/unit/db/test_db_api.py b/nova/tests/unit/db/test_db_api.py index 4da143e49a..825e86b42c 100644 --- a/nova/tests/unit/db/test_db_api.py +++ b/nova/tests/unit/db/test_db_api.py @@ -7909,104 +7909,6 @@ class ConsoleTestCase(test.TestCase, ModelsObjectComparatorMixin): uuidsentinel.uuid2) -class CellTestCase(test.TestCase, ModelsObjectComparatorMixin): - - _ignored_keys = ['id', 'deleted', 'deleted_at', 'created_at', 'updated_at'] - - def setUp(self): - super(CellTestCase, self).setUp() - self.ctxt = context.get_admin_context() - - def _get_cell_base_values(self): - return { - 'name': 'myname', - 'api_url': 'apiurl', - 'transport_url': 'transporturl', - 'weight_offset': 0.5, - 'weight_scale': 1.5, - 'is_parent': True, - } - - def _cell_value_modify(self, value, step): - if isinstance(value, six.string_types): - return value + str(step) - elif isinstance(value, float): - return value + step + 0.6 - elif isinstance(value, bool): - return bool(step % 2) - elif isinstance(value, int): - return value + step - - def _create_cells(self): - test_values = [] - for x in range(1, 4): - modified_val = {k: self._cell_value_modify(v, x) - for k, v in self._get_cell_base_values().items()} - db.cell_create(self.ctxt, modified_val) - test_values.append(modified_val) - return test_values - - def test_cell_create(self): - cell = db.cell_create(self.ctxt, self._get_cell_base_values()) - self.assertIsNotNone(cell['id']) - self._assertEqualObjects(cell, self._get_cell_base_values(), - ignored_keys=self._ignored_keys) - - def test_cell_update(self): - db.cell_create(self.ctxt, self._get_cell_base_values()) - new_values = { - 'api_url': 'apiurl1', - 'transport_url': 'transporturl1', - 'weight_offset': 0.6, - 'weight_scale': 1.6, - 'is_parent': False, - } - test_cellname = self._get_cell_base_values()['name'] - updated_cell = db.cell_update(self.ctxt, test_cellname, new_values) - self._assertEqualObjects(updated_cell, new_values, - ignored_keys=self._ignored_keys + ['name']) - - def test_cell_delete(self): - new_cells = self._create_cells() - for cell in new_cells: - test_cellname = cell['name'] - db.cell_delete(self.ctxt, test_cellname) - self.assertRaises(exception.CellNotFound, db.cell_get, self.ctxt, - test_cellname) - - def test_cell_get(self): - new_cells = self._create_cells() - for cell in new_cells: - cell_get = db.cell_get(self.ctxt, cell['name']) - self._assertEqualObjects(cell_get, cell, - ignored_keys=self._ignored_keys) - - def test_cell_get_all(self): - new_cells = self._create_cells() - cells = db.cell_get_all(self.ctxt) - self.assertEqual(len(new_cells), len(cells)) - cells_byname = {newcell['name']: newcell - for newcell in new_cells} - for cell in cells: - self._assertEqualObjects(cell, cells_byname[cell['name']], - self._ignored_keys) - - def test_cell_get_not_found(self): - self._create_cells() - self.assertRaises(exception.CellNotFound, db.cell_get, self.ctxt, - 'cellnotinbase') - - def test_cell_update_not_found(self): - self._create_cells() - self.assertRaises(exception.CellNotFound, db.cell_update, self.ctxt, - 'cellnotinbase', self._get_cell_base_values()) - - def test_cell_create_exists(self): - db.cell_create(self.ctxt, self._get_cell_base_values()) - self.assertRaises(exception.CellExists, db.cell_create, - self.ctxt, self._get_cell_base_values()) - - class ConsolePoolTestCase(test.TestCase, ModelsObjectComparatorMixin): def setUp(self): super(ConsolePoolTestCase, self).setUp()