diff --git a/certbot/hooks.py b/certbot/hooks.py index ce4f16262..5cda478cc 100644 --- a/certbot/hooks.py +++ b/certbot/hooks.py @@ -85,8 +85,7 @@ def run_saved_post_hooks(): for cmd in post_hook.eventually: logger.info("Running post-hook command: %s", cmd) _run_hook(cmd) - if not post_hook.eventually: - logger.info("No renewals attempted, so not running post-hook") + def renew_hook(config, domains, lineage_path): """Run post-renewal hook if defined.""" diff --git a/certbot/renewal.py b/certbot/renewal.py index 3bc7a30f9..d65cd4904 100644 --- a/certbot/renewal.py +++ b/certbot/renewal.py @@ -304,6 +304,9 @@ def _renew_describe_results(config, renew_successes, renew_failures, notify(report(renew_skipped, "skipped")) if not renew_successes and not renew_failures: notify("No renewals were attempted.") + if (config.pre_hook is not None or + config.renew_hook is not None or config.post_hook is not None): + notify("No hooks were run.") elif renew_successes and not renew_failures: notify("Congratulations, all renewals succeeded. The following certs " "have been renewed:") diff --git a/certbot/tests/hook_test.py b/certbot/tests/hook_test.py index 3165a67fc..87c86ad5c 100644 --- a/certbot/tests/hook_test.py +++ b/certbot/tests/hook_test.py @@ -62,10 +62,7 @@ class HookTest(unittest.TestCase): with mock.patch('certbot.hooks._run_hook') as mock_run: hooks.run_saved_post_hooks() self.assertEqual(mock_run.call_count, expected_count) - if expected_count: - self.assertEqual(mock_info.call_count, expected_count) - else: - self.assertEqual(mock_info.call_count, 1) + self.assertEqual(mock_info.call_count, expected_count) def test_post_hooks(self): config = mock.MagicMock(post_hook="true", verb="splonk") diff --git a/certbot/tests/main_test.py b/certbot/tests/main_test.py index 673952b4e..635a7c41d 100644 --- a/certbot/tests/main_test.py +++ b/certbot/tests/main_test.py @@ -994,6 +994,12 @@ class MainTest(unittest.TestCase): # pylint: disable=too-many-public-methods self._test_renewal_common(True, None, args='renew --csr {0}'.format(CSR).split(), should_renew=False, error_expected=True) + def test_no_renewal_with_hooks(self): + _, _, stdout = self._test_renewal_common( + due_for_renewal=False, extra_args=None, should_renew=False, + args=['renew', '--post-hook', 'echo hello world']) + self.assertTrue('No hooks were run.' in stdout.getvalue()) + @mock.patch('certbot.main.zope.component.getUtility') @mock.patch('certbot.main._find_lineage_for_domains_and_certname') @mock.patch('certbot.main._init_le_client')