~stub/charms/precise/postgresql/docs

« back to all changes in this revision

Viewing changes to test.py

  • Committer: Marco Ceppi
  • Date: 2014-03-04 16:02:06 UTC
  • mfrom: (46.10.53 syslog)
  • Revision ID: marco@ceppi.net-20140304160206-87ms64nn3afvvpxq
[stub] Ship PostgreSQL log files via syslog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
import subprocess
15
15
import time
16
16
import unittest
 
17
import uuid
17
18
 
18
19
import fixtures
19
20
import psycopg2
137
138
        result = self.sql('SELECT TRUE')
138
139
        self.assertEqual(result, [['t']])
139
140
 
 
141
        # Confirm that the relation tears down without errors.
 
142
        self.juju.do(['destroy-relation', 'postgresql:db', 'psql:db'])
 
143
        self.juju.wait_until_ready()
 
144
 
140
145
    def test_streaming_replication(self):
141
146
        self.juju.deploy(
142
147
            TEST_CHARM, 'postgresql', num_units=2, config=self.pg_config)
163
168
        result = self.sql('SELECT TRUE', dbname='postgres')
164
169
        self.assertEqual(result, [['t']])
165
170
 
 
171
        # Confirm that the relation tears down without errors.
 
172
        self.juju.do([
 
173
            'destroy-relation', 'postgresql:db-admin', 'psql:db-admin'])
 
174
        self.juju.wait_until_ready()
 
175
 
166
176
    def is_master(self, postgres_unit, dbname=None):
167
177
        is_master = self.sql(
168
178
            'SELECT NOT pg_is_in_recovery()',
425
435
            ''')
426
436
        self.assertEqual(result, [['f', 'f', 'f']])
427
437
 
 
438
    def test_syslog(self):
 
439
        # Deploy 2 PostgreSQL units and 2 rsyslog units to ensure that
 
440
        # log messages from every source reach every sink.
 
441
        self.pg_config['log_min_duration_statement'] = 0  # Log all statements
 
442
        self.juju.deploy(
 
443
            TEST_CHARM, 'postgresql', num_units=2, config=self.pg_config)
 
444
        self.juju.deploy(PSQL_CHARM, 'psql')
 
445
        self.juju.do(['add-relation', 'postgresql:db', 'psql:db'])
 
446
        self.juju.deploy('cs:rsyslog', 'rsyslog', num_units=2)
 
447
        self.juju.do([
 
448
            'add-relation', 'postgresql:syslog', 'rsyslog:aggregator'])
 
449
        self.juju.wait_until_ready()
 
450
 
 
451
        token = str(uuid.uuid1())
 
452
 
 
453
        self.sql("SELECT 'master {}'".format(token), 'master')
 
454
        self.sql("SELECT 'hot standby {}'".format(token), 'hot standby')
 
455
        time.sleep(2)
 
456
 
 
457
        for runit in ['rsyslog/0', 'rsyslog/1']:
 
458
            cmd = ['juju', 'ssh', runit, 'tail -100 /var/log/syslog']
 
459
            out = run(self, cmd)
 
460
            self.failUnless('master {}'.format(token) in out)
 
461
            self.failUnless('hot standby {}'.format(token) in out)
 
462
 
 
463
        # Confirm that the relation tears down correctly.
 
464
        self.juju.do([
 
465
            'destroy-relation', 'postgresql:syslog', 'rsyslog:aggregator'])
 
466
        self.juju.wait_until_ready()
 
467
 
428
468
 
429
469
class PG91Tests(
430
470
        PostgreSQLCharmBaseTestCase,