From b0954652c69543d2abd8cb17a9f7070a011e18d6 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Fri, 1 Jun 2012 11:32:01 -0700 Subject: [PATCH] Add meta-jobs. If a job is named with a regex starting with ^, treat it as a meta-job and apply its attributes to matching jobs. Explicitly set attributes on normal job definitions will override those set by a meta job. This should reduce the need to copy/paste error messages for some common jobs. Change-Id: I4362f4892d1c60514fbaa9092ecd8b44493c7421 --- zuul/model.py | 5 +++++ zuul/scheduler.py | 32 +++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/zuul/model.py b/zuul/model.py index 5a630d9363..c8cfc3bd2a 100644 --- a/zuul/model.py +++ b/zuul/model.py @@ -67,6 +67,11 @@ class Job(object): def __repr__(self): return '' % (self.name) + def copy(self, other): + self.failure_message = other.failure_message + self.success_message = other.failure_message + self.event_filters = other.event_filters[:] + class Build(object): def __init__(self, job, uuid): diff --git a/zuul/scheduler.py b/zuul/scheduler.py index 9a0afe4d90..1a24d7d015 100644 --- a/zuul/scheduler.py +++ b/zuul/scheduler.py @@ -16,6 +16,7 @@ import os import Queue import threading import logging +import re import yaml from model import Job, Change, Project, ChangeQueue, EventFilter @@ -39,6 +40,7 @@ class Scheduler(threading.Thread): self.queue_managers = {} self.jobs = {} self.projects = {} + self.metajobs = {} def _parseConfig(self, fp): def toList(item): @@ -74,15 +76,18 @@ class Scheduler(threading.Thread): for config_job in data['jobs']: job = self.getJob(config_job['name']) - job.failure_message = config_job.get('failure-message', None) - job.success_message = config_job.get('success-message', None) - silent = config_job.get('silent', None) - if silent: - job.silent = True + # Be careful to only set attributes explicitly present on + # this job, to avoid squashing attributes set by a meta-job. + m = config_job.get('failure-message', None) + if m: + job.failure_message = m + m = config_job.get('success-message', None) + if m: + job.success_message = m branches = toList(config_job.get('branch')) if branches: f = EventFilter(branches=branches) - job.event_filters.append(f) + job.event_filters = [f] def add_jobs(job_tree, config_jobs): for job in config_jobs: @@ -105,6 +110,10 @@ class Scheduler(threading.Thread): config_jobs = config_project[qname] add_jobs(job_tree, config_jobs) + # All jobs should be defined at this point, get rid of + # metajobs so that getJob isn't doing anything weird. + self.metajobs = {} + # TODO(jeblair): check that we don't end up with jobs like # "foo - bar" because a ':' is missing in the yaml for a dependent job for manager in self.queue_managers.values(): @@ -114,7 +123,16 @@ class Scheduler(threading.Thread): if name in self.jobs: return self.jobs[name] job = Job(name) - self.jobs[name] = job + if name.startswith('^'): + # This is a meta-job + regex = re.compile(name) + self.metajobs[regex] = job + else: + # Apply attributes from matching meta-jobs + for regex, metajob in self.metajobs.items(): + if regex.match(name): + job.copy(metajob) + self.jobs[name] = job return job def setLauncher(self, launcher):