mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-18 15:33:02 +00:00
add tests for db upgrade with mysql, postgres
This commit is contained in:
19
test-db-upgrade/docker-db.sh
Normal file
19
test-db-upgrade/docker-db.sh
Normal file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
NAME="hub-test-$DB"
|
||||
docker rm -f $NAME 2>/dev/null || true
|
||||
|
||||
case $DB in
|
||||
mysql)
|
||||
ARGS="-p 13306:3306 -e MYSQL_ROOT_PASSWORD=x -e MYSQL_DATABASE=jupyterhub mysql:5.7"
|
||||
;;
|
||||
postgres)
|
||||
ARGS="-p 15432:5432 -e POSTGRES_DB=jupyterhub postgres:9.5"
|
||||
;;
|
||||
*)
|
||||
echo "must be mysql or postgres"
|
||||
exit -1
|
||||
esac
|
||||
|
||||
set -x
|
||||
docker run --rm --name $NAME -d $ARGS
|
11
test-db-upgrade/jupyterhub_config.py
Normal file
11
test-db-upgrade/jupyterhub_config.py
Normal file
@@ -0,0 +1,11 @@
|
||||
import os
|
||||
c.JupyterHub.cookie_secret = os.urandom(32)
|
||||
|
||||
DB = os.environ.get('DB')
|
||||
if DB == 'mysql':
|
||||
c.JupyterHub.db_url = 'mysql+pymysql://root:x@127.0.0.1:13306/jupyterhub'
|
||||
elif DB == 'postgres':
|
||||
c.JupyterHub.db_url = 'postgresql://postgres@127.0.0.1:15432/jupyterhub'
|
||||
|
||||
c.JupyterHub.authenticator_class = 'jupyterhub.auth.Authenticator'
|
||||
c.Authenticator.whitelist = {'alpha', 'beta', 'gamma'}
|
4
test-db-upgrade/old-requirements.txt
Normal file
4
test-db-upgrade/old-requirements.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
jupyterhub-dummyauthenticator
|
||||
jupyterhub==0.7.2
|
||||
psycopg2
|
||||
pymysql
|
43
test-db-upgrade/test.sh
Normal file
43
test-db-upgrade/test.sh
Normal file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
TMPDIR=$(mktemp -d)
|
||||
ENVDIR="$TMPDIR/env"
|
||||
|
||||
# start mysql and postgres (do this first, so they have time to startup)
|
||||
for DB in postgres mysql; do
|
||||
export DB
|
||||
bash docker-db.sh
|
||||
done
|
||||
|
||||
# create virtualenv with jupyterhub 0.7
|
||||
echo "creating virutalenv in $ENVDIR"
|
||||
python -m virtualenv "$ENVDIR"
|
||||
$ENVDIR/bin/pip install -q -r old-requirements.txt
|
||||
|
||||
echo "env-jupyterhub: $($ENVDIR/bin/jupyterhub --version)"
|
||||
echo "jupyterhub-$(jupyterhub --version)"
|
||||
|
||||
set -x
|
||||
# launch jupyterhub-0.7 token entrypoint to ensure db is initialized
|
||||
for DB in sqlite postgres mysql; do
|
||||
export $DB
|
||||
echo -e "\n\n\nupgrade-db test: $DB"
|
||||
for i in {1..60}; do
|
||||
if "$ENVDIR/bin/jupyterhub" token alpha; then
|
||||
break
|
||||
else
|
||||
echo "waiting for $DB"
|
||||
sleep 2
|
||||
fi
|
||||
done
|
||||
|
||||
# run upgrade-db
|
||||
jupyterhub upgrade-db
|
||||
# generate a token, for basic exercise
|
||||
jupyterhub token beta
|
||||
|
||||
echo -e "\n\n$DB OK"
|
||||
done
|
||||
|
||||
docker rm -f hub-test-postgres hub-test-mysql
|
||||
rm -rf $ENVDIR
|
Reference in New Issue
Block a user