~ionutbalutoiu/charms/trusty/neutron-api/next

« back to all changes in this revision

Viewing changes to hooks/neutron_api_hooks.py

  • Committer: Liam Young
  • Date: 2014-10-23 07:38:47 UTC
  • mfrom: (60.2.1 trunk)
  • Revision ID: liam.young@canonical.com-20141023073847-us3llkowc8t98v79
[gnuoy,r=james-page] Remove code to run neutron-db-manage from neutron-api as it's racey with the nova-cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
from charmhelpers.core.host import (
22
22
    restart_on_change,
23
 
    service_restart,
24
23
)
25
24
 
26
25
from charmhelpers.fetch import (
32
31
from charmhelpers.contrib.openstack.utils import (
33
32
    configure_installation_source,
34
33
    openstack_upgrade_available,
35
 
    os_release,
36
34
    sync_db_with_multi_ipv6_addresses
37
35
)
38
36
from charmhelpers.contrib.openstack.neutron import (
40
38
)
41
39
 
42
40
from neutron_api_utils import (
43
 
    CLUSTER_RES,
44
41
    NEUTRON_CONF,
45
42
    api_port,
46
43
    determine_packages,
47
44
    determine_ports,
48
45
    do_openstack_upgrade,
49
 
    migrate_neutron_database,
50
46
    register_configs,
51
47
    restart_map,
52
48
    setup_ipv6
58
54
 
59
55
from charmhelpers.contrib.hahelpers.cluster import (
60
56
    get_hacluster_config,
61
 
    is_leader,
62
57
)
63
58
 
64
59
from charmhelpers.payload.execd import execd_preinstall
153
148
    CONFIGS.write(NEUTRON_CONF)
154
149
 
155
150
 
156
 
def conditional_neutron_migration():
157
 
    # This is an attempt to stop a race over the db migration between nova-cc
158
 
    # and neutron-api by having the migration master decided by the presence
159
 
    # of the neutron-api relation. In the long term this should only be done
160
 
    # the neutron-api charm and nova-cc should play no hand in it
161
 
    # * neutron-api refuses to run migrations until neutron-api relation is
162
 
    #   present
163
 
    # * nova-cc refuses to run migration if neutron-api relations is present
164
 
    clustered = relation_get('clustered')
165
 
    if not relation_ids('neutron-api'):
166
 
        log('Not running neutron database migration, no nova-cloud-controller'
167
 
            'is present.')
168
 
    elif os_release('neutron-server') <= 'icehouse':
169
 
        log('Not running neutron database migration as migrations are handled'
170
 
            'by the neutron-server process.')
171
 
    else:
172
 
        if clustered:
173
 
            if is_leader(CLUSTER_RES):
174
 
                migrate_neutron_database()
175
 
                service_restart('neutron-server')
176
 
            else:
177
 
                log('Not running neutron database migration, not leader')
178
 
        else:
179
 
            migrate_neutron_database()
180
 
            service_restart('neutron-server')
181
 
 
182
 
 
183
151
@hooks.hook('shared-db-relation-joined')
184
152
def db_joined():
185
153
    if is_relation_made('pgsql-db'):
218
186
        log('shared-db relation incomplete. Peer not ready?')
219
187
        return
220
188
    CONFIGS.write_all()
221
 
    conditional_neutron_migration()
222
189
 
223
190
 
224
191
@hooks.hook('pgsql-db-relation-changed')
227
194
    plugin = config('neutron-plugin')
228
195
    # DB config might have been moved to main neutron.conf in H?
229
196
    CONFIGS.write(neutron_plugin_attribute(plugin, 'config'))
230
 
    conditional_neutron_migration()
231
197
 
232
198
 
233
199
@hooks.hook('amqp-relation-broken',
294
260
@restart_on_change(restart_map())
295
261
def neutron_api_relation_changed():
296
262
    CONFIGS.write(NEUTRON_CONF)
297
 
    if 'shared-db' in CONFIGS.complete_contexts():
298
 
        conditional_neutron_migration()
299
263
 
300
264
 
301
265
@hooks.hook('neutron-plugin-api-relation-joined')