From 1e4384747dd968a698c408db962e68c4189e2390 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Tue, 13 Mar 2018 13:59:18 -0700 Subject: [PATCH] Add zuul_json tests This adds a test of zuul_json to the 'remote' test suite. We could probably test this aspect of zuul_json at least in the normal unit test suite, however, the streaming callback has some behavior which can only be tested remotely, and it might be nice for all of the callback tests to behave in the same way. Change-Id: If9aa0d65e60b011b0c69da582c9bdc2d2bb9a8a6 --- .../git/common-config/zuul.yaml | 17 ++++ .../remote-zuul-json/git/org_project/README | 1 + .../git/org_project/playbooks/no-log.yaml | 7 ++ .../git/org_project/zuul.yaml | 4 + .../config/remote-zuul-json/main.yaml | 8 ++ tests/remote/test_remote_zuul_json.py | 80 +++++++++++++++++++ 6 files changed, 117 insertions(+) create mode 100644 tests/fixtures/config/remote-zuul-json/git/common-config/zuul.yaml create mode 100644 tests/fixtures/config/remote-zuul-json/git/org_project/README create mode 100644 tests/fixtures/config/remote-zuul-json/git/org_project/playbooks/no-log.yaml create mode 100644 tests/fixtures/config/remote-zuul-json/git/org_project/zuul.yaml create mode 100644 tests/fixtures/config/remote-zuul-json/main.yaml create mode 100644 tests/remote/test_remote_zuul_json.py diff --git a/tests/fixtures/config/remote-zuul-json/git/common-config/zuul.yaml b/tests/fixtures/config/remote-zuul-json/git/common-config/zuul.yaml new file mode 100644 index 0000000000..a07342e2ec --- /dev/null +++ b/tests/fixtures/config/remote-zuul-json/git/common-config/zuul.yaml @@ -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 diff --git a/tests/fixtures/config/remote-zuul-json/git/org_project/README b/tests/fixtures/config/remote-zuul-json/git/org_project/README new file mode 100644 index 0000000000..9daeafb986 --- /dev/null +++ b/tests/fixtures/config/remote-zuul-json/git/org_project/README @@ -0,0 +1 @@ +test diff --git a/tests/fixtures/config/remote-zuul-json/git/org_project/playbooks/no-log.yaml b/tests/fixtures/config/remote-zuul-json/git/org_project/playbooks/no-log.yaml new file mode 100644 index 0000000000..8d2bdd4738 --- /dev/null +++ b/tests/fixtures/config/remote-zuul-json/git/org_project/playbooks/no-log.yaml @@ -0,0 +1,7 @@ +- hosts: all + tasks: + - debug: + msg: rosebud + - debug: + msg: setec astronomy + no_log: true diff --git a/tests/fixtures/config/remote-zuul-json/git/org_project/zuul.yaml b/tests/fixtures/config/remote-zuul-json/git/org_project/zuul.yaml new file mode 100644 index 0000000000..2a5dca97f2 --- /dev/null +++ b/tests/fixtures/config/remote-zuul-json/git/org_project/zuul.yaml @@ -0,0 +1,4 @@ +- project: + check: + jobs: + - noop diff --git a/tests/fixtures/config/remote-zuul-json/main.yaml b/tests/fixtures/config/remote-zuul-json/main.yaml new file mode 100644 index 0000000000..208e274b13 --- /dev/null +++ b/tests/fixtures/config/remote-zuul-json/main.yaml @@ -0,0 +1,8 @@ +- tenant: + name: tenant-one + source: + gerrit: + config-projects: + - common-config + untrusted-projects: + - org/project diff --git a/tests/remote/test_remote_zuul_json.py b/tests/remote/test_remote_zuul_json.py new file mode 100644 index 0000000000..1535f4b503 --- /dev/null +++ b/tests/remote/test_remote_zuul_json.py @@ -0,0 +1,80 @@ +# 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 textwrap + +from tests.base import AnsibleZuulTestCase + + +class TestZuulJSON(AnsibleZuulTestCase): + tenant_config_file = 'config/remote-zuul-json/main.yaml' + + def setUp(self): + super(TestZuulJSON, 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_json_as_text(self, build): + path = os.path.join(self.test_root, build.uuid, + 'work', 'logs', 'job-output.json') + with open(path) as f: + return f.read() + + def test_no_log(self): + job = self._run_job('no-log') + with self.jobLog(job): + build = self.history[-1] + self.assertEqual(build.result, 'SUCCESS') + + text = self._get_json_as_text(build) + self.assertIn('rosebud', text) + self.assertNotIn('setec', text)