Merge lp:~allenap/postgresfixture/trusty-compatibility into lp:~lazr-developers/postgresfixture/trunk

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: 9
Merged at revision: 9
Proposed branch: lp:~allenap/postgresfixture/trusty-compatibility
Merge into: lp:~lazr-developers/postgresfixture/trunk
Diff against target: 51 lines (+19/-4)
2 files modified
postgresfixture/cluster.py (+12/-3)
postgresfixture/tests/test_cluster.py (+7/-1)
To merge this branch: bzr merge lp:~allenap/postgresfixture/trusty-compatibility
Reviewer Review Type Date Requested Status
Gavin Panella Approve
Review via email: mp+202151@code.launchpad.net

Commit message

Accommodate differences between PostgreSQL's pg_ctl in version 9.1 and >= 9.2.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

Selfie.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'postgresfixture/cluster.py'
2--- postgresfixture/cluster.py 2014-01-17 16:35:21 +0000
3+++ postgresfixture/cluster.py 2014-01-17 17:57:51 +0000
4@@ -141,10 +141,19 @@
5 try:
6 self.execute("pg_ctl", "status", stdout=null)
7 except CalledProcessError as error:
8- if error.returncode == 1:
9- return False
10+ # pg_ctl in PostgreSQL 9.1 returns 1 when the server is
11+ # not running, whereas it returns 3 in PostgreSQL 9.2
12+ # and later. This checks for specific codes to avoid
13+ # masking errors from insufficient permissions or
14+ # missing executables, for example.
15+ if LooseVersion(self.version) >= LooseVersion("9.2"):
16+ if error.returncode == 3:
17+ return False
18 else:
19- raise
20+ if error.returncode == 1:
21+ return False
22+ # Some other error: moan about it.
23+ raise
24 else:
25 return True
26
27
28=== modified file 'postgresfixture/tests/test_cluster.py'
29--- postgresfixture/tests/test_cluster.py 2014-01-17 16:35:21 +0000
30+++ postgresfixture/tests/test_cluster.py 2014-01-17 17:57:51 +0000
31@@ -13,6 +13,7 @@
32 __all__ = []
33
34 from contextlib import closing
35+from distutils.version import LooseVersion
36 from os import (
37 getpid,
38 path,
39@@ -177,7 +178,12 @@
40 self.assertEqual(("pg_ctl", "status"), command)
41
42 def test_running_not(self):
43- self.patch_check_call(returncode=1)
44+ # pg_ctl in PostgreSQL 9.1 returns 1 when the server is not
45+ # running, whereas it returns 3 in PostgreSQL 9.2 and later.
46+ if LooseVersion(self.version) >= LooseVersion("9.2"):
47+ self.patch_check_call(returncode=3)
48+ else:
49+ self.patch_check_call(returncode=1)
50 cluster = self.make(self.make_dir())
51 self.assertFalse(cluster.running)
52

Subscribers

People subscribed via source and target branches

to all changes: