-
Notifications
You must be signed in to change notification settings - Fork 41
/
after_run_setup.sh
executable file
·174 lines (153 loc) · 4.93 KB
/
after_run_setup.sh
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
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
#
# Prepares the next test run after finished running the before_run_setup.sh script.
# * Restores database
# * Restores dataroot
# * Upgrades moodle if necessary
#
# Auto-restore feature only available for postgres and mysql.
#
# Usage: cd /path/to/moodle-performance-comparison && ./after_run_setup.sh
#
# No arguments
#
##############################################
# Exit on errors.
set -e
# Dependencies.
. ./lib/lib.sh
# We need the paths.
if [ ! -z "$1" ]; then
output="Usage: `basename $0`
Prepares the next test run after finished running the before_run_setup.sh script.
* Restores database
* Restores dataroot
* Upgrades moodle if necessary
"
echo "$output" >&2
exit 1
fi
# Checking as much as we can that before_run_setup.sh was
# already executed and finished successfully.
errormsg="Error: Did you run before_run_test.sh before running this one? "
if [ ! -e "test_files.properties" ]; then
echo $errormsg >&2
exit 1
fi
if [ ! -d "moodle" ]; then
echo $errormsg >&2
exit 1
fi
if [ ! -d "moodle/.git" ]; then
echo $errormsg >&2
exit 1
fi
# Get user info.
load_properties "defaults.properties"
load_properties "webserver_config.properties"
# Checks the $cmds.
check_cmds
# Get generated test plan values.
load_properties "test_files.properties"
# Move to the moodle directory.
cd moodle
# Remove current dataroot and restore the provided one (Better using chown...).
if [ ! -d "$dataroot" ] || [ -z "$dataroot" ]; then
echo "Error: Armageddon prevented just 2 lines of code above a rm -rf.
Please, assign a value to \$dataroot var in webserver_config.properties" >&2
exit 1
fi
delete_files $dataroot 1
cp -r $datarootbackup $dataroot || \
throw_error "$datarootbackup can not be copied to $dataroot"
chmod -R 777 $dataroot
# Drop and restore the database.
if [ "$dbtype" == "pgsql" ]; then
echo "#######################################################################"
echo "Restoring database and dataroot to Moodle ($basecommit)"
export PGPASSWORD=${dbpass}
# Checking that the table exists.
databaseexists="$( ${pgsqlcmd} -h "$dbhost" -U "$dbuser" -l | \
grep "$dbname" | \
wc -l )"
if [ "$databaseexists" != "0" ]; then
${pgsqlcmd} \
-h "$dbhost" \
-U "$dbuser" \
-d template1 \
-c "DROP DATABASE $dbname" \
--quiet
fi
${pgsqlcmd} \
-h "$dbhost" \
-U "$dbuser" \
-d template1 \
-c "CREATE DATABASE $dbname WITH OWNER $dbuser ENCODING 'UTF8'" --quiet
${pgsqlcmd} \
--quiet \
-h "$dbhost" \
-U "$dbuser" \
$dbname < $databasebackup > /dev/null
elif [ "$dbtype" == "mysqli" ]; then
echo "#######################################################################"
echo "Restoring database and dataroot to Moodle ($basecommit)"
# Checking that the table exists.
databaseexists="$( ${mysqlcmd} \
--host=${dbhost} \
--user=${dbuser} \
--password=${dbpass} \
-e "SHOW DATABASES LIKE '$dbname'" )"
if [ ! -z "$databaseexists" ];then
${mysqlcmd} \
--host=${dbhost} \
--user=${dbuser} \
--password=${dbpass} \
-e "DROP DATABASE $dbname" \
--silent
fi
${mysqlcmd} \
--host=${dbhost} \
--user=${dbuser} \
--password=${dbpass} \
-e "CREATE DATABASE $dbname DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci" \
--silent
${mysqlcmd} \
--silent \
--host=${dbhost} \
--user=${dbuser} \
--password=${dbpass} \
$dbname < $databasebackup > /dev/null
else
confirmoutput="Only postgres and mysql support: You need to manually restore your database.
Press [q] to stop the script or, if you have already done it, any other key to continue.
"
echo "$confirmoutput"
read confirmation
if [ "$confirmation" == "q" ]; then
exit 1
fi
fi
# Upgrading moodle, although we are not sure that before and after branches are different.
echo "Checking out Moodle from repo: $afterbranchrepository, ref: $afterbranch"
checkout_branch $afterbranchrepository 'after' $afterbranch
echo "Upgrading Moodle ($basecommit) to $(git rev-parse after/$afterbranch)"
${phpcmd} admin/cli/upgrade.php --non-interactive --allow-unstable > /dev/null || \
throw_error "Moodle can not be upgraded to $afterbranch"
# Stores the site data in an jmeter-accessible file.
save_moodle_site_data
# Returning to the root.
cd ..
# Info, all went as expected and we are all happy.
outputinfo="
#######################################################################
'After' run setup finished successfully.
Now you can:
- Change the site configuration
- Change the cache stores
And to continue with the test you should:
- Run restart_services.sh (or manually restart web and database servers
if this script doesn\'t suit your system)
- Run test_runner.sh
"
echo "$outputinfo"
exit 0