'Tests that we can lookup a service in the HostAPI using a uuid.
There are two calls to objects.Service.get_by_uuid and the first
raises ServiceNotFound so that we ensure we keep looping over the
cells. We\'ll find the service in the second cell and break the loop
so that we don\'t needlessly check in the third cell.'

@mock.patch.object(objects.CellMappingList, 'get_all', return_value=objects.CellMappingList(objects=[objects.CellMapping(uuid=uuids.cell1_uuid, transport_url='mq://fake1', database_connection='db://fake1'), objects.CellMapping(uuid=uuids.cell2_uuid, transport_url='mq://fake2', database_connection='db://fake2'), objects.CellMapping(uuid=uuids.cell3_uuid, transport_url='mq://fake3', database_connection='db://fake3')]))
@mock.patch.object(objects.Service, 'get_by_uuid', side_effect=[exception.ServiceNotFound(service_id=uuids.service_uuid), objects.Service(uuid=uuids.service_uuid)])
def test_service_get_by_id_using_uuid(self, service_get_by_uuid, cell_mappings_get_all):

    def _fake_set_target_cell(ctxt, cell_mapping):
        if cell_mapping:
            ctxt.db_connection = cell_mapping.database_connection
            ctxt.mq_connection = cell_mapping.transport_url
    self.useFixture(fixtures.MonkeyPatch('nova.context.set_target_cell', _fake_set_target_cell))
    ctxt = context.get_admin_context()
    self.assertIsNone(ctxt.db_connection)
    self.host_api.service_get_by_id(ctxt, uuids.service_uuid)
    service_get_by_uuid.assert_has_calls(([mock.call(ctxt, uuids.service_uuid)] * 2))
    self.assertEqual('db://fake2', ctxt.db_connection)
