diff options
author | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2015-10-09 22:59:03 +0200 |
commit | 972dcfcdbfe75dcfeb777150c136576cf1a71e99 (patch) | |
tree | 97a61cd7e293d7ae9d56ef7ed0f81253365bb026 /bitbake/lib/toaster/bldcontrol/bbcontroller.py | |
download | poky-972dcfcdbfe75dcfeb777150c136576cf1a71e99.tar.gz |
initial commit for Enea Linux 5.0 arm
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'bitbake/lib/toaster/bldcontrol/bbcontroller.py')
-rw-r--r-- | bitbake/lib/toaster/bldcontrol/bbcontroller.py | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/bitbake/lib/toaster/bldcontrol/bbcontroller.py b/bitbake/lib/toaster/bldcontrol/bbcontroller.py new file mode 100644 index 0000000000..6812ae3e6e --- /dev/null +++ b/bitbake/lib/toaster/bldcontrol/bbcontroller.py | |||
@@ -0,0 +1,183 @@ | |||
1 | # | ||
2 | # ex:ts=4:sw=4:sts=4:et | ||
3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
4 | # | ||
5 | # BitBake Toaster Implementation | ||
6 | # | ||
7 | # Copyright (C) 2014 Intel Corporation | ||
8 | # | ||
9 | # This program is free software; you can redistribute it and/or modify | ||
10 | # it under the terms of the GNU General Public License version 2 as | ||
11 | # published by the Free Software Foundation. | ||
12 | # | ||
13 | # This program is distributed in the hope that it will be useful, | ||
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | # GNU General Public License for more details. | ||
17 | # | ||
18 | # You should have received a copy of the GNU General Public License along | ||
19 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
20 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
21 | |||
22 | |||
23 | import os | ||
24 | import sys | ||
25 | import re | ||
26 | from django.db import transaction | ||
27 | from django.db.models import Q | ||
28 | from bldcontrol.models import BuildEnvironment, BRLayer, BRVariable, BRTarget, BRBitbake | ||
29 | |||
30 | # load Bitbake components | ||
31 | path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) | ||
32 | sys.path.insert(0, path) | ||
33 | import bb.server.xmlrpc | ||
34 | |||
35 | class BitbakeController(object): | ||
36 | """ This is the basic class that controlls a bitbake server. | ||
37 | It is outside the scope of this class on how the server is started and aquired | ||
38 | """ | ||
39 | |||
40 | def __init__(self, connection): | ||
41 | self.connection = connection | ||
42 | |||
43 | def _runCommand(self, command): | ||
44 | result, error = self.connection.connection.runCommand(command) | ||
45 | if error: | ||
46 | raise Exception(error) | ||
47 | return result | ||
48 | |||
49 | def disconnect(self): | ||
50 | return self.connection.removeClient() | ||
51 | |||
52 | def setVariable(self, name, value): | ||
53 | return self._runCommand(["setVariable", name, value]) | ||
54 | |||
55 | def build(self, targets, task = None): | ||
56 | if task is None: | ||
57 | task = "build" | ||
58 | return self._runCommand(["buildTargets", targets, task]) | ||
59 | |||
60 | |||
61 | |||
62 | def getBuildEnvironmentController(**kwargs): | ||
63 | """ Gets you a BuildEnvironmentController that encapsulates a build environment, | ||
64 | based on the query dictionary sent in. | ||
65 | |||
66 | This is used to retrieve, for example, the currently running BE from inside | ||
67 | the toaster UI, or find a new BE to start a new build in it. | ||
68 | |||
69 | The return object MUST always be a BuildEnvironmentController. | ||
70 | """ | ||
71 | |||
72 | from localhostbecontroller import LocalhostBEController | ||
73 | from sshbecontroller import SSHBEController | ||
74 | |||
75 | be = BuildEnvironment.objects.filter(Q(**kwargs))[0] | ||
76 | if be.betype == BuildEnvironment.TYPE_LOCAL: | ||
77 | return LocalhostBEController(be) | ||
78 | elif be.betype == BuildEnvironment.TYPE_SSH: | ||
79 | return SSHBEController(be) | ||
80 | else: | ||
81 | raise Exception("FIXME: Implement BEC for type %s" % str(be.betype)) | ||
82 | |||
83 | |||
84 | def _getgitcheckoutdirectoryname(url): | ||
85 | """ Utility that returns the last component of a git path as directory | ||
86 | """ | ||
87 | import re | ||
88 | components = re.split(r'[:\.\/]', url) | ||
89 | return components[-2] if components[-1] == "git" else components[-1] | ||
90 | |||
91 | |||
92 | class BuildEnvironmentController(object): | ||
93 | """ BuildEnvironmentController (BEC) is the abstract class that defines the operations that MUST | ||
94 | or SHOULD be supported by a Build Environment. It is used to establish the framework, and must | ||
95 | not be instantiated directly by the user. | ||
96 | |||
97 | Use the "getBuildEnvironmentController()" function to get a working BEC for your remote. | ||
98 | |||
99 | How the BuildEnvironments are discovered is outside the scope of this class. | ||
100 | |||
101 | You must derive this class to teach Toaster how to operate in your own infrastructure. | ||
102 | We provide some specific BuildEnvironmentController classes that can be used either to | ||
103 | directly set-up Toaster infrastructure, or as a model for your own infrastructure set: | ||
104 | |||
105 | * Localhost controller will run the Toaster BE on the same account as the web server | ||
106 | (current user if you are using the the Django development web server) | ||
107 | on the local machine, with the "build/" directory under the "poky/" source checkout directory. | ||
108 | Bash is expected to be available. | ||
109 | |||
110 | * SSH controller will run the Toaster BE on a remote machine, where the current user | ||
111 | can connect without raise Exception("FIXME: implement")word (set up with either ssh-agent or raise Exception("FIXME: implement")phrase-less key authentication) | ||
112 | |||
113 | """ | ||
114 | def __init__(self, be): | ||
115 | """ Takes a BuildEnvironment object as parameter that points to the settings of the BE. | ||
116 | """ | ||
117 | self.be = be | ||
118 | self.connection = None | ||
119 | |||
120 | |||
121 | def startBBServer(self): | ||
122 | """ Starts a BB server with Toaster toasterui set up to record the builds, an no controlling UI. | ||
123 | After this method executes, self.be bbaddress/bbport MUST point to a running and free server, | ||
124 | and the bbstate MUST be updated to "started". | ||
125 | """ | ||
126 | raise Exception("Must override in order to actually start the BB server") | ||
127 | |||
128 | def stopBBServer(self): | ||
129 | """ Stops the currently running BB server. | ||
130 | The bbstate MUST be updated to "stopped". | ||
131 | self.connection must be none. | ||
132 | """ | ||
133 | |||
134 | def setLayers(self, bbs, ls): | ||
135 | """ Checks-out bitbake executor and layers from git repositories. | ||
136 | Sets the layer variables in the config file, after validating local layer paths. | ||
137 | The bitbakes must be a 1-length list of BRBitbake | ||
138 | The layer paths must be in a list of BRLayer object | ||
139 | |||
140 | a word of attention: by convention, the first layer for any build will be poky! | ||
141 | """ | ||
142 | raise Exception("Must override setLayers") | ||
143 | |||
144 | |||
145 | def getBBController(self): | ||
146 | """ returns a BitbakeController to an already started server; this is the point where the server | ||
147 | starts if needed; or reconnects to the server if we can | ||
148 | """ | ||
149 | if not self.connection: | ||
150 | self.startBBServer() | ||
151 | self.be.lock = BuildEnvironment.LOCK_RUNNING | ||
152 | self.be.save() | ||
153 | |||
154 | server = bb.server.xmlrpc.BitBakeXMLRPCClient() | ||
155 | server.initServer() | ||
156 | server.saveConnectionDetails("%s:%s" % (self.be.bbaddress, self.be.bbport)) | ||
157 | self.connection = server.establishConnection([]) | ||
158 | |||
159 | self.be.bbtoken = self.connection.transport.connection_token | ||
160 | self.be.save() | ||
161 | |||
162 | return BitbakeController(self.connection) | ||
163 | |||
164 | def getArtifact(path): | ||
165 | """ This call returns an artifact identified by the 'path'. How 'path' is interpreted as | ||
166 | up to the implementing BEC. The return MUST be a REST URL where a GET will actually return | ||
167 | the content of the artifact, e.g. for use as a "download link" in a web UI. | ||
168 | """ | ||
169 | raise Exception("Must return the REST URL of the artifact") | ||
170 | |||
171 | def release(self): | ||
172 | """ This stops the server and releases any resources. After this point, all resources | ||
173 | are un-available for further reference | ||
174 | """ | ||
175 | raise Exception("Must override BE release") | ||
176 | |||
177 | class ShellCmdException(Exception): | ||
178 | pass | ||
179 | |||
180 | |||
181 | class BuildSetupException(Exception): | ||
182 | pass | ||
183 | |||