Add tilt button to run pytest, fix local dev config for pytest, minor improvements to til (#3927)
# What this PR does Fixes for https://github.com/grafana/oncall-private/issues/2423 ## Which issue(s) this PR fixes ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated - [ ] Documentation added (or `pr:no public docs` PR label added if not required) --------- Co-authored-by: Joey Orlando <joey.orlando@grafana.com> Co-authored-by: Dominik <dominik.broj@grafana.com>
This commit is contained in:
parent
6c575e050b
commit
6511e439c5
7 changed files with 77 additions and 4 deletions
36
Tiltfile
36
Tiltfile
|
|
@ -83,7 +83,7 @@ if not is_ci:
|
|||
|
||||
local_resource(
|
||||
"e2e-tests",
|
||||
labels=["E2eTests"],
|
||||
labels=["allTests"],
|
||||
cmd=e2e_tests_cmd,
|
||||
trigger_mode=TRIGGER_MODE_MANUAL,
|
||||
auto_init=is_ci,
|
||||
|
|
@ -127,6 +127,34 @@ cmd_button(
|
|||
icon_name="dangerous",
|
||||
)
|
||||
|
||||
# Inspired by https://github.com/grafana/slo/blob/main/Tiltfile#L72
|
||||
pod_engine_pytest_script = '''
|
||||
set -eu
|
||||
# get engine k8s pod name from tilt resource name
|
||||
POD_NAME="$(tilt get kubernetesdiscovery "engine" -ojsonpath='{.status.pods[0].name}')"
|
||||
kubectl exec "$POD_NAME" -- pytest . $STOP_ON_FIRST_FAILURE $TESTS_FILTER
|
||||
'''
|
||||
local_resource(
|
||||
"pytest-tests",
|
||||
labels=["allTests"],
|
||||
cmd=['sh', '-c', pod_engine_pytest_script],
|
||||
trigger_mode=TRIGGER_MODE_MANUAL,
|
||||
auto_init=False,
|
||||
resource_deps=["engine"]
|
||||
)
|
||||
|
||||
cmd_button(
|
||||
name="pytest Tests - headless run",
|
||||
argv=['sh', '-c', pod_engine_pytest_script],
|
||||
text="Run pytest",
|
||||
resource="pytest-tests",
|
||||
icon_name="replay",
|
||||
inputs=[
|
||||
text_input("TESTS_FILTER", "pytest optional arguments (e.g. \"apps/webhooks/tests/test_webhook.py::test_build_url_private_raises\")", "", "Test file names to run"),
|
||||
bool_input("STOP_ON_FIRST_FAILURE", "Stop on first failure", True, "-x", ""),
|
||||
]
|
||||
)
|
||||
|
||||
helm_oncall_values = ["./dev/helm-local.yml", "./dev/helm-local.dev.yml"]
|
||||
if is_ci:
|
||||
helm_oncall_values = helm_oncall_values + ["./.github/helm-ci.yml"]
|
||||
|
|
@ -174,7 +202,10 @@ k8s_resource(
|
|||
resource_deps=["mariadb", "redis-master"],
|
||||
labels=["OnCallBackend"],
|
||||
)
|
||||
k8s_resource(workload="engine-migrate", labels=["OnCallBackend"])
|
||||
|
||||
k8s_resource(workload="redis-master", labels=["OnCallDeps"])
|
||||
k8s_resource(workload="prometheus-server", labels=["OnCallDeps"])
|
||||
k8s_resource(
|
||||
workload="mariadb",
|
||||
port_forwards='3307:3306', # <host_port>:<container_port>
|
||||
|
|
@ -184,6 +215,9 @@ k8s_resource(
|
|||
|
||||
# name all tilt resources after the k8s object namespace + name
|
||||
def resource_name(id):
|
||||
# Remove variable date from job name
|
||||
if id.name.startswith(HELM_PREFIX + "-engine-migrate"):
|
||||
return "engine-migrate"
|
||||
return id.name.replace(HELM_PREFIX + "-", "")
|
||||
|
||||
workload_to_resource_function(resource_name)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,14 @@ env:
|
|||
value: "False"
|
||||
- name: FEATURE_PROMETHEUS_EXPORTER_ENABLED
|
||||
value: "True"
|
||||
- name: DJANGO_SETTINGS_MODULE
|
||||
value: "settings.dev"
|
||||
- name: FEATURE_TELEGRAM_INTEGRATION_ENABLED
|
||||
value: "True"
|
||||
- name: FEATURE_SLACK_INTEGRATION_ENABLED
|
||||
value: "True"
|
||||
- name: SLACK_SLASH_COMMAND_NAME
|
||||
value: "/oncall"
|
||||
# enabled to be able to test docker.host.internal in the webhook e2e tests
|
||||
- name: DANGEROUS_WEBHOOKS_ENABLED
|
||||
value: "True"
|
||||
|
|
@ -131,6 +139,14 @@ service:
|
|||
nodePort: 30001
|
||||
prometheus:
|
||||
enabled: true
|
||||
alertmanager:
|
||||
enabled: false
|
||||
kube-state-metrics:
|
||||
enabled: false
|
||||
prometheus-node-exporter:
|
||||
enabled: false
|
||||
prometheus-pushgateway:
|
||||
enabled: false
|
||||
server:
|
||||
global:
|
||||
scrape_interval: 10s
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
import os
|
||||
from unittest import mock
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
from django.conf import settings
|
||||
from django.db import IntegrityError
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
|
|
@ -10,6 +12,7 @@ from apps.alerts.models import AlertReceiveChannel
|
|||
from common.api_helpers.utils import create_engine_url
|
||||
from common.exceptions import UnableToSendDemoAlert
|
||||
from engine.management.commands import alertmanager_v2_migrate
|
||||
from settings.base import DatabaseTypes
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
|
@ -272,6 +275,13 @@ def test_create_missing_direct_paging_integrations(
|
|||
def test_create_duplicate_direct_paging_integrations(make_organization, make_team, make_alert_receive_channel):
|
||||
"""Check that it's not possible to have more than one active direct paging integration per team."""
|
||||
|
||||
# MariaDB is not supported for this test
|
||||
# See comment: https://github.com/grafana/oncall/commit/381a9ecf54bf0dd076f233b207c13d72ed792181#diff-9d96504027309f2bd1e95352bac1433b09b60eb4fafb611b52a6c15ed16cbc48R219-R223
|
||||
is_local_dev_env = os.environ.get("DJANGO_SETTINGS_MODULE") == "settings.dev"
|
||||
is_db_type_mysql = settings.DATABASE_TYPE == DatabaseTypes.MYSQL
|
||||
if is_local_dev_env and is_db_type_mysql:
|
||||
pytest.skip("This test is not supported by Mariadb (used by settings.dev)")
|
||||
|
||||
organization = make_organization()
|
||||
team = make_team(organization)
|
||||
make_alert_receive_channel(organization, team=team, integration=AlertReceiveChannel.INTEGRATION_DIRECT_PAGING)
|
||||
|
|
|
|||
|
|
@ -132,7 +132,9 @@ def create_alert(
|
|||
},
|
||||
countdown=countdown,
|
||||
)
|
||||
logger.warning(f"Retrying the task gracefully in {countdown} seconds due to ConcurrentUpdateError")
|
||||
logger.warning(
|
||||
f"Retrying the task gracefully in {countdown} seconds due to ConcurrentUpdateError for alert_receive_channel={alert_receive_channel_pk}"
|
||||
)
|
||||
|
||||
|
||||
@shared_dedicated_queue_retry_task()
|
||||
|
|
|
|||
|
|
@ -168,6 +168,9 @@ def test_build_url_invalid_url(make_organization, make_custom_webhook):
|
|||
|
||||
@pytest.mark.django_db
|
||||
def test_build_url_private_raises(make_organization, make_custom_webhook):
|
||||
if settings.DANGEROUS_WEBHOOKS_ENABLED:
|
||||
pytest.skip("Dangerous webhooks are enabled")
|
||||
|
||||
organization = make_organization()
|
||||
webhook = make_custom_webhook(organization=organization, url="{{foo}}")
|
||||
|
||||
|
|
@ -241,6 +244,9 @@ def test_make_request(make_organization, make_custom_webhook):
|
|||
@httpretty.activate(verbose=True, allow_net_connect=False)
|
||||
@pytest.mark.django_db
|
||||
def test_make_request_bad_redirect(make_organization, make_custom_webhook):
|
||||
if settings.DANGEROUS_WEBHOOKS_ENABLED:
|
||||
pytest.skip("Dangerous webhooks are enabled")
|
||||
|
||||
organization = make_organization()
|
||||
webhook = make_custom_webhook(organization=organization, http_method="POST")
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,13 @@ if TESTING:
|
|||
TELEGRAM_TOKEN = "0000000000:XXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXX"
|
||||
TWILIO_AUTH_TOKEN = "twilio_auth_token"
|
||||
|
||||
# charset/collation related tests don't work without this
|
||||
TEST_SETTINGS = {
|
||||
"CHARSET": "utf8mb4",
|
||||
"COLLATION": "utf8mb4_unicode_ci",
|
||||
}
|
||||
DATABASES["default"]["TEST"] = TEST_SETTINGS
|
||||
|
||||
INTERNAL_IPS = [
|
||||
"127.0.0.1",
|
||||
]
|
||||
|
|
|
|||
|
|
@ -16,11 +16,9 @@ except ModuleNotFoundError:
|
|||
# Only works under uwsgi web server environment
|
||||
pass
|
||||
|
||||
|
||||
SLACK_SIGNING_SECRET = os.environ.get("SLACK_SIGNING_SECRET")
|
||||
SLACK_SIGNING_SECRET_LIVE = os.environ.get("SLACK_SIGNING_SECRET_LIVE", "")
|
||||
|
||||
|
||||
STATICFILES_DIRS = [
|
||||
"/etc/app/static",
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue