Merge "Add InstanceList.get_uuids_by_host() call"

This commit is contained in:
Jenkins 2016-08-02 20:30:15 +00:00 committed by Gerrit Code Review
commit e0905535fe
3 changed files with 25 additions and 2 deletions

View File

@ -1132,7 +1132,8 @@ def _make_instance_list(context, inst_list, db_inst_list, expected_attrs):
@base.NovaObjectRegistry.register
class InstanceList(base.ObjectListBase, base.NovaObject):
# Version 2.0: Initial Version
VERSION = '2.0'
# Version 2.1: Add get_uuids_by_host()
VERSION = '2.1'
fields = {
'objects': fields.ListOfObjectsField('Instance'),
@ -1308,6 +1309,14 @@ class InstanceList(base.ObjectListBase, base.NovaObject):
return faults_by_uuid.keys()
@base.remotable_classmethod
def get_uuids_by_host(cls, context, host):
# NOTE(danms): We could potentially do this a little more efficiently
# but for now just pull all the instances and scrape the uuids.
db_instances = db.instance_get_all_by_host(context, host,
columns_to_join=[])
return [inst['uuid'] for inst in db_instances]
@db_api.main_context_manager.writer
def _migrate_instance_keypairs(ctxt, count):

View File

@ -1822,6 +1822,20 @@ class _TestInstanceListObject(object):
self.assertEqual(2, len(instances))
self.assertEqual([1, 2], [x.id for x in instances])
@mock.patch('nova.db.instance_get_all_by_host')
def test_get_uuids_by_host(self, mock_get_all):
fake_instances = [
fake_instance.fake_db_instance(id=1),
fake_instance.fake_db_instance(id=2),
]
mock_get_all.return_value = fake_instances
expected_uuids = [inst['uuid'] for inst in fake_instances]
actual_uuids = objects.InstanceList.get_uuids_by_host(
self.context, 'b')
self.assertEqual(expected_uuids, actual_uuids)
mock_get_all.assert_called_once_with(self.context, 'b',
columns_to_join=[])
class TestInstanceListObject(test_objects._LocalTest,
_TestInstanceListObject):

View File

@ -1145,7 +1145,7 @@ object_data = {
'InstanceGroup': '1.10-1a0c8c7447dc7ecb9da53849430c4a5f',
'InstanceGroupList': '1.7-be18078220513316abd0ae1b2d916873',
'InstanceInfoCache': '1.5-cd8b96fefe0fc8d4d337243ba0bf0e1e',
'InstanceList': '2.0-6c8ba6147cca3082b1e4643f795068bf',
'InstanceList': '2.1-e64b9f623db6370b22ec910461f06a52',
'InstanceMapping': '1.0-65de80c491f54d19374703c0753c4d47',
'InstanceMappingList': '1.0-9e982e3de1613b9ada85e35f69b23d47',
'InstanceNUMACell': '1.3-6991a20992c5faa57fae71a45b40241b',