Skip to content

Commit 9c2cbf3

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Refactor HostAPI.service_update"
2 parents d93724d + 1c51443 commit 9c2cbf3

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

nova/api/openstack/compute/services.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ def _update(self, context, host, binary, payload):
204204
raise webob.exc.HTTPBadRequest(explanation=msg)
205205

206206
try:
207-
self.host_api.service_update(context, host, binary, payload)
207+
self.host_api.service_update_by_host_and_binary(
208+
context, host, binary, payload)
208209
except (exception.HostBinaryNotFound,
209210
exception.HostMappingNotFound) as exc:
210211
raise webob.exc.HTTPNotFound(explanation=exc.format_message())
@@ -403,7 +404,7 @@ def update(self, req, id, body):
403404
raise webob.exc.HTTPBadRequest(explanation=msg)
404405

405406
# Now save our updates to the service record in the database.
406-
service.save()
407+
self.host_api.service_update(context, service)
407408

408409
# Return the full service record details.
409410
additional_fields = ['forced_down']

nova/compute/api.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5047,22 +5047,44 @@ def service_get_by_compute_host(self, context, host_name):
50475047
"""Get service entry for the given compute hostname."""
50485048
return objects.Service.get_by_compute_host(context, host_name)
50495049

5050-
def _service_update(self, context, host_name, binary, params_to_update):
5051-
"""Performs the actual service update operation."""
5052-
service = objects.Service.get_by_args(context, host_name, binary)
5053-
service.update(params_to_update)
5050+
def service_update(self, context, service):
5051+
"""Performs the actual service update operation.
5052+
5053+
:param context: nova auth RequestContext
5054+
:param service: nova.objects.Service object with changes already
5055+
set on the object
5056+
"""
50545057
service.save()
5058+
# TODO(mriedem): Reflect COMPUTE_STATUS_DISABLED trait changes to the
5059+
# associated compute node resource providers if the service's disabled
5060+
# status changed.
50555061
return service
50565062

50575063
@target_host_cell
5058-
def service_update(self, context, host_name, binary, params_to_update):
5064+
def service_update_by_host_and_binary(self, context, host_name, binary,
5065+
params_to_update):
50595066
"""Enable / Disable a service.
50605067
5068+
Determines the cell that the service is in using the HostMapping.
5069+
50615070
For compute services, this stops new builds and migrations going to
50625071
the host.
5072+
5073+
See also ``service_update``.
5074+
5075+
:param context: nova auth RequestContext
5076+
:param host_name: hostname of the service
5077+
:param binary: service binary (really only supports "nova-compute")
5078+
:param params_to_update: dict of changes to make to the Service object
5079+
:raises: HostMappingNotFound if the host is not mapped to a cell
5080+
:raises: HostBinaryNotFound if a services table record is not found
5081+
with the given host_name and binary
50635082
"""
5064-
return self._service_update(context, host_name, binary,
5065-
params_to_update)
5083+
# TODO(mriedem): Service.get_by_args is deprecated; we should use
5084+
# get_by_compute_host here (remember to update the "raises" docstring).
5085+
service = objects.Service.get_by_args(context, host_name, binary)
5086+
service.update(params_to_update)
5087+
return self.service_update(context, service)
50665088

50675089
def _service_delete(self, context, service_id):
50685090
"""Performs the actual Service deletion operation."""

nova/tests/unit/compute/test_host_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def _do_test(mock_service_get_by_compute_host):
320320

321321
_do_test()
322322

323-
def test_service_update(self):
323+
def test_service_update_by_host_and_binary(self):
324324
host_name = 'fake-host'
325325
binary = 'nova-compute'
326326
params_to_update = dict(disabled=True)
@@ -333,7 +333,7 @@ def _do_test(mock_service_update, mock_service_get_by_host_and_binary):
333333
mock_service_get_by_host_and_binary.return_value = expected_result
334334
mock_service_update.return_value = expected_result
335335

336-
result = self.host_api.service_update(
336+
result = self.host_api.service_update_by_host_and_binary(
337337
self.ctxt, host_name, binary, params_to_update)
338338
self._compare_obj(result, expected_result)
339339

0 commit comments

Comments
 (0)