summaryrefslogtreecommitdiffstats
path: root/roles/taskotron/buildmaster-configure/templates/taskotron.master.cfg.j2
blob: 7f23b95b1eb3b30dbe6e7eb4d5d64531761b0360 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# -*- python -*-
# ex: set syntax=python:

# This is a sample buildmaster config file. It must be installed as
# 'master.cfg' in your buildmaster's base directory.

# This is the dictionary that the buildmaster pays attention to. We also use
# a shorter alias to save typing.
c = BuildmasterConfig = {}

####### BUILDSLAVES

# The 'slaves' list defines the set of recognized buildslaves. Each element is
# a BuildSlave object, specifying a unique slave name and password.  The same
# slave name and password must be configured on the slave.
from buildbot.buildslave import BuildSlave
c['slaves'] = [
                {% for buildslave in buildslaves %}
                {% if deployment_type in ['dev', 'stg', 'prod'] %}
                BuildSlave("{{ buildslave }}", "{{ buildslave_password }}"),
                {% endif %}
                {% if deployment_type == 'local' %}
                BuildSlave("{{ buildslave }}", "{{ local_buildslave_password }}"),
                {% endif %}
                {% endfor %}
              ]

# 'slavePortnum' defines the TCP port to listen on for connections from slaves.
# This must match the value configured into the buildslaves (with their
# --master option)
c['slavePortnum'] = {{ buildslave_port }}

####### CHANGESOURCES

# the 'change_source' setting tells the buildmaster how it should find out
# about source code changes.  Here we point to the buildbot clone of pyflakes.

#from buildbot.changes.gitpoller import GitPoller
#c['change_source'] = []
#c['change_source'].append(GitPoller(
#        'gitolite3@localhost:exampletrigger',
#        workdir='gitpoller-workdir', branch='master',
#        pollinterval=300))

#c['change_source'].append(GitPoller(
#        'git://github.com/buildbot/pyflakes.git',
#        workdir='gitpoller-workdir', branch='master',
#        pollinterval=300))
####### SCHEDULERS

# Configure the Schedulers, which decide how to react to incoming changes.  In this
# case, just kick off a 'runtests' build

from buildbot.schedulers.basic import SingleBranchScheduler
from buildbot.schedulers.forcesched import ForceScheduler, StringParameter
from buildbot.changes import filter
from buildbot.schedulers.basic import BaseBasicScheduler
from buildbot import util

class JobScheduler(BaseBasicScheduler):

    def __init__(self, name, **kwargs):
        BaseBasicScheduler.__init__(self, name, **kwargs)

    def getChangeFilter(self, branch, branches, change_filter, categories):
        return filter.ChangeFilter.fromSchedulerConstructorArgs(
                change_filter=change_filter, categories=categories)

    def getTimerNameForChange(self, changes):
        return "only"

    def getChangeClassificationsForTimer(self, objectid, timer_name):
        return self.master.db.schedulers.getChangeClassifications(
                self.objectid)


c['schedulers'] = []
c['schedulers'].append(JobScheduler(
                            name="jobsched-noarch",
                            builderNames=["all"],
                            treeStableTimer=None,
                            change_filter=filter.ChangeFilter(project='rpmcheck',
                                                                category='noarch')))

c['schedulers'].append(JobScheduler(
                            name="jobsched-i386",
                            builderNames=['i386'],
                            treeStableTimer=None,
                            change_filter=filter.ChangeFilter(project='rpmcheck',
                                                                category='i386')))

c['schedulers'].append(JobScheduler(
                            name="jobsched-x86_64",
                            builderNames=['x86_64'],
                            treeStableTimer=None,
                            change_filter=filter.ChangeFilter(project='rpmcheck',
                                                                category='x86_64')))

#c['schedulers'].append(SingleBranchScheduler(
#                            name="all",
#                            change_filter=filter.ChangeFilter(branch='master'),
#                            treeStableTimer=None,
#                            builderNames=["all", 'x86_64', 'i386']))
c['schedulers'].append(ForceScheduler(
                            name="force",
                            builderNames=["all", 'x86_64', 'i386']))
c['schedulers'].append(ForceScheduler(
                            name="rpmcheck",
                            builderNames=["all", 'x86_64', 'i386'],
                            properties=[
                            StringParameter(name='taskname',
                                            label='name of check to run',
                                            default='',
                                            size=256),
                            StringParameter(name='item',
                                            label='object to use',
                                            default='',
                                            size=256),
                            StringParameter(name='item_type',
                                            label='type of object to use',
                                            default='',
                                            size=256),
                            StringParameter(name='uuid',
                                            label='UUID of the build in progress',
                                            default='',
                                            size=256),
                            StringParameter(name='arch',
                                            label='arch of rpm to test',
                                            default='x86_64',
                                            size=128)]))

####### BUILDERS

# The 'builders' list defines the Builders, which tell Buildbot how to perform a build:
# what steps, and which slaves can execute them.  Note that any particular build will
# only take place on one slave.

from buildbot.process.factory import BuildFactory
from buildbot.steps.source.git import Git
from buildbot.steps.shell import ShellCommand
from buildbot.process.properties import Property, Interpolate
from buildbot.steps.slave import RemoveDirectory
from buildbot.steps.transfer import DirectoryUpload, FileUpload
from buildbot.steps.master import MasterShellCommand

factory = BuildFactory()

{% if deployment_type in ['local'] %}
# clean out /var/tmp/taskotron (see T253)
factory.addStep(ShellCommand(command="rm -rf /var/tmp/taskotron/*", name="rm_tmp", descriptionDone=['Clean tmp']))

# clean the log (see T230)
factory.addStep(ShellCommand(command=["rm", "-f", "/var/log/taskotron/taskotron.log"], name="rm_log", descriptionDone=['Clean log']))
{% endif %}

{% if deployment_type in ['dev', 'stg', 'prod'] %}
# clean out /var/tmp/taskotron (see T253)
factory.addStep(ShellCommand(command=Interpolate("rm -rf /var/tmp/taskotron/%(prop:slavename)s/*"), name="rm_tmp", descriptionDone=['Clean tmp']))
{% endif %}

# check out the source
factory.addStep(Git(repourl=Interpolate('{{ grokmirror_user }}@{{ buildmaster }}:/var/lib/git/mirror/fedoraqa/%(prop:taskname)s/'),
                    mode='full', method='clobber'))

# run the runner
factory.addStep(ShellCommand(command=["runtask",
                                        '-i', Interpolate('%(prop:item)s'),
                                        '-t', Interpolate('%(prop:item_type)s'),
                                        '-a', Interpolate('%(prop:arch)s'),
                                        '-j', Interpolate('%(prop:buildername)s/%(prop:buildnumber)s'),
                                        '--uuid', Interpolate('%(prop:uuid)s'),
                                        Interpolate('%(prop:taskname)s.yml')],
                             descriptionDone=[Interpolate('%(prop:taskname)s on %(prop:item)s')],
                             name='runtask',
                             timeout=2400,
{% if deployment_type in ['dev', 'stg', 'prod'] %}
                             logfiles={
                                 'taskotron-overlord.log': {'filename': Interpolate('/var/lib/taskotron/artifacts/%(prop:uuid)s/taskotron-overlord.log')},
                                 'taskotron-stdio.log': {'filename': Interpolate('/var/lib/taskotron/artifacts/%(prop:uuid)s/taskotron-stdio.log')},
                                 'taskotron.log': {'filename': Interpolate('/var/lib/taskotron/artifacts/%(prop:uuid)s/taskotron.log')}
                             }
))
{% endif %}
{% if deployment_type in ['local'] %}
                             logfiles={'taskotron.log': {'filename': '/var/log/taskotron/taskotron.log', }}))
{% endif %}

# create artifacts dir on master
factory.addStep(MasterShellCommand(command=["mkdir", '-m', '0755', Interpolate('{{ public_artifacts_dir }}/%(prop:uuid)s')],
                                   descriptionDone=['Create artifacs dir']))

# copy artifacts to master
factory.addStep(DirectoryUpload(slavesrc=Interpolate('/var/lib/taskotron/artifacts/%(prop:uuid)s/'),
                                masterdest=Interpolate('{{ public_artifacts_dir }}/%(prop:uuid)s/task_output')))


{% if deployment_type in ['local'] %}
# copy taskotron log to master
factory.addStep(FileUpload(slavesrc='/var/log/taskotron/taskotron.log',
                           masterdest=Interpolate('{{ public_artifacts_dir }}/%(prop:uuid)s/taskotron.log'),
                           mode=0644))
{% endif %}

import datetime
from buildbot.process.properties import renderer

@renderer
def today(props):
    return datetime.datetime.now().strftime("%Y%m%d")

# move artifacts dir
factory.addStep(MasterShellCommand(command=Interpolate('mkdir -p -m 0755 {{ public_artifacts_dir }}/%(kw:today)s && mkdir -p -m 0755 {{ public_artifacts_dir }}/all && mv {{ public_artifacts_dir }}/%(prop:uuid)s/ {{ public_artifacts_dir }}/%(kw:today)s/ && ln -s {{ public_artifacts_dir }}/%(kw:today)s/%(prop:uuid)s {{ public_artifacts_dir }}/all/', today=today),
                                   descriptionDone=['Move artifacs dir']))

####### RESOURCE LOCKS
#
# This is a set of resource locks to make sure that we don't have too many things
# going on on each slave at one time.

from buildbot import locks

build_lock = locks.SlaveLock("slave_builds",
                             maxCount = 1)



####### Builders
#
# The builders associate factories with slaves which are capable of executing those factory's tasks

from buildbot.config import BuilderConfig

c['builders'] = []
c['builders'].append(
    BuilderConfig(name="x86_64",
      slavenames=[{% for buildslave in x86_64_buildslaves %}"{{ buildslave }}",{% endfor %}],
      factory=factory, locks=[build_lock.access('counting')],
      mergeRequests=False))

c['builders'].append(
    BuilderConfig(name="i386",
      slavenames=[{% for buildslave in i386_buildslaves %}"{{ buildslave }}",{% endfor %}],
      factory=factory, locks=[build_lock.access('counting')],
      mergeRequests=False))

c['builders'].append(
    BuilderConfig(name="all",
      slavenames=[{% for buildslave in buildslaves %}"{{ buildslave }}",{% endfor %}],
      factory=factory, locks=[build_lock.access('counting')],
      mergeRequests=False))

####### STATUS TARGETS

# 'status' is a list of Status Targets. The results of each build will be
# pushed to these targets. buildbot/status/*.py has a variety to choose from,
# including web pages, email senders, and IRC bots.

c['status'] = []

from buildbot.status import html
from buildbot.status.web import authz, auth

authz_cfg=authz.Authz(
    # change any of these to True to enable; see the manual for more
    # options
    {% if deployment_type == 'dev' %}
    auth=auth.BasicAuth([("{{ dev_buildbot_user }}","{{ dev_buildbot_password }}")]),
    {% endif %}
    {% if deployment_type == 'stg' %}
    auth=auth.BasicAuth([("{{ stg_buildbot_user }}","{{ stg_buildbot_password }}")]),
    {% endif %}
    {% if deployment_type == 'prod' %}
    auth=auth.BasicAuth([("{{ prod_buildbot_user }}","{{ prod_buildbot_password }}")]),
    {% endif %}
    {% if deployment_type == 'local' %}
    auth=auth.BasicAuth([("{{ local_buildbot_user }}","{{ local_buildbot_password }}")]),
    {% endif %}
    gracefulShutdown = False,
    forceBuild = 'auth', # use this to test your slave once it is set up
    forceAllBuilds = False,
    pingBuilder = False,
    stopBuild = False,
    stopAllBuilds = False,
    cancelPendingBuild = False,
)
c['status'].append(html.WebStatus(http_port=8080, authz=authz_cfg,
                                    change_hook_dialects={'base':True}))
c['status'].append(html.WebStatus(http_port=8010, authz=authz_cfg))

from buildbot.status.mail import MailNotifier
from buildbot.status.builder import Results
from buildbot.status.results import FAILURE, EXCEPTION, WARNINGS

import cgi
import re

# http://docs.buildbot.net/current/manual/cfg-statustargets.html#mailnotifier
def html_message_formatter(mode, name, build, results, master_status):
    """Provide a customized message to Buildbot's MailNotifier.

    The last 80 lines of the log are provided as well as the changes
    relevant to the build.  Message content is formatted as html.
    """
    result = Results[results]

    limit_lines = 40
    text = list()
    text.append(u'<h4>Build status: %s</h4>' % result.upper())
    text.append(u'<table cellspacing="10"><tr>')
    text.append(u"<td>Buildslave for this Build:</td><td><b>%s</b></td></tr>" % build.getSlavename())
    if master_status.getURLForThing(build):
        text.append(u'<tr><td>Complete logs for all build steps:</td><td><a href="%s">%s</a></td></tr>'
                    % (master_status.getURLForThing(build),
                       master_status.getURLForThing(build))
                    )
        text.append(u'</table>')

        logs = []
        steps = build.getSteps()
        for step in steps:
            status, dummy = step.getResults()

            if status not in [FAILURE, EXCEPTION, WARNINGS]:
                continue

            logs = step.getLogs()

            # logs within a step are in reverse order. Search back until we find stdio
            for log in reversed(logs):
                if log.getName() == 'stdio':
                    break

            name = "%s.%s" % (log.getStep().getName(), log.getName())
            status, dummy = log.getStep().getResults()
            content = log.getText().splitlines() # Note: can be VERY LARGE

            if step.getName() == 'runtask':
                found = re.search("task=\['(.*)\.yml'\]", ''.join(content[0:5]))
                if found:
                    taskname = found.group(1)
                    text.insert(0, '<h4>Task name: %s</h4>' % taskname.upper())

            url = u'%s/steps/%s/logs/%s' % (master_status.getURLForThing(build),
                                           log.getStep().getName(), log.getName())

            text.append(u'<h4>Last %d lines of "%s"</h4>' % (limit_lines, name))

            unilist = list()
            for line in content[len(content)-limit_lines:]:
                unilist.append(cgi.escape(unicode(line,'utf-8')))
            text.append(u'<pre>')
            text.extend(unilist)
            text.append(u'</pre>')

        return {
            'body': u"\n".join(text),
            'type': 'html'
            }

mn = MailNotifier(fromaddr='taskotron@fedoraproject.org',
                  sendToInterestedUsers=False,
                  subject="%(projectName)s %(result)s on {{ deployment_type }} %(builder)s",
                  mode=('failing', 'exception', 'warnings'),
                  extraRecipients=['qa-taskotron-admin-members@fedoraproject.org'],
                  relayhost="bastion.phx2.fedoraproject.org",
                  messageFormatter=html_message_formatter)

c['status'].append(mn)

# ExecDB's push-notifications:
import buildbot.status.status_push
sp = buildbot.status.status_push.HttpStatusPush(
        serverUrl="{{ execdb_statuspush }}",
        debug=True)
c['status'].append(sp)

####### PROJECT IDENTITY

# the 'title' string will appear at the top of this buildbot
# installation's html.WebStatus home page (linked to the
# 'titleURL') and is embedded in the title of the waterfall HTML page.

c['title'] = "Taskotron"
c['titleURL'] = "http://{{ external_hostname }}/{{buildmaster_endpoint}}/"

# the 'buildbotURL' string should point to the location where the buildbot's
# internal web server (usually the html.WebStatus page) is visible. This
# typically uses the port number set in the Waterfall 'status' entry, but
# with an externally-visible host name which the buildbot cannot figure out
# without some help.

c['buildbotURL'] = "http://{{ external_hostname }}/{{buildmaster_endpoint}}/"

####### DB URL

c['db'] = {
    # This specifies what database buildbot uses to store its state.  You can leave
    # this at its default for all but the largest installations.
    {% if deployment_type in ['dev', 'stg', 'prod'] %}
    'db_url' : "postgresql://{{ buildmaster_db_user }}:{{ buildmaster_db_password }}@{{ buildmaster_db_host }}/{{ buildmaster_db_name }}",
    {% endif %}
    {% if deployment_type == 'local' %}
    'db_url' : "postgresql://{{ local_buildmaster_db_user }}:{{ local_buildmaster_db_password }}@127.0.0.1/{{ buildmaster_db_name }}",
    {% endif %}

}