From a37c43135e84f497c6bacadd47434750e47a3a5b Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Mon, 28 Sep 2026 19:25:45 +0200 Subject: [PATCH] test_new_image_with_location: Do not rely on DNS resolution Tests are often run in an environment that does not have any kind of Internet access and cannot use DNS resolution. Change-Id: I8ec68ff70e18fab68ed6a90fe30a1bbfc28c715c Signed-off-by: Cyril Roelandt --- glance/tests/unit/test_store_image.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/glance/tests/unit/test_store_image.py b/glance/tests/unit/test_store_image.py index a00832f28b..185ee692b3 100644 --- a/glance/tests/unit/test_store_image.py +++ b/glance/tests/unit/test_store_image.py @@ -1323,7 +1323,13 @@ class TestImageFactory(unit_test_base.StoreClearingUnitTest): self.assertEqual('private', image.visibility) self.assertEqual([], image.locations) - def test_new_image_with_location(self): + @mock.patch("glance.common.utils.socket.getaddrinfo") + def test_new_image_with_location(self, mock_getaddrinfo): + # This avoid internet access in validate_external_location() + # (ie: DNS resolution of storeurl.com) + mock_getaddrinfo.return_value = [ + (None, None, None, None, ('93.184.216.34', 80)) + ] locations = [{'url': '%s/%s' % (BASE_URI, UUID1), 'metadata': {}}] image = self.image_factory.new_image(locations=locations)