diff --git a/patroni/postgresql/bootstrap.py b/patroni/postgresql/bootstrap.py index a544bd73..e6904878 100644 --- a/patroni/postgresql/bootstrap.py +++ b/patroni/postgresql/bootstrap.py @@ -100,10 +100,11 @@ class Bootstrap(object): user_options.append('--{0}'.format(opt)) elif isinstance(opt, dict): keys = list(opt.keys()) - if len(keys) != 1 or not isinstance(opt[keys[0]], str) or not option_is_allowed(keys[0]): + if len(keys) == 1 and isinstance(opt[keys[0]], str) and option_is_allowed(keys[0]): + user_options.append('--{0}={1}'.format(keys[0], unquote(opt[keys[0]]))) + else: error_handler('Error when parsing {0} key-value option {1}: only one key-value is allowed' ' and value should be a string'.format(tool, opt[keys[0]])) - user_options.append('--{0}={1}'.format(keys[0], unquote(opt[keys[0]]))) else: error_handler('Error when parsing {0} option {1}: value should be string value' ' or a single key-value pair'.format(tool, opt)) diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index 8724b03c..9eaeb1af 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -142,6 +142,16 @@ class TestBootstrap(BaseTestPostgresql): (), error_handler ), ["--key=value with spaces"]) + # not allowed options in list of dicts/strs are filtered out + self.assertEqual( + self.b.process_user_options( + 'pg_basebackup', + [{'checkpoint': 'fast'}, {'dbname': 'dbname=postgres'}, 'gzip', {'label': 'standby'}, 'verbose'], + ('dbname', 'verbose'), + print + ), + ['--checkpoint=fast', '--gzip', '--label=standby'], + ) @patch.object(CancellableSubprocess, 'call', Mock()) @patch.object(Postgresql, 'is_running', Mock(return_value=True))