Fix python3 compat in tox siblings handling
This fixes a byte vs str problem on python3 in the tox role's sibling library. As part of this fix add unit testing of the function that was failing under python3 and functional testing of the role that covers siblings. Change-Id: I2df4ddce91dfd53f5c4177a19288e97120bc3e3b
This commit is contained in:
parent
641baedc4c
commit
f418a8d533
2
roles/tox/library/test-constraints.txt
Normal file
2
roles/tox/library/test-constraints.txt
Normal file
@ -0,0 +1,2 @@
|
||||
zuul===3.12.0
|
||||
doesnotexistonpypi===0.0.1
|
@ -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)
|
||||
|
@ -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]
|
||||
|
11
test-playbooks/tox-siblings.yaml
Normal file
11
test-playbooks/tox-siblings.yaml
Normal file
@ -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'
|
@ -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
|
||||
|
3
zuul-tests.d/test-constraints.txt
Normal file
3
zuul-tests.d/test-constraints.txt
Normal file
@ -0,0 +1,3 @@
|
||||
nodepool===3.10.0
|
||||
zuul===3.12.0
|
||||
openstacksdk==0.39.0
|
Loading…
Reference in New Issue
Block a user