Don't expect module build tasks to have "rpms"
There are module builds, which won't build any components. These module builds won't have an "rpms" key in "tasks".
Expect this to happen and don't fail when watching module builds of this kind.
Signed-off-by: Mariana Ulaieva mulaieva@redhat.com
@csomh . Review please :)
Is this connected with some known od opened bug/ticket? Do you have some specific build id, where it happens? I found multiple builds in mbs, where even module_build['tasks'] was empty, so "rpms" item access would raise an exception. But maybe it is unrelated.
These outer-parenthesis can be dropped, so this can be:
for pkg_name, task_info in module_build['tasks'].get("rpms", {}).items():
No, it doesn't connect with some opened bug or ticket. I've discovered it in the process of integration tests implementation. There will be no "rpms" key in "tasks" when a module without any components is built. And that in such cases watching the module build will fail. You can try build_id=1583
Or in Fedora MBS:
$ fedpkg module-build-watch 7216 Could not execute module_build_watch: 'rpms'
Right, that fixes the issue. There is another occurence of the construction, that might involve the functionality: line 3941: task_infos = module_build['tasks']['rpms'] What do you think?
rebased onto 44df7f046cd0e1c05027ed09bdbbfaf4acb614c7
with the fix in the code: module-build-watch 7216 Could not execute module_build_watch: float division by zero
The "division by zero" error comes from stats_module_build_components. When there are no components built, the iteration there will never execute, so stats['total'] will be zero.
stats_module_build_components
stats['total']
To fix that stats['completion_percentage'] should be initialised with 100 instead of 0, and calculating its value should only happen when stats['total'] > 0 after the for-loop.
stats['completion_percentage']
stats['total'] > 0
module_build['tasks']['rpms'] in line 3941 is a different data structure then the one produced by the MBS API, in that case 'rpms' will always be set, even though it might be empty.
module_build['tasks']['rpms']
Commit 02affb45 fixes this pull-request
Pull-Request has been merged by onosek
Thanks to you both, I modified the original commit that way.
Don't expect module build tasks to have "rpms"
There are module builds, which won't build any components. These module builds won't have an "rpms" key in "tasks".
Expect this to happen and don't fail when watching module builds of this kind.
Signed-off-by: Mariana Ulaieva mulaieva@redhat.com