diff --git a/glance/tests/functional/__init__.py b/glance/tests/functional/__init__.py index d6ac835dd1..ac42b1da26 100644 --- a/glance/tests/functional/__init__.py +++ b/glance/tests/functional/__init__.py @@ -364,6 +364,8 @@ store_type_preference = %(store_type_location_strategy_preference)s [glance_store] filesystem_store_datadir=%(image_dir)s default_store = %(default_store)s +[import_filtering_opts] +allowed_ports = [] """ self.paste_conf_base = """[pipeline:glance-api] pipeline = @@ -549,6 +551,8 @@ default_backend = %(default_backend)s filesystem_store_datadir=%(image_dir_backend_1)s [file2] filesystem_store_datadir=%(image_dir_backend_2)s +[import_filtering_opts] +allowed_ports = [] """ self.paste_conf_base = """[pipeline:glance-api] pipeline = diff --git a/glance/tests/functional/v2/test_images.py b/glance/tests/functional/v2/test_images.py index eb584365b2..7d6d933989 100644 --- a/glance/tests/functional/v2/test_images.py +++ b/glance/tests/functional/v2/test_images.py @@ -341,8 +341,11 @@ class TestImages(functional.FunctionalTest): 'content-type': 'application/json', 'X-Roles': 'admin', }) - image_data_uri = ('https://www.openstack.org/assets/openstack-logo/' - '2016R/OpenStack-Logo-Horizontal.eps.zip') + + # Start http server locally + pid, port = test_utils.start_standalone_http_server() + + image_data_uri = 'http://localhost:%s/' % port data = jsonutils.dumps({'method': { 'name': 'web-download', 'uri': image_data_uri @@ -369,6 +372,9 @@ class TestImages(functional.FunctionalTest): os_hash_value=expect_h, status='active') + # kill the local http server + os.kill(pid, signal.SIGKILL) + # Deleting image should work path = self._url('/v2/images/%s' % image_id) response = requests.delete(path, headers=self._headers()) @@ -4901,8 +4907,11 @@ class TestImagesMultipleBackend(functional.MultipleBackendFunctionalTest): 'content-type': 'application/json', 'X-Roles': 'admin', }) - image_data_uri = ('https://www.openstack.org/assets/openstack-logo/' - '2016R/OpenStack-Logo-Horizontal.eps.zip') + + # Start http server locally + pid, port = test_utils.start_standalone_http_server() + + image_data_uri = 'http://localhost:%s/' % port data = jsonutils.dumps({'method': { 'name': 'web-download', 'uri': image_data_uri @@ -4928,6 +4937,9 @@ class TestImagesMultipleBackend(functional.MultipleBackendFunctionalTest): checksum=expect_c, os_hash_value=expect_h, status='active') + + # kill the local http server + os.kill(pid, signal.SIGKILL) # Ensure image is created in default backend path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) @@ -5055,8 +5067,11 @@ class TestImagesMultipleBackend(functional.MultipleBackendFunctionalTest): 'X-Roles': 'admin', 'X-Image-Meta-Store': 'file2' }) - image_data_uri = ('https://www.openstack.org/assets/openstack-logo/' - '2016R/OpenStack-Logo-Horizontal.eps.zip') + + # Start http server locally + pid, port = test_utils.start_standalone_http_server() + + image_data_uri = 'http://localhost:%s/' % port data = jsonutils.dumps({'method': { 'name': 'web-download', 'uri': image_data_uri @@ -5082,6 +5097,10 @@ class TestImagesMultipleBackend(functional.MultipleBackendFunctionalTest): checksum=expect_c, os_hash_value=expect_h, status='active') + + # kill the local http server + os.kill(pid, signal.SIGKILL) + # Ensure image is created in different backend path = self._url('/v2/images/%s' % image_id) response = requests.get(path, headers=self._headers()) diff --git a/glance/tests/utils.py b/glance/tests/utils.py index 0b0d143b02..bc55f5b0f7 100644 --- a/glance/tests/utils.py +++ b/glance/tests/utils.py @@ -713,3 +713,28 @@ def is_sqlite_version_prior_to(major, minor): import sqlite3 tup = sqlite3.sqlite_version_info return tup[0] < major or (tup[0] == major and tup[1] < minor) + + +def start_standalone_http_server(): + def _get_http_handler_class(): + class StaticHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): + def do_GET(self): + data = b"Hello World!!!" + self.send_response(http.OK) + self.send_header('Content-Length', str(len(data))) + self.end_headers() + self.wfile.write(data) + return + + return StaticHTTPRequestHandler + + server_address = ('127.0.0.1', 0) + handler_class = _get_http_handler_class() + httpd = BaseHTTPServer.HTTPServer(server_address, handler_class) + port = httpd.socket.getsockname()[1] + + pid = os.fork() + if pid == 0: + httpd.serve_forever() + else: + return pid, port