Skip to content

Commit

Permalink
Add basic system check for uwsgi
Browse files Browse the repository at this point in the history
  • Loading branch information
diox committed Mar 22, 2024
1 parent 05cde36 commit 5c102a0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/olympia/core/apps.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
import logging
import subprocess
import warnings

from django.apps import AppConfig
from django.conf import settings
from django.core.checks import Error, Tags, register
from django.utils.translation import gettext_lazy as _


log = logging.getLogger('z.startup')


class CustomTags(Tags):
custom_setup = 'setup'


@register(CustomTags.custom_setup)
def uwsgi_check(app_configs, **kwargs):
errors = []
command = ['uwsgi', '--version']
result = subprocess.run(command, capture_output=True)
if result.returncode != 0:
errors.append(
Error(
f'{" ".join(command)} returned a non-zero value',
id='setup.E001',
)
)
return errors


class CoreConfig(AppConfig):
name = 'olympia.core'
verbose_name = _('Core')
Expand Down
17 changes: 17 additions & 0 deletions src/olympia/core/tests/test_apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from unittest import mock

from django.core.management import call_command
from django.core.management.base import SystemCheckError
from django.test import SimpleTestCase


class SystemCheckIntegrationTest(SimpleTestCase):
def test_uwsgi_check(self):
call_command('check')

with mock.patch('olympia.core.apps.subprocess') as subprocess:
subprocess.run.return_value.returncode = 127
with self.assertRaisesMessage(
SystemCheckError, 'uwsgi --version returned a non-zero value'
):
call_command('check')

0 comments on commit 5c102a0

Please sign in to comment.