Repository: fedora-infra/bodhi

Issue:
The CI yaml file is invalid yaml
I noticed today that our CentOS CI service jobs have been failing for a week or two due to the yaml being invalid:

```
>>> with open('devel/ci/githubprb-project.yml') as yml:
...     a = yaml.load(yml.read())                                                                                      
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/usr/lib64/python2.7/site-packages/yaml/__init__.py", line 71, in load
    return loader.get_single_data()
  File "/usr/lib64/python2.7/site-packages/yaml/constructor.py", line 37, in get_single_data
    node = self.get_single_node()
  File "/usr/lib64/python2.7/site-packages/yaml/composer.py", line 36, in get_single_node
    document = self.compose_document()
  File "/usr/lib64/python2.7/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/usr/lib64/python2.7/site-packages/yaml/composer.py", line 82, in compose_node
    node = self.compose_sequence_node(anchor)
  File "/usr/lib64/python2.7/site-packages/yaml/composer.py", line 111, in compose_sequence_node
    node.value.append(self.compose_node(node, index))
  File "/usr/lib64/python2.7/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/usr/lib64/python2.7/site-packages/yaml/composer.py", line 133, in compose_mapping_node
    item_value = self.compose_node(node, item_key)
  File "/usr/lib64/python2.7/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/usr/lib64/python2.7/site-packages/yaml/composer.py", line 133, in compose_mapping_node
    item_value = self.compose_node(node, item_key)
  File "/usr/lib64/python2.7/site-packages/yaml/composer.py", line 82, in compose_node
    node = self.compose_sequence_node(anchor)
  File "/usr/lib64/python2.7/site-packages/yaml/composer.py", line 111, in compose_sequence_node
    node.value.append(self.compose_node(node, index))
  File "/usr/lib64/python2.7/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/usr/lib64/python2.7/site-packages/yaml/composer.py", line 133, in compose_mapping_node
    item_value = self.compose_node(node, item_key)
  File "/usr/lib64/python2.7/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/usr/lib64/python2.7/site-packages/yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
  File "/usr/lib64/python2.7/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  File "/usr/lib64/python2.7/site-packages/yaml/parser.py", line 428, in parse_block_mapping_key
    if self.check_token(KeyToken):
  File "/usr/lib64/python2.7/site-packages/yaml/scanner.py", line 116, in check_token
    self.fetch_more_tokens()
  File "/usr/lib64/python2.7/site-packages/yaml/scanner.py", line 220, in fetch_more_tokens
    return self.fetch_value()
  File "/usr/lib64/python2.7/site-packages/yaml/scanner.py", line 576, in fetch_value
    self.get_mark())
yaml.scanner.ScannerError: mapping values are not allowed here
  in "<string>", line 20, column 99:
     ... ase review the Jenkins job. Hint: You can search for "JENKIES FA ... 
                                         ^
```

I personally am responsible, when I made https://github.com/fedora-infra/bodhi/commit/791d4e3ea98d252daa6fb4856cb394eb8b07d0b3. Shame!

Anywyays, it's easy to fix and we should add a test that ensures the YAML is at least parseable.


Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -86,6 +86,7 @@ def get_requirements(requirements_file='requirements.txt'):
         'flake8',
         'pytest',
         'pytest-cov',
+        'pyyaml',
         'webtest',
         'mock',
     ],


Test patch:
diff --git a/bodhi/tests/test_ci.py b/bodhi/tests/test_ci.py
new file mode 100644
--- /dev/null
+++ b/bodhi/tests/test_ci.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+# Copyright © 2017 Red Hat, Inc.
+#
+# This file is part of Bodhi.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+"""This module contains tests for the CI yaml file."""
+import os
+import unittest
+
+import yaml
+
+from bodhi.tests.server import base
+
+
+class YAMLLoadTest(unittest.TestCase):
+    """Ensure that the JJB template is parseable YAML."""
+    def test_failure_comment(self):
+        """Ensure that the failure-comment is properly parsed."""
+        with open(os.path.join(base.PROJECT_PATH, 'devel/ci/githubprb-project.yml')) as jjb_f:
+            jjb = jjb_f.read()
+
+        jjb = yaml.safe_load(jjb)
+
+        self.assertEqual(
+            jjb[0]['trigger']['triggers'][0]['github-pull-request']['failure-comment'],
+            ('This pull request fails CI testing. Please review the Jenkins job. Hint: You can '
+             'search for "JENKIES FAIL" in the console output to quickly find errors.'))