diff --git a/swift/proxy/server.py b/swift/proxy/server.py index 5e34b65ff2..58deb94070 100644 --- a/swift/proxy/server.py +++ b/swift/proxy/server.py @@ -87,6 +87,9 @@ def _label_for_policy(policy): return '(default)' +VALID_SORTING_METHODS = ('shuffle', 'timing', 'affinity') + + class ProxyOverrideOptions(object): """ Encapsulates proxy server options that may be overridden e.g. for @@ -100,6 +103,11 @@ class ProxyOverrideOptions(object): return override_conf.get(key, base_conf.get(key, default)) self.sorting_method = get('sorting_method', 'shuffle').lower() + if self.sorting_method not in VALID_SORTING_METHODS: + raise ValueError( + 'Invalid sorting_method value; must be one of %s, not %r' % ( + ', '.join(VALID_SORTING_METHODS), self.sorting_method)) + self.read_affinity = get('read_affinity', '') try: self.read_affinity_sort_key = affinity_key_function( diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index 177da4f738..22b312fbbe 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -1739,6 +1739,35 @@ class TestProxyServerConfigLoading(unittest.TestCase): app = self._write_conf_and_load_app(conf_sections) self._check_policy_options(app, exp_options, {}) + def test_per_policy_conf_invalid_sorting_method_value(self): + def do_test(conf_sections, scope): + with self.assertRaises(ValueError) as cm: + self._write_conf_and_load_app(conf_sections) + self.assertEqual( + 'Invalid sorting_method value; must be one of shuffle, ' + "timing, affinity, not 'broken' for %s" % scope, + cm.exception.message) + + conf_sections = """ + [app:proxy-server] + use = egg:swift#proxy + sorting_method = shuffle + + [proxy-server:policy:0] + sorting_method = broken + """ + do_test(conf_sections, 'policy 0 (nulo)') + + conf_sections = """ + [app:proxy-server] + use = egg:swift#proxy + sorting_method = broken + + [proxy-server:policy:0] + sorting_method = shuffle + """ + do_test(conf_sections, '(default)') + def test_per_policy_conf_invalid_read_affinity_value(self): def do_test(conf_sections, label): with self.assertRaises(ValueError) as cm: