Fixed failing tests, pep8 issues.

This commit is contained in:
Josh Berkus
2015-11-02 17:51:01 -08:00
parent e7a0ce57aa
commit 30aa83c5b2
4 changed files with 16 additions and 15 deletions
+3 -3
View File
@@ -241,9 +241,9 @@ class Postgresql:
else:
cmd = replica_method
method_config = {"scope": self.scope,
"role": "replica",
"datadir": self.data_dir,
"connstring": connstring}
"role": "replica",
"datadir": self.data_dir,
"connstring": connstring}
try:
# call script with the full set of parameters
+10 -10
View File
@@ -3,7 +3,7 @@
# sample script to clone new replicas using WAL-E restore
# falls back to pg_basebackup if WAL-E restore fails, or if
# WAL-E backup is too far behind
# note that pg_basebackup still expects to use restore from
# note that pg_basebackup still expects to use restore from
# WAL-E for transaction logs
# theoretically should work with SWIFT, but not tested on it
@@ -21,8 +21,8 @@
# credentials per WALE Documentation.
# currently also requires that you configure the restore_command to use wal_e, example:
#recovery_conf:
#restore_command: envdir /etc/wal-e.d/env wal-e wal-fetch "%f" "%p"
# recovery_conf:
# restore_command: envdir /etc/wal-e.d/env wal-e wal-fetch "%f" "%p"
import logging
import os
@@ -137,8 +137,8 @@ class WALERestore(object):
# if the size of the accumulated WAL segments is more than a certan percentage of the backup size
# or exceeds the pre-determined size - pg_basebackup is chosen instead.
return (diff_in_bytes < long(threshold_megabytes) * 1048576) and\
(diff_in_bytes < long(backup_size) * float(threshold_backup_size_percentage) / 100)
(diff_in_bytes < long(backup_size) * float(threshold_backup_size_percentage) / 100)
def create_replica_with_s3(self):
if self.init_error:
return 1
@@ -148,7 +148,7 @@ class WALERestore(object):
except Exception as e:
logger.error('Error when fetching backup with WAL-E: {0}'.format(e))
return 1
return ret
@@ -167,12 +167,12 @@ if __name__ == '__main__':
args = parser.parse_args()
# retry cloning in a loop
for retry in range(0,args.retries + 1):
restore = WALERestore(scope=args.scope,datadir=args.datadir,connstring=args.constring,
env_dir=args.env_dir,threshold_mb=args.threshold_megabytes,
for retry in range(0, args.retries + 1):
restore = WALERestore(scope=args.scope, datadir=args.datadir, connstring=args.constring,
env_dir=args.env_dir, threshold_mb=args.threshold_megabytes,
threshold_pct=args.threshold_backup_size_percentage)
ret = restore.run()
if ret == 0:
break
sys.exit(ret)
+1
View File
@@ -51,6 +51,7 @@ postgresql:
admin:
username: admin
password: admin
create_replica_method: basebackup
# commented-out example for wal-e provisioning
#create_replica_method: wal_e, basebackup
#wal_e:
+2 -2
View File
@@ -267,9 +267,9 @@ class TestPostgresql(unittest.TestCase):
def test_create_replica(self):
self.p.delete_trigger_file = Mock(side_effect=OSError())
with patch('subprocess.call', Mock(side_effect=[1, 0])):
self.assertEquals(self.p.create_replica({'host': '', 'port': '', 'user': ''}, ''), 0)
self.assertEquals(self.p.create_replica(self.leader, ''), 0)
with patch('subprocess.call', Mock(side_effect=[Exception(), 0])):
self.assertEquals(self.p.create_replica({'host': '', 'port': '', 'user': ''}, ''), 0)
self.assertEquals(self.p.create_replica(self.leader, ''), 0)
def test_create_connection_users(self):
cfg = self.p.config