diff --git a/_integration-test/backup.py b/_integration-test/backup.py new file mode 100644 index 0000000000..cc79cced08 --- /dev/null +++ b/_integration-test/backup.py @@ -0,0 +1,30 @@ +import subprocess +import os +import pytest + +@pytest.fixture() +def setup_env(): + os.environ['SENTRY_DOCKER_IO_DIR'] = os.path.join(os.getcwd(), 'sentry') + os.environ['SKIP_USER_CREATION'] = "1" + +def test_backup(setup_env): + # Docker was giving me permissioning issues when trying to create this file and write to it even after giving read + write access + # to group and owner. Instead, try creating the empty file and then give everyone write access to the backup file + file_path = os.path.join(os.getcwd(), 'sentry', 'backup.json') + sentry_admin_sh = os.path.join(os.getcwd(), 'sentry-admin.sh') + open(file_path, 'a', encoding='utf8').close() + os.chmod(file_path, 0o666) + assert os.path.getsize(file_path) == 0 + subprocess.run([sentry_admin_sh, "export", "global", "/sentry-admin/backup.json", "--no-prompt"], check=True) + assert os.path.getsize(file_path) > 0 + +def test_import(setup_env): + # Bring postgres down and recreate the docker volume + subprocess.run(["docker", "compose", "--ansi", "never", "stop", "postgres"], check=True) + subprocess.run(["docker", "compose", "--ansi", "never", "rm", "-f", "-v", "postgres"], check=True) + subprocess.run(["docker", "volume", "rm", "sentry-postgres"], check=True) + subprocess.run(["docker", "volume", "create", "--name=sentry-postgres"], check=True) + subprocess.run(["docker", "compose", "--ansi", "never", "run", "web", "upgrade", "--noinput"], check=True) + subprocess.run(["docker", "compose", "--ansi", "never", "up", "-d"], check=True) + sentry_admin_sh = os.path.join(os.getcwd(), 'sentry-admin.sh') + subprocess.run([sentry_admin_sh, "import", "global", "/sentry-admin/backup.json", "--no-prompt"], check=True) diff --git a/_integration-test/conftest.py b/_integration-test/conftest.py new file mode 100644 index 0000000000..d83e2cf704 --- /dev/null +++ b/_integration-test/conftest.py @@ -0,0 +1,47 @@ +import subprocess +import os +import time +import httpx +import pytest + +SENTRY_CONFIG_PY = "sentry/sentry.conf.py" +SENTRY_TEST_HOST = os.getenv("SENTRY_TEST_HOST", "http://localhost:9000") +TEST_USER = "test@example.com" +TEST_PASS = "test123TEST" +TIMEOUT_SECONDS = 60 + + +@pytest.fixture(scope="session", autouse=True) +def configure_self_hosted_environment(): + subprocess.run(["docker", "compose", "--ansi", "never", "up", "-d"], check=True) + for i in range(TIMEOUT_SECONDS): + try: + response = httpx.get(SENTRY_TEST_HOST, follow_redirects=True) + except httpx.ConnectionError: + time.sleep(1) + else: + if response.status_code == 200: + break + else: + raise AssertionError("timeout waiting for self-hosted to come up") + + # Create test user + subprocess.run( + [ + "docker", + "compose", + "exec", + "web", + "sentry", + "createuser", + "--force-update", + "--superuser", + "--email", + TEST_USER, + "--password", + TEST_PASS, + "--no-input", + ], + check=True, + text=True, + ) diff --git a/_integration-test/ensure-backup-restore-works.sh b/_integration-test/ensure-backup-restore-works.sh deleted file mode 100755 index 2b8a13f8ce..0000000000 --- a/_integration-test/ensure-backup-restore-works.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env bash -set -ex - -source install/_lib.sh -source install/dc-detect-version.sh - -echo "${_group}Test that backup/restore works..." -echo "Creating backup..." -# Docker was giving me permissioning issues when trying to create this file and write to it even after giving read + write access -# to group and owner. Instead, try creating the empty file and then give everyone write access to the backup file -touch $(pwd)/sentry/backup.json -chmod 666 $(pwd)/sentry/backup.json -SENTRY_DOCKER_IO_DIR=$(pwd)/sentry /bin/bash $(pwd)/sentry-admin.sh export global /sentry-admin/backup.json --no-prompt -if [ ! -s "$(pwd)/sentry/backup.json" ]; then - echo "Backup file is empty" - exit 1 -fi - -# Print backup.json contents -echo "Backup file contents:\n\n" -cat "$(pwd)/sentry/backup.json" - -# Bring postgres down and recreate the docker volume -$dc stop postgres -sleep 5 -$dc rm -f -v postgres -docker volume rm sentry-postgres -export SKIP_USER_CREATION=1 -source install/create-docker-volumes.sh -source install/set-up-and-migrate-database.sh -$dc up -d - -echo "Importing backup..." -SENTRY_DOCKER_IO_DIR=$(pwd)/sentry /bin/bash $(pwd)/sentry-admin.sh import global /sentry-admin/backup.json --no-prompt - -rm $(pwd)/sentry/backup.json diff --git a/_integration-test/run.py b/_integration-test/run.py index 885c115ef9..6162e02f43 100644 --- a/_integration-test/run.py +++ b/_integration-test/run.py @@ -46,42 +46,6 @@ def get_sentry_dsn(client: httpx.Client) -> str: return sentry_dsn -@pytest.fixture(scope="session", autouse=True) -def configure_self_hosted_environment(): - subprocess.run(["docker", "compose", "--ansi", "never", "up", "-d"], check=True) - for i in range(TIMEOUT_SECONDS): - try: - response = httpx.get(SENTRY_TEST_HOST, follow_redirects=True) - except httpx.ConnectionError: - time.sleep(1) - else: - if response.status_code == 200: - break - else: - raise AssertionError("timeout waiting for self-hosted to come up") - - # Create test user - subprocess.run( - [ - "docker", - "compose", - "exec", - "web", - "sentry", - "createuser", - "--force-update", - "--superuser", - "--email", - TEST_USER, - "--password", - TEST_PASS, - "--no-input", - ], - check=True, - text=True, - ) - - @pytest.fixture() def client_login(): client = httpx.Client() diff --git a/integration-test.sh b/integration-test.sh index 29295abc77..33738d23d5 100755 --- a/integration-test.sh +++ b/integration-test.sh @@ -17,7 +17,7 @@ if [[ "$test_option" == "--initial-install" ]]; then echo "Testing initial install" pytest --reruns 5 _integration-test/run.py source _integration-test/ensure-customizations-not-present.sh - source _integration-test/ensure-backup-restore-works.sh + pytest _integration-test/backup.py elif [[ "$test_option" == "--customizations" ]]; then echo "Testing customizations" $dc up -d @@ -36,5 +36,5 @@ EOT ./install.sh pytest --reruns 5 _integration-test/run.py source _integration-test/ensure-customizations-work.sh - source _integration-test/ensure-backup-restore-works.sh + pytest _integration-test/backup.py fi