diff --git a/nova/compute/cells_api.py b/nova/compute/cells_api.py index 812e52e13c66..6828a4fc3d29 100644 --- a/nova/compute/cells_api.py +++ b/nova/compute/cells_api.py @@ -554,10 +554,15 @@ class HostAPI(compute_api.HostAPI): # NOTE(danms): Currently cells does not support objects as # return values, so just convert the db-formatted service objects # to new-world objects here + + # NOTE(dheeraj): Use ServiceProxy here too. See johannes' + # note on service_get_all if db_service: - return service_obj.Service._from_db_object(context, - service_obj.Service(), - db_service) + cell_path, _id = cells_utils.split_cell_and_item(db_service['id']) + db_service['id'] = _id + ser_obj = service_obj.Service._from_db_object( + context, service_obj.Service(), db_service) + return ServiceProxy(ser_obj, cell_path) def service_update(self, context, host_name, binary, params_to_update): """Used to enable/disable a service. For compute services, setting to @@ -573,10 +578,15 @@ class HostAPI(compute_api.HostAPI): # NOTE(danms): Currently cells does not support objects as # return values, so just convert the db-formatted service objects # to new-world objects here + + # NOTE(dheeraj): Use ServiceProxy here too. See johannes' + # note on service_get_all if db_service: - return service_obj.Service._from_db_object(context, - service_obj.Service(), - db_service) + cell_path, _id = cells_utils.split_cell_and_item(db_service['id']) + db_service['id'] = _id + ser_obj = service_obj.Service._from_db_object( + context, service_obj.Service(), db_service) + return ServiceProxy(ser_obj, cell_path) def service_delete(self, context, service_id): """Deletes the specified service.""" diff --git a/nova/tests/compute/test_host_api.py b/nova/tests/compute/test_host_api.py index e4214cfb7f10..b6c45b84fa32 100644 --- a/nova/tests/compute/test_host_api.py +++ b/nova/tests/compute/test_host_api.py @@ -400,24 +400,30 @@ class ComputeHostAPICellsTestCase(ComputeHostAPITestCase): self.mox.StubOutWithMock(self.host_api.cells_rpcapi, 'service_get_by_compute_host') + # Cells return services with full cell_path prepended to IDs + fake_service = dict(test_service.fake_service, id='cell1@1') + exp_service = fake_service.copy() + self.host_api.cells_rpcapi.service_get_by_compute_host(self.ctxt, - 'fake-host').AndReturn(test_service.fake_service) + 'fake-host').AndReturn(fake_service) self.mox.ReplayAll() result = self.host_api.service_get_by_compute_host(self.ctxt, 'fake-host') - self._compare_obj(result, test_service.fake_service) + self._compare_obj(result, exp_service) def test_service_update(self): host_name = 'fake-host' binary = 'nova-compute' params_to_update = dict(disabled=True) - service_id = 42 - expected_result = dict(test_service.fake_service, id=service_id) + service_id = 'cell1@42' # Cells prepend full cell path to ID + + update_result = dict(test_service.fake_service, id=service_id) + expected_result = update_result.copy() self.mox.StubOutWithMock(self.host_api.cells_rpcapi, 'service_update') self.host_api.cells_rpcapi.service_update( self.ctxt, host_name, - binary, params_to_update).AndReturn(expected_result) + binary, params_to_update).AndReturn(update_result) self.mox.ReplayAll()