~stub/charms/precise/postgresql/admin-addresses-test

« back to all changes in this revision

Viewing changes to hooks/hooks.py

  • Committer: Stuart Bishop
  • Date: 2013-10-10 11:00:39 UTC
  • mfrom: (46.4.29 fix-races)
  • Revision ID: stuart.bishop@canonical.com-20131010110039-9ra2w8uy1ek0tnmm
Resolve conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
hooks = hookenv.Hooks()
28
28
 
29
29
 
30
 
# jinja2 may not be importable until the install hook has installed the
31
 
# required packages.
32
30
def Template(*args, **kw):
33
 
    """jinja2.Template with deferred jinja2 import"""
 
31
    """jinja2.Template with deferred jinja2 import.
 
32
 
 
33
    jinja2 may not be importable until the install hook has installed the
 
34
    required packages.
 
35
    """
34
36
    from jinja2 import Template
35
37
    return Template(*args, **kw)
36
38
 
253
255
                run('pg_ctlcluster -force {version} {cluster_name} '
254
256
                    'restart'.format(**config_data))
255
257
                success = True
256
 
            except subprocess.CalledProcessError as e:
 
258
            except subprocess.CalledProcessError:
257
259
                success = False
258
260
    else:
259
261
        success = host.service_start('postgresql')
402
404
 
403
405
 
404
406
def generate_postgresql_hba(
405
 
    postgresql_hba, user=None, schema_user=None, database=None):
 
407
        postgresql_hba, user=None, schema_user=None, database=None):
406
408
    '''Create the pg_hba.conf file.'''
407
409
 
408
410
    # Per Bug #1117542, when generating the postgresql_hba file we
548
550
 
549
551
    recovery_conf = Template(
550
552
        open("templates/recovery.conf.tmpl").read()).render({
551
 
            'host': master_host,
552
 
            'password': local_state['replication_password']})
 
553
        'host': master_host,
 
554
        'password': local_state['replication_password']})
553
555
    log(recovery_conf, DEBUG)
554
556
    host.write_file(
555
557
        os.path.join(postgresql_cluster_dir, 'recovery.conf'),
729
731
            log("postgresql_stop() failed - can't migrate data.", ERROR)
730
732
            return False
731
733
        if not os.path.exists(os.path.join(
732
 
            new_pg_version_cluster_dir, "PG_VERSION")):
 
734
                new_pg_version_cluster_dir, "PG_VERSION")):
733
735
            log("migrating PG data {}/ -> {}/".format(
734
736
                data_directory_path, new_pg_version_cluster_dir), WARNING)
735
737
            # void copying PID file to perm storage (shouldn't be any...)
1708
1710
        postgresql_stop()
1709
1711
        log("Cloning master {}".format(master_unit))
1710
1712
 
1711
 
        cmd = ['sudo', '-E',  # -E needed to locate pgpass file.
 
1713
        cmd = [
 
1714
            'sudo', '-E',  # -E needed to locate pgpass file.
1712
1715
            '-u', 'postgres', 'pg_basebackup', '-D', postgresql_cluster_dir,
1713
1716
            '--xlog', '--checkpoint=fast', '--no-password',
1714
1717
            '-h', master_host, '-p', '5432', '--username=juju_replication']