From 5c102a00288b21862ccdd2a724584cc4a6a394ac Mon Sep 17 00:00:00 2001 From: Mathieu Pillard Date: Thu, 21 Mar 2024 10:48:24 +0100 Subject: [PATCH] Add basic system check for uwsgi --- src/olympia/core/apps.py | 21 +++++++++++++++++++++ src/olympia/core/tests/test_apps.py | 17 +++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/olympia/core/tests/test_apps.py diff --git a/src/olympia/core/apps.py b/src/olympia/core/apps.py index ddf34506f549..629b3f2cf149 100644 --- a/src/olympia/core/apps.py +++ b/src/olympia/core/apps.py @@ -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') diff --git a/src/olympia/core/tests/test_apps.py b/src/olympia/core/tests/test_apps.py new file mode 100644 index 000000000000..7fefd167d20d --- /dev/null +++ b/src/olympia/core/tests/test_apps.py @@ -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')