~charmers/charms/trusty/postgresql/trunk

« back to all changes in this revision

Viewing changes to hooks/hooks.py

[stub] Add some tunables needed for Launchpad and Landscape deployments. Also remove a config item that has done nothing for ages, and remove beta comments about the no-longer beta PostgreSQL 9.4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from charmhelpers import fetch
23
23
from charmhelpers.core import hookenv, host
24
24
from charmhelpers.core.hookenv import (
25
 
    CRITICAL, ERROR, WARNING, INFO, DEBUG,
26
 
    )
 
25
    CRITICAL, ERROR, WARNING, INFO, DEBUG)
27
26
 
28
27
try:
29
28
    import psycopg2
212
211
        log("ERROR: {}".format(p.returncode), ERROR)
213
212
        sys.exit(p.returncode)
214
213
 
215
 
    raise subprocess.CalledProcessError(
216
 
        p.returncode, command, '\n'.join(lines))
 
214
    raise subprocess.CalledProcessError(p.returncode, command,
 
215
                                        '\n'.join(lines))
217
216
 
218
217
 
219
218
def postgresql_is_running():
447
446
        open(template_file).read()).render(config_data)
448
447
    host.write_file(
449
448
        config_file, pg_config,
450
 
        owner="postgres",  group="postgres", perms=0600)
 
449
        owner="postgres", group="postgres", perms=0600)
451
450
 
452
451
    # Create or update files included from postgresql.conf.
453
452
    configure_log_destination(os.path.dirname(config_file))
963
962
            CRITICAL)
964
963
 
965
964
    valid_workloads = [
966
 
        'dw',  'oltp', 'web', 'mixed', 'desktop', 'manual', 'auto']
 
965
        'dw', 'oltp', 'web', 'mixed', 'desktop', 'manual', 'auto']
967
966
    requested_workload = config_data['performance_tuning'].lower()
968
967
    if requested_workload not in valid_workloads:
969
968
        valid = False
2148
2147
 
2149
2148
    # Build the set of client relations that both the master and this
2150
2149
    # unit have joined.
2151
 
    active_client_relations = set(
2152
 
        hookenv.relation_ids('db') + hookenv.relation_ids('db-admin')
2153
 
        ).intersection(set(client_relations.split()))
 
2150
    possible_client_relations = set(hookenv.relation_ids('db') +
 
2151
                                    hookenv.relation_ids('db-admin'))
 
2152
    active_client_relations = possible_client_relations.intersection(
 
2153
        set(client_relations.split()))
2154
2154
 
2155
2155
    for client_relation in active_client_relations:
2156
2156
        # We need to pull the credentials from the master unit's
2513
2513
    if len(relations) == 1 and 'nagios_hostname' in relations[0]:
2514
2514
        nagios_hostname = relations[0]['nagios_hostname']
2515
2515
        log("update_nrpe_checks: Obtained nagios_hostname ({}) "
2516
 
            "from nrpe-external-master relation.".format(
2517
 
            nagios_hostname))
 
2516
            "from nrpe-external-master relation.".format(nagios_hostname))
2518
2517
    else:
2519
2518
        unit = hookenv.local_unit()
2520
2519
        unit_name = unit.replace('/', '-')
2521
2520
        nagios_hostname = "%s-%s" % (config_data['nagios_context'], unit_name)
2522
 
        log("update_nrpe_checks: Deduced nagios_hostname ({}) from charm config "
2523
 
            "(nagios_hostname not found in nrpe-external-master relation, or "
2524
 
            "wrong number of relations found)".format(
2525
 
            nagios_hostname))
 
2521
        log("update_nrpe_checks: Deduced nagios_hostname ({}) from charm "
 
2522
            "config (nagios_hostname not found in nrpe-external-master "
 
2523
            "relation, or wrong number of relations "
 
2524
            "found)".format(nagios_hostname))
2526
2525
 
2527
2526
    nrpe_service_file = \
2528
2527
        '/var/lib/nagios/export/service__{}_check_pgsql.cfg'.format(