From 221a3e89e8988bc664298106ee691a4e41ca71f9 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 19 May 2025 08:55:41 -0700 Subject: [PATCH] Revert "Support glance's new location API" Due to glance behavioral changes, using the new location API causes async hashing jobs to create confusion for tooling not expecting undeletable images. Revert this until glance can resolve the issue. This reverts commit eab0de290099fedf1119e9056c5f86b52c8e58fb. Change-Id: Ifc4631720a1872cb6d93e9ee490c19edd1a7b98e --- nova/image/glance.py | 22 ++++++------------- nova/tests/unit/image/test_glance.py | 32 +++------------------------- requirements.txt | 2 +- 3 files changed, 11 insertions(+), 45 deletions(-) diff --git a/nova/image/glance.py b/nova/image/glance.py index 92417feafa..cb5633fe68 100644 --- a/nova/image/glance.py +++ b/nova/image/glance.py @@ -563,19 +563,11 @@ class GlanceImageServiceV2(object): def _add_location(self, context, image_id, location): # 'show_multiple_locations' must be enabled in glance api conf file. - try_methods = ('add_image_location', 'add_location') - exc = None - for method in try_methods: - try: - return self._client.call( - context, 2, method, args=(image_id, location, {})) - except glanceclient.exc.HTTPNotImplemented as e: - exc = e - LOG.debug('Glance method %s not available', method) - except glanceclient.exc.HTTPBadRequest as e: - exc = e - _reraise_translated_exception() - raise exc + try: + return self._client.call( + context, 2, 'add_location', args=(image_id, location, {})) + except glanceclient.exc.HTTPBadRequest: + _reraise_translated_exception() def _add_image_member(self, context, image_id, member_id): """Grant access to another project that does not own the image @@ -674,7 +666,7 @@ class GlanceImageServiceV2(object): # Sending image location in a separate request. if location: - self._add_location(context, image_id, location) + image = self._add_location(context, image_id, location) # Add image membership in a separate request. if sharing_member_id: @@ -723,7 +715,7 @@ class GlanceImageServiceV2(object): # Sending image location in a separate request. if location: - self._add_location(context, image_id, location) + image = self._add_location(context, image_id, location) # If we have some data we have to send it in separate request and # update the image then. diff --git a/nova/tests/unit/image/test_glance.py b/nova/tests/unit/image/test_glance.py index 18d06ab950..a7051a733f 100644 --- a/nova/tests/unit/image/test_glance.py +++ b/nova/tests/unit/image/test_glance.py @@ -1745,8 +1745,7 @@ class TestCreate(test.NoDBTestCase): @mock.patch('nova.image.glance._translate_from_glance') @mock.patch('nova.image.glance._translate_to_glance') def test_create_success_v2_with_location( - self, trans_to_mock, trans_from_mock, old_api=False, - new_api=True): + self, trans_to_mock, trans_from_mock): translated = { 'id': mock.sentinel.id, 'name': mock.sentinel.name, @@ -1756,40 +1755,15 @@ class TestCreate(test.NoDBTestCase): trans_from_mock.return_value = mock.sentinel.trans_from image_mock = {} client = mock.MagicMock() - if old_api: - client.call.side_effect = [translated, - glanceclient.exc.HTTPNotImplemented, - None] - elif not new_api: - # If neither API is available we expect back whatever glanceclient - # raised to us - client.call.side_effect = test.TestingException - else: - client.call.side_effect = [translated, None] + client.call.return_value = translated ctx = mock.sentinel.ctx service = glance.GlanceImageServiceV2(client) - if not new_api and not old_api: - self.assertRaises(test.TestingException, - service.create, ctx, image_mock) - return image_meta = service.create(ctx, image_mock) trans_to_mock.assert_called_once_with(image_mock) - calls = [c[0][2] for c in client.call.call_args_list] - if old_api: - expected = ['create', 'add_image_location', 'add_location'] - else: - expected = ['create', 'add_image_location'] - self.assertEqual(expected, calls) + self.assertEqual(2, client.call.call_count) trans_from_mock.assert_called_once_with(translated) self.assertEqual(mock.sentinel.trans_from, image_meta) - def test_create_success_v2_with_location_old_api(self): - self.test_create_success_v2_with_location(old_api=True) - - def test_create_success_v2_with_location_no_api(self): - self.test_create_success_v2_with_location(old_api=False, - new_api=False) - @mock.patch('nova.image.glance._translate_from_glance') @mock.patch('nova.image.glance._translate_to_glance') def test_create_success_v2_with_sharing( diff --git a/requirements.txt b/requirements.txt index 2a62a4b336..fb751b9947 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,7 +24,7 @@ jsonschema>=4.0.0 # MIT python-cinderclient>=4.0.1 # Apache-2.0 keystoneauth1>=3.16.0 # Apache-2.0 python-neutronclient>=7.1.0 # Apache-2.0 -python-glanceclient>=4.7.0 # Apache-2.0 +python-glanceclient>=2.8.0 # Apache-2.0 requests>=2.25.1 # Apache-2.0 stevedore>=1.20.0 # Apache-2.0 websockify>=0.9.0 # LGPLv3