Skip to content

Commit 8089e23

Browse files
committed
Add update_symlinks participant found in production.
Signed-off-by: David Greaves <david.greaves@jolla.com>
1 parent 16a3b17 commit 8089e23

4 files changed

Lines changed: 135 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[program:update_symlinks]
2+
command = /usr/bin/skynet_exo /etc/supervisor/conf.d/update_symlinks.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 = update_symlinks
19+
queue = update_symlinks
20+
regexp = update_symlinks
21+
code = /usr/share/boss-skynet/update_symlinks.py

rpm/imager.spec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,13 @@ fi
165165
%{python_sitelib}/img_web
166166
%{_datadir}/img_web
167167
%{_datadir}/boss-skynet/update_image_status.py
168+
%{_datadir}/boss-skynet/update_symlinks.py
168169
%{_datadir}/boss-skynet/request_image.py
170+
%config(noreplace) %{_sysconfdir}/skynet/update_symlinks.conf
169171
%config(noreplace) %{_sysconfdir}/skynet/request_image.conf
170172
%config(noreplace) %{svdir}/request_image.conf
171173
%config(noreplace) %{svdir}/update_image_status.conf
174+
%config(noreplace) %{svdir}/update_symlinks.conf
172175
%config(noreplace) %{svdir}/img_web.conf
173176
%dir /etc/supervisor
174177
%dir /etc/supervisor/conf.d

src/img_boss/update_symlinks.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[releases]
2+
prefix = /srv/releases/releases/

src/img_boss/update_symlinks.py

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/usr/bin/python
2+
""" Updates symlinks to repositories for image building to stay in sync with build paths
3+
4+
5+
:term:`Workitem` fields IN:
6+
7+
:Parameters:
8+
ev.namespace(string):
9+
Namespace to use, see here:
10+
http://wiki.meego.com/Release_Infrastructure/BOSS/OBS_Event_List
11+
project(string):
12+
Name of symlink project to get symlink target from
13+
14+
:term:`Workitem` fields OUT:
15+
16+
:Returns:
17+
result(Boolean):
18+
True if the update was successfull
19+
msg(list):
20+
List of error messages
21+
22+
"""
23+
import os
24+
from boss.obs import BuildServiceParticipant
25+
from osc import core
26+
27+
class ParticipantHandler(BuildServiceParticipant):
28+
"""Participant class as defined by the SkyNET API."""
29+
30+
def __init__(self):
31+
"""Initializator."""
32+
33+
BuildServiceParticipant.__init__(self)
34+
self.prefix = None
35+
36+
def handle_wi_control(self, ctrl):
37+
"""Job control thread."""
38+
pass
39+
40+
@BuildServiceParticipant.get_oscrc
41+
def handle_lifecycle_control(self, ctrl):
42+
"""Participant control thread."""
43+
if ctrl.message == "start":
44+
self.prefix = ctrl.config.get("releases", "prefix")
45+
46+
@BuildServiceParticipant.setup_obs
47+
def handle_wi(self, wid):
48+
"""Actual job thread."""
49+
wid.result = False
50+
51+
if not wid.fields.project:
52+
raise RuntimeError("Missing mandatory field 'project'")
53+
project = wid.fields.project
54+
55+
prj_parts = project.split(":")
56+
if len(prj_parts) < 2 or len(prj_parts) > 3:
57+
raise RuntimeError("Don't know how to handle %s" % project)
58+
59+
symlink = prj_parts[-1]
60+
depth = 2
61+
62+
while depth > 0:
63+
release_id = None
64+
platform = None
65+
platform, release_id, next_project = self._get_plat_rel(project)
66+
67+
self._update_symlink(platform, release_id, symlink)
68+
if next_project:
69+
project = next_project
70+
71+
depth = depth - 1
72+
73+
def _update_symlink(self, platform, release_id, symlink):
74+
75+
symlink_path = os.path.join(self.prefix, platform, symlink)
76+
symlink_id_path = "%s.id" % symlink_path
77+
release_path = os.path.join(self.prefix, platform, release_id)
78+
79+
if not os.path.isdir(release_path):
80+
raise RuntimeError("Release %s doesn't exist at %s" % (release_id, release_path))
81+
82+
print "creating symlink %s -> %s" % (symlink_path, release_id)
83+
old_umask = os.umask(000)
84+
try:
85+
if os.path.lexists(symlink_path):
86+
os.unlink(symlink_path)
87+
os.symlink(release_id, symlink_path)
88+
89+
with open(symlink_id_path, 'w') as id_file:
90+
id_file.write(release_id)
91+
finally:
92+
os.umask(old_umask)
93+
94+
def _get_plat_rel(self, start_project):
95+
96+
next_project = None
97+
98+
for repo in self.obs.getProjectRepositories(start_project):
99+
for target in self.obs.getRepositoryTargets(start_project, repo):
100+
next_project = target.split("/")[0]
101+
platform = next_project.split(":")[0]
102+
release_id = next_project.split(":")[-1]
103+
break
104+
break
105+
106+
if not release_id:
107+
raise RuntimeError("Couldn't determine release ID for %s %s" % (platform, symlink))
108+
109+
return platform, release_id, next_project

0 commit comments

Comments
 (0)