From 50e91cc18678896a75502da178b680c7bac63512 Mon Sep 17 00:00:00 2001 From: Jiri Kozel Date: Wed, 20 Dec 2023 13:24:22 +0100 Subject: [PATCH 1/3] Drop role service DB schema before tests --- Makefile | 8 +++++--- src/drop_layman_role_service_schema.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/drop_layman_role_service_schema.py diff --git a/Makefile b/Makefile index 9d8a15476..7739fd322 100644 --- a/Makefile +++ b/Makefile @@ -205,11 +205,12 @@ test: docker compose -f docker-compose.deps.yml -f docker-compose.test.yml rm -f layman_test docker compose -f docker-compose.deps.yml -f docker-compose.test.yml up -d postgresql docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps layman_test bash -c "bash ensure-test-data.sh && python3 src/assert_db.py" - docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps -u root layman_test bash -c "cd src && python3 -B setup_geoserver.py" + docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps -u root layman_test bash -c "cd src && python3 -B drop_layman_role_service_schema.py && python3 -B setup_geoserver.py" docker compose -f docker-compose.deps.yml -f docker-compose.test.yml up --force-recreate --no-deps -d celery_worker_test docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --name layman_test_run_1 layman_test test-fast: + docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps -u root layman_test bash -c "cd src && python3 -B drop_layman_role_service_schema.py && python3 -B setup_geoserver.py" docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps --name layman_test_run_1 layman_test test-separated: @@ -226,11 +227,12 @@ test-separated: docker compose -f docker-compose.deps.yml -f docker-compose.test.yml rm -f layman_test docker compose -f docker-compose.deps.yml -f docker-compose.test.yml up -d postgresql docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps layman_test bash -c "bash ensure-test-data.sh && python3 src/assert_db.py" - docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps -u root layman_test bash -c "cd src && python3 -B setup_geoserver.py" + docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps -u root layman_test bash -c "cd src && python3 -B drop_layman_role_service_schema.py && python3 -B setup_geoserver.py" docker compose -f docker-compose.deps.yml -f docker-compose.test.yml up --force-recreate --no-deps -d celery_worker_test docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --name layman_test_run_1 -e "TEST_TYPE=$(test_type)" layman_test bash -c "bash test_separated.sh $(max_fail)" test-separated-fast: + docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps -u root layman_test bash -c "cd src && python3 -B drop_layman_role_service_schema.py && python3 -B setup_geoserver.py" docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps --name layman_test_run_1 -e "TEST_TYPE=$(test_type)" layman_test bash -c "bash test_separated.sh $(max_fail)" test-static: @@ -247,7 +249,7 @@ test-static: docker compose -f docker-compose.deps.yml -f docker-compose.test.yml rm -f layman_test docker compose -f docker-compose.deps.yml -f docker-compose.test.yml up -d postgresql docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps layman_test bash -c "bash ensure-test-data.sh && python3 src/assert_db.py" - docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps -u root layman_test bash -c "cd src && python3 -B setup_geoserver.py" + docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --no-deps -u root layman_test bash -c "cd src && python3 -B drop_layman_role_service_schema.py && python3 -B setup_geoserver.py" docker compose -f docker-compose.deps.yml -f docker-compose.test.yml up --force-recreate --no-deps -d celery_worker_test docker compose -f docker-compose.deps.yml -f docker-compose.test.yml run --rm --name layman_test_run_1 layman_test bash -c "bash test_static.sh" diff --git a/src/drop_layman_role_service_schema.py b/src/drop_layman_role_service_schema.py new file mode 100644 index 000000000..271b6e698 --- /dev/null +++ b/src/drop_layman_role_service_schema.py @@ -0,0 +1,19 @@ +import psycopg2 +import layman_settings as settings + + +def main(): + print(f"Drop Layman role service DB schema.") + + # Layman DB + conn = psycopg2.connect(**settings.PG_CONN) + conn.autocommit = True + cur = conn.cursor() + cur.execute(f""" +DROP SCHEMA IF EXISTS "{settings.LAYMAN_INTERNAL_ROLE_SERVICE_SCHEMA}" CASCADE; +""") + conn.commit() + + +if __name__ == "__main__": + main() From edc3ec7c12299252d6b287310d9c3ea00e2cacbb Mon Sep 17 00:00:00 2001 From: Jiri Kozel Date: Wed, 20 Dec 2023 14:13:09 +0100 Subject: [PATCH 2/3] Try to reload GS --- .env.test | 2 +- src/layman/upgrade/upgrade_v1_23.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.env.test b/.env.test index 219359460..9633a26d1 100644 --- a/.env.test +++ b/.env.test @@ -16,7 +16,7 @@ LAYMAN_AUTHN_MODULES=layman.authn.http_header LAYMAN_AUTHN_HTTP_HEADER_NAME=a0468616f9968eaecdc3377988aba650 GRANT_CREATE_PUBLIC_WORKSPACE=EVERYONE GRANT_PUBLISH_IN_PUBLIC_WORKSPACE=EVERYONE -LAYMAN_ROLE_SERVICE_URI=postgresql://docker:docker@postgresql:5432/layman_test?schema=_role_service +LAYMAN_ROLE_SERVICE_URI=postgresql://docker:docker@postgresql:5432/layman_test?autosave=conservative&schema=_role_service # connection parameters to PostgreSQL database LAYMAN_PG_HOST=postgresql diff --git a/src/layman/upgrade/upgrade_v1_23.py b/src/layman/upgrade/upgrade_v1_23.py index 643c1bec5..b777cb5de 100644 --- a/src/layman/upgrade/upgrade_v1_23.py +++ b/src/layman/upgrade/upgrade_v1_23.py @@ -1,5 +1,6 @@ import logging +from geoserver import util as gs_util from db import util as db_util from layman import settings @@ -134,3 +135,5 @@ def create_role_service_schema(): create index group_roles_idx on {ROLE_SERVICE_SCHEMA}.group_roles(rolename,groupname); """ db_util.run_statement(create_other_tables) + + gs_util.reload(settings.LAYMAN_GS_AUTH) From 2e5221ccdfadf9e0f73914714d6f53890abf98e1 Mon Sep 17 00:00:00 2001 From: Jiri Kozel Date: Wed, 20 Dec 2023 14:19:26 +0100 Subject: [PATCH 3/3] Minor log changes in __init__.py --- src/layman/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/layman/__init__.py b/src/layman/__init__.py index 9ceef916b..9ebdbcf3c 100644 --- a/src/layman/__init__.py +++ b/src/layman/__init__.py @@ -83,11 +83,12 @@ pipe.execute() with app.app_context(): - logger.info(f'Adjusting GeoServer roles') if settings.GEOSERVER_ADMIN_AUTH: + logger.info(f'Ensuring Layman user on GeoServer') gs_util.ensure_user(settings.LAYMAN_GS_USER, settings.LAYMAN_GS_PASSWORD, settings.GEOSERVER_ADMIN_AUTH) + logger.info(f'Adjusting GeoServer proxy base URL') gs_util.ensure_proxy_base_url(settings.LAYMAN_GS_PROXY_BASE_URL_WITH_PLACEHOLDERS, settings.LAYMAN_GS_AUTH) if not IN_UPGRADE_PROCESS: