Run pre and post playbooks

This allows jobs to specify pre and post playbooks.  Jobs which inherit
from parents or variants add their pre and post playbooks to their
parents in onion fashion -- the outermost pre playbooks run first and post
playbooks run last.

Change-Id: Ic844dcac77d87481534745a220664d72be2ffa7c
diff --git a/tests/fixtures/config/ansible/git/common-config/playbooks/post.yaml b/tests/fixtures/config/ansible/git/common-config/playbooks/post.yaml
new file mode 100644
index 0000000..2e512b1
--- /dev/null
+++ b/tests/fixtures/config/ansible/git/common-config/playbooks/post.yaml
@@ -0,0 +1,5 @@
+- hosts: all
+  tasks:
+    - file:
+        path: "{{zuul._test.test_root}}/{{zuul.uuid}}.post.flag"
+        state: touch
diff --git a/tests/fixtures/config/ansible/git/common-config/playbooks/pre.yaml b/tests/fixtures/config/ansible/git/common-config/playbooks/pre.yaml
new file mode 100644
index 0000000..f4222ff
--- /dev/null
+++ b/tests/fixtures/config/ansible/git/common-config/playbooks/pre.yaml
@@ -0,0 +1,5 @@
+- hosts: all
+  tasks:
+    - file:
+        path: "{{zuul._test.test_root}}/{{zuul.uuid}}.pre.flag"
+        state: touch
diff --git a/tests/fixtures/config/ansible/git/common-config/zuul.yaml b/tests/fixtures/config/ansible/git/common-config/zuul.yaml
index f00eab7..7964243 100644
--- a/tests/fixtures/config/ansible/git/common-config/zuul.yaml
+++ b/tests/fixtures/config/ansible/git/common-config/zuul.yaml
@@ -38,3 +38,5 @@
 
 - job:
     name: python27
+    pre-run: pre
+    post-run: post
diff --git a/tests/unit/test_model.py b/tests/unit/test_model.py
index ae40416..a71dc28 100644
--- a/tests/unit/test_model.py
+++ b/tests/unit/test_model.py
@@ -94,6 +94,9 @@
         layout.addJob(python27diablo)
 
         project_config = configloader.ProjectParser.fromYaml(layout, {
+            '_source_project': project,
+            '_source_branch': 'master',
+            '_source_configrepo': True,
             'name': 'project',
             'gate': {
                 'jobs': [
@@ -247,6 +250,9 @@
         layout.addJob(python27diablo)
 
         project_config = configloader.ProjectParser.fromYaml(layout, {
+            '_source_project': project,
+            '_source_branch': 'master',
+            '_source_configrepo': True,
             'name': 'project',
             'gate': {
                 'jobs': [
@@ -309,6 +315,9 @@
         layout.addJob(python27)
 
         project_config = configloader.ProjectParser.fromYaml(layout, {
+            '_source_project': project,
+            '_source_branch': 'master',
+            '_source_configrepo': True,
             'name': 'project',
             'gate': {
                 'jobs': [
diff --git a/tests/unit/test_v3.py b/tests/unit/test_v3.py
index 31410fb..0ba5ff8 100644
--- a/tests/unit/test_v3.py
+++ b/tests/unit/test_v3.py
@@ -129,3 +129,9 @@
         self.assertEqual(build.result, 'SUCCESS')
         flag_path = os.path.join(self.test_root, build.uuid + '.flag')
         self.assertTrue(os.path.exists(flag_path))
+        pre_flag_path = os.path.join(self.test_root, build.uuid +
+                                     '.pre.flag')
+        self.assertTrue(os.path.exists(pre_flag_path))
+        post_flag_path = os.path.join(self.test_root, build.uuid +
+                                      '.post.flag')
+        self.assertTrue(os.path.exists(post_flag_path))