Skip to content

Commit aa500fb

Browse files
author
liwenjian
committed
Fixed an error when caching multiple images in aggregate
Because in the process of judging whether the image id is Duplicate,there is only deduplication without sorting, so no duplicate image error is judged as duplicate and an error "Duplicate images in request" is reported. Now it is changed to sort after deduplication and then compare. Two unit test cases were added to verify the fix Related-Bug: #2034702 Change-Id: I300a3e29ba56584f4c99d534a6cf8ee7dc0ed4b7
1 parent 49bff9b commit aa500fb

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

nova/api/openstack/compute/aggregates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def images(self, req, id, body):
289289
for image_req in body.get('cache'):
290290
image_ids.append(image_req['id'])
291291

292-
if image_ids != list(set(image_ids)):
292+
if sorted(image_ids) != sorted(list(set(image_ids))):
293293
raise exc.HTTPBadRequest(
294294
explanation=_('Duplicate images in request'))
295295

nova/tests/unit/api/openstack/compute/test_aggregates.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,3 +738,28 @@ def test_images_with_invalid_id(self):
738738
version='2.81')
739739
self.assertRaises(exc.HTTPBadRequest, self.controller.images,
740740
req, 'foo', body=body)
741+
742+
def test_images_with_duplicate_id(self):
743+
body = {"cache": [{"id": "faae1bd3-c848-41d6-b4dd-97d5b8be8b7e"},
744+
{"id": "faae1bd3-c848-41d6-b4dd-97d5b8be8b7e"}]}
745+
req = fakes.HTTPRequest.blank('/v2/os-aggregates',
746+
use_admin_context=True,
747+
version='2.81')
748+
self.assertRaises(exc.HTTPBadRequest, self.controller.images,
749+
req, '1', body=body)
750+
751+
def test_images_with_disorder_id(self):
752+
body = {"cache": [{"id": "faae1bd3-c848-41d6-b4dd-97d5b8be8b7e"},
753+
{"id": "290de658-cf55-4cce-b025-9a1a9f93676a"},
754+
{"id": "896f7f54-4e4e-4c21-a2b7-47cff4e99ab0"},
755+
{"id": "d982bb82-04a0-4e9b-b40e-470f20a7b5d1"}]}
756+
req = fakes.HTTPRequest.blank('/v2/os-aggregates',
757+
use_admin_context=True,
758+
version='2.81')
759+
context = req.environ['nova.context']
760+
with mock.patch.object(self.controller.api,
761+
'get_aggregate') as mock_get:
762+
with mock.patch.object(self.controller.conductor_tasks,
763+
'cache_images'):
764+
self.controller.images(req, '1', body=body)
765+
mock_get.assert_called_once_with(context, '1')

0 commit comments

Comments
 (0)