1.. SPDX-License-Identifier: CC-BY-SA-2.0-UK 2 3********************** 4Concepts and Reference 5********************** 6 7In order to configure and use Toaster, you should understand some 8concepts and have some basic command reference material available. This 9final chapter provides conceptual information on layer sources, 10releases, and JSON configuration files. Also provided is a quick look at 11some useful ``manage.py`` commands that are Toaster-specific. 12Information on ``manage.py`` commands is available across the Web and 13this manual by no means attempts to provide a command 14comprehensive reference. 15 16Layer Source 17============ 18 19In general, a "layer source" is a source of information about existing 20layers. In particular, we are concerned with layers that you can use 21with the Yocto Project and Toaster. This chapter describes a particular 22type of layer source called a "layer index." 23 24A layer index is a web application that contains information about a set 25of custom layers. A good example of an existing layer index is the 26OpenEmbedded Layer Index. A public instance of this layer index exists 27at :oe_layerindex:`/`. You can find the code for this 28layer index's web application at :yocto_git:`/layerindex-web/`. 29 30When you tie a layer source into Toaster, it can query the layer source 31through a :wikipedia:`REST <Representational_state_transfer>` 32API, store the information about the layers in the Toaster database, and 33then show the information to users. Users are then able to view that 34information and build layers from Toaster itself without having to 35clone or edit the BitBake layers configuration file ``bblayers.conf``. 36 37Tying a layer source into Toaster is convenient when you have many 38custom layers that need to be built on a regular basis by a community of 39developers. In fact, Toaster comes pre-configured with the OpenEmbedded 40Metadata Index. 41 42.. note:: 43 44 You do not have to use a layer source to use Toaster. Tying into a 45 layer source is optional. 46 47Setting Up and Using a Layer Source 48----------------------------------- 49 50To use your own layer source, you need to set up the layer source and 51then tie it into Toaster. This section describes how to tie into a layer 52index in a manner similar to the way Toaster ties into the OpenEmbedded 53Metadata Index. 54 55Understanding Your Layers 56~~~~~~~~~~~~~~~~~~~~~~~~~ 57 58The obvious first step for using a layer index is to have several custom 59layers that developers build and access using the Yocto Project on a 60regular basis. This set of layers needs to exist and you need to be 61familiar with where they reside. You will need that information when you 62set up the code for the web application that "hooks" into your set of 63layers. 64 65For general information on layers, see the 66":ref:`overview-manual/yp-intro:the yocto project layer model`" 67section in the Yocto Project Overview and Concepts Manual. For information on how 68to create layers, see the ":ref:`dev-manual/layers:understanding and creating layers`" 69section in the Yocto Project Development Tasks Manual. 70 71Configuring Toaster to Hook Into Your Layer Index 72~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 73 74If you want Toaster to use your layer index, you must host the web 75application in a server to which Toaster can connect. You also need to 76give Toaster the information about your layer index. In other words, you 77have to configure Toaster to use your layer index. This section 78describes two methods by which you can configure and use your layer 79index. 80 81In the previous section, the code for the OpenEmbedded Metadata Index 82(i.e. :oe_layerindex:`/`) was referenced. You can use 83this code, which is at :yocto_git:`/layerindex-web/`, as a base to create 84your own layer index. 85 86Use the Administration Interface 87^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 88 89Access the administration interface through a browser by entering the 90URL of your Toaster instance and adding "``/admin``" to the end of the 91URL. As an example, if you are running Toaster locally, use the 92following URL:: 93 94 http://127.0.0.1:8000/admin 95 96The administration interface has a "Layer sources" section that includes 97an "Add layer source" button. Click that button and provide the required 98information. Make sure you select "layerindex" as the layer source type. 99 100Use the Fixture Feature 101^^^^^^^^^^^^^^^^^^^^^^^ 102 103The Django fixture feature overrides the default layer server when you 104use it to specify a custom URL. To use the fixture feature, create (or 105edit) the file ``bitbake/lib/toaster.orm/fixtures/custom.xml``, and then 106set the following Toaster setting to your custom URL: 107 108.. code-block:: xml 109 110 <?xml version="1.0" ?> 111 <django-objects version="1.0"> 112 <object model="orm.toastersetting" pk="100"> 113 <field name="name" type="CharField">CUSTOM_LAYERINDEX_SERVER</field> 114 <field name="value" type="CharField">https://layers.my_organization.org/layerindex/branch/master/layers/</field> 115 </object> 116 <django-objects> 117 118When you start Toaster for the first time, or 119if you delete the file ``toaster.sqlite`` and restart, the database will 120populate cleanly from this layer index server. 121 122Once the information has been updated, verify the new layer information 123is available by using the Toaster web interface. To do that, visit the 124"All compatible layers" page inside a Toaster project. The layers from 125your layer source should be listed there. 126 127If you change the information in your layer index server, refresh the 128Toaster database by running the following command: 129 130.. code-block:: shell 131 132 $ bitbake/lib/toaster/manage.py lsupdates 133 134 135If Toaster can reach the API URL, you should see a message telling you that 136Toaster is updating the layer source information. 137 138Releases 139======== 140 141When you create a Toaster project using the web interface, you are asked 142to choose a "Release." In the context of Toaster, the term "Release" 143refers to a set of layers and a BitBake version the OpenEmbedded build 144system uses to build something. As shipped, Toaster is pre-configured 145with releases that correspond to Yocto Project release branches. 146However, you can modify, delete, and create new releases according to 147your needs. This section provides some background information on 148releases. 149 150Pre-Configured Releases 151----------------------- 152 153As shipped, Toaster is configured to use a specific set of releases. Of 154course, you can always configure Toaster to use any release. For 155example, you might want your project to build against a specific commit 156of any of the "out-of-the-box" releases. Or, you might want your project 157to build against different revisions of OpenEmbedded and BitBake. 158 159As shipped, Toaster is configured to work with the following releases: 160 161- *Yocto Project &DISTRO; "&DISTRO_NAME;" or OpenEmbedded "&DISTRO_NAME;":* 162 This release causes your Toaster projects to build against the head 163 of the &DISTRO_NAME_NO_CAP; branch at 164 :yocto_git:`/poky/log/?h=&DISTRO_NAME_NO_CAP;` or 165 :oe_git:`/openembedded-core/commit/?h=&DISTRO_NAME_NO_CAP;`. 166 167- *Yocto Project "Master" or OpenEmbedded "Master":* This release 168 causes your Toaster Projects to build against the head of the master 169 branch, which is where active development takes place, at 170 :yocto_git:`/poky/log/` or :oe_git:`/openembedded-core/log/`. 171 172- *Local Yocto Project or Local OpenEmbedded:* This release causes your 173 Toaster Projects to build against the head of the ``poky`` or 174 ``openembedded-core`` clone you have local to the machine running 175 Toaster. 176 177Configuring Toaster 178=================== 179 180In order to use Toaster, you must configure the database with the 181default content. The following subsections describe various aspects of 182Toaster configuration. 183 184Configuring the Workflow 185------------------------ 186 187The ``bldcontrol/management/commands/checksettings.py`` file controls 188workflow configuration. Here is the process to 189initially populate this database. 190 191#. The default project settings are set from 192 ``orm/fixtures/settings.xml``. 193 194#. The default project distro and layers are added from 195 ``orm/fixtures/poky.xml`` if poky is installed. If poky is not 196 installed, they are added from ``orm/fixtures/oe-core.xml``. 197 198#. If the ``orm/fixtures/custom.xml`` file exists, then its values are 199 added. 200 201#. The layer index is then scanned and added to the database. 202 203Once these steps complete, Toaster is set up and ready to use. 204 205Customizing Pre-Set Data 206------------------------ 207 208The pre-set data for Toaster is easily customizable. You can create the 209``orm/fixtures/custom.xml`` file to customize the values that go into 210the database. Customization is additive, and can either extend or 211completely replace the existing values. 212 213You use the ``orm/fixtures/custom.xml`` file to change the default 214project settings for the machine, distro, file images, and layers. When 215creating a new project, you can use the file to define the offered 216alternate project release selections. For example, you can add one or 217more additional selections that present custom layer sets or distros, 218and any other local or proprietary content. 219 220Additionally, you can completely disable the content from the 221``oe-core.xml`` and ``poky.xml`` files by defining the section shown 222below in the ``settings.xml`` file. For example, this option is 223particularly useful if your custom configuration defines fewer releases 224or layers than the default fixture files. 225 226The following example sets "name" to "CUSTOM_XML_ONLY" and its value to 227"True". 228 229.. code-block:: xml 230 231 <object model="orm.toastersetting" pk="99"> 232 <field type="CharField" name="name">CUSTOM_XML_ONLY</field> 233 <field type="CharField" name="value">True</field> 234 </object> 235 236Understanding Fixture File Format 237--------------------------------- 238 239Here is an overview of the file format used by the 240``oe-core.xml``, ``poky.xml``, and ``custom.xml`` files. 241 242The following subsections describe each of the sections in the fixture 243files, and outline an example section of the XML code. you can use to 244help understand this information and create a local ``custom.xml`` file. 245 246Defining the Default Distro and Other Values 247~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 248 249This section defines the default distro value for new projects. By 250default, it reserves the first Toaster Setting record "1". The following 251demonstrates how to set the project default value for 252:term:`DISTRO`: 253 254.. code-block:: xml 255 256 <!-- Set the project default value for DISTRO --> 257 <object model="orm.toastersetting" pk="1"> 258 <field type="CharField" name="name">DEFCONF_DISTRO</field> 259 <field type="CharField" name="value">poky</field> 260 </object> 261 262You can override 263other default project values by adding additional Toaster Setting 264sections such as any of the settings coming from the ``settings.xml`` 265file. Also, you can add custom values that are included in the BitBake 266environment. The "pk" values must be unique. By convention, values that 267set default project values have a "DEFCONF" prefix. 268 269Defining BitBake Version 270~~~~~~~~~~~~~~~~~~~~~~~~ 271 272The following defines which version of BitBake is used for the following 273release selection: 274 275.. code-block:: xml 276 277 <!-- Bitbake versions which correspond to the metadata release --> 278 <object model="orm.bitbakeversion" pk="1"> 279 <field type="CharField" name="name">&DISTRO_NAME_NO_CAP;</field> 280 <field type="CharField" name="giturl">git://git.yoctoproject.org/poky</field> 281 <field type="CharField" name="branch">&DISTRO_NAME_NO_CAP;</field> 282 <field type="CharField" name="dirpath">bitbake</field> 283 </object> 284 285Defining Release 286~~~~~~~~~~~~~~~~ 287 288The following defines the releases when you create a new project: 289 290.. code-block:: xml 291 292 <!-- Releases available --> 293 <object model="orm.release" pk="1"> 294 <field type="CharField" name="name">&DISTRO_NAME_NO_CAP;</field> 295 <field type="CharField" name="description">Yocto Project &DISTRO; "&DISTRO_NAME;"</field> 296 <field rel="ManyToOneRel" to="orm.bitbakeversion" name="bitbake_version">1</field> 297 <field type="CharField" name="branch_name">&DISTRO_NAME_NO_CAP;</field> 298 <field type="TextField" name="helptext">Toaster will run your builds using the tip of the <a href="https://git.yoctoproject.org/cgit/cgit.cgi/poky/log/?h=&DISTRO_NAME_NO_CAP;">Yocto Project &DISTRO_NAME; branch</a>.</field> 299 </object> 300 301The "pk" value must match the above respective BitBake version record. 302 303Defining the Release Default Layer Names 304~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 305 306The following defines the default layers for each release: 307 308.. code-block:: xml 309 310 <!-- Default project layers for each release --> 311 <object model="orm.releasedefaultlayer" pk="1"> 312 <field rel="ManyToOneRel" to="orm.release" name="release">1</field> 313 <field type="CharField" name="layer_name">openembedded-core</field> 314 </object> 315 316The 'pk' values in the example above should start at "1" and increment 317uniquely. You can use the same layer name in multiple releases. 318 319Defining Layer Definitions 320~~~~~~~~~~~~~~~~~~~~~~~~~~ 321 322Layer definitions are the most complex. The following defines each of 323the layers, and then defines the exact layer version of the layer used 324for each respective release. You must have one ``orm.layer`` entry for 325each layer. Then, with each entry you need a set of 326``orm.layer_version`` entries that connects the layer with each release 327that includes the layer. In general all releases include the layer. 328 329.. code-block:: xml 330 331 <object model="orm.layer" pk="1"> 332 <field type="CharField" name="name">openembedded-core</field> 333 <field type="CharField" name="layer_index_url"></field> 334 <field type="CharField" name="vcs_url">git://git.yoctoproject.org/poky</field> 335 <field type="CharField" name="vcs_web_url">https://git.yoctoproject.org/cgit/cgit.cgi/poky</field> 336 <field type="CharField" name="vcs_web_tree_base_url">https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/%path%?h=%branch%</field> 337 <field type="CharField" name="vcs_web_file_base_url">https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/%path%?h=%branch%</field> 338 </object> 339 <object model="orm.layer_version" pk="1"> 340 <field rel="ManyToOneRel" to="orm.layer" name="layer">1</field> 341 <field type="IntegerField" name="layer_source">0</field> 342 <field rel="ManyToOneRel" to="orm.release" name="release">1</field> 343 <field type="CharField" name="branch">&DISTRO_NAME_NO_CAP;</field> 344 <field type="CharField" name="dirpath">meta</field> 345 </object> <object model="orm.layer_version" pk="2"> 346 <field rel="ManyToOneRel" to="orm.layer" name="layer">1</field> 347 <field type="IntegerField" name="layer_source">0</field> 348 <field rel="ManyToOneRel" to="orm.release" name="release">2</field> 349 <field type="CharField" name="branch">HEAD</field> 350 <field type="CharField" name="commit">HEAD</field> 351 <field type="CharField" name="dirpath">meta</field> 352 </object> 353 <object model="orm.layer_version" pk="3"> 354 <field rel="ManyToOneRel" to="orm.layer" name="layer">1</field> 355 <field type="IntegerField" name="layer_source">0</field> 356 <field rel="ManyToOneRel" to="orm.release" name="release">3</field> 357 <field type="CharField" name="branch">master</field> 358 <field type="CharField" name="dirpath">meta</field> 359 </object> 360 361The layer "pk" values above must be unique, and typically start at "1". The 362layer version "pk" values must also be unique across all layers, and typically 363start at "1". 364 365Remote Toaster Monitoring 366========================= 367 368Toaster has an API that allows remote management applications to 369directly query the state of the Toaster server and its builds in a 370machine-to-machine manner. This API uses the 371:wikipedia:`REST <Representational_state_transfer>` interface and the 372transfer of JSON files. For example, you might monitor 373a build inside a container through well supported known HTTP ports in 374order to easily access a Toaster server inside the container. In this 375example, when you use this direct JSON API, you avoid having web page 376parsing against the display the user sees. 377 378Checking Health 379--------------- 380 381Before you use remote Toaster monitoring, you should do a health check. 382To do this, ping the Toaster server using the following call to see if 383it is still alive:: 384 385 http://host:port/health 386 387Be sure to provide values for host and port. If the server is alive, you will 388get the response HTML: 389 390.. code-block:: html 391 392 <!DOCTYPE html> 393 <html lang="en"> 394 <head><title>Toaster Health</title></head> 395 <body>Ok</body> 396 </html> 397 398Determining Status of Builds in Progress 399---------------------------------------- 400 401Sometimes it is useful to determine the status of a build in progress. 402To get the status of pending builds, use the following call:: 403 404 http://host:port/toastergui/api/building 405 406Be sure to provide values for host and port. The output is a JSON file that 407itemizes all builds in progress. This file includes the time in seconds since 408each respective build started as well as the progress of the cloning, parsing, 409and task execution. Here is sample output for a build in progress: 410 411.. code-block:: JSON 412 413 {"count": 1, 414 "building": [ 415 {"machine": "beaglebone", 416 "seconds": "463.869", 417 "task": "927:2384", 418 "distro": "poky", 419 "clone": "1:1", 420 "id": 2, 421 "start": "2017-09-22T09:31:44.887Z", 422 "name": "20170922093200", 423 "parse": "818:818", 424 "project": "my_rocko", 425 "target": "core-image-minimal" 426 }] 427 } 428 429The JSON data for this query is returned in a 430single line. In the previous example the line has been artificially 431split for readability. 432 433Checking Status of Builds Completed 434----------------------------------- 435 436Once a build is completed, you get the status when you use the following 437call:: 438 439 http://host:port/toastergui/api/builds 440 441Be sure to provide values for host and port. The output is a JSON file that 442itemizes all complete builds, and includes build summary information. Here 443is sample output for a completed build: 444 445.. code-block:: JSON 446 447 {"count": 1, 448 "builds": [ 449 {"distro": "poky", 450 "errors": 0, 451 "machine": "beaglebone", 452 "project": "my_rocko", 453 "stop": "2017-09-22T09:26:36.017Z", 454 "target": "quilt-native", 455 "seconds": "78.193", 456 "outcome": "Succeeded", 457 "id": 1, 458 "start": "2017-09-22T09:25:17.824Z", 459 "warnings": 1, 460 "name": "20170922092618" 461 }] 462 } 463 464The JSON data for this query is returned in a single line. In the 465previous example the line has been artificially split for readability. 466 467Determining Status of a Specific Build 468-------------------------------------- 469 470Sometimes it is useful to determine the status of a specific build. To 471get the status of a specific build, use the following call:: 472 473 http://host:port/toastergui/api/build/ID 474 475Be sure to provide values for 476host, port, and ID. You can find the value for ID from the Builds 477Completed query. See the ":ref:`toaster-manual/reference:checking status of builds completed`" 478section for more information. 479 480The output is a JSON file that itemizes the specific build and includes 481build summary information. Here is sample output for a specific 482build: 483 484.. code-block:: JSON 485 486 {"build": 487 {"distro": "poky", 488 "errors": 0, 489 "machine": "beaglebone", 490 "project": "my_rocko", 491 "stop": "2017-09-22T09:26:36.017Z", 492 "target": "quilt-native", 493 "seconds": "78.193", 494 "outcome": "Succeeded", 495 "id": 1, 496 "start": "2017-09-22T09:25:17.824Z", 497 "warnings": 1, 498 "name": "20170922092618", 499 "cooker_log": "/opt/user/poky/build-toaster-2/tmp/log/cooker/beaglebone/build_20170922_022607.991.log" 500 } 501 } 502 503The JSON data for this query is returned in a single line. In the 504previous example the line has been artificially split for readability. 505 506Useful Commands 507=============== 508 509In addition to the web user interface and the scripts that start and 510stop Toaster, command-line commands are available through the ``manage.py`` 511management script. You can find general documentation on ``manage.py`` 512at the 513`Django <https://docs.djangoproject.com/en/2.2/topics/settings/>`__ 514site. However, several ``manage.py`` commands have been created that are 515specific to Toaster and are used to control configuration and back-end 516tasks. You can locate these commands in the 517:term:`Source Directory` (e.g. ``poky``) at 518``bitbake/lib/manage.py``. This section documents those commands. 519 520.. note:: 521 522 - When using ``manage.py`` commands given a default configuration, 523 you must be sure that your working directory is set to the 524 :term:`Build Directory`. Using ``manage.py`` commands from the 525 :term:`Build Directory` allows Toaster to find the ``toaster.sqlite`` 526 file, which is located in the :term:`Build Directory`. 527 528 - For non-default database configurations, it is possible that you 529 can use ``manage.py`` commands from a directory other than the 530 :term:`Build Directory`. To do so, the ``toastermain/settings.py`` file 531 must be configured to point to the correct database backend. 532 533``buildslist`` 534-------------- 535 536The ``buildslist`` command lists all builds that Toaster has recorded. 537Access the command as follows: 538 539.. code-block:: shell 540 541 $ bitbake/lib/toaster/manage.py buildslist 542 543The command returns a list, which includes numeric 544identifications, of the builds that Toaster has recorded in the current 545database. 546 547You need to run the ``buildslist`` command first to identify existing 548builds in the database before using the 549:ref:`toaster-manual/reference:\`\`builddelete\`\`` command. Here is an 550example that assumes default repository and :term:`Build Directory` names: 551 552.. code-block:: shell 553 554 $ cd poky/build 555 $ python ../bitbake/lib/toaster/manage.py buildslist 556 557If your Toaster database had only one build, the above 558:ref:`toaster-manual/reference:\`\`buildslist\`\`` 559command would return something like the following:: 560 561 1: qemux86 poky core-image-minimal 562 563``builddelete`` 564--------------- 565 566The ``builddelete`` command deletes data associated with a build. Access 567the command as follows: 568 569.. code-block:: 570 571 $ bitbake/lib/toaster/manage.py builddelete build_id 572 573The command deletes all the build data for the specified 574build_id. This command is useful for removing old and unused data from 575the database. 576 577Prior to running the ``builddelete`` command, you need to get the ID 578associated with builds by using the 579:ref:`toaster-manual/reference:\`\`buildslist\`\`` command. 580 581``perf`` 582-------- 583 584The ``perf`` command measures Toaster performance. Access the command as 585follows: 586 587.. code-block:: shell 588 589 $ bitbake/lib/toaster/manage.py perf 590 591The command is a sanity check that returns page loading times in order to 592identify performance problems. 593 594``checksettings`` 595----------------- 596 597The ``checksettings`` command verifies existing Toaster settings. Access 598the command as follows: 599 600.. code-block:: shell 601 602 $ bitbake/lib/toaster/manage.py checksettings 603 604Toaster uses settings that are based on the database to configure the 605building tasks. The ``checksettings`` command verifies that the database 606settings are valid in the sense that they have the minimal information 607needed to start a build. 608 609In order for the ``checksettings`` command to work, the database must be 610correctly set up and not have existing data. To be sure the database is 611ready, you can run the following: 612 613.. code-block:: shell 614 615 $ bitbake/lib/toaster/manage.py syncdb 616 $ bitbake/lib/toaster/manage.py migrate orm 617 $ bitbake/lib/toaster/manage.py migrate bldcontrol 618 619After running these commands, you can run the ``checksettings`` command. 620 621``runbuilds`` 622------------- 623 624The ``runbuilds`` command launches scheduled builds. Access the command 625as follows: 626 627.. code-block:: shell 628 629 $ bitbake/lib/toaster/manage.py runbuilds 630 631The ``runbuilds`` command checks if scheduled builds exist in the database 632and then launches them per schedule. The command returns after the builds 633start but before they complete. The Toaster Logging Interface records and 634updates the database when the builds complete. 635