Example #1
0
 def test_migrate_neutron_database(self):
     nutils.migrate_neutron_database()
     cmd = [
         'neutron-db-manage', '--config-file', '/etc/neutron/neutron.conf',
         '--config-file', '/etc/neutron/plugins/ml2/ml2_conf.ini',
         'upgrade', 'head'
     ]
     self.subprocess.check_output.assert_called_with(cmd)
 def test_migrate_neutron_database(self):
     nutils.migrate_neutron_database()
     cmd = ['neutron-db-manage',
            '--config-file', '/etc/neutron/neutron.conf',
            '--config-file', '/etc/neutron/plugins/ml2/ml2_conf.ini',
            'upgrade',
            'head']
     self.subprocess.check_output.assert_called_with(cmd)
 def test_migrate_neutron_database(self, mock_is_db_initd, mock_rel_ids):
     mock_is_db_initd.return_value = False
     nutils.migrate_neutron_database()
     cmd = [
         'neutron-db-manage', '--config-file', '/etc/neutron/neutron.conf',
         '--config-file', '/etc/neutron/plugins/ml2/ml2_conf.ini',
         'upgrade', 'head'
     ]
     self.subprocess.check_output.assert_called_with(cmd)
 def test_migrate_neutron_database(self, mock_is_db_initd, mock_rel_ids):
     mock_is_db_initd.return_value = False
     nutils.migrate_neutron_database()
     cmd = ['neutron-db-manage',
            '--config-file', '/etc/neutron/neutron.conf',
            '--config-file', '/etc/neutron/plugins/ml2/ml2_conf.ini',
            'upgrade',
            'head']
     self.subprocess.check_output.assert_called_with(cmd)
def conditional_neutron_migration():
    if CompareOpenStackReleases(os_release('neutron-server')) <= 'icehouse':
        log('Not running neutron database migration as migrations are handled '
            'by the neutron-server process.')
        return
    if is_elected_leader(CLUSTER_RES):
        allowed_units = relation_get('allowed_units')
        if allowed_units and local_unit() in allowed_units.split():
            migrate_neutron_database()
            if not is_unit_paused_set():
                service_restart('neutron-server')
        else:
            log('Not running neutron database migration, either no'
                ' allowed_units or this unit is not present')
            return
    else:
        log('Not running neutron database migration, not leader')
Example #6
0
def conditional_neutron_migration():
    if os_release('neutron-common') < 'kilo':
        log('Not running neutron database migration as migrations are handled '
            'by the neutron-server process or nova-cloud-controller charm.')
        return

    if is_elected_leader(CLUSTER_RES):
        allowed_units = relation_get('allowed_units')
        if allowed_units and local_unit() in allowed_units.split():
            migrate_neutron_database()
            service_restart('neutron-server')
        else:
            log('Not running neutron database migration, either no'
                ' allowed_units or this unit is not present')
            return
    else:
        log('Not running neutron database migration, not leader')
def infoblox_changed():
    # The neutron DB upgrade will add new tables to
    # neutron db related to infoblox service.
    # Please take a look to charm-infoblox docs.
    if 'infoblox-neutron' not in CONFIGS.complete_contexts():
        log('infoblox-neutron relation incomplete. Peer not ready?')
        return

    CONFIGS.write(NEUTRON_CONF)

    if is_leader():
        ready = False
        if is_db_initialised() and neutron_ready():
            migrate_neutron_database(upgrade=True)
            ready = True
        for rid in relation_ids('infoblox-neutron'):
            relation_set(relation_id=rid, neutron_api_ready=ready)
Example #8
0
def conditional_neutron_migration():
    if os_release('neutron-common') < 'kilo':
        log('Not running neutron database migration as migrations are handled '
            'by the neutron-server process or nova-cloud-controller charm.')
        return

    if is_elected_leader(CLUSTER_RES):
        allowed_units = relation_get('allowed_units')
        if allowed_units and local_unit() in allowed_units.split():
            migrate_neutron_database()
            service_restart('neutron-server')
        else:
            log('Not running neutron database migration, either no'
                ' allowed_units or this unit is not present')
            return
    else:
        log('Not running neutron database migration, not leader')
def conditional_neutron_migration():
    if os_release('neutron-server') <= 'icehouse':
        log('Not running neutron database migration as migrations are handled '
            'by the neutron-server process.')
        return
    if is_elected_leader(CLUSTER_RES):
        allowed_units = relation_get('allowed_units')
        if allowed_units and local_unit() in allowed_units.split():
            migrate_neutron_database()
            if not is_unit_paused_set():
                service_restart('neutron-server')
        else:
            log('Not running neutron database migration, either no'
                ' allowed_units or this unit is not present')
            return
    else:
        log('Not running neutron database migration, not leader')
def conditional_neutron_migration():
    if os_release('neutron-server') < 'kilo':
        if not (os_release('neutron-server') == 'juno' and
           config('neutron-plugin') == 'vsp'):
            log('Not running neutron database migration as migrations '
                'are handled by the neutron-server process or'
                ' nova-cloud-controller charm.')
            return

    if is_elected_leader(CLUSTER_RES):
        allowed_units = relation_get('allowed_units')
        if allowed_units and local_unit() in allowed_units.split():
            migrate_neutron_database()
            if not is_unit_paused_set():
                service_restart('neutron-server')
        else:
            log('Not running neutron database migration, either no'
                ' allowed_units or this unit is not present')
            return
    else:
        log('Not running neutron database migration, not leader')
Example #11
0
def conditional_neutron_migration():
    if os_release('neutron-server') < 'kilo':
        if not (os_release('neutron-server') == 'juno'
                and config('neutron-plugin') == 'vsp'):
            log('Not running neutron database migration as migrations '
                'are handled by the neutron-server process or'
                ' nova-cloud-controller charm.')
            return

    if is_elected_leader(CLUSTER_RES):
        allowed_units = relation_get('allowed_units')
        if allowed_units and local_unit() in allowed_units.split():
            migrate_neutron_database()
            if not is_unit_paused_set():
                service_restart('neutron-server')
        else:
            log('Not running neutron database migration, either no'
                ' allowed_units or this unit is not present')
            return
    else:
        log('Not running neutron database migration, not leader')
def neutron_plugin_api_subordinate_relation_joined(relid=None):
    relation_data = {}
    if is_db_initialised():
        db_migration_key = 'migrate-database-nonce'
        if not relid:
            relid = relation_id()
        leader_key = '{}-{}'.format(db_migration_key, relid)
        for unit in related_units(relid):
            nonce = relation_get(db_migration_key, rid=relid, unit=unit)
            if nonce:
                if is_leader() and leader_get(leader_key) != nonce:
                    migrate_neutron_database(upgrade=True)
                    # track nonce in leader storage to avoid superfluous
                    # migrations
                    leader_set({leader_key: nonce})
                # set nonce back on relation to signal completion to other end
                # we do this regardless of leadership status so that
                # subordinates connected to non-leader units can proceed.
                relation_data[db_migration_key] = nonce

    relation_data['neutron-api-ready'] = 'no'
    if is_api_ready(CONFIGS):
        relation_data['neutron-api-ready'] = 'yes'
    if not manage_plugin():
        neutron_cc_ctxt = NeutronCCContext()()
        plugin_instance = NeutronApiSDNContext()
        neutron_config_data = {
            k: v
            for k, v in neutron_cc_ctxt.items()
            if plugin_instance.is_allowed(k)
        }
        if neutron_config_data:
            relation_data['neutron_config_data'] = json.dumps(
                neutron_config_data)
    relation_set(relation_id=relid, **relation_data)

    # there is no race condition with the neutron service restart
    # as juju propagates the changes done in relation_set only after
    # the hook exists
    CONFIGS.write_all()
def conditional_neutron_migration():
    """Initialise neutron database if not already done so.

    Runs neutron-manage to initialize a new database or migrate existing and
    restarts services to ensure that the changes are picked up. The first
    (leader) unit to perform this action should have broadcast this information
    to its peers so first we check whether this has already occurred.
    """
    if CompareOpenStackReleases(os_release('neutron-server')) <= 'icehouse':
        log('Not running neutron database migration as migrations are handled '
            'by the neutron-server process.')
        return

    if not is_elected_leader(CLUSTER_RES):
        log('Not running neutron database migration, not leader')
        return

    allowed_units = relation_get('allowed_units')
    if not (allowed_units and local_unit() in allowed_units.split()):
        log('Not running neutron database migration, either no '
            'allowed_units or this unit is not present')
        return

    migrate_neutron_database()
def conditional_neutron_migration():
    """Initialise neutron database if not already done so.

    Runs neutron-manage to initialize a new database or migrate existing and
    restarts services to ensure that the changes are picked up. The first
    (leader) unit to perform this action should have broadcast this information
    to its peers so first we check whether this has already occurred.
    """
    if CompareOpenStackReleases(os_release('neutron-server')) <= 'icehouse':
        log('Not running neutron database migration as migrations are handled '
            'by the neutron-server process.')
        return

    if not is_elected_leader(CLUSTER_RES):
        log('Not running neutron database migration, not leader')
        return

    allowed_units = relation_get('allowed_units')
    if not (allowed_units and local_unit() in allowed_units.split()):
        log('Not running neutron database migration, either no '
            'allowed_units or this unit is not present')
        return

    migrate_neutron_database()