Correctly report when we skip hooks during renewal (#3977)

* Remove incorrect hook message

* Add generalized msg about skipping hooks

* Properly report when hooks were skipped

* Also print message about renew hook

* Change quotes to help OCD
This commit is contained in:
Brad Warren 2017-01-05 19:47:10 -05:00 committed by GitHub
parent 13ed5c06ea
commit dc16013abe
4 changed files with 11 additions and 6 deletions

View file

@ -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."""

View file

@ -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:")

View file

@ -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")

View file

@ -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')