From 6cfc493a71bc04f90c3c6435f62475ec97b893f8 Mon Sep 17 00:00:00 2001 From: Joona Hoikkala Date: Fri, 24 Jan 2020 15:02:25 +0200 Subject: [PATCH] Move restart() override and interface registration to OCSPPrefetchMixin --- .../_internal/override_debian.py | 26 ------------------- .../certbot_apache/_internal/prefetch_ocsp.py | 26 +++++++++++++++++++ certbot-apache/tests/ocsp_prefetch_test.py | 4 +-- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/certbot-apache/certbot_apache/_internal/override_debian.py b/certbot-apache/certbot_apache/_internal/override_debian.py index fcc61ff2b..e7837ea61 100644 --- a/certbot-apache/certbot_apache/_internal/override_debian.py +++ b/certbot-apache/certbot_apache/_internal/override_debian.py @@ -9,7 +9,6 @@ from certbot import interfaces from certbot import util from certbot.compat import filesystem from certbot.compat import os -from certbot.plugins.enhancements import OCSPPrefetchEnhancement from certbot_apache._internal import apache_util from certbot_apache._internal import configurator @@ -145,28 +144,3 @@ class DebianConfigurator(prefetch_ocsp.OCSPPrefetchMixin, configurator.ApacheCon self.reverter.register_undo_command( temp, [self.option("dismod"), "-f", mod_name]) util.run_script([self.option("enmod"), mod_name]) - - def restart(self): - """Runs a config test and reloads the Apache server. - - :raises .errors.MisconfigurationError: If either the config test - or reload fails. - - """ - self.config_test() - - if not self._ocsp_prefetch: - # Try to populate OCSP prefetch structure from pluginstorage - self._ocsp_prefetch_fetch_state() - if self._ocsp_prefetch: - # OCSP prefetching is enabled, so back up the db - self._ocsp_prefetch_backup_db() - - self._reload() - - if self._ocsp_prefetch: - # Restore the backed up dbm database - self._ocsp_prefetch_restore_db() - - -OCSPPrefetchEnhancement.register(DebianConfigurator) # pylint: disable=no-member diff --git a/certbot-apache/certbot_apache/_internal/prefetch_ocsp.py b/certbot-apache/certbot_apache/_internal/prefetch_ocsp.py index a770062f1..185e11674 100644 --- a/certbot-apache/certbot_apache/_internal/prefetch_ocsp.py +++ b/certbot-apache/certbot_apache/_internal/prefetch_ocsp.py @@ -7,6 +7,7 @@ from acme.magic_typing import Dict # pylint: disable=unused-import, no-name-in- from certbot import errors from certbot._internal import ocsp +from certbot.plugins.enhancements import OCSPPrefetchEnhancement from certbot.compat import filesystem from certbot.compat import os @@ -244,3 +245,28 @@ class OCSPPrefetchMixin(object): if self._ocsp_refresh_if_needed(pf): # Save the status to pluginstorage self._ocsp_prefetch_save(pf["cert_path"], pf["chain_path"]) + + def restart(self): + """Runs a config test and reloads the Apache server. + + :raises .errors.MisconfigurationError: If either the config test + or reload fails. + + """ + self.config_test() + + if not self._ocsp_prefetch: + # Try to populate OCSP prefetch structure from pluginstorage + self._ocsp_prefetch_fetch_state() + if self._ocsp_prefetch: + # OCSP prefetching is enabled, so back up the db + self._ocsp_prefetch_backup_db() + + self._reload() + + if self._ocsp_prefetch: + # Restore the backed up dbm database + self._ocsp_prefetch_restore_db() + + +OCSPPrefetchEnhancement.register(OCSPPrefetchMixin) # pylint: disable=no-member diff --git a/certbot-apache/tests/ocsp_prefetch_test.py b/certbot-apache/tests/ocsp_prefetch_test.py index c55f867fa..95d7fbbe5 100644 --- a/certbot-apache/tests/ocsp_prefetch_test.py +++ b/certbot-apache/tests/ocsp_prefetch_test.py @@ -111,7 +111,7 @@ class OCSPPrefetchTest(util.ApacheTest): open(db_fullpath, 'a').close() ver_path = "certbot_apache._internal.configurator.ApacheConfigurator.get_version" - res_path = "certbot_apache._internal.override_debian.DebianConfigurator.restart" + res_path = "certbot_apache._internal.prefetch_ocsp.OCSPPrefetchMixin.restart" cry_path = "certbot.crypto_util.cert_sha1_fingerprint" with mock.patch(ver_path) as mock_ver: @@ -248,7 +248,7 @@ class OCSPPrefetchTest(util.ApacheTest): self.assertTrue(log_string in mock_log.call_args_list[0][0][0]) self.assertTrue(log_string2 in mock_log.call_args_list[1][0][0]) - @mock.patch("certbot_apache._internal.configurator.ApacheConfigurator.restart") + @mock.patch("certbot_apache._internal.prefetch_ocsp.OCSPPrefetchMixin.restart") def test_ocsp_prefetch_refresh_fail(self, _mock_restart): ocsp_path = "certbot._internal.ocsp.RevocationChecker.revoked" log_path = "certbot_apache._internal.prefetch_ocsp.logger.warning"