blob: 1b377cd8e04b6c069bf81639777bc3752cd8a0ae [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={}):
41 defaults = {
42 'ZUUL_UUID': str(uuid.uuid1()),
43 'ZUUL_REF': 'a',
44 'ZUUL_COMMIT': 'a',
45 'ZUUL_PROJECT': 'a',
46 'ZUUL_PIPELINE': 'a',
47 'ZUUL_URL': 'http://localhost',
48 'BASE_LOG_PATH': '56/123456/8',
49 'LOG_PATH': '56/123456/8/check/job_name/uuid123'
50 }
51 defaults.update(data)
52 return defaults
53
54 def submit_job(self, name, data):
55 if not self.job:
56 self.job = gear.Job(name,
57 json.dumps(data),
58 unique=str(time.time()))
59 self.gearman.submitJob(self.job)
60 else:
61 raise Exception('A job already exists in self.job')
62
63 return self.job
64
65 def wait_for_completion(self):
66 if self.job:
67 while not self.job.complete:
68 time.sleep(0.1)