Add some ansible plugin tests
This is not complete, but it's a start.
While doing this it became clear that the upstream csvfile lookup plugin does
not work in python3. Work around that by putting in a simpler version of
the code into our copy.
Change-Id: Ic84d8265e6fd7e15a0e5d66c781409a087d761d7
diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py
index 8555208..7038471 100755
--- a/tests/unit/test_v3.py
+++ b/tests/unit/test_v3.py
@@ -757,6 +757,54 @@
self.assertIn(fail.format("timeout", build_timeout.uuid), msg)
self.assertIn(fail.format("failpost", build_failpost.uuid), msg)
+ def _add_job(self, job_name):
+ conf = textwrap.dedent(
+ """
+ - job:
+ name: %s
+
+ - project:
+ name: org/plugin-project
+ check:
+ jobs:
+ - %s
+ """ % (job_name, job_name))
+
+ file_dict = {'.zuul.yaml': conf}
+ A = self.fake_gerrit.addFakeChange('org/plugin-project', 'master', 'A',
+ files=file_dict)
+ self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
+ self.waitUntilSettled()
+
+ def test_plugins(self):
+ # Keep the jobdir around so we can inspect contents if an
+ # assert fails.
+ self.executor_server.keep_jobdir = True
+ # Output extra ansible info so we might see errors.
+ self.executor_server.verbose = True
+
+ count = 0
+ plugin_tests = [
+ ('passwd', 'FAILURE'),
+ ('cartesian', 'SUCCESS'),
+ ('consul_kv', 'FAILURE'),
+ ('credstash', 'FAILURE'),
+ ('csvfile_good', 'SUCCESS'),
+ ('csvfile_bad', 'FAILURE'),
+ ]
+ for job_name, result in plugin_tests:
+ count += 1
+ self._add_job(job_name)
+
+ job = self.getJobFromHistory(job_name)
+ with self.jobLog(job):
+ self.assertEqual(count, len(self.history))
+ build = self.history[-1]
+ self.assertEqual(build.result, result)
+
+ # TODOv3(jeblair): parse the ansible output and verify we're
+ # getting the exception we expect.
+
class TestPrePlaybooks(AnsibleZuulTestCase):
# A temporary class to hold new tests while others are disabled