Browse Source

chg: [odoo-tecnativa] make drop more reliable and use manual drop if necessary

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
pull/19/head 1.5.14
Valentin Lab 3 years ago
parent
commit
86357dfc69
  1. 72
      odoo-tecnativa/actions/drop

72
odoo-tecnativa/actions/drop

@ -54,6 +54,35 @@ while [ "$1" ]; do
done done
db_drop() {
local dbname="$1"
(
switch_to_relation_service postgres-database
set +e
. lib/common
set -e
ensure_db_docker_running || exit 1
if db_has_database "$dbname"; then
info "Found a postgres database '$dbname' and deleting it."
PGM rm -f "$dbname" || exit 1
else
info "No postgres database '$dbname' found."
fi
) || exit 1
if [ -d "$SERVICE_DATASTORE"/var/lib/odoo/filestore/"$dbname" ]; then
rm -rf "$SERVICE_DATASTORE"/var/lib/odoo/filestore/"$dbname" >&2 || exit 1
info "Deleted filestore for database '$dbname'."
else
info "No filestore for database '$dbname' found."
fi
}
if [ -z "$dbname" ]; then if [ -z "$dbname" ]; then
## ##
@ -118,21 +147,44 @@ cmd=(
http://${container_ip}:8069/web/database/drop http://${container_ip}:8069/web/database/drop
) )
## XXXvlab: contains password, left only for advanced debug ## XXXvlab: contains password, left only for advanced debug
#debug "${cmd[@]}"
#echo "${cmd[@]}" >&2
out=$("${cmd[@]}") || { out=$("${cmd[@]}") || {
die "Posting to odoo drop API through curl was unsuccessfull."
errlvl="$?"
if [ "$errlvl" == "28" ]; then
## Curl timeout
warn "Standard method through curl timed out. Trying manual drop of database."
db_drop "$dbname" || exit 1
exit 0
else
die "Posting to odoo drop API through curl was unsuccessfull ($errlvl)."
fi
} }
if [[ "$out" == *"<html>"* ]]; then if [[ "$out" == *"<html>"* ]]; then
errmsg=$(echo "$out" | grep "alert-danger")
errmsg=${errmsg#*>}
errmsg=${errmsg%%<*}
if [ "$errmsg" ]; then
errmsg=$(echo "$out" | grep -m1 "alert-danger") ||
errmsg=$(echo "$out" | grep -m1 "errormsg") ||
errmsg=$(echo "$out" | grep -m1 "<title>")
errmsg="${errmsg#*>}"
errmsg="${errmsg%%<*}"
if [ -n "$errmsg" ]; then
errmsg=$(echo "$errmsg" | recode html..utf8) errmsg=$(echo "$errmsg" | recode html..utf8)
die "$errmsg"
if [[ "$errmsg" == "psycopg2.OperationalError: FATAL: database \"$dbname\" does not exist" ]]; then
warn "Received error we can probably ignore."
elif [[ "$errmsg" == "KeyError: 'ir.http'" ]] ||
[[ "$errmsg" == \
"psycopg2.ProgrammingError: relation \"base_registry_signaling\" already exists" ]]; then
## Hooks must have created an empty database, messing up things
warn "Standard method failed as if postgres db was empty but existing."
echo " Trying manual drop of database.." >&2
db_drop "$dbname" || exit 1 ## Let's do it the legacy way !
else
die "$errmsg"
fi
else
die "Unexpected output. Drop probably failed."
fi fi
die "Unexpected output. Drop probably failed."
else
info "Dropped odoo database '$dbname'."
fi >&2 fi >&2
info "Dropped odoo database '$dbname'."
Loading…
Cancel
Save