summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhishek Kekane <akekane@redhat.com>2018-10-09 06:14:27 +0000
committerAbhishek Kekane <akekane@redhat.com>2018-10-12 14:24:16 +0000
commit6951f8daac02b85b44990e157538c1ff1c505f2e (patch)
tree3b0aa190a256abcfc4178e1f021dfe7ab964b858
parent02a405a41012b96970c0a5cd7b5781deaadc5877 (diff)
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
Notes
Notes (review): Code-Review+2: Sean McGinnis <sean.mcginnis@gmail.com> Code-Review+2: Brian Rosmaita <rosmaita.fossdev@gmail.com> Workflow+1: Brian Rosmaita <rosmaita.fossdev@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 30 Oct 2018 15:08:22 +0000 Reviewed-on: https://review.openstack.org/608856 Project: openstack/glance Branch: refs/heads/master
-rw-r--r--glance/tests/functional/__init__.py4
-rw-r--r--glance/tests/functional/v2/test_images.py31
-rw-r--r--glance/tests/utils.py25
3 files changed, 54 insertions, 6 deletions
diff --git a/glance/tests/functional/__init__.py b/glance/tests/functional/__init__.py
index d6ac835..ac42b1d 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
364[glance_store] 364[glance_store]
365filesystem_store_datadir=%(image_dir)s 365filesystem_store_datadir=%(image_dir)s
366default_store = %(default_store)s 366default_store = %(default_store)s
367[import_filtering_opts]
368allowed_ports = []
367""" 369"""
368 self.paste_conf_base = """[pipeline:glance-api] 370 self.paste_conf_base = """[pipeline:glance-api]
369pipeline = 371pipeline =
@@ -549,6 +551,8 @@ default_backend = %(default_backend)s
549filesystem_store_datadir=%(image_dir_backend_1)s 551filesystem_store_datadir=%(image_dir_backend_1)s
550[file2] 552[file2]
551filesystem_store_datadir=%(image_dir_backend_2)s 553filesystem_store_datadir=%(image_dir_backend_2)s
554[import_filtering_opts]
555allowed_ports = []
552""" 556"""
553 self.paste_conf_base = """[pipeline:glance-api] 557 self.paste_conf_base = """[pipeline:glance-api]
554pipeline = 558pipeline =
diff --git a/glance/tests/functional/v2/test_images.py b/glance/tests/functional/v2/test_images.py
index eb58436..7d6d933 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):
341 'content-type': 'application/json', 341 'content-type': 'application/json',
342 'X-Roles': 'admin', 342 'X-Roles': 'admin',
343 }) 343 })
344 image_data_uri = ('https://www.openstack.org/assets/openstack-logo/' 344
345 '2016R/OpenStack-Logo-Horizontal.eps.zip') 345 # Start http server locally
346 pid, port = test_utils.start_standalone_http_server()
347
348 image_data_uri = 'http://localhost:%s/' % port
346 data = jsonutils.dumps({'method': { 349 data = jsonutils.dumps({'method': {
347 'name': 'web-download', 350 'name': 'web-download',
348 'uri': image_data_uri 351 'uri': image_data_uri
@@ -369,6 +372,9 @@ class TestImages(functional.FunctionalTest):
369 os_hash_value=expect_h, 372 os_hash_value=expect_h,
370 status='active') 373 status='active')
371 374
375 # kill the local http server
376 os.kill(pid, signal.SIGKILL)
377
372 # Deleting image should work 378 # Deleting image should work
373 path = self._url('/v2/images/%s' % image_id) 379 path = self._url('/v2/images/%s' % image_id)
374 response = requests.delete(path, headers=self._headers()) 380 response = requests.delete(path, headers=self._headers())
@@ -4901,8 +4907,11 @@ class TestImagesMultipleBackend(functional.MultipleBackendFunctionalTest):
4901 'content-type': 'application/json', 4907 'content-type': 'application/json',
4902 'X-Roles': 'admin', 4908 'X-Roles': 'admin',
4903 }) 4909 })
4904 image_data_uri = ('https://www.openstack.org/assets/openstack-logo/' 4910
4905 '2016R/OpenStack-Logo-Horizontal.eps.zip') 4911 # Start http server locally
4912 pid, port = test_utils.start_standalone_http_server()
4913
4914 image_data_uri = 'http://localhost:%s/' % port
4906 data = jsonutils.dumps({'method': { 4915 data = jsonutils.dumps({'method': {
4907 'name': 'web-download', 4916 'name': 'web-download',
4908 'uri': image_data_uri 4917 'uri': image_data_uri
@@ -4928,6 +4937,9 @@ class TestImagesMultipleBackend(functional.MultipleBackendFunctionalTest):
4928 checksum=expect_c, 4937 checksum=expect_c,
4929 os_hash_value=expect_h, 4938 os_hash_value=expect_h,
4930 status='active') 4939 status='active')
4940
4941 # kill the local http server
4942 os.kill(pid, signal.SIGKILL)
4931 # Ensure image is created in default backend 4943 # Ensure image is created in default backend
4932 path = self._url('/v2/images/%s' % image_id) 4944 path = self._url('/v2/images/%s' % image_id)
4933 response = requests.get(path, headers=self._headers()) 4945 response = requests.get(path, headers=self._headers())
@@ -5055,8 +5067,11 @@ class TestImagesMultipleBackend(functional.MultipleBackendFunctionalTest):
5055 'X-Roles': 'admin', 5067 'X-Roles': 'admin',
5056 'X-Image-Meta-Store': 'file2' 5068 'X-Image-Meta-Store': 'file2'
5057 }) 5069 })
5058 image_data_uri = ('https://www.openstack.org/assets/openstack-logo/' 5070
5059 '2016R/OpenStack-Logo-Horizontal.eps.zip') 5071 # Start http server locally
5072 pid, port = test_utils.start_standalone_http_server()
5073
5074 image_data_uri = 'http://localhost:%s/' % port
5060 data = jsonutils.dumps({'method': { 5075 data = jsonutils.dumps({'method': {
5061 'name': 'web-download', 5076 'name': 'web-download',
5062 'uri': image_data_uri 5077 'uri': image_data_uri
@@ -5082,6 +5097,10 @@ class TestImagesMultipleBackend(functional.MultipleBackendFunctionalTest):
5082 checksum=expect_c, 5097 checksum=expect_c,
5083 os_hash_value=expect_h, 5098 os_hash_value=expect_h,
5084 status='active') 5099 status='active')
5100
5101 # kill the local http server
5102 os.kill(pid, signal.SIGKILL)
5103
5085 # Ensure image is created in different backend 5104 # Ensure image is created in different backend
5086 path = self._url('/v2/images/%s' % image_id) 5105 path = self._url('/v2/images/%s' % image_id)
5087 response = requests.get(path, headers=self._headers()) 5106 response = requests.get(path, headers=self._headers())
diff --git a/glance/tests/utils.py b/glance/tests/utils.py
index 0b0d143..bc55f5b 100644
--- a/glance/tests/utils.py
+++ b/glance/tests/utils.py
@@ -713,3 +713,28 @@ def is_sqlite_version_prior_to(major, minor):
713 import sqlite3 713 import sqlite3
714 tup = sqlite3.sqlite_version_info 714 tup = sqlite3.sqlite_version_info
715 return tup[0] < major or (tup[0] == major and tup[1] < minor) 715 return tup[0] < major or (tup[0] == major and tup[1] < minor)
716
717
718def 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