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

Port backup tests to python #2907

Merged
merged 19 commits into from
Mar 21, 2024
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
30 changes: 30 additions & 0 deletions _integration-test/backup.py
Original file line number Diff line number Diff line change
@@ -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)
47 changes: 47 additions & 0 deletions _integration-test/conftest.py
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"
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,
)
36 changes: 0 additions & 36 deletions _integration-test/ensure-backup-restore-works.sh

This file was deleted.

36 changes: 0 additions & 36 deletions _integration-test/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Loading