Merge "Add further test cases to tox-remote"

This commit is contained in:
Zuul 2018-03-12 22:13:55 +00:00 committed by Gerrit Code Review
commit 108e074b78
57 changed files with 250 additions and 4 deletions

View File

@ -2006,6 +2006,11 @@ class BaseTestCase(testtools.TestCase):
pass
class SymLink(object):
def __init__(self, target):
self.target = target
class ZuulTestCase(BaseTestCase):
"""A test case with a functioning Zuul.
@ -2399,13 +2404,24 @@ class ZuulTestCase(BaseTestCase):
files = {}
for (dirpath, dirnames, filenames) in os.walk(source_path):
# Note: In case a symlink points to an already existing directory
# os.walk includes that in the dirnames list. In order to properly
# copy these links, just add them to the filenames list.
for dirname in dirnames:
test_tree_filepath = os.path.join(dirpath, dirname)
if os.path.islink(test_tree_filepath):
filenames.append(dirname)
for filename in filenames:
test_tree_filepath = os.path.join(dirpath, filename)
common_path = os.path.commonprefix([test_tree_filepath,
source_path])
relative_filepath = test_tree_filepath[len(common_path) + 1:]
with open(test_tree_filepath, 'r') as f:
content = f.read()
if os.path.islink(test_tree_filepath):
content = SymLink(os.readlink(test_tree_filepath))
else:
with open(test_tree_filepath, 'rb') as f:
content = f.read()
files[relative_filepath] = content
self.addCommitToRepo(project, 'add content from fixture',
files, branch='master', tag='init')
@ -2925,8 +2941,16 @@ class ZuulTestCase(BaseTestCase):
os.makedirs(os.path.dirname(fn))
except OSError:
pass
with open(fn, 'w') as f:
f.write(content)
if isinstance(content, SymLink):
os.symlink(content.target, fn)
else:
mode = 'w'
if isinstance(content, bytes):
# the file fixtures are loaded as bytes such that
# we also support binary files
mode = 'wb'
with open(fn, mode) as f:
f.write(content)
repo.index.add([fn])
commit = repo.index.commit(message)
before = repo.heads[branch].commit

BIN
tests/fixtures/bwrap-mounts/archive.tar vendored Normal file

Binary file not shown.

View File

@ -0,0 +1 @@
one

View File

@ -0,0 +1 @@
two

7
tests/fixtures/bwrap-mounts/patch vendored Normal file
View File

@ -0,0 +1,7 @@
diff --git a/readme.txt b/readme.txt
index 24308cb..b07f0ed 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1 +1 @@
-This is a readme
+This is a README

3
tests/fixtures/bwrap-mounts/script.sh vendored Normal file
View File

@ -0,0 +1,3 @@
#!/bin/sh
echo one

3
tests/fixtures/bwrap-mounts/vars.yaml vendored Normal file
View File

@ -0,0 +1,3 @@
---
some_var: one

View File

@ -0,0 +1,3 @@
---
first_var: one

View File

@ -0,0 +1,3 @@
---
second_var: two

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: assemble-test
src_file: symlink

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: assemble-test
src_file: /opt/assemble

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: assemble-test
src_file: dir

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: copy-test
src_file: symlink

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: includevarsdir-test
src_file: symlink

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: includevarsdir-test
src_file: /opt/vars

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: includevars-test
src_file: symlink.yaml

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: includevars-test
src_file: /opt/vars.yaml

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: includevarsdir-test
src_file: dir

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: includevars-test
src_file: vars.yaml

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: patch-test
src_file: symlink

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: patch-test
src_file: /opt/patch

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: patch-test
src_file: patch

View File

@ -0,0 +1,11 @@
- name: Create a destination directory for copied files
tempfile:
state: directory
register: destdir
- name: Assemble
assemble:
src: "{{src_file}}"
dest: "{{destdir.path}}/copy"
remote_src: no
regexp: resolv.conf

View File

@ -0,0 +1,2 @@
- name: Include vars
include_vars: "{{src_file}}"

View File

@ -0,0 +1,3 @@
- name: Include vars
include_vars:
dir: "{{src_file}}"

View File

@ -0,0 +1,7 @@
diff --git a/readme.txt b/readme.txt
index 24308cb..b07f0ed 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1 +1 @@
-This is a readme
+This is a README

View File

@ -0,0 +1,15 @@
- name: Create a destination directory for copied files
tempfile:
state: directory
register: destdir
- name: Copy readme
copy:
src: readme.txt
dest: "{{destdir.path}}/readme.txt"
- name: Patch
patch:
src: "{{src_file}}"
basedir: "{{destdir.path}}"
strip: 1

View File

@ -0,0 +1,3 @@
#!/bin/sh
echo one

View File

@ -0,0 +1,2 @@
- name: Script
script: "{{src_file}}"

View File

@ -0,0 +1,9 @@
- name: Create a destination directory for copied files
tempfile:
state: directory
register: destdir
- name: Copy
template:
src: "{{src_file}}"
dest: "{{destdir.path}}/template"

View File

@ -0,0 +1,9 @@
- name: Create a destination directory for copied files
tempfile:
state: directory
register: destdir
- name: Unarchive
copy:
src: "{{src_file}}"
dest: "{{destdir.path}}"

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: script-test
src_file: symlink

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: script-test
src_file: /opt/script.sh

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: script-test
src_file: script.sh

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: template-test
src_file: symlink

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: template-test
src_file: /opt/file

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: template-test
src_file: template

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: unarchive-test
src_file: symlink

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: unarchive-test
src_file: /opt/archive.tar

View File

@ -0,0 +1,4 @@
- hosts: all
roles:
- role: unarchive-test
src_file: archive.tar

View File

@ -68,6 +68,47 @@ class TestActionModules(AnsibleZuulTestCase):
build = self.history[-1]
self.assertEqual(build.result, result)
def test_assemble_module(self):
self._run_job('assemble-good', 'SUCCESS')
self._run_job('assemble-bad', 'FAILURE')
self._run_job('assemble-bad-symlink', 'FAILURE')
def test_copy_module(self):
self._run_job('copy-good', 'SUCCESS')
self._run_job('copy-bad', 'FAILURE')
self._run_job('copy-bad-symlink', 'FAILURE')
def test_includevars_module(self):
self._run_job('includevars-good', 'SUCCESS')
self._run_job('includevars-good-dir', 'SUCCESS')
self._run_job('includevars-bad', 'FAILURE')
self._run_job('includevars-bad-symlink', 'FAILURE')
self._run_job('includevars-bad-dir', 'FAILURE')
self._run_job('includevars-bad-dir-symlink', 'FAILURE')
def test_patch_module(self):
self._run_job('patch-good', 'SUCCESS')
self._run_job('patch-bad', 'FAILURE')
self._run_job('patch-bad-symlink', 'FAILURE')
def test_script_module(self):
self._run_job('script-good', 'SUCCESS')
self._run_job('script-bad', 'FAILURE')
self._run_job('script-bad-symlink', 'FAILURE')
def test_template_module(self):
self._run_job('template-good', 'SUCCESS')
self._run_job('template-bad', 'FAILURE')
self._run_job('template-bad-symlink', 'FAILURE')
def test_unarchive_module(self):
self._run_job('unarchive-good', 'SUCCESS')
self._run_job('unarchive-bad', 'FAILURE')
self._run_job('unarchive-bad-symlink', 'FAILURE')