JJB runner POC
The initial work to support running job instructions pulled in from
jenkins-job-builder config.
Because the XML is tightly coupled with JJB it's easier to use
xmltodict at this point. Ideally a new interpreter for JJB formatted
files to turbo-hipster instructions could be made.
At the moment we're ignoring JJB instructions from items we aren't
interested in (for example, publishers and build wrappers). Some
level of support should be added later for these or the job
instructions should be updated to not use them.
Change-Id: I0560d8e0a7e33548bacee3aa98bd45a5907bec21
diff --git a/tests/etc/jjb-config.yaml b/tests/etc/jjb-config.yaml
new file mode 100644
index 0000000..bcc341c
--- /dev/null
+++ b/tests/etc/jjb-config.yaml
@@ -0,0 +1,21 @@
+zuul_server:
+ gerrit_site: http://review.openstack.org
+ zuul_site: http://119.9.13.90
+ git_origin: git://git.openstack.org/
+ gearman_host: localhost
+ gearman_port: 0
+
+debug_log: /var/log/turbo-hipster/debug.log
+jobs_working_dir: /var/lib/turbo-hipster/jobs
+git_working_dir: /var/lib/turbo-hipster/git
+pip_download_cache: /var/cache/pip
+
+plugins:
+ - name: jjb_runner
+ function: build:gate-turbo-hipster-pep8
+ jjb_config: modules/openstack_project/files/jenkins_job_builder/config
+
+publish_logs:
+ type: local
+ path: /var/lib/turbo_hipster/logs
+ prepend_url: http://mylogserver/
\ No newline at end of file
diff --git a/tests/fakes.py b/tests/fakes.py
index 1b377cd..07e5eeb 100644
--- a/tests/fakes.py
+++ b/tests/fakes.py
@@ -38,15 +38,16 @@
self.job = None
def make_zuul_data(self, data={}):
+ job_uuid = str(uuid.uuid1())
defaults = {
- 'ZUUL_UUID': str(uuid.uuid1()),
+ 'ZUUL_UUID': job_uuid,
'ZUUL_REF': 'a',
'ZUUL_COMMIT': 'a',
'ZUUL_PROJECT': 'a',
'ZUUL_PIPELINE': 'a',
'ZUUL_URL': 'http://localhost',
'BASE_LOG_PATH': '56/123456/8',
- 'LOG_PATH': '56/123456/8/check/job_name/uuid123'
+ 'LOG_PATH': '56/123456/8/check/job_name/%s' % job_uuid
}
defaults.update(data)
return defaults
diff --git a/tests/test_jjb_runner.py b/tests/test_jjb_runner.py
new file mode 100644
index 0000000..fd60eb7
--- /dev/null
+++ b/tests/test_jjb_runner.py
@@ -0,0 +1,66 @@
+# Copyright 2014 Rackspace Australia
+#
+# 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 base
+import fakes
+import fixtures
+import json
+import logging
+import os
+import uuid
+
+from turbo_hipster.lib import utils
+
+
+class TestTaskRunner(base.TestWithGearman):
+ log = logging.getLogger("TestTaskRunner")
+
+ def setUp(self):
+ super(TestTaskRunner, self).setUp()
+ # Grab a copy of JJB's config
+ temp_path = self.useFixture(fixtures.TempDir()).path
+ cmd = 'git clone git://git.openstack.org/openstack-infra/config'
+ utils.execute_to_log(cmd, '/dev/null', cwd=temp_path)
+ self.jjb_config_dir = os.path.join(
+ temp_path, 'config',
+ 'modules/openstack_project/files/jenkins_job_builder/config'
+ )
+
+ def test_job_can_shutdown_th(self):
+ self._load_config_fixture('jjb-config.yaml')
+ # set jjb_config to pulled in config
+ self.config['plugins'][0]['jjb_config'] = self.jjb_config_dir
+
+ self.start_server()
+ zuul = fakes.FakeZuul(self.config['zuul_server']['gearman_host'],
+ self.config['zuul_server']['gearman_port'])
+
+ job_uuid = str(uuid.uuid1())[:8]
+ data_req = {
+ 'ZUUL_UUID': job_uuid,
+ 'ZUUL_PROJECT': 'stackforge/turbo-hipster',
+ 'ZUUL_PIPELINE': 'check',
+ 'ZUUL_URL': 'git://git.openstack.org/',
+ 'BRANCH': 'master',
+ 'BASE_LOG_PATH': '56/123456/8',
+ 'LOG_PATH': '56/123456/8/check/job_name/%s' % job_uuid
+ }
+
+ zuul.submit_job('build:gate-turbo-hipster-pep8', data_req)
+ zuul.wait_for_completion()
+
+ self.assertTrue(zuul.job.complete)
+ last_data = json.loads(zuul.job.data[-1])
+ self.log.debug(last_data)
+ self.assertEqual("SUCCESS", last_data['result'])
diff --git a/tests/test_utils.py b/tests/test_utils.py
index dcaec8f..4965c03 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -48,7 +48,7 @@
print d
self.assertNotEqual('', d)
- self.assertEqual(3, len(d.split('\n')))
+ self.assertEqual(4, len(d.split('\n')))
self.assertNotEqual(-1, d.find('yay'))
self.assertNotEqual(-1, d.find('[script exit code = 0]'))