Allow loading additional variables file for site config
It would be useful to allow deployment specific configuration that can
be fed into the project-config deployments so that we can customize
things like host ip without having to change job definitions for each
site.
Also, add a method to display the build log from a failed assertion in
the Ansible test (this was used in the development of the tests for
this change).
Change-Id: I87e8bffc540bcafab543c46244f3d5327b56fcae
Co-Authored-By: James E. Blair <jeblair@redhat.com>
diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py
index fb80660..ad0b2cc 100644
--- a/tests/unit/test_v3.py
+++ b/tests/unit/test_v3.py
@@ -595,54 +595,70 @@
tenant_config_file = 'config/ansible/main.yaml'
def test_playbook(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
+ # Add a site variables file, used by check-vars
+ path = os.path.join(FIXTURE_DIR, 'config', 'ansible',
+ 'variables.yaml')
+ self.config.set('executor', 'variables', path)
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
self.fake_gerrit.addEvent(A.getPatchsetCreatedEvent(1))
self.waitUntilSettled()
build_timeout = self.getJobFromHistory('timeout')
- self.assertEqual(build_timeout.result, 'TIMED_OUT')
+ with self.jobLog(build_timeout):
+ self.assertEqual(build_timeout.result, 'TIMED_OUT')
build_faillocal = self.getJobFromHistory('faillocal')
- self.assertEqual(build_faillocal.result, 'FAILURE')
+ with self.jobLog(build_faillocal):
+ self.assertEqual(build_faillocal.result, 'FAILURE')
build_failpost = self.getJobFromHistory('failpost')
- self.assertEqual(build_failpost.result, 'POST_FAILURE')
+ with self.jobLog(build_failpost):
+ self.assertEqual(build_failpost.result, 'POST_FAILURE')
build_check_vars = self.getJobFromHistory('check-vars')
- self.assertEqual(build_check_vars.result, 'SUCCESS')
+ with self.jobLog(build_check_vars):
+ self.assertEqual(build_check_vars.result, 'SUCCESS')
build_hello = self.getJobFromHistory('hello-world')
- self.assertEqual(build_hello.result, 'SUCCESS')
+ with self.jobLog(build_hello):
+ self.assertEqual(build_hello.result, 'SUCCESS')
build_python27 = self.getJobFromHistory('python27')
- self.assertEqual(build_python27.result, 'SUCCESS')
- flag_path = os.path.join(self.test_root, build_python27.uuid + '.flag')
- self.assertTrue(os.path.exists(flag_path))
- copied_path = os.path.join(self.test_root, build_python27.uuid +
- '.copied')
- self.assertTrue(os.path.exists(copied_path))
- failed_path = os.path.join(self.test_root, build_python27.uuid +
- '.failed')
- self.assertFalse(os.path.exists(failed_path))
- pre_flag_path = os.path.join(self.test_root, build_python27.uuid +
- '.pre.flag')
- self.assertTrue(os.path.exists(pre_flag_path))
- post_flag_path = os.path.join(self.test_root, build_python27.uuid +
- '.post.flag')
- self.assertTrue(os.path.exists(post_flag_path))
- bare_role_flag_path = os.path.join(self.test_root,
- build_python27.uuid +
- '.bare-role.flag')
- self.assertTrue(os.path.exists(bare_role_flag_path))
+ with self.jobLog(build_python27):
+ self.assertEqual(build_python27.result, 'SUCCESS')
+ flag_path = os.path.join(self.test_root,
+ build_python27.uuid + '.flag')
+ self.assertTrue(os.path.exists(flag_path))
+ copied_path = os.path.join(self.test_root, build_python27.uuid +
+ '.copied')
+ self.assertTrue(os.path.exists(copied_path))
+ failed_path = os.path.join(self.test_root, build_python27.uuid +
+ '.failed')
+ self.assertFalse(os.path.exists(failed_path))
+ pre_flag_path = os.path.join(self.test_root, build_python27.uuid +
+ '.pre.flag')
+ self.assertTrue(os.path.exists(pre_flag_path))
+ post_flag_path = os.path.join(self.test_root, build_python27.uuid +
+ '.post.flag')
+ self.assertTrue(os.path.exists(post_flag_path))
+ bare_role_flag_path = os.path.join(self.test_root,
+ build_python27.uuid +
+ '.bare-role.flag')
+ self.assertTrue(os.path.exists(bare_role_flag_path))
+ secrets_path = os.path.join(self.test_root,
+ build_python27.uuid + '.secrets')
+ with open(secrets_path) as f:
+ self.assertEqual(f.read(), "test-username test-password")
- secrets_path = os.path.join(self.test_root,
- build_python27.uuid + '.secrets')
- with open(secrets_path) as f:
- self.assertEqual(f.read(), "test-username test-password")
-
- msg = A.messages[0]
- success = "{} https://success.example.com/zuul-logs/{}"
- fail = "{} https://failure.example.com/zuul-logs/{}"
- self.assertIn(success.format("python27", build_python27.uuid), msg)
- self.assertIn(fail.format("faillocal", build_faillocal.uuid), msg)
- self.assertIn(success.format("check-vars", build_check_vars.uuid), msg)
- self.assertIn(success.format("hello-world", build_hello.uuid), msg)
- self.assertIn(fail.format("timeout", build_timeout.uuid), msg)
- self.assertIn(fail.format("failpost", build_failpost.uuid), msg)
+ msg = A.messages[0]
+ success = "{} https://success.example.com/zuul-logs/{}"
+ fail = "{} https://failure.example.com/zuul-logs/{}"
+ self.assertIn(success.format("python27", build_python27.uuid), msg)
+ self.assertIn(fail.format("faillocal", build_faillocal.uuid), msg)
+ self.assertIn(success.format("check-vars",
+ build_check_vars.uuid), msg)
+ self.assertIn(success.format("hello-world", build_hello.uuid), msg)
+ self.assertIn(fail.format("timeout", build_timeout.uuid), msg)
+ self.assertIn(fail.format("failpost", build_failpost.uuid), msg)
class TestPrePlaybooks(AnsibleZuulTestCase):