From 14b8dfa3e8b5f43e3640b2872c79c24a35902661 Mon Sep 17 00:00:00 2001 From: Oleksii Kliukin Date: Wed, 25 Nov 2015 10:29:17 +0100 Subject: [PATCH] Make create_replica_method a YAML array. Make sure the absense of this key or empty value in it is handled correctly. Update tests and sample configuration files. --- patroni/postgresql.py | 6 +++--- postgres0.yml | 4 +++- postgres1.yml | 5 ++++- tests/test_postgresql.py | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/patroni/postgresql.py b/patroni/postgresql.py index 37c20764..033de46a 100644 --- a/patroni/postgresql.py +++ b/patroni/postgresql.py @@ -240,9 +240,9 @@ class Postgresql: # defined by the user. this is a list, so we need to # loop through all methods the user supplies connstring = leader.conn_url - # get list of replica methods from config - replica_list = self.config.get('create_replica_method', 'basebackup') - replica_methods = [rm.strip() for rm in replica_list.split(',')] + # get list of replica methods from config. + # If there is no configuration key, or no value is specified, use basebackup + replica_methods = self.config.get('create_replica_method') or ['basebackup'] # go through them in priority order ret = 1 for replica_method in replica_methods: diff --git a/postgres0.yml b/postgres0.yml index 66690367..84c74acd 100644 --- a/postgres0.yml +++ b/postgres0.yml @@ -68,7 +68,9 @@ postgresql: admin: username: admin password: admin - create_replica_method: basebackup + create_replica_method: + - basebackup +# - wal_e # commented-out example for wal-e provisioning #create_replica_method: wal_e, basebackup #wal_e: diff --git a/postgres1.yml b/postgres1.yml index 56072a52..32919843 100644 --- a/postgres1.yml +++ b/postgres1.yml @@ -69,7 +69,10 @@ postgresql: username: admin password: admin # commented-out example for wal-e provisioning - #create_replica_method: wal_e, basebackup + create_replica_method: + - basebackup +# - wal_e +# commented-out example for wal-e provisioning #wal_e: #command: /patroni/scripts/wale_restore.py #env_dir: /home/postgres/etc/wal-e.d/env diff --git a/tests/test_postgresql.py b/tests/test_postgresql.py index e13e65fa..2097bcb7 100644 --- a/tests/test_postgresql.py +++ b/tests/test_postgresql.py @@ -284,7 +284,7 @@ class TestPostgresql(unittest.TestCase): with patch('subprocess.call', Mock(side_effect=[Exception(), 0])): self.assertEquals(self.p.create_replica(self.leader, ''), 0) - self.p.config['create_replica_method'] = 'wale, basebackup' + self.p.config['create_replica_method'] = ['wale', 'basebackup'] self.p.config['wale'] = {'command': 'foo'} with patch('subprocess.call', Mock(return_value=0)): self.assertEquals(self.p.create_replica(self.leader, ''), 0)