Skip to content
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: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ local_config.py
db.sqlite3
db.sqlite3-journal
src/static
src/errors/errors.sqlite
src/errors/.errors_secret_key

# Flask stuff:
instance/
Expand Down
9 changes: 9 additions & 0 deletions charm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
BASE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

.PHONY: tests pack

pack:
charmcraft pack --project-dir $(BASE_DIR)..

tests:
uv run --all-extras pytest -o log_cli=1 -v --log-level=INFO --pdb --charm-path ../error-tracker_ubuntu@24.04-amd64.charm tests/
37 changes: 21 additions & 16 deletions charm/tests/integration/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,24 @@ def test_http(juju: jubilant.Juju):
session = Session()
session.mount("https://", DNSResolverHTTPSAdapter(external_hostname, haproxy_ip))

# Let give this test a few chances to succeed, as it can sometimes be a bit
# early and hit 503
for attempt in Retrying(
stop=stop_after_attempt(10),
wait=wait_exponential(min=5, max=30),
reraise=True,
):
with attempt:
response = session.get(
f"https://{haproxy_ip}/",
headers={"Host": external_hostname},
verify=False,
timeout=30,
)
assert response.status_code == 200
assert "We collect hundreds of thousands of error reports daily" in response.text
for uri, content in [
("/", "We collect hundreds of thousands of error reports daily"),
("/static/css/main.css", "body {"),
("/static/js/yui/build/yui/yui-min.js", "/* YUI 3.9.0 (build 5827)"),
]:
# Let give this test a few chances to succeed, as it can sometimes be a bit
# early and hit 503
for attempt in Retrying(
stop=stop_after_attempt(10),
wait=wait_exponential(min=5, max=30),
reraise=True,
):
with attempt:
response = session.get(
f"https://{haproxy_ip}{uri}",
headers={"Host": external_hostname},
verify=False,
timeout=30,
)
assert response.status_code == 200
assert content in response.text
25 changes: 17 additions & 8 deletions src/errors/settings.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Django settings for errors project.
import os
import random
import string
from pathlib import Path

from errortracker import config

ALLOWED_HOSTS = ["*"]

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
PROJECT_ROOT = Path(__file__).absolute().parent

DEBUG = True
DEBUG = config.errors_debug

WSGI_APPLICATION = "errors.wsgi.application"

Expand All @@ -23,14 +25,14 @@
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(os.environ.get("XDG_RUNTIME_DIR", "/tmp"), "errors.sqlite"),
"NAME": str(PROJECT_ROOT / "errors.sqlite"),
}
}

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
STATIC_ROOT = os.path.join(PROJECT_ROOT, "../static")
STATIC_ROOT = str(PROJECT_ROOT / "../static")

# URL prefix for static files.
STATIC_URL = "/static/"
Expand All @@ -40,7 +42,7 @@
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(PROJECT_ROOT, "static"),
str(PROJECT_ROOT / "static"),
]

# List of finder classes that know how to find static files in
Expand All @@ -51,7 +53,14 @@
]

# Make this unique, and don't share it with anybody.
SECRET_KEY = config.errors_secret_key
secret_key_path = PROJECT_ROOT / ".errors_secret_key"
try:
SECRET_KEY = secret_key_path.read_text()
except Exception:
SECRET_KEY = "".join(
random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in range(32)
)
secret_key_path.write_text(SECRET_KEY)

MIDDLEWARE = (
"django.middleware.common.CommonMiddleware",
Expand All @@ -71,7 +80,7 @@
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(PROJECT_ROOT, "templates")],
"DIRS": [str(PROJECT_ROOT / "templates")],
"OPTIONS": {
"context_processors": [
"django.template.context_processors.request",
Expand Down
7 changes: 6 additions & 1 deletion src/errortracker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@
# Path used to keep some crashes in case of failure, for manual investigation
failure_storage = None

errors_secret_key = "hellotheregeneralkenobi"
# Is the Django app running in debug mode
errors_debug = True

# Allow the Django app to fill bugs
allow_bug_filing = True

# Some variable still used by the launchpad.py module
lp_oauth_token = "todofixme"
lp_oauth_secret = "todofixme"
lp_use_staging = True
Expand Down
Loading