Skip to content

Commit d28a559

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Fixed an error when caching multiple images in aggregate"
2 parents 55a27f0 + aa500fb commit d28a559

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)