diff --git a/roles/tox/library/test-constraints.txt b/roles/tox/library/test-constraints.txt new file mode 100644 index 000000000..d2c6e43fe --- /dev/null +++ b/roles/tox/library/test-constraints.txt @@ -0,0 +1,2 @@ +zuul===3.12.0 +doesnotexistonpypi===0.0.1 diff --git a/roles/tox/library/test_tox_install_sibling_packages.py b/roles/tox/library/test_tox_install_sibling_packages.py index 6b145c28a..8ab245c8f 100644 --- a/roles/tox/library/test_tox_install_sibling_packages.py +++ b/roles/tox/library/test_tox_install_sibling_packages.py @@ -18,10 +18,12 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +import os import sys import testtools from .tox_install_sibling_packages import get_installed_packages +from .tox_install_sibling_packages import write_new_constraints_file class TestToxInstallSiblingPackages(testtools.TestCase): @@ -35,3 +37,27 @@ class TestToxInstallSiblingPackages(testtools.TestCase): # but this might fail later if we stop adding Zuul # in the unit tests. self.assertIn("zuul", pkgs) + + def test_write_new_constraints_file(self): + # NOTE(mnaser): Given that we run our tests inside Tox, we can + # leverage the tox virtual environment we use in + # unit tests instead of mocking up everything. + pkgs = get_installed_packages(sys.executable) + + # NOTE(mnaser): Zuul should be installed in this virtualenv + # but this might fail later if we stop adding Zuul + # in the unit tests. + test_constraints = os.path.join(os.path.dirname(__file__), + 'test-constraints.txt') + constraints = write_new_constraints_file(test_constraints, pkgs) + + def cleanup_constraints_file(): + if os.path.exists(constraints): + os.unlink(constraints) + self.addCleanup(cleanup_constraints_file) + + self.assertTrue(os.path.exists(constraints)) + with open(constraints) as f: + s = f.read() + self.assertNotIn("zuul", s) + self.assertIn("doesnotexistonpypi", s) diff --git a/roles/tox/library/tox_install_sibling_packages.py b/roles/tox/library/tox_install_sibling_packages.py index abec207e6..915186c1b 100644 --- a/roles/tox/library/tox_install_sibling_packages.py +++ b/roles/tox/library/tox_install_sibling_packages.py @@ -121,7 +121,8 @@ def get_installed_packages(tox_python): def write_new_constraints_file(constraints, packages): - with tempfile.NamedTemporaryFile(delete=False) as constraints_file: + with tempfile.NamedTemporaryFile(mode='w', delete=False) \ + as constraints_file: constraints_lines = open(constraints, 'r').read().split('\n') for line in constraints_lines: package_name = line.split('===')[0] diff --git a/test-playbooks/tox-siblings.yaml b/test-playbooks/tox-siblings.yaml new file mode 100644 index 000000000..3cf5e0686 --- /dev/null +++ b/test-playbooks/tox-siblings.yaml @@ -0,0 +1,11 @@ +- hosts: all + tasks: + - name: Run bindep + include_role: + name: bindep + - name: Run tox with constraints + include_role: + name: tox + vars: + tox_envlist: docs + tox_constraints_file: '{{ zuul.project.src_dir }}/zuul-tests.d/test-constraints.txt' diff --git a/zuul-tests.d/python-jobs.yaml b/zuul-tests.d/python-jobs.yaml index 4b9485532..79f987c26 100644 --- a/zuul-tests.d/python-jobs.yaml +++ b/zuul-tests.d/python-jobs.yaml @@ -7,6 +7,16 @@ vars: role_name: ensure-sphinx +- job: + name: zuul-jobs-test-tox-siblings + description: Test the tox role's sibling functionality + files: + - roles/tox/.* + run: test-playbooks/tox-siblings.yaml + required-projects: + - zuul/zuul + - zuul/nodepool + # -* AUTOGENERATED *- # The following project section is autogenerated by # tools/update-test-platforms.py @@ -16,5 +26,6 @@ check: jobs: &id001 - zuul-jobs-test-ensure-sphinx + - zuul-jobs-test-tox-siblings gate: jobs: *id001 diff --git a/zuul-tests.d/test-constraints.txt b/zuul-tests.d/test-constraints.txt new file mode 100644 index 000000000..8b0f3353f --- /dev/null +++ b/zuul-tests.d/test-constraints.txt @@ -0,0 +1,3 @@ +nodepool===3.10.0 +zuul===3.12.0 +openstacksdk==0.39.0