summaryrefslogtreecommitdiff
path: root/tests/cloud_tests
diff options
context:
space:
mode:
authorDaniel Watkins <oddbloke@ubuntu.com>2020-05-14 09:27:44 -0400
committerGitHub <noreply@github.com>2020-05-14 09:27:44 -0400
commit089408751cdbd7950f58616f9d85ff9dfd9aa3c7 (patch)
tree376b9e7663eb82e84d5129c1dc04e6fce4904dff /tests/cloud_tests
parent2e32c40a607250bc9e713c0daf360dc6617f4420 (diff)
downloadvyos-cloud-init-089408751cdbd7950f58616f9d85ff9dfd9aa3c7.tar.gz
vyos-cloud-init-089408751cdbd7950f58616f9d85ff9dfd9aa3c7.zip
cloud_tests: emit dots on Travis while fetching images (#347)
This ensures that Travis will not kill our tests if fetching images is taking a long time. In implementation terms, this introduces a context manager which will spin up a multiprocessing.Process in the background and print a dot to stdout every 10 seconds. The process is terminated when the context manager exits. This also drop the use of travis_wait, which was being used to work around this issue.
Diffstat (limited to 'tests/cloud_tests')
-rw-r--r--tests/cloud_tests/platforms/__init__.py4
-rw-r--r--tests/cloud_tests/util.py33
2 files changed, 36 insertions, 1 deletions
diff --git a/tests/cloud_tests/platforms/__init__.py b/tests/cloud_tests/platforms/__init__.py
index 6a410b84..e506baa0 100644
--- a/tests/cloud_tests/platforms/__init__.py
+++ b/tests/cloud_tests/platforms/__init__.py
@@ -6,6 +6,7 @@ from .ec2 import platform as ec2
from .lxd import platform as lxd
from .nocloudkvm import platform as nocloudkvm
from .azurecloud import platform as azurecloud
+from ..util import emit_dots_on_travis
PLATFORMS = {
'ec2': ec2.EC2Platform,
@@ -17,7 +18,8 @@ PLATFORMS = {
def get_image(platform, config):
"""Get image from platform object using os_name."""
- return platform.get_image(config)
+ with emit_dots_on_travis():
+ return platform.get_image(config)
def get_instance(snapshot, *args, **kwargs):
diff --git a/tests/cloud_tests/util.py b/tests/cloud_tests/util.py
index 06f7d865..e65771b1 100644
--- a/tests/cloud_tests/util.py
+++ b/tests/cloud_tests/util.py
@@ -5,6 +5,7 @@
import base64
import copy
import glob
+import multiprocessing
import os
import random
import shlex
@@ -12,7 +13,9 @@ import shutil
import string
import subprocess
import tempfile
+import time
import yaml
+from contextlib import contextmanager
from cloudinit import util as c_util
from tests.cloud_tests import LOG
@@ -118,6 +121,36 @@ def current_verbosity():
return max(min(3 - int(LOG.level / 10), 2), 0)
+@contextmanager
+def emit_dots_on_travis():
+ """
+ A context manager that emits a dot every 10 seconds if running on Travis.
+
+ Travis will kill jobs that don't emit output for a certain amount of time.
+ This context manager spins up a background process which will emit a dot to
+ stdout every 10 seconds to avoid being killed.
+
+ It should be wrapped selectively around operations that are known to take a
+ long time.
+ """
+ if os.environ.get('TRAVIS') != "true":
+ # If we aren't on Travis, don't do anything.
+ yield
+ return
+
+ def emit_dots():
+ while True:
+ print(".")
+ time.sleep(10)
+
+ dot_process = multiprocessing.Process(target=emit_dots)
+ dot_process.start()
+ try:
+ yield
+ finally:
+ dot_process.terminate()
+
+
def is_writable_dir(path):
"""Make sure dir is writable.