Newer
Older

Vincent Hatakeyama
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/zsh
# vim: set shiftwidth=4 softtabstop=4:
#
# This script will create a database, install some modules and run tests on it
#
# Arguments:
#
# - db host if any (will use socket if nothing is provided)
# - db user
# - other arguments are forwarded as is to the setup command.
#
# Required:
#
# - access to pg database
#
# Version 20.2.0
here=$(dirname $0)
source $here/common
# this is the same value as conf/drone/odoo.conf
if [[ -e "${project_home}/conf/drone/odoo.conf" ]];
then
echo "$DEBUG Reading configuration from ${project_home}/conf/drone/odoo.conf"
dbowner=$(read_configuration_key ${project_home}/conf/drone/odoo.conf options db_user)
unaccent=$(read_configuration_key ${project_home}/conf/drone/odoo.conf options unaccent False)
# this is the same value as conf/dev/odoo.conf
elif [[ -e "${project_home}/conf/dev/odoo.conf" ]];
then
echo "$DEBUG Reading configuration from ${project_home}/conf/dev/odoo.conf"
dbowner=$(read_configuration_key ${project_home}/conf/dev/odoo.conf options db_user)
unaccent=$(read_configuration_key ${project_home}/conf/dev/odoo.conf options unaccent False)
else
echo "$DEBUG Use default owner and unaccent"
dbowner=odoo
unaccent=False
fi
echo "$DEBUG Looking for modules to install"
module_list=${ODOO_SCRIPTS_MODULE_LIST-$(read_odoo_scripts_expandable_configuration_key module_list)}
modules_to_tests=${ODOO_SCRIPTS_MODULE_LIST_TESTS-$(read_odoo_scripts_expandable_configuration_key module_list_tests)}
# Install modules that will not be tested
modules_to_install=$($python -B -c "print(','.join(set('$module_list'.split(','))-set('$modules_to_tests'.split(','))))")
echo "$DEBUG module_list=$module_list"
echo "$DEBUG module_to_install=$modules_to_install"
echo "$DEBUG module_list_tests=$modules_to_tests"
if [[ -z "$modules_to_tests" ]];
then
echo "$INFO No module to tests"
exit 0
fi
echo "$DEBUG Looking value of fail_on_errors"
fail_on_errors=${ODOO_SCRIPTS_FAIL_ON_ERRORS-$(read_odoo_scripts_configuration_key fail_on_errors True)}
echo "$DEBUG fail_on_errors=$fail_on_errors"
# argument handling
if [[ $# -gt 0 ]];
then
echo "$INFO Using database host $1"
PG_HOST=-h$1
ODOO_HOST=--db_host=$1
shift
if [[ $# -gt 0 ]];
then
echo "$INFO Using database user $1"
PG_USER=-U$1
ODOO_USER=--db_user=$1
dbowner=$1
shift
if [[ $# -gt 0 ]];
then
dbname=$1
shift
else
dbname=$(basename $project_home)_test
fi
else
PG_USER=""
ODOO_USER=""
fi
else
echo "$DEBUG No argument provided"
PG_HOST=""
ODOO_HOST=""
PG_USER=""
ODOO_USER=""
fi
# This should be a parameter if it was simple to parse
INSTALL_ARGUMENTS="--log-level=${INSTALL_LOG_LEVEL:-warn}"
if [[ -n "$ODOO_WITHOUT_DEMO" ]];
then
INSTALL_ARGUMENTS="$INSTALL_ARGUMENTS --without-demo=$ODOO_WITHOUT_DEMO"
fi
if [[ -z "$ODOO_NO_DROP" ]];
then
echo "$INFO Drop any existing database '$dbname'"
dropdb $PG_HOST $PG_USER --if-exists $dbname --no-password
echo "$INFO Create database '$dbname' with owner $dbowner"
createdb $PG_HOST $PG_USER -O $dbowner $dbname --no-password || { echo "$FATAL Cannot create test database" ; exit 1; }
fi
# Add extensions
typeset -a extensions
if [[ "$unaccent" == "True" ]];
then
extensions+=unaccent
fi
extensions+=($(read_odoo_scripts_configuration_key pg.extensions))
for extension in $extensions; do
echo "$INFO Create extension $extension in '$dbname'"
psql $PG_HOST $PG_USER $dbname -c "CREATE EXTENSION IF NOT EXISTS $extension;"
done
echo "$INFO Modules to install: $modules_to_install"
echo "$INFO Install those modules"
logfile=$(tempfile --suffix=.log)
function clean_logfile() {
rm $logfile
}
trap clean_logfile INT TERM
$here/start $INSTALL_ARGUMENTS -i $modules_to_install -d $dbname --max-cron-threads=0 --stop-after-init $* $ODOO_HOST $ODOO_USER 2>&1 | tee $logfile | sed -e 's/\(.*\) \(INFO\) \(.*\)/\o033[2m\1\o033[22m \o033[32m\o033[7m\2\o033[27m \3\o033[39m/' -e 's/\(.*\) \(DEBUG\) \(.*\)/\o033[2m\1\o033[22m \o033[33m\o033[7m\2\o033[27m \2\o033[39m/' -e 's/\(.*\) \(WARNING\) \(.*\)/\o033[2m\1\o033[22m \o033[33m\o033[7m\2\o033[27m \3\o033[39m/' -e 's/\(.*\) \(ERROR\) \(.*\)/\o033[2m\1\o033[22m \o033[31m\o033[7m\2\o033[27m \3\o033[0m/' -e 's/ FAILED/ \o033[41m\o033[97m\o033[1mFAILED\o033[0m/' -e 's/ FAIL\(.*\)/ \o033[41m\o033[97m\o033[1mFAIL\o033[49m\o033[31m\1\o033[0m/' -e 's/\(.*\) \(CRITICAL\) \(.*\)/\o033[2m\1\o033[22m \o033[33m\o033[7m\2\o033[27m \3\o033[39m/' -e 's/\(.*\) \(TEST\) \(.*\) \(ERROR\)\(.*\)/\o033[2m\1\o033[22m \o033[34m\o033[7m\2\o033[27m \3\o033[0m \o033[41m\o033[97m\o033[1m\4\o033[49m\o033[31m\5\o033[0m/' -e 's/\(.*\) \(TEST\) \(.*\) \(OK\)/\o033[2m\1\o033[22m \o033[34m\o033[7m\2\o033[27m \3\o033[0m \o033[32m\o033[7m\4\o033[27m\o033[39m/' -e 's/\(.*\) \(TEST\) \(.*\)/\o033[2m\1\o033[22m \o033[34m\o033[7m\2\o033[27m \3 \o033[0m/'
start_status=$pipestatus[1]
if [[ $start_status -ne 0 ]];
then
echo "$KO Cannot install modules (exit ${start_status})"
exit $start_status
fi
criticals=$(grep ' CRITICAL' -F $logfile -c)
# exclude ALTER COLUMN xxx set not null that are not real errors
errors=$(grep ' ERROR' -F $logfile | grep -E -v "(ALTER COLUMN \"\w*\" SET NOT NULL|unable to set NOT NULL on column)" -c)
warnings=$(grep ' WARNING' -F $logfile -c)
if [[ $criticals -gt 0 ]];
then
echo "$KO Cannot install modules ($criticals CRITICAL messages found)"
exit 2
fi
if [[ $errors -gt 0 ]];
then
if [[ "$fail_on_errors" == "False" ]];
then
echo "$WARN Install modules with $errors ERROR messages"
else
echo "$KO Cannot install modules ($errors ERROR messages found)"
exit 1
fi
else
if [[ $warnings -gt 0 ]];
then
if [[ "${FAIL_ON_WARNING:-False}" == "False" ]];
then
echo "$WARN Modules installed ($warnings WARNING messages)"
else
echo "$KO Cannot install modules ($warnings WARNING messages found)"
exit 1
fi
else
echo "$OK Modules installed"
fi
fi
echo "$INFO Run tests on $dbname"
$here/run_tests $dbname $ODOO_HOST $ODOO_USER $*