Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop role service DB schema before tests #984

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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"

Expand Down
19 changes: 19 additions & 0 deletions src/drop_layman_role_service_schema.py
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 2 additions & 1 deletion src/layman/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/layman/upgrade/upgrade_v1_23.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

from geoserver import util as gs_util
from db import util as db_util
from layman import settings

Expand Down Expand Up @@ -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)