From 11b11695d5e06b329162e10d171c7311da7a9ea6 Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Mon, 24 Jan 2022 12:54:24 +0100 Subject: [PATCH] Add heartbeat check for Remote Settings config --- normandy/recipes/checks.py | 18 +++++++++++++++++- normandy/recipes/tests/test_checks.py | 10 ++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/normandy/recipes/checks.py b/normandy/recipes/checks.py index f4cd4fd95..78b1cc8b4 100644 --- a/normandy/recipes/checks.py +++ b/normandy/recipes/checks.py @@ -9,7 +9,7 @@ import requests.exceptions -from normandy.recipes import signing, geolocation +from normandy.recipes import exports, signing, geolocation INFO_COULD_NOT_RETRIEVE_ACTIONS = "normandy.recipes.I001" @@ -23,6 +23,7 @@ ERROR_COULD_NOT_VERIFY_CERTIFICATE = "normandy.recipes.E005" ERROR_GEOIP_DB_NOT_AVAILABLE = "normandy.recipes.E006" ERROR_GEOIP_DB_UNEXPECTED_RESULT = "normandy.recipes.E007" +ERROR_REMOTE_SETTINGS_INCORRECT_CONFIG = "normandy.recipes.E008" def actions_have_consistent_hashes(app_configs, **kwargs): @@ -187,9 +188,24 @@ def geoip_db_is_available(app_configs, **kwargs): return errors +def remotesettings_config_is_correct(app_configs, **kwargs): + errors = [] + try: + exports.RemoteSettings().check_config() + except ImproperlyConfigured as e: + errors.append( + Error( + f"Remote Settings config is incorrect: {e}", + id=ERROR_REMOTE_SETTINGS_INCORRECT_CONFIG, + ) + ) + return errors + + def register(): register_check(actions_have_consistent_hashes) register_check(recipe_signatures_are_correct) register_check(action_signatures_are_correct) register_check(signatures_use_good_certificates) register_check(geoip_db_is_available) + register_check(remotesettings_config_is_correct) diff --git a/normandy/recipes/tests/test_checks.py b/normandy/recipes/tests/test_checks.py index 501cafe2b..f63e19c34 100644 --- a/normandy/recipes/tests/test_checks.py +++ b/normandy/recipes/tests/test_checks.py @@ -1,5 +1,6 @@ from datetime import timedelta +from django.core.exceptions import ImproperlyConfigured from django.db.utils import ProgrammingError import pytest @@ -93,3 +94,12 @@ def test_it_warns_if_a_field_isnt_available(self, mocker): errors = checks.action_signatures_are_correct(None) assert len(errors) == 1 assert errors[0].id == checks.WARNING_COULD_NOT_CHECK_SIGNATURES + + +class TestRemoteSettingsConfigIsCorrect: + def test_it_warns_if_remote_settings_config_is_incorrect(self, mocker): + mock_check_config = mocker.patch("normandy.recipes.exports.RemoteSettings.check_config") + mock_check_config.side_effect = ImproperlyConfigured("error for testing") + errors = checks.remotesettings_config_is_correct(None) + assert len(errors) == 1 + assert errors[0].id == checks.ERROR_REMOTE_SETTINGS_INCORRECT_CONFIG