Compare commits

...

15 Commits

Author SHA1 Message Date
ohemorange
0f47568dc7 Merge branch 'master' into randomsleep 2018-11-15 15:11:33 -08:00
Seth Schoen
696ce6e479 Test coverage for random sleep() logic in main.py 2018-10-17 04:11:27 -07:00
Seth Schoen
7ccb29b1d2 Log specific duration of random sleep 2018-10-16 14:38:43 -07:00
Seth Schoen
ccbb45bbe1 Revert "Somewhat ugly synthetic PTY trick"
This reverts commit 89c704a4be.
2018-10-16 14:31:06 -07:00
Seth Schoen
91f26baeee Revert "Move set -u down below self-exec"
This reverts commit 6bde65a738.
2018-10-16 14:31:03 -07:00
Seth Schoen
6bde65a738 Move set -u down below self-exec 2018-10-16 12:36:25 -07:00
Seth Schoen
89c704a4be Somewhat ugly synthetic PTY trick 2018-10-16 12:26:35 -07:00
Seth Schoen
57d5685de1 mock the right object 2018-10-16 06:25:41 -07:00
Seth Schoen
e039920a99 Move mocked sleep elsewhere 2018-10-16 06:13:13 -07:00
Seth Schoen
ab374c7536 Merge remote-tracking branch 'origin/master' into randomsleep 2018-10-16 05:58:39 -07:00
Seth Schoen
9c82519d74 Try mocking time.sleep for all tests 2018-10-16 05:49:45 -07:00
Seth Schoen
97c89969af stdin may better define interactivity than stdout 2018-09-24 19:38:29 -07:00
Seth Schoen
0cae499738 Log the fact that we're randomly sleeping 2018-09-24 19:38:16 -07:00
Seth Schoen
c004789053 Update changelog 2018-09-24 16:59:01 -07:00
Seth Schoen
3c57f47856 WIP on adding a random sleep for noninteractive renewal 2018-09-24 16:56:30 -07:00
3 changed files with 37 additions and 1 deletions

View File

@@ -6,7 +6,9 @@ Certbot adheres to [Semantic Versioning](http://semver.org/).
### Added
*
* Noninteractive renewals with `certbot renew` (those not started from a
terminal) now randomly sleep 1-480 seconds before beginning work in
order to spread out load spikes on the server side.
### Changed

View File

@@ -4,7 +4,9 @@ from __future__ import print_function
import functools
import logging.handlers
import os
import random
import sys
import time
import configobj
import josepy as jose
@@ -1243,6 +1245,16 @@ def renew(config, unused_plugins):
:rtype: None
"""
if not sys.stdin.isatty():
# Noninteractive renewals include a random delay in order to spread
# out the load on the certificate authority servers, even if many
# users all pick the same time for renewals. This delay precedes
# running any hooks, so that side effects of the hooks (such as
# shutting down a web service) aren't prolonged unnecessarily.
sleep_time = random.randint(1, 60*8)
logger.info("Non-interactive renewal: random delay of %s seconds", sleep_time)
time.sleep(sleep_time)
try:
renewal.handle_renewal_request(config)
finally:

View File

@@ -520,6 +520,8 @@ class MainTest(test_util.ConfigTestCase): # pylint: disable=too-many-public-met
'--work-dir', self.config.work_dir,
'--logs-dir', self.config.logs_dir, '--text']
self.mock_sleep = mock.patch('time.sleep').start()
def tearDown(self):
# Reset globals in cli
reload_module(cli)
@@ -1092,6 +1094,26 @@ class MainTest(test_util.ConfigTestCase): # pylint: disable=too-many-public-met
args = ["renew", "--reuse-key"]
self._test_renewal_common(True, [], args=args, should_renew=True, reuse_key=True)
@mock.patch('sys.stdin')
def test_noninteractive_renewal_delay(self, stdin):
stdin.isatty.return_value = False
test_util.make_lineage(self.config.config_dir, 'sample-renewal.conf')
args = ["renew", "--dry-run", "-tvv"]
self._test_renewal_common(True, [], args=args, should_renew=True)
self.assertEqual(self.mock_sleep.call_count, 1)
# in main.py:
# sleep_time = random.randint(1, 60*8)
sleep_call_arg = self.mock_sleep.call_args[0][0]
self.assertTrue(1 <= sleep_call_arg <= 60*8)
@mock.patch('sys.stdin')
def test_interactive_no_renewal_delay(self, stdin):
stdin.isatty.return_value = True
test_util.make_lineage(self.config.config_dir, 'sample-renewal.conf')
args = ["renew", "--dry-run", "-tvv"]
self._test_renewal_common(True, [], args=args, should_renew=True)
self.assertEqual(self.mock_sleep.call_count, 0)
@mock.patch('certbot.renewal.should_renew')
def test_renew_skips_recent_certs(self, should_renew):
should_renew.return_value = False