Skip to contentSkip to conversation

build to toaster fixes

RFC New Michael Wood 2 participants 7 messages Sep 18, 2015 – Sep 23, 2015

lore
Share & tools
lore
#0 lore raw

I've been working on a number of fixes to make sure that the build and layer information is stored correctly in toaster.

There is quite a bit of stuff needed to fix this more fully and definitely scope for refactoring - I've left in old code paths as I don't think the full extent of how the information is handled can be fully tested without a large suite of unit tests.

Branch is at 'michaelw/toaster/build-recognition-fixes' on poky-contrib. I've had good results in testing building core-image-* on the fido release.

Michael

#1 lore raw

PATCH 1/4 toaster: Special case the openembedded-core layer to avoid duplicates

If the openembedded-core layer is specified in the toasterconf we need to treat it differently because we may also get this layer either from the layerindex source or I can also be provided locally.

---
 bitbake/lib/toaster/orm/models.py | 21 +++++++++++++++++++++
 meta-yocto/conf/toasterconf.json  |  2 +-
 2 files changed, 22 insertions(+), 1 deletion(-)
bitbake/lib/toaster/orm/models.py +21 -0
index e4d2e87..bdb1124 100644
@@ -828,6 +828,7 @@ class LayerIndexLayerSource(LayerSource):
         import urllib2, urlparse, json
         import os
         proxy_settings = os.environ.get("http_proxy", None)
+        oe_core_layer = 'openembedded-core'
 
         def _get_json_response(apiurl = self.apiurl):
             _parsedurl = urlparse.urlparse(apiurl)
@@ -872,6 +873,25 @@ class LayerIndexLayerSource(LayerSource):
         if not connection.features.autocommits_when_autocommit_is_off:
             transaction.set_autocommit(False)
         for li in layers_info:
+            # Special case for the openembedded-core layer
+            if li['name'] == oe_core_layer:
+                try:
+                    # If we have an existing openembedded-core for example
+                    # from the toasterconf.json augment the info using the
+                    # layerindex rather than duplicate it
+                    oe_core_l =  Layer.objects.get(name=oe_core_layer)
+                    # Take ownership of the layer as now coming from the
+                    # layerindex
+                    oe_core_l.layer_source = self
+                    oe_core_l.up_id = li['id']
+                    oe_core_l.summary = li['summary']
+                    oe_core_l.description = li['description']
+                    oe_core_l.save()
+                    continue
+
+                except DoesNotExist:
+                    pass
+
             l, created = Layer.objects.get_or_create(layer_source = self, name = li['name'])
             l.up_id = li['id']
             l.up_date = li['updated']
@@ -882,6 +902,7 @@ class LayerIndexLayerSource(LayerSource):
             l.summary = li['summary']
             l.description = li['description']
             l.save()
+
         if not connection.features.autocommits_when_autocommit_is_off:
             transaction.set_autocommit(True)
 
meta-yocto/conf/toasterconf.json +1 -1
index c455276..9e45ff0 100644
@@ -12,7 +12,7 @@
             "name": "Local Yocto Project",
             "sourcetype": "local",
             "apiurl": "../../",
-            "branches": ["HEAD", "master", "fido", "dizzy"],
+            "branches": ["HEAD" ],
             "layers": [
                 {
                     "name": "openembedded-core",
Signature · 1 line
2.1.4
#2 lore raw

PATCH 2/4 toaster: Create a relationship between build information and toaster layers

Previously this layer relationship was done by trying to match path information that came back to the buildinfohelper with trying to query for data in toaster's layers table. This rarely matched due to the lose coupling.

---
 bitbake/lib/bb/ui/buildinfohelper.py               |  30 +++-
 .../0009_auto__add_field_brlayer_layer_version.py  | 180 +++++++++++++++++++++
 bitbake/lib/toaster/bldcontrol/models.py           |   3 +-
 bitbake/lib/toaster/orm/models.py                  |   2 +-
 4 files changed, 211 insertions(+), 4 deletions(-)
 create mode 100644 bitbake/lib/toaster/bldcontrol/migrations/0009_auto__add_field_brlayer_layer_version.py
bitbake/lib/bb/ui/buildinfohelper.py +28 -2
index 6e313fe..a7afb99 100644
@@ -94,8 +94,8 @@ class ORMWrapper(object):
 
         created = False
         if not key in vars(self)[dictname].keys():
-            vars(self)[dictname][key] = clazz.objects.create(**kwargs)
-            created = True
+            vars(self)[dictname][key], created = \
+                clazz.objects.get_or_create(**kwargs)
 
         return (vars(self)[dictname][key], created)
 
@@ -286,6 +286,17 @@ class ORMWrapper(object):
         return recipe_object
 
     def get_update_layer_version_object(self, build_obj, layer_obj, layer_version_information):
+        if isinstance(layer_obj, Layer_Version):
+            # We already found our layer version for this build so just
+            # update it with the new build information
+            logger.debug("We found our layer from toaster")
+            layer_obj.build = build_obj
+            layer_obj.local_path = layer_version_information['local_path']
+            layer_obj.commit = layer_version_information['commit']
+            layer_obj.save()
+            self.layer_version_objects.append(layer_obj)
+            return layer_obj
+
         assert isinstance(build_obj, Build)
         assert isinstance(layer_obj, Layer)
         assert 'branch' in layer_version_information
@@ -335,8 +346,15 @@ class ORMWrapper(object):
                     localdirname = os.path.join(bc.be.sourcedir, localdirname)
                 #logger.debug(1, "Localdirname %s lcal_path %s" % (localdirname, layer_information['local_path']))
                 if localdirname.startswith(layer_information['local_path']):
+                  # If the build request came from toaster this field
+                  # should contain the information from the layer_version
+                  # That created this build request.
+                    if brl.layer_version:
+                        return brl.layer_version
+
                     # we matched the BRLayer, but we need the layer_version that generated this BR; reverse of the Project.schedule_build()
                     #logger.debug(1, "Matched %s to BRlayer %s" % (pformat(layer_information["local_path"]), localdirname))
+
                     for pl in buildrequest.project.projectlayer_set.filter(layercommit__layer__name = brl.name):
                         if pl.layercommit.layer.vcs_url == brl.giturl :
                             layer = pl.layercommit.layer
@@ -686,6 +704,7 @@ class BuildInfoHelper(object):
     def __init__(self, server, has_build_history = False):
         self.internal_state = {}
         self.internal_state['taskdata'] = {}
+        self.internal_state['targets'] = []
         self.task_order = 0
         self.autocommit_step = 1
         self.server = server
@@ -764,8 +783,15 @@ class BuildInfoHelper(object):
                 if not localdirname.startswith("/"):
                     localdirname = os.path.join(bc.be.sourcedir, localdirname)
                 if path.startswith(localdirname):
+                    # If the build request came from toaster this field
+                    # should contain the information from the layer_version
+                    # That created this build request.
+                    if brl.layer_version:
+                        return brl.layer_version
+
                     #logger.warn("-- managed: matched path %s with layer %s " % (path, localdirname))
                     # we matched the BRLayer, but we need the layer_version that generated this br
+
                     for lvo in self.orm_wrapper.layer_version_objects:
                         if brl.name == lvo.layer.name:
                             return lvo
bitbake/lib/toaster/bldcontrol/migrations/0009_auto__add_field_brlayer_layer_version.py new file +180 -0

181 lines not on this page · raw message

bitbake/lib/toaster/bldcontrol/models.py +2 -1
index b61de58..f2493a8 100644
@@ -1,6 +1,6 @@
 from django.db import models
 from django.core.validators import MaxValueValidator, MinValueValidator
-from orm.models import Project, ProjectLayer, ProjectVariable, ProjectTarget, Build
+from orm.models import Project, ProjectLayer, ProjectVariable, ProjectTarget, Build, Layer_Version
 
 # a BuildEnvironment is the equivalent of the "build/" directory on the localhost
 class BuildEnvironment(models.Model):
@@ -137,6 +137,7 @@ class BRLayer(models.Model):
     giturl      = models.CharField(max_length = 254)
     commit      = models.CharField(max_length = 254)
     dirpath     = models.CharField(max_length = 254)
+    layer_version = models.ForeignKey(Layer_Version, null=True)
 
 class BRBitbake(models.Model):
     req         = models.ForeignKey(BuildRequest, unique = True)    # only one bitbake for a request
bitbake/lib/toaster/orm/models.py +1 -1
index bdb1124..5240ea5 100644
@@ -260,7 +260,7 @@ class Project(models.Model):
             for l in self.projectlayer_set.all().order_by("pk"):
                 commit = l.layercommit.get_vcs_reference()
                 print("ii Building layer ", l.layercommit.layer.name, " at vcs point ", commit)
-                BRLayer.objects.create(req = br, name = l.layercommit.layer.name, giturl = l.layercommit.layer.vcs_url, commit = commit, dirpath = l.layercommit.dirpath)
+                BRLayer.objects.create(req = br, name = l.layercommit.layer.name, giturl = l.layercommit.layer.vcs_url, commit = commit, dirpath = l.layercommit.dirpath, layer_version=l.layercommit)
 
             br.state = BuildRequest.REQ_QUEUED
             now = timezone.now()
Signature · 1 line
2.1.4
#3 lore raw

PATCH 3/4 toaster: Prioroitise the layer more generic vcs reference over the sha

In reply to Michael Wood

When we do a build we update the last commit value that the layer was built at. However in future builds we do want to use the named reference rather than the commit sha, e.g. master/fido

---
 bitbake/lib/toaster/orm/models.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
bitbake/lib/toaster/orm/models.py +2 -2
index 5240ea5..44bbc97 100644
@@ -1153,12 +1153,12 @@ class Layer_Version(models.Model):
         return project.compatible_layerversions(layer_name = self.layer.name)
 
     def get_vcs_reference(self):
-        if self.commit is not None and len(self.commit) > 0:
-            return self.commit
         if self.branch is not None and len(self.branch) > 0:
             return self.branch
         if self.up_branch is not None:
             return self.up_branch.name
+        if self.commit is not None and len(self.commit) > 0:
+            return self.commit
         return ("Cannot determine the vcs_reference for layer version %s" % vars(self))
 
     def get_detailspage_url(self, project_id):
Signature · 1 line
2.1.4
#4 lore raw

PATCH 4/4 toaser: Add a urls to the layer table in the build configuration

In reply to Michael Wood

Allow you click through to the layer details page of a layer that has just been used in a build.
Also rename 'layer branch' to layer revision for clarity.

---
 bitbake/lib/toaster/toastergui/templates/configuration.html | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
bitbake/lib/toaster/toastergui/templates/configuration.html +3 -3
index 3e48991..6239e99 100644
@@ -48,14 +48,14 @@
       <thead>
         <tr>
           <th>Layer</th>
-          <th>Layer branch</th>
+          <th>Layer revision</th>
           <th>Layer commit</th>
         </tr>
       </thead>
       <tbody>{% for lv in build.layer_version_build.all|dictsort:"layer.name" %}
         <tr>
-            <td>{{lv.layer.name}}</td>
-            <td>{{lv.branch}}</td>
+          <td><a href="{% url 'layerdetails' build.project.pk lv.pk %}">{{lv.layer.name}}</a></td>
+          <td>{{lv.get_vcs_reference}}</td>
             <td> <a class="btn" data-content="<ul class='unstyled'>
                 <li>{{lv.commit}}</li> </ul>">
                     {{lv.commit|truncatechars:13}}
Signature · 1 line
2.1.4
#5 lore raw
In reply to Michael Wood

Hi,

I tried this branch on master and it worked fine for a core-image-minimal. Could you give an example of what used to fail that this fixes? I tried it with sujith's local layer loading and (for me) that still spews out ton's of errors about :

Cannot determine the vcs_reference for layer version {'build_id': 2, '_layer_cache': <Layer: __FIXME__unidentified_layer / None >, 'layer_id': 10, '_state': <django.db.models.base.ModelState object at 0x7fd03ed98710>, 'up_branch_id': None, 'priority': 7, 'up_date': None, 'local_path': u'/', '_up_branch_cache': None, '_build_cache': <Build:
2 p1-suj (Release local (HEAD), BBV HEAD (Branch: HEAD)) core-image-minimal>, 'branch': u'', 'dirpath': None, 'commit': u'', 'project_id': None, 'up_id': None, 'id': 28, 'layer_source_id': None}, Project p1-suj (Release local (HEAD), BBV HEAD (Branch: HEAD)))>, <Layer_Version: 28 __FIXME__unidentified_layer / None (VCS Cannot determine the vcs_reference for layer version {'build_id': 2, '_layer_cache': <Layer: __FIXME__unidentified_layer / None >, 'layer_id': 10, '_state': <django.db.models.base.ModelState object at 0x7fd03ed60d90>, 'up_branch_id': None, 'priority': 7, 'up_date': None, 'local_path': u'/', '_up_branch_cache': None, '_build_cache': <Build:
2 p1-suj (Release local (HEAD), BBV HEAD (Branch: HEAD)) core-image-minimal>, 'branch': u'', 'dirpath': None, 'commit': u'', 'project_

so, sadly this patch doesn't fix that problem :(

-b

Quoted 17 lines · Michael Wood

I've been working on a number of fixes to make sure that the build and layer information is stored correctly in toaster.

There is quite a bit of stuff needed to fix this more fully and definitely scope for refactoring - I've left in old code paths as I don't think the full extent of how the information is handled can be fully tested without a large suite of unit tests.

Branch is at 'michaelw/toaster/build-recognition-fixes' on poky-contrib. I've had good results in testing building core-image-* on the fido release.

Michael
--
_______________________________________________
toaster mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/toaster

#6 lore raw

New branch: michaelw/toaster/ic-4-and-buildinfo-matching

This is based ontop of the image customisation branch to make sure we use the latest schema

Michael

Quoted 49 lines · Brian Avery

Hi,

I tried this branch on master and it worked fine for a core-image-minimal. Could you give an example of what used to fail that this fixes? I tried it with sujith's local layer loading and (for me) that still spews out ton's of errors about :

Cannot determine the vcs_reference for layer version {'build_id': 2, '_layer_cache': <Layer: __FIXME__unidentified_layer / None >, 'layer_id': 10, '_state': <django.db.models.base.ModelState object at 0x7fd03ed98710>, 'up_branch_id': None, 'priority': 7, 'up_date': None, 'local_path': u'/', '_up_branch_cache': None, '_build_cache': <Build:
2 p1-suj (Release local (HEAD), BBV HEAD (Branch: HEAD)) core-image-minimal>, 'branch': u'', 'dirpath': None, 'commit': u'', 'project_id': None, 'up_id': None, 'id': 28, 'layer_source_id': None}, Project p1-suj (Release local (HEAD), BBV HEAD (Branch: HEAD)))>, <Layer_Version: 28 __FIXME__unidentified_layer / None (VCS Cannot determine the vcs_reference for layer version {'build_id': 2, '_layer_cache': <Layer: __FIXME__unidentified_layer / None >, 'layer_id': 10, '_state': <django.db.models.base.ModelState object at 0x7fd03ed60d90>, 'up_branch_id': None, 'priority': 7, 'up_date': None, 'local_path': u'/', '_up_branch_cache': None, '_build_cache': <Build:
2 p1-suj (Release local (HEAD), BBV HEAD (Branch: HEAD)) core-image-minimal>, 'branch': u'', 'dirpath': None, 'commit': u'', 'project_

so, sadly this patch doesn't fix that problem :(

-b

Quoted 17 lines · Michael Wood

I've been working on a number of fixes to make sure that the build and layer information is stored correctly in toaster.

There is quite a bit of stuff needed to fix this more fully and definitely scope for refactoring - I've left in old code paths as I don't think the full extent of how the information is handled can be fully tested without a large suite of unit tests.

Branch is at 'michaelw/toaster/build-recognition-fixes' on poky-contrib. I've had good results in testing building core-image-* on the fido release.

Michael
--
_______________________________________________
toaster mailing list
[email protected]
https://lists.yoctoproject.org/listinfo/toaster