From c053e5f228ddd99a8210f50b5f89b0cf42ce6833 Mon Sep 17 00:00:00 2001 From: songwenping Date: Tue, 15 Sep 2020 10:10:58 +0800 Subject: [PATCH] Change arq delete to cyborg-conductor service write db Remove `#TODO` for arq delete api. Use Cyborg conductor service contact with db to delete arq resoruces by arq uuids and instance uuid. Change-Id: I2a2869b4fb15cd60f10f1c0d59bca148b9dfab97 --- cyborg/api/controllers/v2/arqs.py | 10 +++++----- cyborg/conductor/manager.py | 20 +++++++++++++++++++ cyborg/conductor/rpcapi.py | 20 +++++++++++++++++++ .../unit/api/controllers/v2/test_arqs.py | 5 +++-- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/cyborg/api/controllers/v2/arqs.py b/cyborg/api/controllers/v2/arqs.py index 62ee0ef2..c1c74a4e 100644 --- a/cyborg/api/controllers/v2/arqs.py +++ b/cyborg/api/controllers/v2/arqs.py @@ -234,21 +234,21 @@ class ARQsController(base.CyborgController): an error. Nova uses the second form: so repeated calls do not cause issues. - :param arq: List of ARQ UUIDs + :param arqs: List of ARQ UUIDs :param instance: UUID of instance whose ARQs need to be deleted """ context = pecan.request.context - if (arqs and instance) or ((not arqs) and (not instance)): + if (arqs and instance) or (not arqs and not instance): raise exception.ObjectActionError( action='delete', reason='Provide either an ARQ uuid list or an instance UUID') elif arqs: LOG.info("[arqs] delete. arqs=(%s)", arqs) - arqlist = arqs.split(',') - objects.ExtARQ.delete_by_uuid(context, arqlist) + pecan.request.conductor_api.arq_delete_by_uuid(context, arqs) else: # instance is not None LOG.info("[arqs] delete. instance=(%s)", instance) - objects.ExtARQ.delete_by_instance(context, instance) + pecan.request.conductor_api.arq_delete_by_instance_uuid( + context, instance) def _validate_arq_patch(self, patch): """Validate a single patch for an ARQ. diff --git a/cyborg/conductor/manager.py b/cyborg/conductor/manager.py index 4d0e4fd9..edd017c3 100644 --- a/cyborg/conductor/manager.py +++ b/cyborg/conductor/manager.py @@ -29,6 +29,7 @@ from cyborg.objects.deployable import Deployable from cyborg.objects.device import Device from cyborg.objects.driver_objects.driver_device import DriverDeployable from cyborg.objects.driver_objects.driver_device import DriverDevice +from cyborg.objects.ext_arq import ExtARQ LOG = logging.getLogger(__name__) @@ -77,6 +78,25 @@ class ConductorManager(object): obj_extarq.create(context, devprof_id) return obj_extarq + def arq_delete_by_uuid(self, context, arqs): + """Signal to conductor service to delete accelerator requests by + ARQ UUIDs. + + :param context: request context. + :param arqs: ARQ UUIDs joined with ',' + """ + arqlist = arqs.split(',') + ExtARQ.delete_by_uuid(context, arqlist) + + def arq_delete_by_instance_uuid(self, context, instance): + """Signal to conductor service to delete accelerator requests by + instance UUID. + + :param context: request context. + :param instance: UUID of instance whose ARQs need to be deleted + """ + ExtARQ.delete_by_instance(context, instance) + def report_data(self, context, hostname, driver_device_list): """Update the Cyborg DB in one hostname according to the discovered device list. diff --git a/cyborg/conductor/rpcapi.py b/cyborg/conductor/rpcapi.py index c46d525f..7d38f868 100644 --- a/cyborg/conductor/rpcapi.py +++ b/cyborg/conductor/rpcapi.py @@ -87,3 +87,23 @@ class ConductorAPI(object): cctxt = self.client.prepare(topic=self.topic) return cctxt.call(context, 'arq_create', obj_extarq=obj_extarq, devprof_id=devprof_id) + + def arq_delete_by_uuid(self, context, arqs): + """Signal to conductor service to delete accelerator requests by + ARQ UUIDs. + + :param context: request context. + :param arqs: ARQ UUIDs joined with ',' + """ + cctxt = self.client.prepare(topic=self.topic) + cctxt.call(context, 'arq_delete_by_uuid', arqs=arqs) + + def arq_delete_by_instance_uuid(self, context, instance): + """Signal to conductor service to delete accelerator requests by + instance UUID. + + :param context: request context. + :param instance: UUID of instance whose ARQs need to be deleted + """ + cctxt = self.client.prepare(topic=self.topic) + cctxt.call(context, 'arq_delete_by_instance_uuid', instance=instance) diff --git a/cyborg/tests/unit/api/controllers/v2/test_arqs.py b/cyborg/tests/unit/api/controllers/v2/test_arqs.py index 5e9734e9..f5e840f9 100644 --- a/cyborg/tests/unit/api/controllers/v2/test_arqs.py +++ b/cyborg/tests/unit/api/controllers/v2/test_arqs.py @@ -218,8 +218,9 @@ class TestARQsController(v2_test.APITestV2): "Device Profile not found with " "name=wrong_device_profile_name", exc.args[0]) - @mock.patch('cyborg.objects.ExtARQ.delete_by_uuid') - @mock.patch('cyborg.objects.ExtARQ.delete_by_instance') + @mock.patch('cyborg.conductor.rpcapi.ConductorAPI.arq_delete_by_uuid') + @mock.patch('cyborg.conductor.rpcapi.ConductorAPI.' + 'arq_delete_by_instance_uuid') def test_delete(self, mock_by_inst, mock_by_arq): url = self.ARQ_URL arq = self.fake_extarqs[0].arq