def test_is_db_initisalised_true(self, mock_related_units, mock_relation_ids, mock_relation_get, mock_local_unit): shared_db_rel_id = 'shared-db:1' init_db_val = 'unit/1-{}-1234'.format(shared_db_rel_id) mock_relation_ids.return_value = [shared_db_rel_id] settings = {'0': {nutils.NEUTRON_DB_INIT_RKEY: init_db_val}, '1': {nutils.NEUTRON_DB_INIT_ECHO_RKEY: init_db_val}} def mock_rel_ids(name): if name == 'cluster': return 'cluster:1' elif name == 'shared-db': return 'shared-db:1' raise Exception("Uknown relation '{}'".format(name)) def mock_rel_get(unit=None, rid=None, attribute=None): if not unit: unit = '0' if attribute: return settings[unit].get(attribute) return settings[unit] mock_relation_ids.side_effect = mock_rel_ids mock_local_unit.return_value = '0' mock_relation_get.side_effect = mock_rel_get mock_related_units.return_value = ['1'] self.assertTrue(nutils.is_db_initialised())
def test_is_db_initisalised_true(self, mock_related_units, mock_relation_ids, mock_relation_get, mock_local_unit): shared_db_rel_id = 'shared-db:1' init_db_val = 'unit/1-{}-1234'.format(shared_db_rel_id) mock_relation_ids.return_value = [shared_db_rel_id] settings = {'0': {nutils.NEUTRON_DB_INIT_RKEY: init_db_val}, '1': {nutils.NEUTRON_DB_INIT_ECHO_RKEY: init_db_val}} def mock_rel_ids(name): if name == 'cluster': return 'cluster:1' elif name == 'shared-db': return 'shared-db:1' raise Exception("Uknown relation '{}'".format(name)) def mock_rel_get(unit=None, rid=None, attribute=None): if not unit: unit = '0' if attribute: return settings[unit].get(attribute) return settings[unit] mock_relation_ids.side_effect = mock_rel_ids mock_local_unit.return_value = '0' mock_relation_get.side_effect = mock_rel_get mock_related_units.return_value = ['1'] self.assertTrue(nutils.is_db_initialised())
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)
def test_is_db_initisalised_false(self, mock_related_units, mock_relation_ids, mock_relation_get, mock_local_unit): shared_db_rel_id = 'shared-db:1' mock_relation_ids.return_value = [shared_db_rel_id] settings = {'0': {}, '1': {}} def mock_rel_get(unit=None, rid=None, attribute=None): if not unit: unit = '0' if attribute: return settings[unit].get(attribute) return settings[unit] mock_local_unit.return_value = '0' mock_relation_get.side_effect = mock_rel_get mock_related_units.return_value = ['1'] mock_relation_ids.return_value = ['cluster:1'] self.assertFalse(nutils.is_db_initialised())
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 test_is_db_initisalised_false(self, mock_related_units, mock_relation_ids, mock_relation_get, mock_local_unit): shared_db_rel_id = 'shared-db:1' mock_relation_ids.return_value = [shared_db_rel_id] settings = {'0': {}, '1': {}} def mock_rel_get(unit=None, rid=None, attribute=None): if not unit: unit = '0' if attribute: return settings[unit].get(attribute) return settings[unit] mock_local_unit.return_value = '0' mock_relation_get.side_effect = mock_rel_get mock_related_units.return_value = ['1'] mock_relation_ids.return_value = ['cluster:1'] self.assertFalse(nutils.is_db_initialised())