From df85db5677776da4f6f4f80b5d75aa9e2f80519a Mon Sep 17 00:00:00 2001 From: songwenping Date: Fri, 19 May 2023 18:06:42 +0800 Subject: [PATCH] Fix delete attribute api bug Closes-Bug: #2020179 Change-Id: I7a97cecff3bdfa1ee80bb1d2ee5f8a9e9d1448cf --- cyborg/api/controllers/v2/attributes.py | 3 ++- cyborg/tests/unit/api/controllers/v2/test_attributes.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cyborg/api/controllers/v2/attributes.py b/cyborg/api/controllers/v2/attributes.py index 9f0c39d0..0613ff56 100644 --- a/cyborg/api/controllers/v2/attributes.py +++ b/cyborg/api/controllers/v2/attributes.py @@ -163,4 +163,5 @@ class AttributesController(base.CyborgController, """ LOG.info('[attributes] delete by uuid: %s.', uuid) context = pecan.request.context - objects.Attribute.destroy(context, uuid) + api_obj_attribute = objects.Attribute.get(context, uuid) + api_obj_attribute.destroy(context) diff --git a/cyborg/tests/unit/api/controllers/v2/test_attributes.py b/cyborg/tests/unit/api/controllers/v2/test_attributes.py index 9dbb5a3e..cc2389c3 100644 --- a/cyborg/tests/unit/api/controllers/v2/test_attributes.py +++ b/cyborg/tests/unit/api/controllers/v2/test_attributes.py @@ -114,8 +114,9 @@ class TestAttributes(v2_test.APITestV2): for in_attribute, out_attribute in zip(attributes, out_attributes): self._validate_attributes(in_attribute, out_attribute) + @mock.patch('cyborg.objects.Attribute.get') @mock.patch('cyborg.objects.Attribute.destroy') - def test_delete(self, mock_attribute_uuid): + def test_delete(self, mock_attribute_delete, mock_attribute): uuid = self.fake_attribute_objs[0]['uuid'] # Delete by UUID url = self.ATTRIBUTE_URL + '/%s' % uuid