Create HostMappingList object

This creates the HostMappingList object which will provide
a way to list HostMappings by a given CellMapping.id. This
is going to be used later in a "nova-manage cell_v2 delete_cell"
command.

Change-Id: I58e0c5565013d8ef9753a9566841e83573a85afd
Related-Bug: #1656691
This commit is contained in:
Matt Riedemann 2017-01-15 15:28:01 -05:00
parent 4bfc550261
commit 8677aca654
3 changed files with 37 additions and 0 deletions

View File

@ -141,3 +141,25 @@ class HostMapping(base.NovaTimestampObject, base.NovaObject):
@base.remotable
def destroy(self):
self._destroy_in_db(self._context, self.host)
@base.NovaObjectRegistry.register
class HostMappingList(base.ObjectListBase, base.NovaObject):
# Version 1.0: Initial version
VERSION = '1.0'
fields = {
'objects': fields.ListOfObjectsField('HostMapping'),
}
@staticmethod
@db_api.api_context_manager.reader
def _get_by_cell_id_from_db(context, cell_id):
return (context.session.query(api_models.HostMapping)
.options(joinedload('cell_mapping'))
.filter(api_models.HostMapping.cell_id == cell_id)).all()
@base.remotable_classmethod
def get_by_cell_id(cls, context, cell_id):
db_mappings = cls._get_by_cell_id_from_db(context, cell_id)
return base.obj_make_list(context, cls(), HostMapping, db_mappings)

View File

@ -120,3 +120,17 @@ class HostMappingTestCase(test.NoDBTestCase):
mapping_obj = create_mapping_obj(self.context, cell_mapping=cell)
cell_map_obj = mapping_obj.cell_mapping
self._compare_cell_obj_to_mapping(cell_map_obj, cell)
def test_host_mapping_list_get_by_cell_id(self):
"""Tests getting all of the HostMappings for a given CellMapping id.
"""
# we shouldn't have any host mappings yet
self.assertEqual(0, len(host_mapping.HostMappingList.get_by_cell_id(
self.context, sample_cell_mapping['id'])))
# now create a host mapping
db_host_mapping = create_mapping()
# now we should list out one host mapping for the cell
host_mapping_list = host_mapping.HostMappingList.get_by_cell_id(
self.context, db_host_mapping['cell_id'])
self.assertEqual(1, len(host_mapping_list))
self.assertEqual(db_host_mapping['id'], host_mapping_list[0].id)

View File

@ -1091,6 +1091,7 @@ object_data = {
'FloatingIP': '1.10-52a67d52d85eb8b3f324a5b7935a335b',
'FloatingIPList': '1.11-7f2ba670714e1b7bab462ab3290f7159',
'HostMapping': '1.0-1a3390a696792a552ab7bd31a77ba9ac',
'HostMappingList': '1.0-267d952a5d48361d6d7604f50775bc34',
'HyperVLiveMigrateData': '1.1-9987a3cec31a81abac6fba7cc722e43f',
'HVSpec': '1.2-de06bcec472a2f04966b855a49c46b41',
'IDEDeviceBus': '1.0-29d4c9f27ac44197f01b6ac1b7e16502',