Add CellMappingList object
The ability to get a list of all CellMapping objects is needed for some tooling around adding new hosts to a cell. This adds the necessary class/method. Change-Id: Ia402a49d68a5c69891d39c95ac92ea1ceeb99739
This commit is contained in:
@@ -103,3 +103,23 @@ class CellMapping(base.NovaTimestampObject, base.NovaObject):
|
|||||||
@base.remotable
|
@base.remotable
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
self._destroy_in_db(self._context, self.uuid)
|
self._destroy_in_db(self._context, self.uuid)
|
||||||
|
|
||||||
|
|
||||||
|
@base.NovaObjectRegistry.register
|
||||||
|
class CellMappingList(base.ObjectListBase, base.NovaObject):
|
||||||
|
# Version 1.0: Initial version
|
||||||
|
VERSION = '1.0'
|
||||||
|
|
||||||
|
fields = {
|
||||||
|
'objects': fields.ListOfObjectsField('CellMapping'),
|
||||||
|
}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
@db_api.api_context_manager.reader
|
||||||
|
def _get_all_from_db(context):
|
||||||
|
return context.session.query(api_models.CellMapping).all()
|
||||||
|
|
||||||
|
@base.remotable_classmethod
|
||||||
|
def get_all(cls, context):
|
||||||
|
db_mappings = cls._get_all_from_db(context)
|
||||||
|
return base.obj_make_list(context, cls(), CellMapping, db_mappings)
|
||||||
|
|||||||
@@ -19,6 +19,21 @@ from nova import test
|
|||||||
from nova.tests import fixtures
|
from nova.tests import fixtures
|
||||||
|
|
||||||
|
|
||||||
|
SAMPLE_MAPPING = {'uuid': '',
|
||||||
|
'name': 'fake-cell',
|
||||||
|
'transport_url': 'rabbit:///',
|
||||||
|
'database_connection': 'mysql+pymysql:///'}
|
||||||
|
|
||||||
|
|
||||||
|
def create_mapping(**kwargs):
|
||||||
|
args = SAMPLE_MAPPING.copy()
|
||||||
|
if 'uuid' not in kwargs:
|
||||||
|
args['uuid'] = uuidutils.generate_uuid()
|
||||||
|
args.update(kwargs)
|
||||||
|
ctxt = context.RequestContext()
|
||||||
|
return cell_mapping.CellMapping._create_in_db(ctxt, args)
|
||||||
|
|
||||||
|
|
||||||
class CellMappingTestCase(test.NoDBTestCase):
|
class CellMappingTestCase(test.NoDBTestCase):
|
||||||
USES_DB_SELF = True
|
USES_DB_SELF = True
|
||||||
|
|
||||||
@@ -27,22 +42,9 @@ class CellMappingTestCase(test.NoDBTestCase):
|
|||||||
self.useFixture(fixtures.Database(database='api'))
|
self.useFixture(fixtures.Database(database='api'))
|
||||||
self.context = context.RequestContext('fake-user', 'fake-project')
|
self.context = context.RequestContext('fake-user', 'fake-project')
|
||||||
self.mapping_obj = cell_mapping.CellMapping()
|
self.mapping_obj = cell_mapping.CellMapping()
|
||||||
self.uuid = uuidutils.generate_uuid()
|
|
||||||
|
|
||||||
sample_mapping = {'uuid': '',
|
|
||||||
'name': 'fake-cell',
|
|
||||||
'transport_url': 'rabbit:///',
|
|
||||||
'database_connection': 'mysql+pymysql:///'}
|
|
||||||
|
|
||||||
def _create_mapping(self, **kwargs):
|
|
||||||
args = self.sample_mapping.copy()
|
|
||||||
if 'uuid' not in kwargs:
|
|
||||||
args['uuid'] = self.uuid
|
|
||||||
args.update(kwargs)
|
|
||||||
return self.mapping_obj._create_in_db(self.context, args)
|
|
||||||
|
|
||||||
def test_get_by_uuid(self):
|
def test_get_by_uuid(self):
|
||||||
mapping = self._create_mapping()
|
mapping = create_mapping()
|
||||||
db_mapping = self.mapping_obj._get_by_uuid_from_db(self.context,
|
db_mapping = self.mapping_obj._get_by_uuid_from_db(self.context,
|
||||||
mapping['uuid'])
|
mapping['uuid'])
|
||||||
for key in self.mapping_obj.fields.keys():
|
for key in self.mapping_obj.fields.keys():
|
||||||
@@ -50,10 +52,11 @@ class CellMappingTestCase(test.NoDBTestCase):
|
|||||||
|
|
||||||
def test_get_by_uuid_not_found(self):
|
def test_get_by_uuid_not_found(self):
|
||||||
self.assertRaises(exception.CellMappingNotFound,
|
self.assertRaises(exception.CellMappingNotFound,
|
||||||
self.mapping_obj._get_by_uuid_from_db, self.context, self.uuid)
|
self.mapping_obj._get_by_uuid_from_db, self.context,
|
||||||
|
uuidutils.generate_uuid())
|
||||||
|
|
||||||
def test_save_in_db(self):
|
def test_save_in_db(self):
|
||||||
mapping = self._create_mapping()
|
mapping = create_mapping()
|
||||||
self.mapping_obj._save_in_db(self.context, mapping['uuid'],
|
self.mapping_obj._save_in_db(self.context, mapping['uuid'],
|
||||||
{'name': 'meow'})
|
{'name': 'meow'})
|
||||||
db_mapping = self.mapping_obj._get_by_uuid_from_db(self.context,
|
db_mapping = self.mapping_obj._get_by_uuid_from_db(self.context,
|
||||||
@@ -64,7 +67,7 @@ class CellMappingTestCase(test.NoDBTestCase):
|
|||||||
self.assertEqual(db_mapping[key], mapping[key])
|
self.assertEqual(db_mapping[key], mapping[key])
|
||||||
|
|
||||||
def test_destroy_in_db(self):
|
def test_destroy_in_db(self):
|
||||||
mapping = self._create_mapping()
|
mapping = create_mapping()
|
||||||
self.mapping_obj._get_by_uuid_from_db(self.context, mapping['uuid'])
|
self.mapping_obj._get_by_uuid_from_db(self.context, mapping['uuid'])
|
||||||
self.mapping_obj._destroy_in_db(self.context, mapping['uuid'])
|
self.mapping_obj._destroy_in_db(self.context, mapping['uuid'])
|
||||||
self.assertRaises(exception.CellMappingNotFound,
|
self.assertRaises(exception.CellMappingNotFound,
|
||||||
@@ -73,4 +76,25 @@ class CellMappingTestCase(test.NoDBTestCase):
|
|||||||
|
|
||||||
def test_destroy_in_db_not_found(self):
|
def test_destroy_in_db_not_found(self):
|
||||||
self.assertRaises(exception.CellMappingNotFound,
|
self.assertRaises(exception.CellMappingNotFound,
|
||||||
self.mapping_obj._destroy_in_db, self.context, self.uuid)
|
self.mapping_obj._destroy_in_db, self.context,
|
||||||
|
uuidutils.generate_uuid())
|
||||||
|
|
||||||
|
|
||||||
|
class CellMappingListTestCase(test.NoDBTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super(CellMappingListTestCase, self).setUp()
|
||||||
|
self.useFixture(fixtures.Database(database='api'))
|
||||||
|
|
||||||
|
def test_get_all(self):
|
||||||
|
mappings = {}
|
||||||
|
mapping = create_mapping()
|
||||||
|
mappings[mapping['uuid']] = mapping
|
||||||
|
mapping = create_mapping()
|
||||||
|
mappings[mapping['uuid']] = mapping
|
||||||
|
|
||||||
|
ctxt = context.RequestContext()
|
||||||
|
db_mappings = cell_mapping.CellMappingList._get_all_from_db(ctxt)
|
||||||
|
for db_mapping in db_mappings:
|
||||||
|
mapping = mappings[db_mapping.uuid]
|
||||||
|
for key in cell_mapping.CellMapping.fields.keys():
|
||||||
|
self.assertEqual(db_mapping[key], mapping[key])
|
||||||
|
|||||||
@@ -106,3 +106,25 @@ class TestCellMappingObject(test_objects._LocalTest,
|
|||||||
class TestRemoteCellMappingObject(test_objects._RemoteTest,
|
class TestRemoteCellMappingObject(test_objects._RemoteTest,
|
||||||
_TestCellMappingObject):
|
_TestCellMappingObject):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class _TestCellMappingListObject(object):
|
||||||
|
@mock.patch.object(cell_mapping.CellMappingList, '_get_all_from_db')
|
||||||
|
def test_get_all(self, get_all_from_db):
|
||||||
|
db_mapping = get_db_mapping()
|
||||||
|
get_all_from_db.return_value = [db_mapping]
|
||||||
|
|
||||||
|
mapping_obj = objects.CellMappingList.get_all(self.context)
|
||||||
|
|
||||||
|
get_all_from_db.assert_called_once_with(self.context)
|
||||||
|
self.compare_obj(mapping_obj.objects[0], db_mapping)
|
||||||
|
|
||||||
|
|
||||||
|
class TestCellMappingListObject(test_objects._LocalTest,
|
||||||
|
_TestCellMappingListObject):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class TestRemoteCellMappingListObject(test_objects._RemoteTest,
|
||||||
|
_TestCellMappingListObject):
|
||||||
|
pass
|
||||||
|
|||||||
@@ -1108,6 +1108,7 @@ object_data = {
|
|||||||
'BlockDeviceMappingList': '1.17-1e568eecb91d06d4112db9fd656de235',
|
'BlockDeviceMappingList': '1.17-1e568eecb91d06d4112db9fd656de235',
|
||||||
'BuildRequest': '1.0-c6cd434db5cbdb4d1ebb935424261377',
|
'BuildRequest': '1.0-c6cd434db5cbdb4d1ebb935424261377',
|
||||||
'CellMapping': '1.0-7f1a7e85a22bbb7559fc730ab658b9bd',
|
'CellMapping': '1.0-7f1a7e85a22bbb7559fc730ab658b9bd',
|
||||||
|
'CellMappingList': '1.0-4ee0d9efdfd681fed822da88376e04d2',
|
||||||
'ComputeNode': '1.16-2436e5b836fa0306a3c4e6d9e5ddacec',
|
'ComputeNode': '1.16-2436e5b836fa0306a3c4e6d9e5ddacec',
|
||||||
'ComputeNodeList': '1.14-3b6f4f5ade621c40e70cb116db237844',
|
'ComputeNodeList': '1.14-3b6f4f5ade621c40e70cb116db237844',
|
||||||
'DNSDomain': '1.0-7b0b2dab778454b6a7b6c66afe163a1a',
|
'DNSDomain': '1.0-7b0b2dab778454b6a7b6c66afe163a1a',
|
||||||
|
|||||||
Reference in New Issue
Block a user