useful_scripts/fix_ovn_dbs.sh

69 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
set -ax
. functions.sh
check_juju_version
get_juju_status
ovn_ips=$(jq -r '.applications."ovn-central".units | to_entries[].value."public-address"' "${juju_status_out}")
neutron_ips=$(jq -r '.applications."neutron-api".units | to_entries[].value."public-address"' "${juju_status_out}")
ovn_names=$(jq -r '.applications."ovn-central".units | keys[]' "${juju_status_out}")
ovn_lead=$(echo $ovn_names | awk '{print $1}')
ovn_lead_ip=$(jq -r '.applications."ovn-central".units."'${ovn_lead}'"."public-address"' "${juju_status_out}")
for unit in $ovn_names
do
${juju_run_action} $unit pause
done
${juju_run} -u ${ovn_lead} -- mv /var/lib/ovn/ovnnb_db.db /var/lib/ovn/ovnnb_db.db.old -v
${juju_run} -u ${ovn_lead} -- mv /var/lib/ovn/ovnsb_db.db /var/lib/ovn/ovnsb_db.db.old -v
${juju_run} -u ${ovn_lead} -- rm -rf /tmp/standalone_ovnnb_db.db
${juju_run} -u ${ovn_lead} -- rm -rf /tmp/standalone_ovnsb_db.db
${juju_run} -u ${ovn_lead} -- ovsdb-tool create /tmp/standalone_ovnnb_db.db /usr/share/ovn/ovn-nb.ovsschema
${juju_run} -u ${ovn_lead} -- ovsdb-tool create /tmp/standalone_ovnsb_db.db /usr/share/ovn/ovn-sb.ovsschema
${juju_run} -u ${ovn_lead} -- ovsdb-tool create-cluster /var/lib/ovn/ovnnb_db.db /tmp/standalone_ovnnb_db.db ssl:${ovn_lead_ip}:6643
${juju_run} -u ${ovn_lead} -- ovsdb-tool create-cluster /var/lib/ovn/ovnsb_db.db /tmp/standalone_ovnsb_db.db ssl:${ovn_lead_ip}:6644
${juju_run_action} ${ovn_lead} resume
ovn_nb_uuid=$(${juju_run} -u ${ovn_lead} -- "ovn-appctl -t /var/run/ovn/ovnnb_db.ctl cluster/status OVN_Northbound | grep ^Cluster | awk '{print \$4}' | sed -e s/\(//g -e s/\)//g")
ovn_sb_uuid=$(${juju_run} -u ${ovn_lead} -- "ovn-appctl -t /var/run/ovn/ovnsb_db.ctl cluster/status OVN_Southbound | grep ^Cluster | awk '{print \$4}' | sed -e s/\(//g -e s/\)//g")
ovn_hosts_nb="ssl:${ovn_lead_ip}:6643"
ovn_hosts_sb="ssl:${ovn_lead_ip}:6644"
for unit in $ovn_names
do
[[ "$unit" == "$ovn_lead" ]] && continue
ovn_unit_ip=$(jq -r '.applications."ovn-central".units."'${unit}'"."public-address"' "${juju_status_out}")
ovn_hosts_nb="ssl:${ovn_unit_ip}:6643 ${ovn_hosts_nb}"
ovn_hosts_sb="ssl:${ovn_unit_ip}:6644 ${ovn_hosts_sb}"
${juju_run} -u ${unit} -- mv /var/lib/ovn/ovnnb_db.db /var/lib/ovn/ovnnb_db.db.old -v
${juju_run} -u ${unit} -- mv /var/lib/ovn/ovnsb_db.db /var/lib/ovn/ovnsb_db.db.old -v
${juju_run} -u ${unit} -- ovsdb-tool --cid=${ovn_nb_uuid} join-cluster /var/lib/ovn/ovnnb_db.db OVN_Northbound ${ovn_hosts_nb}
${juju_run} -u ${unit} -- ovsdb-tool --cid=${ovn_sb_uuid} join-cluster /var/lib/ovn/ovnsb_db.db OVN_Southbound ${ovn_hosts_sb}
${juju_run_action} $unit resume
done
${juju_run} -a ovn-central -- hooks/update-status
${juju_run} -a ovn-central -- hooks/config-changed
${juju_run} -u neutron-api/leader -- cp -v /etc/neutron/neutron.conf /etc/neutron/neutron.conf.copy
${juju_run} -u neutron-api/leader -- sed -i "s@auth_section = .*@#auth_section = keystone_authtoken@g" /etc/neutron/neutron.conf.copy
${juju_run} -u neutron-api/leader -- neutron-ovn-db-sync-util --config-file /etc/neutron/neutron.conf.copy --config-file /etc/neutron/plugins/ml2/ml2_conf.ini --ovn-neutron_sync_mode repair
${juju_run} -u neutron-api/leader -- rm -v /etc/neutron/neutron.conf.copy
${juju_run} -a ovn-chassis -- sudo systemctl restart ovn-controller
${juju_run} -a neutron-api -- sudo systemctl restart neutron-api