Skip to content

Commit

Permalink
cloud_tests: emit dots on Travis while fetching images
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
OddBloke committed May 6, 2020
1 parent 73d8748 commit bed65fa
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ matrix:
- sudo -E su $USER -c 'mk-sbuild xenial'
- sudo -E su $USER -c 'sbuild --nolog --verbose --dist=xenial cloud-init_*.dsc'
# Ubuntu LTS: Integration
- travis_wait 30 sg lxd -c 'tox -e citest -- run --verbose --preserve-data --data-dir results --os-name xenial --test modules/apt_configure_sources_list.yaml --test modules/ntp_servers --test modules/set_password_list --test modules/user_groups --deb cloud-init_*_all.deb'
- sg lxd -c 'tox -e citest -- run --verbose --preserve-data --data-dir results --os-name xenial --test modules/apt_configure_sources_list.yaml --test modules/ntp_servers --test modules/set_password_list --test modules/user_groups --deb cloud-init_*_all.deb'
- python: 3.5
env:
TOXENV=xenial
Expand Down
4 changes: 3 additions & 1 deletion tests/cloud_tests/platforms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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,
Expand All @@ -17,7 +18,8 @@

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):
Expand Down
33 changes: 33 additions & 0 deletions tests/cloud_tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
import base64
import copy
import glob
import multiprocessing
import os
import random
import shlex
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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,6 @@ deps =
[testenv:citest]
basepython = python3
commands = {envpython} -m tests.cloud_tests {posargs}
passenv = HOME
passenv = HOME TRAVIS
deps =
-r{toxinidir}/integration-requirements.txt

0 comments on commit bed65fa

Please sign in to comment.