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 <cyril@redhat.com>
This commit is contained in:
Cyril Roelandt committed 2026-09-28 19:26:35 +02:00
1 parent d18aef5d74
commit a37c43135e
1 file changed
+7 -1
+7 -1
View File
@@ -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)