Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/certbot/certbot.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrien Ferrand <adferrand@users.noreply.github.com>2019-03-02 00:18:06 +0300
committerohemorange <ebportnoy@gmail.com>2019-03-02 00:18:06 +0300
commit841f8efd0aa7dc2ba249b303e6be664d0a6647e3 (patch)
tree6d1408e31198fb6d743eb6caa8b3a3ee8775fc98 /certbot-ci/certbot_integration_tests/utils/misc.py
parentefc8d49806b14a31d88cfc0f1b6daca1dd373d8d (diff)
[Unix] Create a framework for certbot integration tests: PART 1 (#6578)
* First part * Several optimizations about the docker env setup * Documentation * Various corrections and documentation. Add acme and certbot explicitly as dependencies of certbot-ci. * Correct a variable misinterpreted as a pytest hook * Correct strict parsing option on pebble * Refactor acme setup to be executed from pytest hooks. * Pass TRAVIS env variable to trigger specific xdist logic * Retrigger build. * Work in progress * Config operational * Propagate to xdist * Corrections on acme and misc * Correct subnet for pebble * Remove gobetween, as tls-sni challenges are not tested anymore. * Improve pebble setup. Reduce LOC. * Update acme.py * Optimize acme ca setup, with less temporary assets * Silent setup * Clean code * Remove unused workspace * Use default network driver * Remove bridge * Update package documentation * Remove rerun capability for integration tests, not needed. * Add documentation * Variable for all ports and subnets used by the stack * Update certbot-ci/certbot_integration_tests/conftest.py Co-Authored-By: adferrand <adferrand@users.noreply.github.com> * Update certbot-ci/certbot_integration_tests/utils/acme.py Co-Authored-By: adferrand <adferrand@users.noreply.github.com> * Update certbot-ci/certbot_integration_tests/utils/misc.py Co-Authored-By: adferrand <adferrand@users.noreply.github.com> * Update tox.ini Co-Authored-By: adferrand <adferrand@users.noreply.github.com> * Update certbot-ci/certbot_integration_tests/utils/misc.py Co-Authored-By: adferrand <adferrand@users.noreply.github.com> * Update certbot-ci/certbot_integration_tests/utils/acme.py Co-Authored-By: adferrand <adferrand@users.noreply.github.com> * Update certbot-ci/certbot_integration_tests/utils/acme.py Co-Authored-By: adferrand <adferrand@users.noreply.github.com> * Update certbot-ci/certbot_integration_tests/conftest.py Co-Authored-By: adferrand <adferrand@users.noreply.github.com> * Rename to acme_server * Add comment * Refactor in a unique context fixture * Remove the need of CERTBOT_ACME_XDIST environment variable * Remove nonstrict/strict options in pebble * Clean dependencies * Clean tox * Change function name * Add comment about coveragerc specificities * Change a comment. * Update setup.py * Update conftest.py * Use the production-ready docker-compose.yml file for Pebble * New style class * Tune pebble to have a stable test environment * Pin a dependency
Diffstat (limited to 'certbot-ci/certbot_integration_tests/utils/misc.py')
-rw-r--r--certbot-ci/certbot_integration_tests/utils/misc.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/certbot-ci/certbot_integration_tests/utils/misc.py b/certbot-ci/certbot_integration_tests/utils/misc.py
new file mode 100644
index 000000000..a3b134788
--- /dev/null
+++ b/certbot-ci/certbot_integration_tests/utils/misc.py
@@ -0,0 +1,45 @@
+"""
+Misc module contains stateless functions that could be used during pytest execution,
+or outside during setup/teardown of the integration tests environment.
+"""
+import os
+import time
+import contextlib
+
+import requests
+
+
+def check_until_timeout(url):
+ """
+ Wait and block until given url responds with status 200, or raise an exception
+ after 150 attempts.
+ :param str url: the URL to test
+ :raise ValueError: exception raised after 150 unsuccessful attempts to reach the URL
+ """
+ import urllib3
+ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
+
+ for _ in range(0, 150):
+ time.sleep(1)
+ try:
+ if requests.get(url, verify=False).status_code == 200:
+ return
+ except requests.exceptions.ConnectionError:
+ pass
+
+ raise ValueError('Error, url did not respond after 150 attempts: {0}'.format(url))
+
+
+@contextlib.contextmanager
+def execute_in_given_cwd(cwd):
+ """
+ Context manager that will execute any command in the given cwd after entering context,
+ and restore current cwd when context is destroyed.
+ :param str cwd: the path to use as the temporary current workspace for python execution
+ """
+ current_cwd = os.getcwd()
+ try:
+ os.chdir(cwd)
+ yield
+ finally:
+ os.chdir(current_cwd)