Browse Source

fix: dev: [odoo-tecnativa] factorize code to ``lib/common``

master
Valentin Lab 3 days ago
parent
commit
bc84fecf3e
  1. 32
      odoo-tecnativa/actions/load
  2. 18
      odoo-tecnativa/actions/save
  3. 37
      odoo-tecnativa/lib/common

32
odoo-tecnativa/actions/load

@ -71,38 +71,22 @@ if [ -z "$dbname" ]; then
} }
fi fi
. "$CHARM_PATH/lib/common"
set -e set -e
curl_opts=() curl_opts=()
## Ensure odoo is launched
service_def=$(get_compose_service_def "$SERVICE_NAME")
## XXXvlab: should be moved to lib
CONFIG=$SERVICE_CONFIGSTORE/etc/odoo-server.conf
ADMIN_PASSWORD=$(echo "$service_def" | shyaml -q get-value options.admin-password) || {
if [ -e "$CONFIG" ]; then
ADMIN_PASSWORD=$(grep ^admin_passwd "$CONFIG" | sed -r 's/^admin_passwd\s+=\s+(.+)$/\1/g')
fi
if [ -z "$ADMIN_PASSWORD" ]; then
err "Could not find 'admin-password' in $SERVICE_NAME service definition nor in config file."
exit 1
fi
}
containers="$(get_running_containers_for_service "$SERVICE_NAME")"
if [ -z "$containers" ]; then
err "No containers running for service $DARKYELLOW$SERVICE_NAME$NORMAL."
ADMIN_PASSWORD=$(odoo:get-admin-password) || {
err "Couldn't retrieve admin password for ${DARKYELLOW}$SERVICE_NAME${NORMAL}."
exit 1 exit 1
fi
}
if [ "$(echo "$containers" | wc -l)" -gt 1 ]; then
err "More than 1 container running for service $DARKYELLOW$SERVICE_NAME$NORMAL."
echo " Please contact administrator to fix this issue." >&2
container="$(get_running_container_for_service "$SERVICE_NAME")" || {
err "Couldn't find running container for service ${DARKYELLOW}$SERVICE_NAME${NORMAL}."
exit 1 exit 1
fi
}
container="$(echo "$containers" | head -n 1)"
odoo_version=$(docker exec "$container" python -c 'import odoo.release; print(odoo.release.version)') || { odoo_version=$(docker exec "$container" python -c 'import odoo.release; print(odoo.release.version)') || {
err "Failed to get odoo version." err "Failed to get odoo version."
exit 1 exit 1

18
odoo-tecnativa/actions/save

@ -63,21 +63,13 @@ if [ -z "$dbname" ]; then
} }
fi fi
set -e
. $CHARM_PATH/lib/common
## Ensure odoo is launched
service_def=$(get_compose_service_def "$SERVICE_NAME")
set -e
## XXXvlab: should be moved to lib
CONFIG=$SERVICE_CONFIGSTORE/etc/odoo-server.conf
ADMIN_PASSWORD=$(echo "$service_def" | shyaml -q get-value options.admin-password) || {
if [ -e "$CONFIG" ]; then
ADMIN_PASSWORD=$(grep ^admin_passwd "$CONFIG" | sed -r 's/^admin_passwd\s+=\s+(.+)$/\1/g')
fi
if [ -z "$ADMIN_PASSWORD" ]; then
err "Could not find 'admin-password' in $SERVICE_NAME service definition nor in config file."
exit 1
fi
ADMIN_PASSWORD=$(odoo:get-admin-password) || {
err "Couldn't retrieve admin password for $SERVICE_NAME."
exit 1
} }
container_network_ip=$(get_healthy_container_ip_for_service "$SERVICE_NAME" 8069 4) || { container_network_ip=$(get_healthy_container_ip_for_service "$SERVICE_NAME" 8069 4) || {

37
odoo-tecnativa/lib/common

@ -38,3 +38,40 @@ sql() {
ddb "${dbname:-$DBNAME}" ddb "${dbname:-$DBNAME}"
) )
} }
odoo:get-admin-password() {
local service_def config admin_password
service_def=$(get_compose_service_def "$SERVICE_NAME")
config=$SERVICE_CONFIGSTORE/etc/odoo-server.conf
admin_password=$(echo "$service_def" | shyaml -q get-value options.admin-password) || {
if [ -e "$config" ]; then
admin_password=$(grep ^admin_passwd "$config" | sed -r 's/^admin_passwd\s+=\s+(.+)$/\1/g')
fi
if [ -z "$admin_password" ]; then
err "Could not find 'admin-password' in $SERVICE_NAME service definition nor in config file."
return 1
fi
}
echo "$admin_password"
}
## XXXvlab: to include in `compose-core`
get_running_container_for_service() {
local containers service="$1"
containers=($(get_running_containers_for_service "$service"))
if [ "${#containers[@]}" == 0 ]; then
err "No containers running for service $DARKYELLOW$service$NORMAL."
return 1
fi
if [ "${#containers[@]}" -gt 1 ]; then
err "More than 1 container running for service $DARKYELLOW$service$NORMAL."
echo " Please contact administrator to fix this issue." >&2
return 1
fi
echo "${containers[0]}"
}
Loading…
Cancel
Save