Merge "Add config paramater pipeline_check to enable/disable pipeline check"

This commit is contained in:
Jenkins
2015-01-14 00:46:46 +00:00
committed by Gerrit Code Review
4 changed files with 37 additions and 5 deletions

View File

@@ -71,6 +71,11 @@ use = egg:swift3#swift3
# Specify a host name of your Swift cluster. This enables virtual-hosted style # Specify a host name of your Swift cluster. This enables virtual-hosted style
# requests. # requests.
# storage_domain = # storage_domain =
#
# Enable pipeline order check for SLO, s3token, authtoken, keystoneauth
# If the order is incorrect, it raises a except to stop proxy.
# pipeline_check = True
#
[filter:catch_errors] [filter:catch_errors]
use = egg:swift#catch_errors use = egg:swift#catch_errors

View File

@@ -58,4 +58,5 @@ CONF = Config({
'max_multi_delete_objects': 1000, 'max_multi_delete_objects': 1000,
's3_acl': False, 's3_acl': False,
'storage_domain': '', 'storage_domain': '',
'pipeline_check': True,
}) })

View File

@@ -120,7 +120,8 @@ class Swift3Middleware(object):
pipeline = str(PipelineWrapper(ctx)).split(' ') pipeline = str(PipelineWrapper(ctx)).split(' ')
# Add compatible with 3rd party middleware. # Add compatible with 3rd party middleware.
if check_filter_order(pipeline, ['swift3', 'proxy-server']): if check_filter_order(pipeline,
['swift3', 'proxy-server']):
auth_pipeline = pipeline[pipeline.index('swift3') + 1: auth_pipeline = pipeline[pipeline.index('swift3') + 1:
pipeline.index('proxy-server')] pipeline.index('proxy-server')]
@@ -136,7 +137,8 @@ class Swift3Middleware(object):
LOGGER.debug('Use tempauth middleware.') LOGGER.debug('Use tempauth middleware.')
return return
elif 'keystoneauth' in auth_pipeline: elif 'keystoneauth' in auth_pipeline:
if check_filter_order(auth_pipeline, ['s3token', if check_filter_order(auth_pipeline,
['s3token',
'authtoken', 'authtoken',
'keystoneauth']): 'keystoneauth']):
LOGGER.debug('Use keystone middleware.') LOGGER.debug('Use keystone middleware.')
@@ -146,6 +148,7 @@ class Swift3Middleware(object):
LOGGER.debug('Use third party(unknown) auth middleware.') LOGGER.debug('Use third party(unknown) auth middleware.')
return return
if conf.pipeline_check:
raise ValueError('Invalid proxy pipeline: %s' % pipeline) raise ValueError('Invalid proxy pipeline: %s' % pipeline)

View File

@@ -320,6 +320,7 @@ class TestSwift3Middleware(Swift3TestCase):
patch("swift3.middleware.PipelineWrapper"), patch("swift3.middleware.PipelineWrapper"),
patch("swift3.middleware.loadcontext")) as \ patch("swift3.middleware.loadcontext")) as \
(conf, pipeline, _): (conf, pipeline, _):
conf.pipeline_check = True
conf.__file__ = '' conf.__file__ = ''
pipeline.return_value = 'swift3 tempauth proxy-server' pipeline.return_value = 'swift3 tempauth proxy-server'
@@ -345,6 +346,28 @@ class TestSwift3Middleware(Swift3TestCase):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
self.swift3.check_pipeline(conf) self.swift3.check_pipeline(conf)
# Disable pipeline check
conf.pipeline_check = False
pipeline.return_value = 'swift3 tempauth proxy-server'
self.swift3.check_pipeline(conf)
pipeline.return_value = 'swift3 s3token authtoken keystoneauth ' \
'proxy-server'
self.swift3.check_pipeline(conf)
pipeline.return_value = 'swift3 swauth proxy-server'
self.swift3.check_pipeline(conf)
pipeline.return_value = 'swift3 authtoken s3token keystoneauth ' \
'proxy-server'
self.swift3.check_pipeline(conf)
pipeline.return_value = 'swift3 proxy-server'
self.swift3.check_pipeline(conf)
pipeline.return_value = 'proxy-server'
self.swift3.check_pipeline(conf)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()