~heut2008/charms/trusty/nova-cloud-controller/sync-charmhelpers-haproxy

« back to all changes in this revision

Viewing changes to hooks/nova_cc_utils.py

[gnuoy,r=james-page] Ensure services are not running prior to a db sync.

Resolves two issues

1) Co-ordination of db sync activity across multiple nodes.

2) Ensures services are not started unil db sync is complete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 
13
13
from charmhelpers.contrib.hahelpers.cluster import eligible_leader
14
14
 
 
15
from charmhelpers.contrib.peerstorage import peer_store
 
16
 
15
17
from charmhelpers.contrib.openstack.utils import (
16
18
    configure_installation_source,
17
19
    get_host_ip,
39
41
)
40
42
 
41
43
from charmhelpers.core.host import (
 
44
    service,
42
45
    service_start,
43
46
    service_stop,
44
47
    service_running
304
307
    '''Assemble a list of API ports for services we are managing'''
305
308
    ports = []
306
309
    for services in restart_map().values():
307
 
        for service in services:
 
310
        for svc in services:
308
311
            try:
309
 
                ports.append(API_PORTS[service])
 
312
                ports.append(API_PORTS[svc])
310
313
            except KeyError:
311
314
                pass
312
315
    return list(set(ports))
545
548
    log('Migrating the nova database.', level=INFO)
546
549
    cmd = ['nova-manage', 'db', 'sync']
547
550
    subprocess.check_output(cmd)
 
551
    if is_relation_made('cluster'):
 
552
        log('Informing peers that dbsync is complete', level=INFO)
 
553
        peer_store('dbsync_state', 'complete')
 
554
    log('Enabling services', level=INFO)
 
555
    enable_services()
 
556
    cmd_all_services('start')
548
557
 
549
558
 
550
559
def auth_token_config(setting):
863
872
                f(*args)
864
873
        return wrapped_f
865
874
    return wrap
 
875
 
 
876
 
 
877
def cmd_all_services(cmd):
 
878
    if cmd == 'start':
 
879
        for svc in services():
 
880
            if not service_running(svc):
 
881
                service_start(svc)
 
882
    else:
 
883
        for svc in services():
 
884
            service(cmd, svc)
 
885
 
 
886
 
 
887
def disable_services():
 
888
    for svc in services():
 
889
        with open('/etc/init/{}.override'.format(svc), 'wb') as out:
 
890
            out.write('exec true\n')
 
891
 
 
892
 
 
893
def enable_services():
 
894
    for svc in services():
 
895
        override_file = '/etc/init/{}.override'.format(svc)
 
896
        if os.path.isfile(override_file):
 
897
            os.remove(override_file)