Add zuul-stream remote tests

This tests zuul-stream using the 'remote' tests since many aspects
of zuul-stream require a remote node to be exercised.

Change-Id: I08edee6f9388faf13615c6dc310df7a94d0419b2
This commit is contained in:
James E. Blair 2018-03-20 14:47:04 -07:00
parent 09ef12843b
commit a51a9e7b8b
8 changed files with 184 additions and 0 deletions

View File

@ -0,0 +1,17 @@
- pipeline:
name: check
manager: independent
post-review: true
trigger:
gerrit:
- event: patchset-created
success:
gerrit:
Verified: 1
failure:
gerrit:
Verified: -1
- job:
name: base
parent: null

View File

@ -0,0 +1 @@
test

View File

@ -0,0 +1,16 @@
- hosts: all
tasks:
- name: Start zuul_console daemon
zuul_console:
- name: Create first file
copy:
content: "command test one\n"
dest: "{{ ansible_user_dir }}/command_test_file1"
- name: Create second file
copy:
content: "command test two\n"
dest: "{{ ansible_user_dir }}/command_test_file2"
- name: Show contents of first file
command: "cat {{ ansible_user_dir }}/command_test_file1"
- name: Show contents of second file
command: "cat {{ ansible_user_dir }}/command_test_file2"

View File

@ -0,0 +1,15 @@
#!/usr/bin/env python
def main():
print("This module is broken")
try:
from ansible.module_utils.basic import * # noqa
except ImportError:
pass
if __name__ == '__main__':
main()

View File

@ -0,0 +1,6 @@
- hosts: all
tasks:
- name: Start zuul_console daemon
zuul_console:
- name: Module failure
broken_module:

View File

@ -0,0 +1,4 @@
- project:
check:
jobs:
- noop

View File

@ -0,0 +1,8 @@
- tenant:
name: tenant-one
source:
gerrit:
config-projects:
- common-config
untrusted-projects:
- org/project

View File

@ -0,0 +1,117 @@
# Copyright 2018 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import re
import textwrap
from tests.base import AnsibleZuulTestCase
class TestZuulStream(AnsibleZuulTestCase):
tenant_config_file = 'config/remote-zuul-stream/main.yaml'
def setUp(self):
super(TestZuulStream, self).setUp()
self.fake_nodepool.remote_ansible = True
ansible_remote = os.environ.get('ZUUL_REMOTE_IPV4')
self.assertIsNotNone(ansible_remote)
def _run_job(self, job_name):
# Keep the jobdir around so we can inspect contents if an
# assert fails. It will be cleaned up anyway as it is contained
# in a tmp dir which gets cleaned up after the test.
self.executor_server.keep_jobdir = True
# Output extra ansible info so we might see errors.
self.executor_server.verbose = True
conf = textwrap.dedent(
"""
- job:
name: {job_name}
run: playbooks/{job_name}.yaml
roles:
- zuul: org/common-config
nodeset:
nodes:
- name: controller
label: whatever
- project:
check:
jobs:
- {job_name}
""".format(job_name=job_name))
file_dict = {'zuul.yaml': conf}
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
files=file_dict)
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
job = self.getJobFromHistory(job_name)
return job
def _get_job_output(self, build):
path = os.path.join(self.test_root, build.uuid,
'work', 'logs', 'job-output.txt')
with open(path) as f:
return f.read()
def assertLogLine(self, line, log):
pattern = ('^\d\d\d\d-\d\d-\d\d \d\d:\d\d\:\d\d\.\d\d\d\d\d\d \| %s$' %
line)
log_re = re.compile(pattern, re.MULTILINE)
m = log_re.search(log)
if m is None:
raise Exception("'%s' not found in log" % (line,))
def test_command(self):
job = self._run_job('command')
with self.jobLog(job):
build = self.history[-1]
self.assertEqual(build.result, 'SUCCESS')
text = self._get_job_output(build)
self.assertLogLine(
'RUN START: \[untrusted : review.example.com/org/project/'
'playbooks/command.yaml@master\]', text)
self.assertLogLine('PLAY \[all\]', text)
self.assertLogLine('TASK \[Show contents of first file\]', text)
self.assertLogLine('controller \| command test one', text)
self.assertLogLine(
'controller \| ok: Runtime: \d:\d\d:\d\d\.\d\d\d\d\d\d', text)
self.assertLogLine('TASK \[Show contents of second file\]', text)
self.assertLogLine('controller \| command test one', text)
self.assertLogLine(
'controller \| ok: Runtime: \d:\d\d:\d\d\.\d\d\d\d\d\d', text)
self.assertLogLine('PLAY RECAP', text)
self.assertLogLine(
'controller \| ok: 5 changed: \d unreachable: 0 failed: 0',
text)
self.assertLogLine(
'RUN END RESULT_NORMAL: \[untrusted : review.example.com/'
'org/project/playbooks/command.yaml@master]', text)
def test_module_failure(self):
job = self._run_job('module_failure')
with self.jobLog(job):
build = self.history[-1]
self.assertEqual(build.result, 'FAILURE')
text = self._get_job_output(build)
self.assertLogLine('TASK \[Module failure\]', text)
self.assertLogLine(
'controller \| MODULE FAILURE: This module is broken', text)