diff options
author | Christian Ehrhardt <christian.ehrhardt@canonical.com> | 2016-06-07 09:09:58 +0200 |
---|---|---|
committer | Christian Ehrhardt <christian.ehrhardt@canonical.com> | 2016-06-07 09:09:58 +0200 |
commit | 3f4d7d4f1fd946b8b6c6c490cb284a58eb6f695e (patch) | |
tree | ddcd57ff793731428bbde6c4ee233d08dd5276be /tests/unittests/test_handler | |
parent | 1f05fd90f38b8ff1f1b2d6418030545d502b3965 (diff) | |
download | vyos-cloud-init-3f4d7d4f1fd946b8b6c6c490cb284a58eb6f695e.tar.gz vyos-cloud-init-3f4d7d4f1fd946b8b6c6c490cb284a58eb6f695e.zip |
harden mirrorfail tests for the fact that even good mirrors can fail
This might happen e.g. in locked down build environments.
In those cases this is detected and the test skipped while not giving up
testing it in more capable environments.
Diffstat (limited to 'tests/unittests/test_handler')
-rw-r--r-- | tests/unittests/test_handler/test_handler_apt_configure_sources_list.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/unittests/test_handler/test_handler_apt_configure_sources_list.py b/tests/unittests/test_handler/test_handler_apt_configure_sources_list.py index 20e61995..6e123af7 100644 --- a/tests/unittests/test_handler/test_handler_apt_configure_sources_list.py +++ b/tests/unittests/test_handler/test_handler_apt_configure_sources_list.py @@ -5,6 +5,24 @@ import logging import os import shutil import tempfile +import socket + +# on SkipTest: +# - unittest SkipTest is first preference, but it's only available +# for >= 2.7 +# - unittest2 SkipTest is second preference for older pythons. This +# mirrors logic for choosing SkipTest exception in testtools +# - if none of the above, provide custom class +try: + from unittest.case import SkipTest +except ImportError: + try: + from unittest2.case import SkipTest + except ImportError: + class SkipTest(Exception): + """Raise this exception to mark a test as skipped. + """ + pass try: from unittest import mock @@ -126,14 +144,28 @@ class TestAptSourceConfigSourceList(t_help.FilesystemMockingTestCase): """Test rendering of a source.list from template for ubuntu""" self.apt_source_list('ubuntu', 'http://archive.ubuntu.com/ubuntu/') + @staticmethod + def check_connectivity(target): + """try original gpg_recv_key, but allow fall back""" + testsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + testsock.settimeout(10) + try: + testsock.connect((target, 80)) + testsock.close() + except socket.error: + raise SkipTest("Test skipped: no network connectivity to %s" + % target) + def test_apt_srcl_debian_mirrorfail(self): """Test rendering of a source.list from template for debian""" + self.check_connectivity('httpredir.debian.org') self.apt_source_list('debian', ['http://does.not.exist', 'http://httpredir.debian.org/debian'], 'http://httpredir.debian.org/debian') def test_apt_srcl_ubuntu_mirrorfail(self): """Test rendering of a source.list from template for ubuntu""" + self.check_connectivity('archive.ubuntu.com') self.apt_source_list('ubuntu', ['http://does.not.exist', 'http://archive.ubuntu.com/ubuntu/'], 'http://archive.ubuntu.com/ubuntu/') |