From 8b44c9df29572efca928c1d36fa3e7a90e94caa0 Mon Sep 17 00:00:00 2001 From: Alistair Coles Date: Thu, 7 Jun 2018 11:35:34 +0100 Subject: [PATCH] Allow domain remap storage_domain to be configured for func tests Previously some tests in /test/functional/test_staticweb.py assumed that domain_remap middleware was configured with the default storage_domain 'example.com'. As a result those tests would fail if run against a cluster with domain_remap middleware installed but not having an 'example.com' storage_domain. This patch allows a storage_domain to be configured in the test.conf file so that the tests may be successfully run against any cluster. If the option is not set then the tests will be skipped. To ensure that the in process test job func-domain-remap-staticweb still runs all the tests in test_staticweb.py, its config loader is modified to add the required storage_domain option to the test config with the same value used by the domain_remap middleware. Related-Change: I6bc70039c1b99b8a5bf5a30e9c6877d4f0aa638d Co-Authored-By: Tim Burke Change-Id: Ifab84fc3ef66b9790e96ebb8e5c8061a12636045 --- test/functional/__init__.py | 14 +++++++++++--- test/functional/test_staticweb.py | 24 +++++++++++++++++++----- test/sample.conf | 5 +++++ 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/test/functional/__init__.py b/test/functional/__init__.py index dcbc064833..37cf9bce5a 100644 --- a/test/functional/__init__.py +++ b/test/functional/__init__.py @@ -381,26 +381,33 @@ def _load_domain_remap_staticweb(proxy_conf_file, swift_conf_file, **kwargs): """ _debug('Setting configuration for domain_remap') + # add a domain_remap storage_domain to the test configuration + storage_domain = 'example.net' + global config + config['storage_domain'] = storage_domain + # The global conf dict cannot be used to modify the pipeline. # The pipeline loader requires the pipeline to be set in the local_conf. # If pipeline is set in the global conf dict (which in turn populates the # DEFAULTS options) then it prevents pipeline being loaded into the local # conf during wsgi load_app. # Therefore we must modify the [pipeline:main] section. - conf = ConfigParser() conf.read(proxy_conf_file) try: section = 'pipeline:main' old_pipeline = conf.get(section, 'pipeline') pipeline = old_pipeline.replace( - "tempauth", - "domain_remap tempauth staticweb") + " tempauth ", + " domain_remap tempauth staticweb ") if pipeline == old_pipeline: raise InProcessException( "Failed to insert domain_remap and staticweb into pipeline: %s" % old_pipeline) conf.set(section, 'pipeline', pipeline) + # set storage_domain in domain_remap middleware to match test config + section = 'filter:domain_remap' + conf.set(section, 'storage_domain', storage_domain) except NoSectionError as err: msg = 'Error problem with proxy conf file %s: %s' % \ (proxy_conf_file, err) @@ -531,6 +538,7 @@ def in_process_setup(the_object_server=object_server): storage_policy.reload_storage_policies() global config + config['__file__'] = 'in_process_setup()' if constraints.SWIFT_CONSTRAINTS_LOADED: # Use the swift constraints that are loaded for the test framework # configuration diff --git a/test/functional/test_staticweb.py b/test/functional/test_staticweb.py index 9851aa1cff..c230a78b27 100644 --- a/test/functional/test_staticweb.py +++ b/test/functional/test_staticweb.py @@ -36,7 +36,14 @@ def requires_domain_remap(func): def wrapper(*args, **kwargs): if 'domain_remap' not in cluster_info: raise SkipTest('Domain Remap is not enabled') + # domain_remap middleware does not advertise its storage_domain values + # in swift /info responses so a storage_domain must be configured in + # test.conf for these tests to succeed + if not tf.config.get('storage_domain'): + raise SkipTest('Domain Remap storage_domain not configured in %s' % + tf.config['__file__']) return func(*args, **kwargs) + return wrapper @@ -72,7 +79,6 @@ class TestStaticWebEnv(BaseEnv): cls.objects = {} for item in sorted(objects): - parent = None if '/' in item.rstrip('/'): parent, _ = item.rstrip('/').rsplit('/', 1) path = '%s/%s' % (cls.objects[parent + '/'].name, @@ -103,12 +109,20 @@ class TestStaticWeb(Base): "Expected static_web_enabled to be True/False, got %r" % (self.env.static_web_enabled,)) + @property + def domain_remap_acct(self): + # the storage_domain option is test.conf must be set to one of the + # domain_remap middleware storage_domain values _, _, acct = self.env.account.conn.storage_url.split('/') + return '.'.join((acct, tf.config.get('storage_domain'))) - self.domain_remap_acct = '%s.example.com' % acct - - self.domain_remap_cont = '%s.%s.example.com' % ( - self.env.container.name, acct) + @property + def domain_remap_cont(self): + # the storage_domain option is test.conf must be set to one of the + # domain_remap middleware storage_domain values + _, _, acct = self.env.account.conn.storage_url.split('/') + return '.'.join( + (self.env.container.name, acct, tf.config.get('storage_domain'))) def _set_staticweb_headers(self, index=False, listings=False, listings_css=False, error=False): diff --git a/test/sample.conf b/test/sample.conf index 96abd68e4a..283e64192a 100644 --- a/test/sample.conf +++ b/test/sample.conf @@ -75,6 +75,11 @@ collate = C # Only necessary if a pre-existing server uses self-signed certificate insecure = no +# Tests that are dependent on domain_remap middleware being installed also +# require one of the domain_remap storage_domain values to be specified here, +# otherwise those tests will be skipped. +storage_domain = + [unit_test] fake_syslog = False