Update scripts

* Move the OVN resync stuff to functions.sh, so that it can be used elsewhere
* Add check mongo python script
This commit is contained in:
Arif Ali 2024-11-07 12:09:27 +00:00
parent 578e41e351
commit 2476319877
Signed by: arif
GPG Key ID: 369608FBA1353A70
5 changed files with 128 additions and 65 deletions

47
check_mongo.py Executable file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env python3
from pymongo import MongoClient
import yaml
import os
import sys
host = "localhost"
port = "37017"
def _import_yaml():
global password, username
agent_dir = "/var/lib/juju/agents"
entries = os.listdir(agent_dir)
for file_name in entries:
if "machine" in file_name:
machine = file_name
break
with open(f'{agent_dir}/{machine}/agent.conf', 'r') as stream:
agent = yaml.safe_load(stream)
password = agent['statepassword']
username = agent['tag']
def main():
_import_yaml()
client = MongoClient(f"{host}:{port}",
username=username,
password=password,
authSource='admin',
tls=True,
tlsAllowInvalidCertificates=True,
)
rep_status = client.admin.command('replSetGetStatus')
for member in rep_status['members']:
print(f"Host: {member['name'].split(':')[0]}, State: {member['stateStr']}")
if __name__ == '__main__':
sys.exit(main())

12
check_mongo_status_py.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash
machine=${1:-0}
model=${2:-controller}
read -d '' -r cmds <<'EOF'
sudo apt -y install python3-pymongo > /dev/null 2>&1
sudo python3 /home/ubuntu/check_mongo.py
EOF
juju scp -m ${model} check_mongo.py ${machine}:.
juju ssh -m ${model} ${machine} "${cmds}"

View File

@ -1,18 +1,21 @@
#!/bin/sh
#!/bin/bash
if [ $# -ne 2 ]; then
echo "Usage: $0 unit/N relation-name (e.g. $0 ceph-mon/0 client)"
exit 1
fi
relation_ids=$(juju run --unit $1 -- relation-ids $2)
source functions.sh
check_juju_version
relation_ids=$(${juju_run} -u $1 -- relation-ids $2)
echo $relation_ids
for relation_id in $relation_ids; do
units=$(juju run --unit $1 -- relation-list -r $relation_id)
units=$(${juju_run} -u $1 -- relation-list -r $relation_id)
for unit in $units; do
echo -----
echo from $1 get $relation_id $unit
juju run --unit $1 -- relation-get -r $relation_id - $unit
${juju_run} -u $1 -- relation-get -r $relation_id - $unit
done &
done

View File

@ -1,68 +1,9 @@
#!/bin/bash
set -ax
#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
do_ovn_resync

View File

@ -216,3 +216,63 @@ do_percona_cluster()
${juju_run} -a nova-cloud-controller -- sudo systemctl restart nova-api-os-compute nova-conductor nova-consoleauth &
}
do_ovn_resync()
{
ovn_app=$(jq -rc ".applications | to_entries[] | select(.value[\"charm-name\"] == \"ovn-central\") | .key" "${juju_status_out}")
ovn_ips=$(jq -r '.applications.${ovn_app}.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_app}.units | keys[]' "${juju_status_out}")
ovn_lead=$(get_lead "${ovn_app}")
ovn_lead_ip=$(jq -r '.applications.${ovn_app}.units."'${ovn_lead}'"."public-address"' "${juju_status_out}")
for unit in $ovn_names
do
${juju_run_action} $unit pause
done
${juju_run} -a ovn-central -- mv /var/lib/ovn/ovnnb_db.db /var/lib/ovn/ovnnb_db.db.old -v
${juju_run} -a ovn-central -- 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} -- 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
}