Merge lp:~stub/charms/precise/postgresql/tests into lp:charms/postgresql

Proposed by Stuart Bishop
Status: Merged
Merged at revision: 100
Proposed branch: lp:~stub/charms/precise/postgresql/tests
Merge into: lp:charms/postgresql
Prerequisite: lp:~stub/charms/precise/postgresql/pg94
Diff against target: 129 lines (+22/-17)
3 files modified
Makefile (+7/-8)
test.py (+11/-8)
testing/jujufixture.py (+4/-1)
To merge this branch: bzr merge lp:~stub/charms/precise/postgresql/tests
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+222628@code.launchpad.net

Description of the change

Allow running of tests in different series, both precise and trusty.

Work around the issue where SSH subprocesses launched by 'juju ssh' are not being reaped.

To post a comment you must log in.
Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2014-06-10 11:44:03 +0000
3+++ Makefile 2014-06-10 11:44:04 +0000
4@@ -1,5 +1,6 @@
5 CHARM_DIR := $(shell pwd)
6 TEST_TIMEOUT := 900
7+SERIES := $(juju get-environment default-series)
8
9 default:
10 @echo "One of:"
11@@ -19,25 +20,23 @@
12 cd hooks && trial test_hooks.py
13
14 integration_test:
15- @echo "PostgreSQL integration tests, all non-beta versions"
16- @make integration_test_91
17- @make integration_test_92
18- @make integration_test_93
19+ @echo "PostgreSQL integration tests, all non-beta versions, ${SERIES}"
20+ trial test.PG91Tests test.PG92Tests test.PG93Tests
21
22 integration_test_91:
23- @echo "PostgreSQL 9.1 integration tests"
24+ @echo "PostgreSQL 9.1 integration tests, ${SERIES}"
25 trial test.PG91Tests
26
27 integration_test_92:
28- @echo "PostgreSQL 9.2 integration tests"
29+ @echo "PostgreSQL 9.2 integration tests, ${SERIES}"
30 trial test.PG92Tests
31
32 integration_test_93:
33- @echo "PostgreSQL 9.3 integration tests"
34+ @echo "PostgreSQL 9.3 integration tests, ${SERIES}"
35 trial test.PG93Tests
36
37 integration_test_94:
38- @echo "PostgreSQL 9.4 (beta) integration tests"
39+ @echo "PostgreSQL 9.4 (beta) integration tests, ${SERIES}"
40 trial test.PG94Tests
41
42 lint:
43
44=== modified file 'test.py'
45--- test.py 2014-06-10 11:44:03 +0000
46+++ test.py 2014-06-10 11:44:04 +0000
47@@ -10,6 +10,7 @@
48 """
49
50 import os.path
51+import signal
52 import socket
53 import subprocess
54 import time
55@@ -23,9 +24,9 @@
56 from testing.jujufixture import JujuFixture, run
57
58
59-SERIES = 'precise'
60-TEST_CHARM = 'local:postgresql'
61-PSQL_CHARM = 'cs:postgresql-psql'
62+SERIES = os.environ.get('SERIES', 'precise').strip()
63+TEST_CHARM = 'local:{}/postgresql'.format(SERIES)
64+PSQL_CHARM = 'local:{}/postgresql-psql'.format(SERIES)
65
66
67 class NotReady(Exception):
68@@ -55,7 +56,7 @@
69 self.pg_config = dict(version=self.VERSION, pgdg=self.PGDG)
70
71 self.juju = self.useFixture(JujuFixture(
72- reuse_machines=True,
73+ series=SERIES, reuse_machines=True,
74 do_teardown='TEST_DONT_TEARDOWN_JUJU' not in os.environ))
75
76 # If the charms fail, we don't want tests to hang indefinitely.
77@@ -287,14 +288,15 @@
78 local_port = s.getsockname()[1]
79 s.close()
80
81- # Open the tunnel and wait for it to come up. The new process
82- # group is to ensure we can reap all the ssh tunnels, as simply
83- # killing the 'juju ssh' process doesn't seem to be enough.
84+ # Open the tunnel and wait for it to come up.
85+ # The new process group is to ensure we can reap all the ssh
86+ # tunnels, as simply killing the 'juju ssh' process doesn't seem
87+ # to be enough.
88 tunnel_cmd = [
89 'juju', 'ssh', psql_unit, '-N', '-L',
90 '{}:{}:{}'.format(local_port, rel_info['host'], rel_info['port'])]
91 tunnel_proc = subprocess.Popen(
92- tunnel_cmd, stdin=subprocess.PIPE)
93+ tunnel_cmd, stdin=subprocess.PIPE, preexec_fn=os.setpgrp)
94 # Don't disable stdout, so we can see when there are SSH
95 # failures like bad host keys.
96 #stdout=open('/dev/null', 'ab'), stderr=subprocess.STDOUT)
97@@ -330,6 +332,7 @@
98 con.close()
99 return rv
100 finally:
101+ os.killpg(tunnel_proc.pid, signal.SIGTERM)
102 tunnel_proc.kill()
103 tunnel_proc.wait()
104
105
106=== modified file 'testing/jujufixture.py'
107--- testing/jujufixture.py 2014-04-04 17:40:36 +0000
108+++ testing/jujufixture.py 2014-06-10 11:44:04 +0000
109@@ -17,9 +17,11 @@
110 Assumes juju environment is bootstrapped.
111 """
112
113- def __init__(self, reuse_machines=False, do_teardown=True):
114+ def __init__(self, series, reuse_machines=False, do_teardown=True):
115 super(JujuFixture, self).__init__()
116
117+ self.series = series
118+
119 self.reuse_machines = reuse_machines
120
121 # Optionally, don't teardown services and machines after running
122@@ -92,6 +94,7 @@
123 int(k) for k, m in self.status['machines'].items()
124 if k != '0'
125 and m.get('life', None) not in ('dead', 'dying')
126+ and m.get('series', None) == self.series
127 and m.get('agent-state', 'pending') in ('started', 'ready'))
128 for service in self.status.get('services', {}).values():
129 for unit in service.get('units', {}).values():

Subscribers

People subscribed via source and target branches