Skip to content

Commit cebc18a

Browse files
authored
Merge pull request #40 from MeeGoIntegration/jb38568-2
Merged after review with Wouter
2 parents be89e34 + 63bf21b commit cebc18a

File tree

10 files changed

+203
-23
lines changed

10 files changed

+203
-23
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ install:
55

66
install -D -m 644 conf/apache_webhook.conf $(DESTDIR)/etc/apache2/vhosts.d/webhook.conf
77

8-
for p in auto_promote create_project delete_webhook handle_webhook relay_webhook trigger_service ; do \
8+
for p in $(cd src/participants; ls *py | cut -f1 -d.) ; do \
99
install -D -m 755 src/participants/$$p.py $(DESTDIR)/usr/share/boss-skynet/$$p.py ; \
1010
install -D -m 644 conf/supervisor/$$p.conf $(DESTDIR)/etc/supervisor/conf.d/$$p.conf ; \
1111
done

conf/supervisor/get_src_state.conf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[program:get_src_state]
2+
command = /usr/bin/skynet_exo /etc/supervisor/conf.d/get_src_state.conf
3+
process_name = %(program_name)s_%(process_num)s
4+
numprocs = 1
5+
user = bossmaintainer
6+
umask = 022
7+
autostart = true
8+
autorestart = true
9+
startsecs = 5
10+
startretries = 100
11+
stopwaitsecs = 10
12+
redirect_stderr = true
13+
stdout_logfile = /var/log/supervisor/%(program_name)s_%(process_num)s.log
14+
stderr_logfile = off
15+
environment = PYTHONUNBUFFERED=1,HOME="/home/bossmaintainer",USER="bossmaintainer"
16+
17+
[participant]
18+
name = get_src_state
19+
queue = get_src_state
20+
regexp = get_src_state
21+
code = /usr/share/boss-skynet/get_src_state.py

rpm/boss-launcher-webhook.spec

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,21 @@ This package provides the participant that handles creating and/or triggering _
5959

6060
%package -n boss-participant-create_project
6161
Group: Applications/Engineering
62-
Requires: python-boss-skynet >= 0.6.0, python-boss-common, boss-standard-workflow, python-lxml, boss-launcher-webhook, python-buildservice >= 0.5.3
62+
Requires: python-boss-skynet >= 0.6.0, python-boss-common, boss-standard-workflow-common, python-lxml, boss-launcher-webhook, python-buildservice >= 0.5.3
6363
Summary: BOSS participant to handle webhooks
6464
%description -n boss-participant-create_project
6565
This package provides the participant that handles creating project files in OBS, in response to webhook triggers
6666

67+
%package -n boss-participant-get_src_state
68+
Group: Applications/Engineering
69+
Requires: python-boss-skynet >= 0.6.0, python-boss-common, boss-standard-workflow-common, python-lxml, boss-launcher-webhook, python-buildservice >= 0.5.3
70+
Summary: BOSS participant to handle webhooks
71+
%description -n boss-participant-get_src_state
72+
This package provides the participant that checks that there is src is ready to build in OBS projects. Usually this means the service has succeeded.
73+
6774
%package -n boss-participant-auto_promote
6875
Group: Applications/Engineering
69-
Requires: python-boss-skynet >= 0.6.0, python-boss-common, boss-standard-workflow, python-lxml, boss-launcher-webhook, python-buildservice >= 0.5.3
76+
Requires: python-boss-skynet >= 0.6.0, python-boss-common, boss-standard-workflow-common, python-lxml, boss-launcher-webhook, python-buildservice >= 0.5.3
7077
Summary: BOSS participant to handle webhooks
7178
%description -n boss-participant-auto_promote
7279
This package provides the participant that handles promotion of gated projects, in response to webhook triggers
@@ -106,6 +113,13 @@ if [ $1 -ge 1 ]; then
106113
skynet register --all || true
107114
fi
108115

116+
%post -n boss-participant-get_src_state
117+
if [ $1 -ge 1 ]; then
118+
skynet apply || true
119+
skynet reload get_src_state || true
120+
skynet register --all || true
121+
fi
122+
109123
%post -n boss-participant-trigger_service
110124
if [ $1 -ge 1 ]; then
111125
skynet apply || true
@@ -150,6 +164,11 @@ fi
150164
%config(noreplace) %{svdir}/create_project.conf
151165
%{_datadir}/boss-skynet/create_project.py*
152166

167+
%files -n boss-participant-get_src_state
168+
%defattr(-,root,root,-)
169+
%config(noreplace) %{svdir}/get_src_state.conf
170+
%{_datadir}/boss-skynet/get_src_state.py*
171+
153172
%files -n boss-participant-trigger_service
154173
%defattr(-,root,root,-)
155174
%config(noreplace) %{svdir}/trigger_service.conf

src/participants/create_project.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def handle_wi(self, wid):
135135
# TODO: deduce project name from "official" mappings of the same repo
136136
# for now just short circuit here
137137
wid.result = True
138+
print "No project given. Continuing"
138139
return
139140

140141
# events for official projects that are gated get diverted to a side
@@ -212,6 +213,9 @@ def handle_wi(self, wid):
212213
if not result:
213214
raise RuntimeError(
214215
"Something went wrong while creating project %s" % project)
216+
print "Created project %s" % project
217+
else:
218+
print "Didn't need to create project %s" % project
215219

216220
wid.result = True
217221

src/participants/get_src_state.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Copyright (C) 2017 Jolla Ltd.
2+
# All rights reserved.
3+
#
4+
# This program is free software; you can redistribute it and/or modify
5+
# it under the terms of the GNU General Public License as published by
6+
# the Free Software Foundation; either version 2 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful, but
10+
# WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
# General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program; if not, write to the Free Software
16+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17+
# 02110-1301, USA.
18+
19+
"""Check to see the source state for a particular package
20+
Success if there is src ready to build
21+
service_state has more details
22+
23+
Packages which don't use a service are indistinguishable from a
24+
successful service run.
25+
26+
:term:`Workitem` fields IN:
27+
28+
:Parameters:
29+
:ev.namespace (string):
30+
Used to contact the right OBS instance.
31+
:package (string):
32+
Package name to be checked
33+
:project (string):
34+
OBS project in which the package lives
35+
36+
37+
:term:`Workitem` params IN
38+
39+
:Parameters:
40+
:package (string):
41+
Package name to be checked, overrides the package field
42+
:project (string):
43+
OBS project in which the package lives, overrides the project field
44+
45+
:term:`Workitem` fields OUT:
46+
47+
:Returns:
48+
:f.service_state (string):
49+
succeeded : src is present : service ran successfully or there's
50+
no _service
51+
running : service is in progress
52+
failed : service failed to run
53+
:result (Boolean):
54+
True if the status is succeeded
55+
False if it's runnning or failed
56+
57+
"""
58+
59+
from boss.obs import BuildServiceParticipant
60+
61+
62+
class ParticipantHandler(BuildServiceParticipant):
63+
64+
""" Participant class as defined by the SkyNET API """
65+
66+
def handle_wi_control(self, ctrl):
67+
""" job control thread """
68+
pass
69+
70+
@BuildServiceParticipant.get_oscrc
71+
def handle_lifecycle_control(self, ctrl):
72+
""" participant control thread """
73+
pass
74+
75+
@BuildServiceParticipant.setup_obs
76+
def handle_wi(self, wid):
77+
""" Workitem handling function """
78+
wid.result = False
79+
f = wid.fields
80+
p = wid.params
81+
82+
project = None
83+
package = None
84+
85+
if f.project and f.package:
86+
project = f.project
87+
package = f.package
88+
print "setting %s/%s from fields" % (project, package)
89+
90+
if p.project and p.package:
91+
project = p.project
92+
package = p.package
93+
print "setting %s/%s from params" % (project, package)
94+
95+
err = []
96+
if not project:
97+
err.append("no project")
98+
if not package:
99+
err.append("no package")
100+
if len(err) > 0:
101+
raise RuntimeError(
102+
"Missing mandatory field or parameter: %s" % ", ".join(err))
103+
104+
print "Checking service for %s/%s" % (project, package)
105+
f.service_state = self.obs.getServiceState(project, package)
106+
print "State : %s" % f.service_state
107+
if f.service_state == "succeeded":
108+
wid.result = True

src/participants/handle_webhook.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
# Copyright (C) 2013 Jolla Ltd.
22
# Contact: Islam Amer <[email protected]>
33
# All rights reserved.
4-
#
4+
#
55
# This program is free software; you can redistribute it and/or
66
# modify it under the terms of the GNU General Public License
77
# as published by the Free Software Foundation; either version 2
88
# of the License, or (at your option) any later version.
9-
#
9+
#
1010
# This program is distributed in the hope that it will be useful,
1111
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
# GNU General Public License for more details.
14-
#
14+
#
1515
# You should have received a copy of the GNU General Public License
1616
# along with this program; if not, write to the Free Software
17-
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18+
# 02110-1301, USA.
1819

1920
"""Used to handle an queued webhook event
2021
@@ -39,6 +40,7 @@
3940

4041
from webhook_launcher.app.payload import get_payload
4142

43+
4244
class ParticipantHandler(object):
4345
""" Participant class as defined by the SkyNET API """
4446

@@ -55,9 +57,11 @@ def handle_wi(self, wid):
5557
wid.result = False
5658

5759
if wid.fields.payload is None:
58-
raise RuntimeError("Missing mandatory field: payload")
60+
raise RuntimeError("Missing mandatory field: payload")
5961

62+
print "Handling a payload"
6063
payload = get_payload(wid.fields.payload.as_dict())
6164
payload.handle()
65+
print "done"
6266

6367
wid.result = True

src/webhook_launcher/app/payload.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def get_payload(data):
5454
]:
5555
try:
5656
payload = klass(data)
57+
print("Parsed payload as %s" % klass)
5758
break
5859
except PayloadParsingError:
5960
continue
@@ -82,11 +83,12 @@ def create_placeholder(self, repourl, branch, packages=None):
8283

8384
print("no mappings, create placeholders")
8485
mapobjs = []
86+
user = User.objects.get(id=1)
87+
obs = BuildService.objects.all()[0]
8588
for package in packages:
8689
mapobj = WebHookMapping(
8790
repourl=repourl, branch=branch,
88-
user=User.objects.get(id=1),
89-
obs=BuildService.objects.all()[0],
91+
user=user, obs=obs,
9092
notify=False, build=False,
9193
project=project, package=package,
9294
placeholder=True,
@@ -311,6 +313,10 @@ def handle(self):
311313
else:
312314
# annotated tag. only continue if we already had a
313315
# mapping with a matching revision
316+
print(
317+
"LastSeenRevision %s was not the same as for this"
318+
" tag: %s" % (seenrev.revision, revision)
319+
)
314320
continue
315321

316322
# notify new branch created or commit in branch

src/webhook_launcher/processes/VCSCOMMIT_BUILD

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# Copyright (C) 2013 Jolla Ltd.
22
# Contact: Islam Amer <[email protected]>
33
# All rights reserved.
4-
#
4+
#
55
# This program is free software; you can redistribute it and/or
66
# modify it under the terms of the GNU General Public License
77
# as published by the Free Software Foundation; either version 2
88
# of the License, or (at your option) any later version.
9-
#
9+
#
1010
# This program is distributed in the hope that it will be useful,
1111
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
# GNU General Public License for more details.
14-
#
14+
#
1515
# You should have received a copy of the GNU General Public License
1616
# along with this program; if not, write to the Free Software
1717
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818

19-
Ruote.process_definition 'vcscommit' do
19+
Ruote.process_definition 'wh_trigger_build' do
2020

2121
sequence do
2222
set :f => 'priority', :value => 'high'
@@ -30,6 +30,10 @@ Ruote.process_definition 'vcscommit' do
3030
# This should be conditional though
3131
create_project
3232
trigger_service
33+
# We wait for the source before checking the build results as
34+
# is_repo_published can fail if the service is still running
35+
do_wait_for_src
36+
3337
_if '"${gated_project}" != ""' do
3438
sequence do
3539
do_wait_for_build
@@ -46,13 +50,27 @@ Ruote.process_definition 'vcscommit' do
4650
end
4751
end
4852

53+
define 'do_wait_for_src' do
54+
sequence do
55+
do_log :msg => 'Waiting for ${project}/${package} source'
56+
repeat :timeout => '4h', :on_timeout => 'error' do
57+
wait '2m'
58+
get_src_state :project => '${project}', :package => '$package'
59+
_break :if => '${f:service_state}' != "running"
60+
end
61+
_if '"${service_state}" != "succeeded"' do
62+
error "Failed to get source for ${project}/${package}"
63+
end
64+
end
65+
end
66+
4967
define 'do_wait_for_build' do
5068
sequence do
5169
do_log :msg => 'Waiting for ${project} to build'
5270
repeat :timeout => '48h', :on_timeout => 'error' do
71+
wait '2m'
5372
is_repo_published :project => '${project}', :package => '$package'
5473
_break :if => '${f:__result__}'
55-
wait '2m'
5674
end
5775
end
5876
end

src/webhook_launcher/processes/VCSCOMMIT_NOTIFY

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# Copyright (C) 2013 Jolla Ltd.
22
# Contact: Islam Amer <[email protected]>
33
# All rights reserved.
4-
#
4+
#
55
# This program is free software; you can redistribute it and/or
66
# modify it under the terms of the GNU General Public License
77
# as published by the Free Software Foundation; either version 2
88
# of the License, or (at your option) any later version.
9-
#
9+
#
1010
# This program is distributed in the hope that it will be useful,
1111
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
# GNU General Public License for more details.
14-
#
14+
#
1515
# You should have received a copy of the GNU General Public License
1616
# along with this program; if not, write to the Free Software
1717
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818

19-
Ruote.process_definition 'vcscommit' do
19+
Ruote.process_definition 'wh_notify' do
2020

2121
sequence do
2222
set :f => 'log_channel', :value => '#mer-boss'

0 commit comments

Comments
 (0)