blob: 07e5eeb6bd4c7813c4974e4e92e2cd097f2fa44b [file] [log] [blame]
Joshua Hesketh66f9f602013-08-14 11:28:10 +10001#!/usr/bin/python2
2#
3# Copyright 2013 Rackspace Australia
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
Joshua Hesketh96adb282014-03-25 16:26:45 +110017import gear
18import json
19import time
20import uuid
21
Joshua Heskethe095c8c2014-01-16 19:19:34 +110022
23class FakeJob(object):
24 def __init__(self):
25 pass
26
27 def sendWorkStatus(self, *args, **kwargs):
28 pass
Joshua Hesketh96adb282014-03-25 16:26:45 +110029
30
31class FakeZuul(object):
32 """A fake zuul/gearman client to request work from gearman and check
33 results"""
34 def __init__(self, server, port):
35 self.gearman = gear.Client('FakeZuul')
36 self.gearman.addServer(server, port)
37 self.gearman.waitForServer()
38 self.job = None
39
40 def make_zuul_data(self, data={}):
Joshua Hesketh96052bf2014-04-05 19:48:06 +110041 job_uuid = str(uuid.uuid1())
Joshua Hesketh96adb282014-03-25 16:26:45 +110042 defaults = {
Joshua Hesketh96052bf2014-04-05 19:48:06 +110043 'ZUUL_UUID': job_uuid,
Joshua Hesketh96adb282014-03-25 16:26:45 +110044 'ZUUL_REF': 'a',
45 'ZUUL_COMMIT': 'a',
46 'ZUUL_PROJECT': 'a',
47 'ZUUL_PIPELINE': 'a',
48 'ZUUL_URL': 'http://localhost',
49 'BASE_LOG_PATH': '56/123456/8',
Joshua Hesketh96052bf2014-04-05 19:48:06 +110050 'LOG_PATH': '56/123456/8/check/job_name/%s' % job_uuid
Joshua Hesketh96adb282014-03-25 16:26:45 +110051 }
52 defaults.update(data)
53 return defaults
54
55 def submit_job(self, name, data):
56 if not self.job:
57 self.job = gear.Job(name,
58 json.dumps(data),
59 unique=str(time.time()))
60 self.gearman.submitJob(self.job)
61 else:
62 raise Exception('A job already exists in self.job')
63
64 return self.job
65
66 def wait_for_completion(self):
67 if self.job:
68 while not self.job.complete:
69 time.sleep(0.1)