Skip to contentSkip to conversation

toaster patchset: localhost build control

PATCH New Alex DAMIAN 1 participant 7 messages Jun 12, 2014

lore
Share & tools
lore
#0 lore raw

cover toaster patchset: localhost build control

From: Alexandru DAMIAN <[email protected]>

Hello,

This toaster patchset contains the core of the build control functionality for running on a localhost backend. Variants of this patchset have been reviewed on the toaster mailing list.

Please merge at your convenience,

Alex

The following changes since commit 2e742c03e8dfdfa67899e7f5d579ed14bd87e139:

bb/utils: fix contains_any() (2014-06-11 13:18:20 +0100)

are available in the git repository at:

git://git.yoctoproject.org/poky-contrib adamian/20140612-submission-bb
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=adamian/20140612-submission-bb

Alexandru DAMIAN (6):
toaster: initial bldcontrol application
toaster: create models for bldcontrol and enable it
toaster: add function to get the database url
xmlrpc: add support for token reusing
toastergui: fix built ETA calculation
toaster: build control functionality

 bin/bitbake                                        |   8 +-
 bin/toaster                                        |   9 +-
 lib/bb/server/xmlrpc.py                            |  19 +-
 lib/bb/ui/buildinfohelper.py                       |  10 +
 lib/bb/ui/toasterui.py                             |   3 +
 lib/toaster/bldcontrol/__init__.py                 |   0
 lib/toaster/bldcontrol/bbcontroller.py             | 239 +++++++++++++++++++++
 lib/toaster/bldcontrol/fixtures/initial_data.json  |   1 +
 lib/toaster/bldcontrol/management/__init__.py      |   0
 .../bldcontrol/management/commands/__init__.py     |   0
 .../bldcontrol/management/commands/runbuilds.py    |  85 ++++++++
 lib/toaster/bldcontrol/migrations/0001_initial.py  | 154 +++++++++++++
 lib/toaster/bldcontrol/migrations/__init__.py      |   0
 lib/toaster/bldcontrol/models.py                   |  83 +++++++
 lib/toaster/bldcontrol/tests.py                    |  81 +++++++
 lib/toaster/bldcontrol/views.py                    |   1 +
 lib/toaster/toastergui/views.py                    |   7 +-
 lib/toaster/toastermain/settings.py                |  20 ++
 18 files changed, 704 insertions(+), 16 deletions(-)
 create mode 100644 lib/toaster/bldcontrol/__init__.py
 create mode 100644 lib/toaster/bldcontrol/bbcontroller.py
 create mode 100644 lib/toaster/bldcontrol/fixtures/initial_data.json
 create mode 100644 lib/toaster/bldcontrol/management/__init__.py
 create mode 100644 lib/toaster/bldcontrol/management/commands/__init__.py
 create mode 100644 lib/toaster/bldcontrol/management/commands/runbuilds.py
 create mode 100644 lib/toaster/bldcontrol/migrations/0001_initial.py
 create mode 100644 lib/toaster/bldcontrol/migrations/__init__.py
 create mode 100644 lib/toaster/bldcontrol/models.py
 create mode 100644 lib/toaster/bldcontrol/tests.py
 create mode 100644 lib/toaster/bldcontrol/views.py
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/6 toaster: initial bldcontrol application

From: Alexandru DAMIAN <[email protected]>

The build features of Toaster will be contained into a separate application, as to modularize the Toaster project and provide multiple options for deployment.

This patch adds the application as a barebone Django application in the Toaster project.

---
 lib/toaster/bldcontrol/__init__.py |  0
 lib/toaster/bldcontrol/models.py   |  3 +++
 lib/toaster/bldcontrol/tests.py    | 16 ++++++++++++++++
 lib/toaster/bldcontrol/views.py    |  1 +
 4 files changed, 20 insertions(+)
 create mode 100644 lib/toaster/bldcontrol/__init__.py
 create mode 100644 lib/toaster/bldcontrol/models.py
 create mode 100644 lib/toaster/bldcontrol/tests.py
 create mode 100644 lib/toaster/bldcontrol/views.py
lib/toaster/bldcontrol/__init__.py new file +0 -0
new file mode 100644
index 0000000..e69de29
lib/toaster/bldcontrol/models.py new file +3 -0
new file mode 100644
index 0000000..71a8362
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
lib/toaster/bldcontrol/tests.py new file +16 -0
new file mode 100644
index 0000000..501deb7
@@ -0,0 +1,16 @@
+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+    def test_basic_addition(self):
+        """
+        Tests that 1 + 1 always equals 2.
+        """
+        self.assertEqual(1 + 1, 2)
lib/toaster/bldcontrol/views.py new file +1 -0
new file mode 100644
index 0000000..60f00ef
@@ -0,0 +1 @@
+# Create your views here.
Signature · 1 line
1.9.1
#2 lore raw

PATCH 2/6 toaster: create models for bldcontrol and enable it

From: Alexandru DAMIAN <[email protected]>

We create the model classes that store information about triggering builds, and the available build environments.

We add a fixture with a default build environment for build control, using a "build/" directory under the poky checkout directory.

We enable the bldcontrol in toaster starting script and in the toaster settings as to allow the actual database to be kept in sync with the source code.

---
 bin/toaster                                       |   2 +-
 lib/toaster/bldcontrol/fixtures/initial_data.json |   1 +
 lib/toaster/bldcontrol/migrations/0001_initial.py | 154 ++++++++++++++++++++++
 lib/toaster/bldcontrol/migrations/__init__.py     |   0
 lib/toaster/bldcontrol/models.py                  |  80 ++++++++++-
 lib/toaster/toastermain/settings.py               |   1 +
 6 files changed, 236 insertions(+), 2 deletions(-)
 create mode 100644 lib/toaster/bldcontrol/fixtures/initial_data.json
 create mode 100644 lib/toaster/bldcontrol/migrations/0001_initial.py
 create mode 100644 lib/toaster/bldcontrol/migrations/__init__.py
bin/toaster +1 -1
index f469e4f..80bda6d 100755
@@ -63,7 +63,7 @@ function webserverStartAll()
             retval=0
             python $BBBASEDIR/lib/toaster/manage.py migrate orm || retval=1
         fi
-        # python $BBBASEDIR/lib/toaster/manage.py migrate bldcontrol || retval=1
+        python $BBBASEDIR/lib/toaster/manage.py migrate bldcontrol || retval=1
 
         if [ $retval -eq 0 ]; then
             python $BBBASEDIR/lib/toaster/manage.py runserver 0.0.0.0:8000 </dev/null >${BUILDDIR}/toaster_web.log 2>&1 & echo $! >${BUILDDIR}/.toastermain.pid
lib/toaster/bldcontrol/fixtures/initial_data.json new file +1 -0
new file mode 100644
index 0000000..21883ab
@@ -0,0 +1 @@
+[{"pk": 1, "model": "bldcontrol.buildenvironment", "fields": {"updated": "2014-05-20T12:17:30Z", "created": "2014-05-20T12:17:30Z", "lock": 0, "bbstate": 0, "bbaddress": "", "betype": 0, "bbtoken": "", "address": "localhost", "bbport": -1}}]
lib/toaster/bldcontrol/migrations/0001_initial.py new file +154 -0

155 lines not on this page · raw message

lib/toaster/bldcontrol/migrations/__init__.py new file +0 -0
new file mode 100644
index 0000000..e69de29
lib/toaster/bldcontrol/models.py +79 -1

82 lines not on this page · raw message

lib/toaster/toastermain/settings.py +1 -0
index adaa56c..2c52b68 100644
@@ -221,6 +221,7 @@ INSTALLED_APPS = (
     'toastergui',
     'bldviewer',
     'south',
+    'bldcontrol',
 )
 
 # A sample logging configuration. The only tangible logging
Signature · 1 line
1.9.1
#3 lore raw

PATCH 3/6 toaster: add function to get the database url

In reply to Alex DAMIAN

From: Alexandru DAMIAN <[email protected]>

We add a function that returns the DATABASE_URL for the current 'default' database settings. This is useful to be able to start other toaster instances with the same database settigns as the currently running instance.

---
 lib/toaster/toastermain/settings.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
lib/toaster/toastermain/settings.py +19 -0
index 2c52b68..2ce10c4 100644
@@ -74,6 +74,25 @@ if 'DATABASE_URL' in os.environ:
     else:
         raise Exception("FIXME: Please implement missing database url schema for url: %s" % dburl)
 
+
+# Allows current database settings to be exported as a DATABASE_URL environment variable value
+
+def getDATABASE_URL():
+    d = DATABASES['default']
+    if d['ENGINE'] == 'django.db.backends.sqlite3':
+        if d['NAME'] == ':memory:':
+            return 'sqlite3://:memory:'
+        elif d['NAME'].startswith("/"):
+            return 'sqlite3://' + d['NAME']
+        return "sqlite3://" + os.path.join(os.getcwd(), d['NAME'])
+
+    elif d['ENGINE'] == 'django.db.backends.mysql':
+        return "mysql://" + d['USER'] + ":" + d['PASSWORD'] + "@" + d['HOST'] + ":" + d['PORT'] + "/" + d['NAME']
+
+    raise Exception("FIXME: Please implement missing database url schema for engine: %s" % d['ENGINE'])
+
+
+
 # Hosts/domain names that are valid for this site; required if DEBUG is False
 # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
 ALLOWED_HOSTS = []
Signature · 1 line
1.9.1
#4 lore raw

PATCH 4/6 xmlrpc: add support for token reusing

In reply to Alex DAMIAN

From: Alexandru DAMIAN <[email protected]>

We add support to specify a connection token in the command line and in the environment variable BBTOKEN.

When a client registers to a bitbake server, that client will have exclusive access to the server. The client is identified by a server-supplied token. If a client terminates, we cannot reconnect to the server as the token is lost.

This patch adds the capability to specify the connection token in the command line for xmlrpc clients. This allows us to have bitbake work as an already-authenticated client with the server and resume sending commands to a server.

---
 bin/bitbake             |  8 +++++++-
 lib/bb/server/xmlrpc.py | 19 ++++++++++++-------
 2 files changed, 19 insertions(+), 8 deletions(-)
bin/bitbake +7 -1
index f120bac..b3acbe1 100755
@@ -169,6 +169,9 @@ class BitBakeConfigParameters(cookerdata.ConfigParameters):
         parser.add_option("-t", "--servertype", help = "Choose which server to use, process or xmlrpc.",
                    action = "store", dest = "servertype")
 
+        parser.add_option("", "--token", help = "Specify the connection token to be used when connecting to a remote server.",
+                   action = "store", dest = "xmlrpctoken")
+
         parser.add_option("", "--revisions-changed", help = "Set the exit code depending on whether upstream floating revisions have changed or not.",
                    action = "store_true", dest = "revisions_changed", default = False)
 
@@ -200,6 +203,9 @@ class BitBakeConfigParameters(cookerdata.ConfigParameters):
             options.servertype = "xmlrpc"
             options.remote_server = os.environ["BBSERVER"]
 
+        if "BBTOKEN" in os.environ:
+            options.xmlrpctoken = os.environ["BBTOKEN"]
+
         # if BBSERVER says to autodetect, let's do that
         if options.remote_server:
             [host, port] = options.remote_server.split(":", 2)
@@ -332,7 +338,7 @@ def main():
         bb.event.ui_queue = []
     else:
         # we start a stub server that is actually a XMLRPClient that connects to a real server
-        server = servermodule.BitBakeXMLRPCClient(configParams.observe_only)
+        server = servermodule.BitBakeXMLRPCClient(configParams.observe_only, configParams.xmlrpctoken)
         server.saveConnectionDetails(configParams.remote_server)
 
 
lib/bb/server/xmlrpc.py +12 -7
index d6f4338..4205a4c 100644
@@ -281,13 +281,16 @@ class BitBakeXMLRPCServerConnection(BitBakeBaseServerConnection):
         self.observer_only = observer_only
         self.featureset = featureset
 
-    def connect(self):
-        if not self.observer_only:
-            token = self.connection.addClient()
-        else:
-            token = "observer"
+    def connect(self, token = None):
+        if token is None:
+            if self.observer_only:
+                token = "observer"
+            else:
+                token = self.connection.addClient()
+
         if token is None:
             return None
+
         self.transport.set_connection_token(token)
 
         self.events = uievent.BBUIEventQueue(self.connection, self.clientinfo)
@@ -336,7 +339,9 @@ class BitBakeServer(BitBakeBaseServer):
 
 class BitBakeXMLRPCClient(BitBakeBaseServer):
 
-    def __init__(self, observer_only = False):
+    def __init__(self, observer_only = False, token = None):
+        self.token = token
+
         self.observer_only = observer_only
         # if we need extra caches, just tell the server to load them all
         pass
@@ -366,7 +371,7 @@ class BitBakeXMLRPCClient(BitBakeBaseServer):
         try:
             self.serverImpl = XMLRPCProxyServer(host, port)
             self.connection = BitBakeXMLRPCServerConnection(self.serverImpl, (ip, 0), self.observer_only, featureset)
-            return self.connection.connect()
+            return self.connection.connect(self.token)
         except Exception as e:
             bb.warn("Could not connect to server at %s:%s (%s)" % (host, port, str(e)))
             raise e
Signature · 1 line
1.9.1
#5 lore raw

PATCH 5/6 toastergui: fix built ETA calculation

In reply to Alex DAMIAN

From: Alexandru DAMIAN <[email protected]>

We fix the calculation showing the estimated time
to build completion.

---
 lib/toaster/toastergui/views.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
lib/toaster/toastergui/views.py +3 -4
index 686cd5c..b38d260 100755
@@ -230,11 +230,10 @@ def builds(request):
             b.completeper = tf.exclude(order__isnull=True).count()*100/tf.count()
         else:
             b.completeper = 0
-        b.eta = timezone.now()
+
+        b.eta = 0
         if b.completeper > 0:
-            b.eta += ((timezone.now() - b.started_on)*100/b.completeper)
-        else:
-            b.eta = 0
+            b.eta = timezone.now() + ((timezone.now() - b.started_on)*(100-b.completeper)/b.completeper)
 
     # set up list of fstypes for each build
     fstypes_map = {};
Signature · 1 line
1.9.1
#6 lore raw

PATCH 6/6 toaster: build control functionality

In reply to Alex DAMIAN

From: Alexandru DAMIAN <[email protected]>

We add the build control functionality to toaster.

* The bldcontrol application gains bbcontroller classes that know how to manage a localhost build environment.

* The toaster UI now detects it is running under build environment controller, and update the build controller database and will shut down the bitbake server once the build is complete.

* The toaster script can now run in standalone mode, launching the build controller and the web interface instead of just monitoring the build, as in the interactive mode.

* A fixture with the default build controller entry for localhost is provided.

[YOCTO #5490]
[YOCTO #5491]
[YOCTO #5492]
[YOCTO #5493]
[YOCTO #5494]
[YOCTO #5537]

---
 bin/toaster                                        |   7 +-
 lib/bb/ui/buildinfohelper.py                       |  10 +
 lib/bb/ui/toasterui.py                             |   3 +
 lib/toaster/bldcontrol/bbcontroller.py             | 239 +++++++++++++++++++++
 lib/toaster/bldcontrol/fixtures/initial_data.json  |   2 +-
 lib/toaster/bldcontrol/management/__init__.py      |   0
 .../bldcontrol/management/commands/__init__.py     |   0
 .../bldcontrol/management/commands/runbuilds.py    |  85 ++++++++
 lib/toaster/bldcontrol/models.py                   |   2 +
 lib/toaster/bldcontrol/tests.py                    |  73 ++++++-
 10 files changed, 413 insertions(+), 8 deletions(-)
 create mode 100644 lib/toaster/bldcontrol/bbcontroller.py
 create mode 100644 lib/toaster/bldcontrol/management/__init__.py
 create mode 100644 lib/toaster/bldcontrol/management/commands/__init__.py
 create mode 100644 lib/toaster/bldcontrol/management/commands/runbuilds.py
bin/toaster +4 -3
index 80bda6d..01ffc7a 100755
@@ -139,15 +139,16 @@ if [ -z "$ZSH_NAME" ] && [ `basename \"$0\"` = `basename \"$BASH_SOURCE\"` ]; th
         webserverKillAll
         RUNNING=0
     }
-    webserverStartAll || exit 1
+    webserverStartAll || (echo "Fail to start the web server, stopping" 1>&2 && exit 1)
     xdg-open http://0.0.0.0:8000/ >/dev/null 2>&1 &
     trap trap_ctrlc SIGINT
     echo "Running. Stop with Ctrl-C"
     while [ $RUNNING -gt 0 ]; do
-        wait;
+	python $BBBASEDIR/lib/toaster/manage.py runbuilds
+	sleep 1
     done
     echo "**** Exit"
-    exit 1
+    exit 0
 fi
 
 # We make sure we're running in the current shell and in a good environment
lib/bb/ui/buildinfohelper.py +10 -0
index 58df687..77be7c7 100644
@@ -916,6 +916,16 @@ class BuildInfoHelper(object):
                             self.internal_state['recipes'],
                             )
 
+    def store_build_done(self, br_id, be_id):
+        from bldcontrol.models import BuildEnvironment, BuildRequest
+        be = BuildEnvironment.objects.get(pk = be_id)
+        be.lock = BuildEnvironment.LOCK_LOCK
+        be.save()
+        br = BuildRequest.objects.get(pk = br_id)
+        br.state = BuildRequest.REQ_COMPLETED
+        br.build = self.internal_state['build']
+        br.save()
+
     def _store_log_information(self, level, text):
         log_information = {}
         log_information['build'] = self.internal_state['build']
lib/bb/ui/toasterui.py +3 -0
index c1696b2..b1c80cc 100644
@@ -228,8 +228,11 @@ def main(server, eventHandler, params ):
 
 
                 brbe = server.runCommand(["getVariable", "TOASTER_BRBE"])[0]
+                br_id, be_id = brbe.split(":")
                 # we start a new build info
                 if brbe is not None:
+                    buildinfohelper.store_build_done(br_id, be_id)
+
                     print "we are under BuildEnvironment management - after the build, we exit"
                     server.terminateServer()
                 else:
lib/toaster/bldcontrol/bbcontroller.py new file +239 -0

239 lines not on this page · raw message

lib/toaster/bldcontrol/fixtures/initial_data.json +1 -1
index 21883ab..b2f12b3 100644
@@ -1 +1 @@
-[{"pk": 1, "model": "bldcontrol.buildenvironment", "fields": {"updated": "2014-05-20T12:17:30Z", "created": "2014-05-20T12:17:30Z", "lock": 0, "bbstate": 0, "bbaddress": "", "betype": 0, "bbtoken": "", "address": "localhost", "bbport": -1}}]
+[{"pk": 1, "model": "bldcontrol.buildenvironment", "fields": {"updated": "2014-05-20T12:17:30Z", "created": "2014-05-20T12:17:30Z", "lock": 0, "bbstate": 0, "bbaddress": "", "betype": 0, "bbtoken": "", "address": "", "bbport": -1}}]
lib/toaster/bldcontrol/management/__init__.py new file +0 -0
new file mode 100644
index 0000000..e69de29
lib/toaster/bldcontrol/management/commands/__init__.py new file +0 -0
new file mode 100644
index 0000000..e69de29
lib/toaster/bldcontrol/management/commands/runbuilds.py new file +85 -0

85 lines not on this page · raw message

lib/toaster/bldcontrol/models.py +2 -0
index 11f487c..158874f 100644
@@ -20,9 +20,11 @@ class BuildEnvironment(models.Model):
 
     LOCK_FREE = 0
     LOCK_LOCK = 1
+    LOCK_RUNNING = 2
     LOCK_STATE = (
         (LOCK_FREE, "free"),
         (LOCK_LOCK, "lock"),
+        (LOCK_RUNNING, "running"),
     )
 
     address     = models.CharField(max_length = 254)
lib/toaster/bldcontrol/tests.py +69 -4

79 lines not on this page · raw message

Signature · 1 line
1.9.1