Browse Source

Fixed intermittent timeout/failing functional tests

In web-download import method functional tests we are trying to download
a file from 'https://www.openstack.org/assets/openstack-logo/2016R/OpenStack-Logo-Horizontal.eps.zip'.
Here we are assuming image is downloaded and will be active within 20
seconds else will be marked as failed. As of now these tests never
fails in local environment but, external networking will always be unreliable
from the CI environment which sometimes causes these tests to either
timeout or failure.

Instead of using external URL to download the image, deploying local http
server to dowload local image.

Closes-Bug: #1797571
Change-Id: I781666327f092ad439c23eca57128b8fd0334c89
tags/18.0.0.0b1
Abhishek Kekane 7 months ago
parent
commit
6951f8daac

+ 4
- 0
glance/tests/functional/__init__.py View File

@@ -364,6 +364,8 @@ store_type_preference = %(store_type_location_strategy_preference)s
364 364
 [glance_store]
365 365
 filesystem_store_datadir=%(image_dir)s
366 366
 default_store = %(default_store)s
367
+[import_filtering_opts]
368
+allowed_ports = []
367 369
 """
368 370
         self.paste_conf_base = """[pipeline:glance-api]
369 371
 pipeline =
@@ -549,6 +551,8 @@ default_backend = %(default_backend)s
549 551
 filesystem_store_datadir=%(image_dir_backend_1)s
550 552
 [file2]
551 553
 filesystem_store_datadir=%(image_dir_backend_2)s
554
+[import_filtering_opts]
555
+allowed_ports = []
552 556
 """
553 557
         self.paste_conf_base = """[pipeline:glance-api]
554 558
 pipeline =

+ 25
- 6
glance/tests/functional/v2/test_images.py View File

@@ -341,8 +341,11 @@ class TestImages(functional.FunctionalTest):
341 341
             'content-type': 'application/json',
342 342
             'X-Roles': 'admin',
343 343
         })
344
-        image_data_uri = ('https://www.openstack.org/assets/openstack-logo/'
345
-                          '2016R/OpenStack-Logo-Horizontal.eps.zip')
344
+
345
+        # Start http server locally
346
+        pid, port = test_utils.start_standalone_http_server()
347
+
348
+        image_data_uri = 'http://localhost:%s/' % port
346 349
         data = jsonutils.dumps({'method': {
347 350
             'name': 'web-download',
348 351
             'uri': image_data_uri
@@ -369,6 +372,9 @@ class TestImages(functional.FunctionalTest):
369 372
                                                   os_hash_value=expect_h,
370 373
                                                   status='active')
371 374
 
375
+        # kill the local http server
376
+        os.kill(pid, signal.SIGKILL)
377
+
372 378
         # Deleting image should work
373 379
         path = self._url('/v2/images/%s' % image_id)
374 380
         response = requests.delete(path, headers=self._headers())
@@ -4901,8 +4907,11 @@ class TestImagesMultipleBackend(functional.MultipleBackendFunctionalTest):
4901 4907
             'content-type': 'application/json',
4902 4908
             'X-Roles': 'admin',
4903 4909
         })
4904
-        image_data_uri = ('https://www.openstack.org/assets/openstack-logo/'
4905
-                          '2016R/OpenStack-Logo-Horizontal.eps.zip')
4910
+
4911
+        # Start http server locally
4912
+        pid, port = test_utils.start_standalone_http_server()
4913
+
4914
+        image_data_uri = 'http://localhost:%s/' % port
4906 4915
         data = jsonutils.dumps({'method': {
4907 4916
             'name': 'web-download',
4908 4917
             'uri': image_data_uri
@@ -4928,6 +4937,9 @@ class TestImagesMultipleBackend(functional.MultipleBackendFunctionalTest):
4928 4937
                                                   checksum=expect_c,
4929 4938
                                                   os_hash_value=expect_h,
4930 4939
                                                   status='active')
4940
+
4941
+        # kill the local http server
4942
+        os.kill(pid, signal.SIGKILL)
4931 4943
         # Ensure image is created in default backend
4932 4944
         path = self._url('/v2/images/%s' % image_id)
4933 4945
         response = requests.get(path, headers=self._headers())
@@ -5055,8 +5067,11 @@ class TestImagesMultipleBackend(functional.MultipleBackendFunctionalTest):
5055 5067
             'X-Roles': 'admin',
5056 5068
             'X-Image-Meta-Store': 'file2'
5057 5069
         })
5058
-        image_data_uri = ('https://www.openstack.org/assets/openstack-logo/'
5059
-                          '2016R/OpenStack-Logo-Horizontal.eps.zip')
5070
+
5071
+        # Start http server locally
5072
+        pid, port = test_utils.start_standalone_http_server()
5073
+
5074
+        image_data_uri = 'http://localhost:%s/' % port
5060 5075
         data = jsonutils.dumps({'method': {
5061 5076
             'name': 'web-download',
5062 5077
             'uri': image_data_uri
@@ -5082,6 +5097,10 @@ class TestImagesMultipleBackend(functional.MultipleBackendFunctionalTest):
5082 5097
                                                   checksum=expect_c,
5083 5098
                                                   os_hash_value=expect_h,
5084 5099
                                                   status='active')
5100
+
5101
+        # kill the local http server
5102
+        os.kill(pid, signal.SIGKILL)
5103
+
5085 5104
         # Ensure image is created in different backend
5086 5105
         path = self._url('/v2/images/%s' % image_id)
5087 5106
         response = requests.get(path, headers=self._headers())

+ 25
- 0
glance/tests/utils.py View File

@@ -713,3 +713,28 @@ def is_sqlite_version_prior_to(major, minor):
713 713
     import sqlite3
714 714
     tup = sqlite3.sqlite_version_info
715 715
     return tup[0] < major or (tup[0] == major and tup[1] < minor)
716
+
717
+
718
+def start_standalone_http_server():
719
+    def _get_http_handler_class():
720
+        class StaticHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
721
+            def do_GET(self):
722
+                data = b"Hello World!!!"
723
+                self.send_response(http.OK)
724
+                self.send_header('Content-Length', str(len(data)))
725
+                self.end_headers()
726
+                self.wfile.write(data)
727
+                return
728
+
729
+        return StaticHTTPRequestHandler
730
+
731
+    server_address = ('127.0.0.1', 0)
732
+    handler_class = _get_http_handler_class()
733
+    httpd = BaseHTTPServer.HTTPServer(server_address, handler_class)
734
+    port = httpd.socket.getsockname()[1]
735
+
736
+    pid = os.fork()
737
+    if pid == 0:
738
+        httpd.serve_forever()
739
+    else:
740
+        return pid, port

Loading…
Cancel
Save