Merge lp:~stub/charms/precise/postgresql/admin-addresses-test into lp:charms/postgresql

Proposed by Stuart Bishop
Status: Merged
Merged at revision: 73
Proposed branch: lp:~stub/charms/precise/postgresql/admin-addresses-test
Merge into: lp:charms/postgresql
Prerequisite: lp:~stub/charms/precise/postgresql/tests
Diff against target: 60 lines (+38/-0)
1 file modified
test.py (+38/-0)
To merge this branch: bzr merge lp:~stub/charms/precise/postgresql/admin-addresses-test
Reviewer Review Type Date Requested Status
Marco Ceppi (community) Approve
Review via email: mp+190469@code.launchpad.net

Description of the change

Add a test for the admin_addresses configuration option.

To post a comment you must log in.
92. By Stuart Bishop

Merged tests into admin-addresses-test.

93. By Stuart Bishop

Merged tests into admin-addresses-test.

94. By Stuart Bishop

Merged tests into admin-addresses-test.

Revision history for this message
Marco Ceppi (marcoceppi) wrote :

LGTM +1

review: Approve
95. By Stuart Bishop

Merged tests into admin-addresses-test.

96. By Stuart Bishop

Merged tests into admin-addresses-test.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'test.py'
2--- test.py 2013-10-11 16:40:51 +0000
3+++ test.py 2013-10-11 16:40:52 +0000
4@@ -10,11 +10,13 @@
5 """
6
7 import os.path
8+import socket
9 import subprocess
10 import time
11 import unittest
12
13 import fixtures
14+import psycopg2
15 import testtools
16 from testtools.content import text_content
17
18@@ -257,6 +259,42 @@
19 self.assertIs(True, self.is_master(standby_unit_2, 'postgres'))
20 self.assertIs(False, self.is_master(standby_unit_1, 'postgres'))
21
22+ def test_admin_addresses(self):
23+ self.juju.deploy(TEST_CHARM, 'postgresql')
24+ self.juju.deploy(PSQL_CHARM, 'psql')
25+ self.juju.do(['add-relation', 'postgresql:db-admin', 'psql:db-admin'])
26+ self.juju.wait_until_ready()
27+
28+ # We need to determine the IP address that the unit will see.
29+ unit = self.juju.status['services']['postgresql']['units'].keys()[0]
30+ unit_ip = self.juju.status['services']['postgresql']['units'][
31+ unit]['public-address']
32+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
33+ s.connect((unit_ip, 5432))
34+ my_ip = s.getsockname()[0]
35+ del s
36+
37+ # We also need to set a password.
38+ self.sql(
39+ "ALTER USER postgres ENCRYPTED PASSWORD 'foo'", dbname='postgres')
40+
41+ # Direct connection string to the unit's database.
42+ conn_str = 'dbname=postgres user=postgres password=foo host={}'.format(
43+ unit_ip)
44+
45+ # Direct database connections should fail at the moment.
46+ self.assertRaises(
47+ psycopg2.OperationalError, psycopg2.connect, conn_str)
48+
49+ # Connections should work after setting the admin-addresses.
50+ self.juju.do([
51+ 'set', 'postgresql', 'admin_addresses={}'.format(my_ip)])
52+ self.juju.wait_until_ready()
53+ con = psycopg2.connect(conn_str)
54+ cur = con.cursor()
55+ cur.execute('SELECT 1')
56+ self.assertEquals(1, cur.fetchone()[0])
57+
58
59 def unit_sorted(units):
60 """Return a correctly sorted list of unit names."""

Subscribers

People subscribed via source and target branches