Merge lp:~cjwatson/launchpad-buildd/translation-merge-states into lp:launchpad-buildd

Proposed by Colin Watson
Status: Merged
Merged at revision: 293
Proposed branch: lp:~cjwatson/launchpad-buildd/translation-merge-states
Merge into: lp:launchpad-buildd
Prerequisite: lp:~cjwatson/launchpad-buildd/translation-refactor-chdir
Diff against target: 266 lines (+62/-67)
4 files modified
bin/generate-translation-templates (+5/-2)
debian/changelog (+2/-0)
lpbuildd/tests/test_translationtemplatesbuildmanager.py (+31/-27)
lpbuildd/translationtemplates.py (+24/-38)
To merge this branch: bzr merge lp:~cjwatson/launchpad-buildd/translation-merge-states
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+330434@code.launchpad.net

Commit message

Merge TranslationTemplatesBuildState.{INSTALL,GENERATE} into a single state.

Description of the change

This will make it easier to turn generate-translation-templates into a subclass of Operation, and brings it more into line with buildlivefs and buildsnap.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/generate-translation-templates'
2--- bin/generate-translation-templates 2017-07-25 22:11:19 +0000
3+++ bin/generate-translation-templates 2017-09-08 14:41:25 +0000
4@@ -1,6 +1,6 @@
5 #!/bin/sh
6 #
7-# Copyright 2010,2011 Canonical Ltd. This software is licensed under the
8+# Copyright 2010-2017 Canonical Ltd. This software is licensed under the
9 # GNU Affero General Public License version 3 (see the file LICENSE).
10
11 # Buildd Slave tool to generate translation templates. Boiler plate code
12@@ -53,6 +53,8 @@
13 $1 || echo "Got error $? from '$1'."
14 }
15
16+$SUDO $CHROOT $BUILD_CHROOT apt-get install -y bzr intltool || exit 200
17+
18 # Copy pottery files to chroot.
19 debug_exec "$SUDO $MKDIR -vp $BUILD_CHROOT$PYMODULES/$BUILDD_PACKAGE"
20 debug_exec "$SUDO $TOUCH $BUILD_CHROOT$PYMODULES/$BUILDD_PACKAGE/__init__.py"
21@@ -63,4 +65,5 @@
22 # Enter chroot, switch back to unprivileged user, execute the generate script.
23 $SUDO $CHROOT $BUILD_CHROOT \
24 $SU - $USER \
25- -c "PYTHONPATH=$PYMODULES $GENERATE_SCRIPT $BRANCH_URL $RESULT_NAME"
26+ -c "PYTHONPATH=$PYMODULES $GENERATE_SCRIPT $BRANCH_URL $RESULT_NAME" \
27+ || exit 201
28
29=== modified file 'debian/changelog'
30--- debian/changelog 2017-09-08 14:41:25 +0000
31+++ debian/changelog 2017-09-08 14:41:25 +0000
32@@ -1,6 +1,8 @@
33 launchpad-buildd (152) UNRELEASED; urgency=medium
34
35 * Refactor lpbuildd.pottery.intltool to avoid calling chdir.
36+ * Merge TranslationTemplatesBuildState.{INSTALL,GENERATE} into a single
37+ state.
38
39 -- Colin Watson <cjwatson@ubuntu.com> Fri, 08 Sep 2017 13:42:17 +0100
40
41
42=== modified file 'lpbuildd/tests/test_translationtemplatesbuildmanager.py'
43--- lpbuildd/tests/test_translationtemplatesbuildmanager.py 2017-08-22 15:55:44 +0000
44+++ lpbuildd/tests/test_translationtemplatesbuildmanager.py 2017-09-08 14:41:25 +0000
45@@ -14,6 +14,8 @@
46 from lpbuildd.tests.fakeslave import FakeSlave
47 from lpbuildd.tests.matchers import HasWaitingFiles
48 from lpbuildd.translationtemplates import (
49+ RETCODE_FAILURE_BUILD,
50+ RETCODE_FAILURE_INSTALL,
51 TranslationTemplatesBuildManager,
52 TranslationTemplatesBuildState,
53 )
54@@ -65,23 +67,9 @@
55 self.buildmanager.backend_name = original_backend_name
56
57 # Skip states that are done in DebianBuildManager to the state
58- # directly before INSTALL.
59+ # directly before GENERATE.
60 self.buildmanager._state = TranslationTemplatesBuildState.UPDATE
61
62- # INSTALL: Install additional packages needed for this job into
63- # the chroot.
64- self.buildmanager.iterate(0)
65- self.assertEqual(
66- TranslationTemplatesBuildState.INSTALL, self.getState())
67- expected_command = [
68- '/usr/bin/sudo',
69- 'sudo', 'chroot', self.chrootdir,
70- 'apt-get',
71- ]
72- self.assertEqual(expected_command, self.buildmanager.commands[-1][:5])
73- self.assertEqual(
74- self.buildmanager.iterate, self.buildmanager.iterators[-1])
75-
76 # GENERATE: Run the slave's payload, the script that generates
77 # templates.
78 self.buildmanager.iterate(0)
79@@ -136,34 +124,50 @@
80 self.buildmanager.iterate, self.buildmanager.iterators[-1])
81 self.assertFalse(self.slave.wasCalled('buildFail'))
82
83- def test_iterate_fail_INSTALL(self):
84- # See that a failing INSTALL is handled properly.
85+ def test_iterate_fail_GENERATE_install(self):
86+ # See that a GENERATE that fails at the install step is handled
87+ # properly.
88 url = 'lp:~my/branch'
89 # The build manager's iterate() kicks off the consecutive states
90 # after INIT.
91 self.buildmanager.initiate(
92 {}, 'chroot.tar.gz', {'series': 'xenial', 'branch_url': url})
93
94- # Skip states to the INSTALL state.
95- self.buildmanager._state = TranslationTemplatesBuildState.INSTALL
96+ # Skip states to the GENERATE state.
97+ self.buildmanager._state = TranslationTemplatesBuildState.GENERATE
98
99- # The buildmanager fails and iterates to the UMOUNT state.
100- self.buildmanager.iterate(-1)
101+ # The buildmanager fails and reaps processes.
102+ self.buildmanager.iterate(RETCODE_FAILURE_INSTALL)
103 self.assertEqual(
104- TranslationTemplatesBuildState.UMOUNT, self.getState())
105+ TranslationTemplatesBuildState.GENERATE, self.getState())
106 expected_command = [
107 'sharepath/slavebin/in-target', 'in-target',
108- 'umount-chroot',
109+ 'scan-for-processes',
110 '--backend=chroot', '--series=xenial', '--arch=i386',
111 self.buildid,
112 ]
113 self.assertEqual(expected_command, self.buildmanager.commands[-1])
114- self.assertEqual(
115+ self.assertNotEqual(
116 self.buildmanager.iterate, self.buildmanager.iterators[-1])
117 self.assertTrue(self.slave.wasCalled('chrootFail'))
118
119- def test_iterate_fail_GENERATE(self):
120- # See that a failing GENERATE is handled properly.
121+ # The buildmanager iterates to the UMOUNT state.
122+ self.buildmanager.iterateReap(self.getState(), 0)
123+ self.assertEqual(
124+ TranslationTemplatesBuildState.UMOUNT, self.getState())
125+ expected_command = [
126+ 'sharepath/slavebin/in-target', 'in-target',
127+ 'umount-chroot',
128+ '--backend=chroot', '--series=xenial', '--arch=i386',
129+ self.buildid,
130+ ]
131+ self.assertEqual(expected_command, self.buildmanager.commands[-1])
132+ self.assertEqual(
133+ self.buildmanager.iterate, self.buildmanager.iterators[-1])
134+
135+ def test_iterate_fail_GENERATE_build(self):
136+ # See that a GENERATE that fails at the build step is handled
137+ # properly.
138 url = 'lp:~my/branch'
139 # The build manager's iterate() kicks off the consecutive states
140 # after INIT.
141@@ -174,7 +178,7 @@
142 self.buildmanager._state = TranslationTemplatesBuildState.GENERATE
143
144 # The buildmanager fails and reaps processes.
145- self.buildmanager.iterate(-1)
146+ self.buildmanager.iterate(RETCODE_FAILURE_BUILD)
147 expected_command = [
148 'sharepath/slavebin/in-target', 'in-target',
149 'scan-for-processes',
150
151=== modified file 'lpbuildd/translationtemplates.py'
152--- lpbuildd/translationtemplates.py 2017-08-05 09:43:43 +0000
153+++ lpbuildd/translationtemplates.py 2017-09-08 14:41:25 +0000
154@@ -1,15 +1,21 @@
155-# Copyright 2010 Canonical Ltd. This software is licensed under the
156+# Copyright 2010-2017 Canonical Ltd. This software is licensed under the
157 # GNU Affero General Public License version 3 (see the file LICENSE).
158
159 __metaclass__ = type
160
161 import os
162
163-from lpbuildd.debian import DebianBuildManager, DebianBuildState
164+from lpbuildd.debian import (
165+ DebianBuildManager,
166+ DebianBuildState,
167+ )
168+
169+
170+RETCODE_FAILURE_INSTALL = 200
171+RETCODE_FAILURE_BUILD = 201
172
173
174 class TranslationTemplatesBuildState(DebianBuildState):
175- INSTALL = "INSTALL"
176 GENERATE = "GENERATE"
177
178
179@@ -21,7 +27,7 @@
180 runs on the build slave.
181 """
182
183- initial_build_state = TranslationTemplatesBuildState.INSTALL
184+ initial_build_state = TranslationTemplatesBuildState.GENERATE
185
186 def __init__(self, slave, buildid):
187 super(TranslationTemplatesBuildManager, self).__init__(slave, buildid)
188@@ -33,26 +39,10 @@
189 def initiate(self, files, chroot, extra_args):
190 """See `BuildManager`."""
191 self._branch_url = extra_args['branch_url']
192- self._chroot_path = os.path.join(
193- self.home, 'build-' + self._buildid, 'chroot-autobuild')
194
195 super(TranslationTemplatesBuildManager, self).initiate(
196 files, chroot, extra_args)
197
198- def doInstall(self):
199- """Install packages required."""
200- required_packages = [
201- 'bzr',
202- 'intltool',
203- ]
204- command = ['apt-get', 'install', '-y'] + required_packages
205- chroot = ['sudo', 'chroot', self._chroot_path]
206- self.runSubProcess('/usr/bin/sudo', chroot + command)
207-
208- # To satisfy DebianPackageManagers needs without having a misleading
209- # method name here.
210- doRunBuild = doInstall
211-
212 def doGenerate(self):
213 """Generate templates."""
214 command = [
215@@ -60,37 +50,33 @@
216 self._buildid, self._branch_url, self._resultname]
217 self.runSubProcess(self._generatepath, command)
218
219+ # Satisfy DebianPackageManager's needs without having a misleading
220+ # method name here.
221+ doRunBuild = doGenerate
222+
223 def gatherResults(self):
224 """Gather the results of the build and add them to the file cache."""
225- # The file is inside the chroot, in the home directory of the buildd
226+ # The file is inside the target, in the home directory of the buildd
227 # user. Should be safe to assume the home dirs are named identically.
228 path = os.path.join(self.home, self._resultname)
229 if self.backend.path_exists(path):
230 self.addWaitingFileFromBackend(path)
231
232- def iterate_INSTALL(self, success):
233- """Installation was done."""
234- if success == 0:
235- self._state = TranslationTemplatesBuildState.GENERATE
236- self.doGenerate()
237- else:
238- if not self.alreadyfailed:
239- self._slave.chrootFail()
240- self.alreadyfailed = True
241- self._state = TranslationTemplatesBuildState.UMOUNT
242- self.doUnmounting()
243-
244- def iterate_GENERATE(self, success):
245+ def iterate_GENERATE(self, retcode):
246 """Template generation finished."""
247- if success == 0:
248+ if retcode == 0:
249 # It worked! Now let's bring in the harvest.
250 self.gatherResults()
251- self.doReapProcesses(self._state)
252 else:
253 if not self.alreadyfailed:
254- self._slave.buildFail()
255+ if retcode == RETCODE_FAILURE_INSTALL:
256+ self._slave.chrootFail()
257+ elif retcode == RETCODE_FAILURE_BUILD:
258+ self._slave.buildFail()
259+ else:
260+ self._slave.builderFail()
261 self.alreadyfailed = True
262- self.doReapProcesses(self._state)
263+ self.doReapProcesses(self._state)
264
265 def iterateReap_GENERATE(self, success):
266 """Finished reaping after template generation."""

Subscribers

People subscribed via source and target branches

to all changes: