Bug 8440

Summary: Toaster has some issues when showing builds that fail at the build request stage
Product: [Build System, Metadata & Runtime] Toaster Reporter: Belen Barros Pena <belen.barros.pena>
Component: toasterAssignee: Elliot Smith <elliot.smith>
Status: RESOLVED FIXED QA Contact: Libertad <libertad.gonzalez.de.la.cruz>
Severity: normal    
Priority: Medium+ CC: belen.barros.pena, brian.avery, elliot.smith, jessica.zhang, joshuagloe, stanciux.mihail
Version: 1.8   
Target Milestone: 2.2 M3   
Hardware: x86   
OS: Multiple   
Whiteboard: GUI design available
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)
Bug Depends on: 8556    
Bug Blocks: 8443, 8604    
Attachments:
Description Flags
Design - Showing builds without target information none

Description Belen Barros Pena 2015-10-05 13:27:42 UTC
If you start a build from Toaster, and it fails at the build request stage, we don't know the location of the build log. We rely on the BuildStarted event to give us this information, but in those builds it doesn't fire.

On the other hand, if you start a build from CLI while Toaster is running, and the build fails during the build request stage, Toaster does not pick up the build at all. Since we show failed build requests for the builds you start with Toaster, we should also aim to show build requests for the builds you start with CLI.
Comment 1 Elliot Smith 2015-10-20 10:04:33 UTC
For case 1, as Toaster aborts before the build, there isn't really a build log to show. Instead, we could default to showing the general console log for this situation, as we can get the path for that file (especially once there is only one console log file, after the patches for bug 8411).
Comment 2 Elliot Smith 2016-01-13 11:19:28 UTC
Belen, could you please give some steps which will enable me to easily reproduce the issue, both for Toaster and CLI builds?
Comment 3 Belen Barros Pena 2016-01-13 11:26:35 UTC
(In reply to comment #2)
> Belen, could you please give some steps which will enable me to easily
> reproduce the issue, both for Toaster and CLI builds?

I think you can just set a machine that doesn't exist or try to build a target that doesn't exist. Like 'xyz' or whatever.
Comment 4 Elliot Smith 2016-01-13 14:51:17 UTC
Situations to cover:

1. In Toaster, run a build for a non-existent target "xyz" for a project. Note that for this situation, we are already capturing the failure, it's just that you can't see the build log.

2. On the command line, run the same build for a non-existent target "xyz". In this situation, the failure is not even noticed by Toaster.
Comment 5 Elliot Smith 2016-01-28 17:21:42 UTC
Belen, I've covered the two situations in comment 4 above. Are there any other types of failure you'd like covered?
Comment 6 Belen Barros Pena 2016-02-01 11:18:13 UTC
(In reply to comment #5)
> Belen, I've covered the two situations in comment 4 above. Are there any
> other types of failure you'd like covered?

Can't think of anything off the top of my head, but something else might come to mind when I look at the patches. Do you have a branch somewhere I could look at?
Comment 7 Elliot Smith 2016-02-01 12:41:43 UTC
The branch is:
elliot/toaster/failed_builds-8440
Comment 8 Elliot Smith 2016-02-01 14:35:50 UTC
Submitted for review to toaster mailing list:
https://lists.yoctoproject.org/pipermail/toaster/2016-February/003754.html
Comment 9 Elliot Smith 2016-02-03 13:19:04 UTC
Need a version 4 rework to incorporate review comments from joshuagl:

* When creating dict objects, use
d = {'foo': 'bar', 'baz': 'bants', ...}
rather than
d = {}
d['foo'] = 'bar'
d['baz'] = 'bants'
...

* When declaring a function with optional arguments, don't put spaces around the '=', i.e. use:
def f(arg1, arg2=None)
rather than
def f(arg1, arg2 = None)

Also need to decide whether we want to capture builds earlier than the buildTargets() command. Here are the pros and cons of using an earlier event:

* Pros: (1) we don't need to add an event to every command called in bitbake: we just capture a really early event in the bitbake run, like SanityCheck; (2) we can capture nearly every type of error bitbake might throw (currently we don't create a build object until we see the buildTargets() command about to run on the server, so the bitbake run might fall over before we have our Build object).

* Cons: (1) if we use a really early event, this will happen before we know what the build targets are (buildTargets() is the first command to the server containing the target information, so if we use any earlier event, we won't have targets for the build). This means that we won't be able to show the targets for the build in the recent builds section or in the builds tables; which will in turn wreck the design (or require a different design).

Belen will need to make a decision on this.
Comment 10 Belen Barros Pena 2016-02-03 20:19:00 UTC
> 
> * Cons: (1) if we use a really early event, this will happen before we know
> what the build targets are (buildTargets() is the first command to the
> server containing the target information, so if we use any earlier event, we
> won't have targets for the build). This means that we won't be able to show
> the targets for the build in the recent builds section or in the builds
> tables; which will in turn wreck the design (or require a different design).
> 
> Belen will need to make a decision on this.

We can definitely find a way of displaying builds with unknown targets in the UI. I'll come up with something.
Comment 11 Belen Barros Pena 2016-02-04 11:13:34 UTC
After some discussion with Elliot, we will work towards getting target information for builds that fail due to:

* invalid machine
* invalid distro
* invalid target

So far, those 3 cases are the earliest build failures I've come across.
Comment 12 Belen Barros Pena 2016-02-04 15:11:36 UTC
Created attachment 2967 [details]
Design - Showing builds without target information

Just in case we manage to show builds started from CLI that fail at early stages.
Comment 13 Elliot Smith 2016-02-09 17:28:15 UTC
I've spent a while trying various things to record early-failing command-line builds, where MACHINE or DISTRO are the reason for the failure. (I haven't managed to resolve these two situations, but have resolved it for TARGET.)

As background, here's what's happening (as I understand it) when you run a command-line build from a Toaster environment (i.e. you've started Toaster and are using the same prompt where you started it from); most of this goes on in bitbake/lib/bb/main.py:

1. Toaster is running two processes: a server process and a client process. We use the client process to trigger builds from the Toaster UI. The server process runs the actual builds in the background.

2. When you run "bitbake <target>" from the command-line, bitbake creates a fake "server", which is in reality an XMLRPC client connecting to the existing server started by Toaster.

3. bitbake (on the command line) connects to the fake server (this really connects a client to the Toaster XMLRPC server); it gets a connection object back.

4. bitbake sets up the event queue on the returned connection. From this point, any events which occur during the build can now be monitored and collected by Toaster.

The problem we have is that the MACHINE and DISTRO failures we are trying to capture occur before step 3. I don't think we can monitor events at the time of those failures as they happen before bitbake has set up the event queue on the XMLRPC client. If we fire events which say that the build has failed, we can't hear them, because there's no channel for those events between bitbake (on the command line) and Toaster.
Comment 14 brian avery 2016-02-10 00:42:44 UTC
I don't think your comment from Feb 9 is correct in that we can't see any events from toasterland that occur very early (like a sanity failure due to a bad machine).  Take a look at poky-contrib/bavery/toaster/earlyBuildTargetNotification.

If you set your MACHINE ??= "BUNNY" in local.conf and run:
$>bitbake zlib
you should see something like:
WARNING: EARLY BUILD TARGET EVENT PRE SANITY TARGET=: ['zlib']
in toaster_ui.log. This means toasterland is seeing a very early event that is fired before the sanity check fails.  A similar event gets fired if the sanity check dies before the distro sanity check.

What I did to see this:
1) made a new event TargetsAcquired in event.py
2) added a line to fire the event if the command was buildTargets in xmlrpc.py
3) subscribed to the event in toasterui.py and then logged it when I saw it.
Comment 15 Elliot Smith 2016-02-10 10:53:50 UTC
Thanks for this, Brian. I've used your code pretty much as is, but modified toasterui.py so that we create the Build object when the TargetsAcquired event occurs.
Comment 16 Elliot Smith 2016-02-19 11:56:50 UTC
Submitted for review:
https://lists.yoctoproject.org/pipermail/toaster/2016-February/003837.html
Comment 17 Elliot Smith 2016-03-29 12:58:34 UTC
Fix is now in master: f73bbc0cbb591c394a30cf5dc3b5628f997c46d7
Comment 18 brian avery 2016-04-01 16:12:26 UTC
feedback on http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/commit/?h=toaster-next&id=78443585bc92eca7140267126d53f749be3cdd6a

RP
elliot, bavery: I guess the other option would be to put in a specific event like BuildInit right at the start of the buildTarget and buildFile functions

RP
bavery: the patch I saw for TargetAcqured only worked for the xmlrpc backend and didn't work for buildFile

RP
I'm happy to have a BuildInit event at the start of those two command functions


Seems like a reasonable plan 2 me !
Comment 19 Elliot Smith 2016-04-07 15:07:32 UTC
I've had a try at implementing this, which does work for the "bitbake zzzz" (invalid target) case.

However, this doesn't work for the bad MACHINE or bad DISTRO case, as those errors occur before buildTargets() (cooker.py) is called.

Is there any way we can fire an event before any of the sanity checking occurs, which effectively states that a bitbake "run" is starting? Where would be the best place to do that?
Comment 20 Elliot Smith 2016-04-07 15:09:46 UTC
(NB it would be useful if this event could also contain the target info.)
Comment 21 Elliot Smith 2016-04-07 15:43:38 UTC
After discussion with RP, it looks like there's not really a way round this.

In cases like a bad MACHINE, bitbake doesn't reach the ConfigParsed event because the base configuration can't be parsed and the targets being built aren't relevant (because they can't be built, regardless of what they are).

RP also pointed out that another problem is that the full target list "includes BBPKGS, yet we can't query BBPKGS until we have a data store...[and] we don't have a data store if we can't parse". So bitbake doesn't have a targets list at all if the configuration is bad.

If we can't get the information out of bitbake, there's no way we can "see" problems which occur before buildTargets() (like bad configuration), unless we wrap bitbake in our own tool which *can* see bitbake's command line. Even then, we would only be guessing at the targets and tasks, as we would still have no access to bitbake's configuration (which contains variables representing the default task if none is specified on the command line etc.).

The solution might have to be that we have to ignore command line builds which fail before buildTargets() due to bad configuration; as the user is on the command line anyway (running the build), I don't think this is a massive problem.

Note that in the previous Toaster version, where we always had an XMLRPC server running, we could get at the buildTargets() arguments as they were passed to the bitbake server, which occurred before the build proper started. We no longer have a permanent server which runs command line builds, so we can't do this any more.

It *is* possible to capture bad targets (e.g. "bitbake zzz") using a BuildInit event, as suggested by RP. I have some tentative code for this already.
Comment 22 Elliot Smith 2016-04-21 11:10:32 UTC
If Brian and Belen don't have any opinion how to deal with this, I will add the BuildInit event to capture bad targets, and ignore bad MACHINE and DISTRO, as we are unable to capture these in environments without an XMLRPCServer.
Comment 23 brian avery 2016-04-21 13:45:28 UTC
Brian is ok with this. From my perspective, Bad MACHINE/DISTRO are really obvious from the command line. Bad Parse, however is something people (me?) have to iterate on a couple of times if they are trying out (or rolling their own) new iffy layers.
Comment 24 Belen Barros Pena 2016-04-22 11:49:29 UTC
(In reply to comment #23)
> Brian is ok with this. From my perspective, Bad MACHINE/DISTRO are really
> obvious from the command line. Bad Parse, however is something people (me?)
> have to iterate on a couple of times if they are trying out (or rolling
> their own) new iffy layers.

FWIW I agree: catching some cases better than nothing. Thanks!
Comment 25 Elliot Smith 2016-04-25 15:29:23 UTC
Submitted v6 to Toaster mailing list:
https://lists.yoctoproject.org/pipermail/toaster/2016-April/004497.html
Comment 26 Elliot Smith 2016-06-30 11:11:57 UTC
Depends on bug 8556, as the changes required here cross over with fixes for it.
Comment 27 Elliot Smith 2016-07-15 12:52:21 UTC
Submitted patches to mailing list:
https://lists.yoctoproject.org/pipermail/toaster/2016-July/004997.html