Skip to content
Snippets Groups Projects
Commit 87d3fac5 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

SW-415: use dbcredentials and envvar LSMR_DBCREDENTIALS to fire up a test django postgres server

parent 9cacedcb
No related branches found
No related tags found
1 merge request!87Lsmr epic
...@@ -18,13 +18,28 @@ ...@@ -18,13 +18,28 @@
# with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>. # with the LOFAR software suite. If not, see <http://www.gnu.org/licenses/>.
# Script to run a temporary postgres instance for easy functional testing # Script to create, setup, and run a temporary postgres instance for easy functional testing
echo "---" #defaults
echo "! This is for testing only! Database is not persistent!" CREDENTIALS="lsmr_test"
echo "---"
# Parse args:
while getopts "C:h" opt; do
case ${opt} in
C ) CREDENTIALS=${OPTARG} ;;
h ) echo "usage: lsmr_testdatabase [OPTIONS]"
echo " where options are:"
echo " -C <credentials-name> the name of the credentials in ~/.lofar/dbcredentials. default=$CREDENTIALS"
exit 0
;;
esac
done
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" echo "!!! This is for testing only! Database is not persistent !!!"
echo "Using credentials=$CREDENTIALS"
# the lsmr django settings module reads this environment variable when available to determine the used database.
export LSMR_DBCREDENTIALS=$CREDENTIALS
/usr/bin/env python3 ${LOFARROOT}/../SAS/LSMR/test/postgres_testrunner.py DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
\ No newline at end of file /usr/bin/env python3 $DIR/../lib*/python*/site-packages/lofar/sas/lsmr/test/postgres_testrunner.py
...@@ -20,4 +20,6 @@ set(_py_files ...@@ -20,4 +20,6 @@ set(_py_files
__init__.py __init__.py
postgres_testrunner.py postgres_testrunner.py
) )
file(COPY ${_py_files} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) python_install(${_py_files}
\ No newline at end of file DESTINATION lofar/sas/lsmr/test)
...@@ -105,14 +105,21 @@ class PostgresqlTestRunner(DiscoverRunner): ...@@ -105,14 +105,21 @@ class PostgresqlTestRunner(DiscoverRunner):
if __name__ == "__main__": if __name__ == "__main__":
""" """
Start Django test database and keep it alive until interrupted Start Django test database and keep it alive until interrupted.
It will use the database credentials found in ~/.lofar/dbcredentials
for the name found in environment variable LSMR_DBCREDENTIALS, or 'lsmr' if the env var is not set.
See also settings.py and the lsmr_testdatabase script for usage.
""" """
pg = create_test_Postgres_from_django_settings() pg = create_test_Postgres_from_django_settings()
name = DATABASES['default']['NAME'] create_project_db(pg, DATABASES['default']['NAME'])
create_project_db(pg, name)
print("Started Postgres server for lsmr django: dbname=%s user=%s host=%s port=%s PID=%s" % (
print("Started Postgres server according to settings.py details with PID %s" % pg.server_pid) DATABASES['default']['NAME'],
DATABASES['default']['USER'],
DATABASES['default']['HOST'],
DATABASES['default']['PORT'],
pg.server_pid))
print("Waiting for your interrupt to stop it.") print("Waiting for your interrupt to stop it.")
while True: while True:
time.sleep(1) time.sleep(1)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment