3 . `dirname "$(readlink -f "$0")"`/run-library.sh
5 read -rd "\000" helpmessage <<EOF
6 $(basename $0): Test Arvados SSO package
9 WORKSPACE=/path/to/arvados-sso $(basename $0) [options]
14 Output debug information (default: false)
16 Distribution to build packages for (default: debian7)
18 WORKSPACE=path Path to the Arvados SSO source tree
23 DEBUG=${ARVADOS_DEBUG:-0}
24 BUILD_BUNDLE_PACKAGES=0
28 if [[ ! -e "$SUDO" ]]; then
32 PARSEDOPTS=$(getopt --name "$0" --longoptions \
33 help,build-bundle-packages,debug,target: \
39 eval set -- "$PARSEDOPTS"
40 while [ $# -gt 0 ]; do
43 echo >&2 "$helpmessage"
53 --build-bundle-packages)
54 BUILD_BUNDLE_PACKAGES=1
58 echo >&2 "$0: unrecognized argument '$2'. Try: $0 --help"
66 STDOUT_IF_DEBUG=/dev/null
67 STDERR_IF_DEBUG=/dev/null
69 if [[ "$DEBUG" != 0 ]]; then
70 STDOUT_IF_DEBUG=/dev/stdout
71 STDERR_IF_DEBUG=/dev/stderr
92 echo -e "$0: Unknown target '$TARGET'.\n" >&2
97 if ! [[ -n "$WORKSPACE" ]]; then
98 echo >&2 "$helpmessage"
100 echo >&2 "Error: WORKSPACE environment variable not set"
105 if ! [[ -d "$WORKSPACE" ]]; then
106 echo >&2 "$helpmessage"
108 echo >&2 "Error: $WORKSPACE is not a directory"
114 txt="********** $1 **********"
115 printf "\n%*s%s\n\n" $((($COLUMNS-${#txt})/2)) "" "$txt"
119 if [[ "$1" != "0" ]]; then
120 title "!!!!!! $2 FAILED !!!!!!"
125 # Find the SSO server package
129 SSO_VERSION=$(version_from_git)
130 PACKAGE_NAME=arvados-sso-server
132 if [[ "$FORMAT" == "deb" ]]; then
133 PACKAGE_PATH=$WORKSPACE/packages/$TARGET/${PACKAGE_NAME}_${SSO_VERSION}_amd64.deb
134 elif [[ "$FORMAT" == "rpm" ]]; then
135 PACKAGE_PATH=$WORKSPACE/packages/$TARGET/${PACKAGE_NAME}-${SSO_VERSION}-1.x86_64.rpm
138 # Test 1a: the package to test must exist
139 if [[ ! -f $PACKAGE_PATH ]]; then
140 echo "Latest package not found at $PACKAGE_PATH. Please build the package first."
144 if [[ "$FORMAT" == "deb" ]]; then
145 # Test 1b: the system/container where we're running the tests must be clean
147 dpkg -l |grep $PACKAGE_NAME -q
148 if [[ "$?" != "1" ]]; then
149 echo "Please make sure the $PACKAGE_NAME package is not installed before running this script"
155 if [[ -e "/var/www/arvados-sso" ]]; then
156 echo "Please make sure /var/www/arvados-sso does not exist before running this script"
160 # Prepare the machine
161 if [[ "$FORMAT" == "deb" ]]; then
163 elif [[ "$FORMAT" == "rpm" ]]; then
164 $SUDO yum check-update
166 $SUDO mkdir -p /etc/arvados/sso
168 if [[ ! -e "/etc/arvados/sso/application.yml" ]]; then
169 RANDOM_PASSWORD=`date | md5sum |cut -f1 -d' '`
170 cp config/application.yml.example /etc/arvados/sso/application.yml
171 sed -i -e 's/uuid_prefix: ~/uuid_prefix: zzzzz/' /etc/arvados/sso/application.yml
172 sed -i -e "s/secret_token: ~/secret_token: $RANDOM_PASSWORD/" /etc/arvados/sso/application.yml
175 if [[ ! -e "/etc/arvados/sso/database.yml" ]]; then
176 # We haven't installed our dependencies yet, but we need to set up our
177 # database configuration now. Install postgresql if need be.
178 if [[ "$FORMAT" == "deb" ]]; then
179 install_package postgresql
180 elif [[ "$FORMAT" == "rpm" ]]; then
181 install_package postgresql-server
182 # postgres packaging on CentOS6 is kind of primitive, needs an initdb
183 $SUDO service postgresql initdb
184 if [ "$TARGET" = "centos6" ]; then
185 sed -i -e "s/127.0.0.1\/32 ident/127.0.0.1\/32 md5/" /var/lib/pgsql/data/pg_hba.conf
186 sed -i -e "s/::1\/128 ident/::1\/128 md5/" /var/lib/pgsql/data/pg_hba.conf
189 $SUDO service postgresql start
191 RANDOM_PASSWORD=`date | md5sum |cut -f1 -d' '`
192 cat >/etc/arvados/sso/database.yml <<EOF
196 database: sso_provider_production
197 username: sso_provider_user
198 password: $RANDOM_PASSWORD
201 if [[ "$SUDO" != '' ]]; then
202 $SUDO -u postgres psql -c "CREATE USER sso_provider_user WITH PASSWORD '$RANDOM_PASSWORD'"
203 $SUDO -u postgres createdb sso_provider_production -O sso_provider_user
206 if [ "$TARGET" = "centos6" ]; then
207 # Work around silly CentOS6 default, cf. https://bugzilla.redhat.com/show_bug.cgi?id=1020147
208 sed -i -e 's/Defaults requiretty/#Defaults requiretty/' /etc/sudoers
210 /usr/bin/sudo -u postgres psql -c "CREATE USER sso_provider_user WITH PASSWORD '$RANDOM_PASSWORD'"
211 /usr/bin/sudo -u postgres createdb sso_provider_production -O sso_provider_user
215 if [[ "$FORMAT" == "deb" ]]; then
216 # Test 2: the package should install cleanly
217 # In order to get the package dependencies, we need to first do an install
218 # with dpkg that will fail, then run apt-get to install the dependencies,
219 # and the subsequent dpkg installation should succeed.
221 $SUDO dpkg -i $PACKAGE_PATH > /dev/null 2>&1
222 $SUDO apt-get -f install --yes
224 $SUDO dpkg -i $PACKAGE_PATH || EXITCODE=2
226 checkexit $EXITCODE "dpkg -i $PACKAGE_PATH"
228 # Test 3: the package should remove cleanly
229 $SUDO apt-get remove $PACKAGE_NAME --yes || EXITCODE=3
231 checkexit $EXITCODE "apt-get remove $PACKAGE_PATH --yes"
233 # Test 4: the package configuration should remove cleanly
234 $SUDO dpkg --purge $PACKAGE_NAME || EXITCODE=4
236 checkexit $EXITCODE "dpkg --purge $PACKAGE_PATH"
238 if [[ -e "/var/www/arvados-sso" ]]; then
242 checkexit $EXITCODE "leftover items under /var/www/arvados-sso"
244 # Test 5: the package should remove cleanly with --purge
245 $SUDO dpkg -i $PACKAGE_PATH || EXITCODE=5
247 checkexit $EXITCODE "dpkg -i $PACKAGE_PATH"
249 $SUDO apt-get remove $PACKAGE_NAME --purge --yes || EXITCODE=5
251 checkexit $EXITCODE "apt-get remove $PACKAGE_PATH --purge --yes"
253 if [[ -e "/var/www/arvados-sso" ]]; then
257 checkexit $EXITCODE "leftover items under /var/www/arvados-sso"
259 elif [[ "$FORMAT" == "rpm" ]]; then
262 # (courtesy of https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/ownserver/nginx/oss/el6/install_passenger.html)
263 $SUDO yum install -q -y epel-release pygpgme curl
264 $SUDO curl --fail -sSLo /etc/yum.repos.d/passenger.repo https://oss-binaries.phusionpassenger.com/yum/definitions/el-passenger.repo
265 $SUDO yum install -q -y nginx passenger
266 $SUDO sed -i -e 's/^# passenger/passenger/' /etc/nginx/conf.d/passenger.conf
267 # Done setting up Nginx
269 # Test 2: the package should install cleanly
270 $SUDO yum -q -y --nogpgcheck localinstall $PACKAGE_PATH || EXITCODE=3
272 checkexit $EXITCODE "yum -q -y --nogpgcheck localinstall $PACKAGE_PATH"
274 # Test 3: the package should remove cleanly
275 $SUDO yum -q -y remove $PACKAGE_NAME || EXITCODE=3
277 checkexit $EXITCODE "yum -q -y remove $PACKAGE_PATH"
279 if [[ -e "/var/www/arvados-sso" ]]; then
283 checkexit $EXITCODE "leftover items under /var/www/arvados-sso"
287 if [[ "$EXITCODE" == "0" ]]; then
288 echo "Testing complete, no errors!"
290 echo "Errors while testing!"