~canonical-launchpad-branches/launchpad-buildd/trunk

« back to all changes in this revision

Viewing changes to lpbuildd/translationtemplates.py

  • Committer: Ubuntu One Auto Copilot
  • Author(s): Colin Watson
  • Date: 2019-12-12 12:45:28 UTC
  • mfrom: (405.1.2 bionic)
  • Revision ID: otto-copilot@canonical.com-20191212124528-1w8aeeymbm3qcj1a
Fix various failures when running on bionic.

Merged from https://code.launchpad.net/~cjwatson/launchpad-buildd/bionic/+merge/376513

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2010 Canonical Ltd.  This software is licensed under the
 
1
# Copyright 2010-2018 Canonical Ltd.  This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
3
3
 
4
4
__metaclass__ = type
5
5
 
6
6
import os
7
7
 
8
 
from lpbuildd.debian import DebianBuildManager, DebianBuildState
 
8
from lpbuildd.debian import (
 
9
    DebianBuildManager,
 
10
    DebianBuildState,
 
11
    )
 
12
from lpbuildd.target.generate_translation_templates import (
 
13
    RETCODE_FAILURE_BUILD,
 
14
    RETCODE_FAILURE_INSTALL,
 
15
    )
9
16
 
10
17
 
11
18
class TranslationTemplatesBuildState(DebianBuildState):
12
 
    INSTALL = "INSTALL"
13
19
    GENERATE = "GENERATE"
14
20
 
15
21
 
18
24
 
19
25
    This is the implementation of `TranslationTemplatesBuildJob`.  The
20
26
    latter runs on the master server; TranslationTemplatesBuildManager
21
 
    runs on the build slave.
 
27
    runs on the builder.
22
28
    """
23
29
 
24
 
    initial_build_state = TranslationTemplatesBuildState.INSTALL
 
30
    initial_build_state = TranslationTemplatesBuildState.GENERATE
25
31
 
26
 
    def __init__(self, slave, buildid):
27
 
        super(TranslationTemplatesBuildManager, self).__init__(slave, buildid)
28
 
        self._generatepath = os.path.join(
29
 
            self._slavebin, "generate-translation-templates")
30
 
        self._resultname = slave._config.get(
 
32
    def __init__(self, builder, buildid):
 
33
        super(TranslationTemplatesBuildManager, self).__init__(
 
34
            builder, buildid)
 
35
        self._resultname = builder._config.get(
31
36
            "translationtemplatesmanager", "resultarchive")
32
37
 
33
38
    def initiate(self, files, chroot, extra_args):
34
39
        """See `BuildManager`."""
35
40
        self._branch_url = extra_args['branch_url']
36
 
        self._chroot_path = os.path.join(
37
 
            self.home, 'build-' + self._buildid, 'chroot-autobuild')
38
41
 
39
42
        super(TranslationTemplatesBuildManager, self).initiate(
40
43
            files, chroot, extra_args)
41
44
 
42
 
    def doInstall(self):
43
 
        """Install packages required."""
44
 
        required_packages = [
45
 
            'bzr',
46
 
            'intltool',
47
 
            ]
48
 
        command = ['apt-get', 'install', '-y'] + required_packages
49
 
        chroot = ['sudo', 'chroot', self._chroot_path]
50
 
        self.runSubProcess('/usr/bin/sudo', chroot + command)
51
 
 
52
 
    # To satisfy DebianPackageManagers needs without having a misleading
53
 
    # method name here.
54
 
    doRunBuild = doInstall
55
 
 
56
45
    def doGenerate(self):
57
46
        """Generate templates."""
58
 
        command = [
59
 
            self._generatepath,
60
 
            self._buildid, self._branch_url, self._resultname]
61
 
        self.runSubProcess(self._generatepath, command)
 
47
        self.runTargetSubProcess(
 
48
            "generate-translation-templates",
 
49
            self._branch_url, self._resultname)
 
50
 
 
51
    # Satisfy DebianPackageManager's needs without having a misleading
 
52
    # method name here.
 
53
    doRunBuild = doGenerate
62
54
 
63
55
    def gatherResults(self):
64
56
        """Gather the results of the build and add them to the file cache."""
65
 
        # The file is inside the chroot, in the home directory of the buildd
 
57
        # The file is inside the target, in the home directory of the buildd
66
58
        # user. Should be safe to assume the home dirs are named identically.
67
 
        assert self.home.startswith('/'), "home directory must be absolute."
68
 
 
69
 
        path = os.path.join(
70
 
            self._chroot_path, self.home[1:], self._resultname)
71
 
        if os.access(path, os.F_OK):
72
 
            self._slave.addWaitingFile(path)
73
 
 
74
 
    def iterate_INSTALL(self, success):
75
 
        """Installation was done."""
76
 
        if success == 0:
77
 
            self._state = TranslationTemplatesBuildState.GENERATE
78
 
            self.doGenerate()
79
 
        else:
80
 
            if not self.alreadyfailed:
81
 
                self._slave.chrootFail()
82
 
                self.alreadyfailed = True
83
 
            self._state = TranslationTemplatesBuildState.UMOUNT
84
 
            self.doUnmounting()
85
 
 
86
 
    def iterate_GENERATE(self, success):
 
59
        path = os.path.join(self.home, self._resultname)
 
60
        if self.backend.path_exists(path):
 
61
            self.addWaitingFileFromBackend(path)
 
62
 
 
63
    def iterate_GENERATE(self, retcode):
87
64
        """Template generation finished."""
88
 
        if success == 0:
 
65
        if retcode == 0:
89
66
            # It worked! Now let's bring in the harvest.
90
 
            self.gatherResults()
91
 
            self.doReapProcesses(self._state)
 
67
            return self.deferGatherResults()
92
68
        else:
93
69
            if not self.alreadyfailed:
94
 
                self._slave.buildFail()
 
70
                if retcode == RETCODE_FAILURE_INSTALL:
 
71
                    self._builder.chrootFail()
 
72
                elif retcode == RETCODE_FAILURE_BUILD:
 
73
                    self._builder.buildFail()
 
74
                else:
 
75
                    self._builder.builderFail()
95
76
                self.alreadyfailed = True
96
 
            self.doReapProcesses(self._state)
 
77
        self.doReapProcesses(self._state)
97
78
 
98
79
    def iterateReap_GENERATE(self, success):
99
80
        """Finished reaping after template generation."""