-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Write Customization tests in python #2918
Changes from 14 commits
981afa1
23bade6
fa0bcaa
ac67a3b
fd28ad4
68da8b0
5c2fd16
2ccd1a5
82eed1e
fbe3713
1799f09
867ed00
fb6d766
fe79de0
b61dd79
6732677
a6fa7b0
2594145
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ defaults: | |
jobs: | ||
e2e-test: | ||
if: github.repository_owner == 'getsentry' | ||
runs-on: ubuntu-20.04 | ||
runs-on: ubuntu-22.04 | ||
name: "Sentry self-hosted end-to-end tests" | ||
steps: | ||
- name: Checkout | ||
|
@@ -59,7 +59,7 @@ jobs: | |
strategy: | ||
fail-fast: false | ||
matrix: | ||
test_type: ["initial-install", "customizations"] | ||
customizations_enabled: ["False", "True"] | ||
compose_version: ["v2.0.1", "v2.7.0"] | ||
include: | ||
- compose_version: "v2.0.1" | ||
|
@@ -68,18 +68,19 @@ jobs: | |
compose_path: "/usr/local/lib/docker/cli-plugins" | ||
env: | ||
COMPOSE_PROJECT_NAME: self-hosted-${{ strategy.job-index }} | ||
SENTRY_DSN: https://[email protected]/6627632 | ||
REPORT_SELF_HOSTED_ISSUES: 1 | ||
REPORT_SELF_HOSTED_ISSUES: 0 | ||
SELF_HOSTED_TESTING_DSN: ${{ vars.SELF_HOSTED_TESTING_DSN }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup dev environment | ||
run: | | ||
pip install -r requirements-dev.txt | ||
echo "PY_COLORS=1" >> "$GITHUB_ENV" | ||
### pytest-sentry configuration ### | ||
if [ "$GITHUB_REPOSITORY" = "getsentry/self-hosted" ]; then | ||
echo "PYTEST_SENTRY_DSN=${{ env.SELF_HOSTED_TESTING_DSN }}" >> $GITHUB_ENV | ||
echo "PYTEST_SENTRY_DSN=$SELF_HOSTED_TESTING_DSN" >> $GITHUB_ENV | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was previously not being picked up correctly |
||
echo "PYTEST_SENTRY_TRACES_SAMPLE_RATE=0" >> $GITHUB_ENV | ||
|
||
# This records failures on master to sentry in order to detect flakey tests, as it's | ||
|
@@ -105,10 +106,22 @@ jobs: | |
run: ./install.sh | ||
|
||
- name: Integration Test | ||
run: ./integration-test.sh --${{ matrix.test_type }} | ||
run: pytest --cov --junitxml=junit.xml --reruns 3 _integration-test/ --customizations=${{ matrix.customizations_enabled }} | ||
|
||
- name: Inspect failure | ||
if: failure() | ||
run: | | ||
docker compose ps | ||
docker compose logs | ||
|
||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v4 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
slug: getsentry/self-hosted | ||
|
||
- name: Upload test results to Codecov | ||
if: ${{ !cancelled() }} | ||
uses: codecov/test-results-action@v1 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,27 +10,49 @@ | |
TEST_PASS = "test123TEST" | ||
TIMEOUT_SECONDS = 60 | ||
|
||
def pytest_addoption(parser): | ||
parser.addoption("--customizations", default=False) | ||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def configure_self_hosted_environment(): | ||
def configure_self_hosted_environment(request): | ||
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: | ||
except httpx.NetworkError: | ||
time.sleep(1) | ||
else: | ||
if response.status_code == 200: | ||
break | ||
else: | ||
raise AssertionError("timeout waiting for self-hosted to come up") | ||
|
||
if request.config.getoption("--customizations") == "True": | ||
os.environ['TEST_CUSTOMIZATIONS'] = "True" | ||
script_content = '''\ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These lines are definitely covered by testing, not sure why Codecov is complaining here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's the reason why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: It's pretty hard for a naive observer to figure out what the "True" in these variants means. Maybe we could have values be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apparently, you can create a custom name for the job. Now it looks like |
||
#!/bin/bash | ||
touch /created-by-enhance-image | ||
apt-get update | ||
apt-get install -y gcc libsasl2-dev python-dev libldap2-dev libssl-dev | ||
''' | ||
|
||
with open('sentry/enhance-image.sh', 'w') as script_file: | ||
script_file.write(script_content) | ||
# Set executable permissions for the shell script | ||
os.chmod('sentry/enhance-image.sh', 0o755) | ||
|
||
# Write content to the requirements.txt file | ||
with open('sentry/requirements.txt', 'w') as req_file: | ||
req_file.write('python-ldap\n') | ||
os.environ['MINIMIZE_DOWNTIME'] = "1" | ||
subprocess.run(["./install.sh"], check=True) | ||
# Create test user | ||
subprocess.run( | ||
[ | ||
"docker", | ||
"compose", | ||
"exec", | ||
"-T", | ||
"web", | ||
"sentry", | ||
"createuser", | ||
|
@@ -45,3 +67,8 @@ | |
check=True, | ||
text=True, | ||
) | ||
|
||
@pytest.fixture() | ||
def setup_backup_restore_env_variables(): | ||
os.environ['SENTRY_DOCKER_IO_DIR'] = os.path.join(os.getcwd(), 'sentry') | ||
os.environ['SKIP_USER_CREATION'] = "1" |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,7 +141,18 @@ | |
try: | ||
subprocess.run(["./_integration-test/custom-ca-roots/setup.sh"], check=True) | ||
subprocess.run( | ||
["docker", "compose", "--ansi", "never", "run", "--no-deps", "web", "python3", "/etc/sentry/test-custom-ca-roots.py"], check=True | ||
[ | ||
"docker", | ||
"compose", | ||
"--ansi", | ||
"never", | ||
"run", | ||
"--no-deps", | ||
"web", | ||
"python3", | ||
"/etc/sentry/test-custom-ca-roots.py", | ||
], | ||
check=True, | ||
) | ||
finally: | ||
subprocess.run(["./_integration-test/custom-ca-roots/teardown.sh"], check=True) | ||
|
@@ -171,3 +182,64 @@ | |
client, | ||
lambda x: len(json.loads(x)["data"]) > 0, | ||
) | ||
|
||
|
||
def test_customizations(): | ||
commands = [ | ||
[ | ||
"docker", | ||
"compose", | ||
"--ansi", | ||
"never", | ||
"run", | ||
"--no-deps", | ||
"web", | ||
"bash", | ||
"-c", | ||
"if [ ! -e /created-by-enhance-image ]; then exit 1; fi", | ||
], | ||
[ | ||
"docker", | ||
"compose", | ||
"--ansi", | ||
"never", | ||
"run", | ||
"--no-deps", | ||
"--entrypoint=/etc/sentry/entrypoint.sh", | ||
"sentry-cleanup", | ||
"bash", | ||
"-c", | ||
"if [ ! -e /created-by-enhance-image ]; then exit 1; fi", | ||
], | ||
[ | ||
"docker", | ||
"compose", | ||
"--ansi", | ||
"never", | ||
"run", | ||
"--no-deps", | ||
"web", | ||
"python", | ||
"-c", | ||
"import ldap", | ||
], | ||
[ | ||
"docker", | ||
"compose", | ||
"--ansi", | ||
"never", | ||
"run", | ||
"--no-deps", | ||
"--entrypoint=/etc/sentry/entrypoint.sh", | ||
"sentry-cleanup", | ||
"python", | ||
"-c", | ||
"import ldap", | ||
] | ||
] | ||
for command in commands: | ||
result = subprocess.run(command, check=False) | ||
if os.getenv("TEST_CUSTOMIZATIONS", "False") == "True": | ||
assert result.returncode == 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it does. If customizations enabled, it checks to ensure that they are truly enabled by making sure a dependency can be imported that is included in the custom image (ldap). If not, it checks to ensure that an error is thrown when trying to import a dependency that comes from the custom image. |
||
else: | ||
assert result.returncode != 0 |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bumped this while at it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Imo we should split this into a separate PR, since I could imagine cases where we want to only roll this bump back.