def pg_ctlcluster(self, unit, command): cmd = [ 'juju', 'ssh', unit, # Due to Bug #1191079, we need to send the whole remote command # as a single argument. 'sudo pg_ctlcluster 9.1 main -force {}'.format(command)] run(self, cmd)
def sql(self, sql, postgres_unit=None, psql_unit=None, dbname=None): '''Run some SQL on postgres_unit from psql_unit. Uses a random psql_unit and postgres_unit if not specified. postgres_unit may be set to an explicit unit name, 'master' or 'hot standby'. A db-admin relation is used if dbname is specified. Otherwise, a standard db relation is used. ''' if psql_unit is None: psql_unit = ( self.juju.status['services']['psql']['units'].keys()[0]) # The psql statements we are going to execute. sql = sql.strip() if not sql.endswith(';'): sql += ';' sql += '\n\\q\n' # The command we run to connect psql to the desired database. if postgres_unit is None: postgres_unit = ( self.juju.status['services']['postgresql']['units'].keys()[0]) elif postgres_unit == 'hot standby': postgres_unit = 'hot-standby' # Munge for generating script name. if dbname is None: psql_cmd = [ 'psql-db-{}'.format(postgres_unit.replace('/', '-'))] else: psql_cmd = [ 'psql-db-admin-{}'.format( postgres_unit.replace('/', '-')), '-d', dbname] psql_args = [ '--quiet', '--tuples-only', '--no-align', '--no-password', '--field-separator=,', '--file=-'] cmd = [ 'juju', 'ssh', psql_unit, # Due to Bug #1191079, we need to send the whole remote command # as a single argument. ' '.join(psql_cmd + psql_args)] out = run(self, cmd, input=sql) result = [line.split(',') for line in out.splitlines()] self.addDetail('sql', text_content(repr((sql, result)))) return result
def test_syslog(self): # Deploy 2 PostgreSQL units and 2 rsyslog units to ensure that # log messages from every source reach every sink. self.pg_config['log_min_duration_statement'] = 0 # Log all statements self.juju.deploy(TEST_CHARM, 'postgresql', num_units=2, config=self.pg_config) self.juju.deploy(PSQL_CHARM, 'psql') self.juju.do(['add-relation', 'postgresql:db', 'psql:db']) self.juju.deploy('cs:rsyslog', 'rsyslog', num_units=2) self.juju.do( ['add-relation', 'postgresql:syslog', 'rsyslog:aggregator']) pg_units = ['postgresql/0', 'postgresql/1'] self.wait_until_ready(pg_units) token = str(uuid.uuid1()) self.sql("SELECT 'master {}'".format(token), 'master') self.sql("SELECT 'hot standby {}'".format(token), 'hot standby') time.sleep(2) for runit in ['rsyslog/0', 'rsyslog/1']: cmd = ['juju', 'run', '--unit', runit, 'tail -100 /var/log/syslog'] out = run(self, cmd) self.failUnless('master {}'.format(token) in out) self.failUnless('hot standby {}'.format(token) in out) # Confirm that the relation tears down correctly. self.juju.do(['destroy-service', 'rsyslog']) timeout = time.time() + 120 while time.time() < timeout: status = self.juju.refresh_status() if 'rsyslog' not in status['services']: break self.assert_('rsyslog' not in status['services'], 'rsyslog failed to die') self.wait_until_ready(pg_units)
def test_syslog(self): # Deploy 2 PostgreSQL units and 2 rsyslog units to ensure that # log messages from every source reach every sink. self.pg_config['log_min_duration_statement'] = 0 # Log all statements self.juju.deploy( TEST_CHARM, 'postgresql', num_units=2, config=self.pg_config) self.juju.deploy(PSQL_CHARM, 'psql') self.juju.do(['add-relation', 'postgresql:db', 'psql:db']) self.juju.deploy('cs:rsyslog', 'rsyslog', num_units=2) self.juju.do([ 'add-relation', 'postgresql:syslog', 'rsyslog:aggregator']) pg_units = ['postgresql/0', 'postgresql/1'] self.wait_until_ready(pg_units) token = str(uuid.uuid1()) self.sql("SELECT 'master {}'".format(token), 'master') self.sql("SELECT 'hot standby {}'".format(token), 'hot standby') time.sleep(2) for runit in ['rsyslog/0', 'rsyslog/1']: cmd = ['juju', 'run', '--unit', runit, 'tail -100 /var/log/syslog'] out = run(self, cmd) self.failUnless('master {}'.format(token) in out) self.failUnless('hot standby {}'.format(token) in out) # Confirm that the relation tears down correctly. self.juju.do(['destroy-service', 'rsyslog']) timeout = time.time() + 120 while time.time() < timeout: status = self.juju.refresh_status() if 'rsyslog' not in status['services']: break self.assert_( 'rsyslog' not in status['services'], 'rsyslog failed to die') self.wait_until_ready(pg_units)
def pg_ctlcluster(self, unit, command): cmd = [ 'juju', 'run', '--unit', unit, 'sudo pg_ctlcluster 9.1 main -force {}'.format(command) ] run(self, cmd)
def pg_ctlcluster(self, unit, command): cmd = [ 'juju', 'run', '--unit', unit, 'sudo pg_ctlcluster 9.1 main -force {}'.format(command)] run(self, cmd)