Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH] image: add mechanism to run QA checks on the image once it's built
@ 2016-06-07 14:50 Joshua Lock
  2016-06-07 15:48 ` Christopher Larson
  2016-06-07 16:59 ` Richard Purdie
  0 siblings, 2 replies; 5+ messages in thread
From: Joshua Lock @ 2016-06-07 14:50 UTC (permalink / raw)
  To: openembedded-core

Add a mechanism to run QA checks on a constructed image once it's
complete. All checks will be run with any one failure resulting in
a failed build.

QA checks should be bitbake functions which throw a
NotImplementedError when the check QA fails, with any error
messages passed to the exception.

Specify which checks to run by adding them to IMAGE_QA_COMMANDS.

i.e.

IMAGE_QA_COMMANDS += " \
    image_check_everything_ok \
"

python image_check_everything_ok () {
    raise NotImplementedError('This check always fails')
}

This code is based heavily on the configuration upgrade code in
sanity.bbclass.

[YOCTO #9448]

Signed-off-by: Joshua Lock <joshua.g.lock@intel.com>
---
 meta/classes/image.bbclass | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 9f4c83f..40bcd16 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -260,6 +260,35 @@ do_image_complete[dirs] = "${TOPDIR}"
 do_image_complete[umask] = "022"
 addtask do_image_complete after do_image before do_build
 
+# Add image-level QA/sanity checks to IMAGE_QA_COMMANDS
+#
+# IMAGE_QA_COMMANDS += " \
+#     image_check_everything_ok \
+# "
+# This task runs all functions in IMAGE_QA_COMMANDS after the image
+# construction has completed in order to validate the resulting image.
+# Image sanity checks should raise a NotImplementedError when they fail,
+# passing any failure messages to the Exception. For example:
+#
+#    python image_check_everything_ok () {
+#        raise NotImplementedError('This check always fails')
+#    }
+fakeroot python do_image_qa () {
+    qa_cmds = (d.getVar('IMAGE_QA_COMMANDS', True) or '').split()
+    imageqasane = True
+
+    for cmd in qa_cmds:
+        try:
+            bb.build.exec_func(cmd, d, pythonexception=True)
+        except NotImplementedError as e:
+            imageqasane = False
+            bb.error(str(e))
+
+    if not imageqasane:
+        bb.fatal("QA errors found whilst validating image: %s" % d.getVar('IMAGE_NAME', True))
+}
+addtask do_image_qa after do_image_complete before do_build
+
 #
 # Write environment variables used by wic
 # to tmp/sysroots/<machine>/imgdata/<image>.env
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-06-07 20:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-07 14:50 [PATCH] image: add mechanism to run QA checks on the image once it's built Joshua Lock
2016-06-07 15:48 ` Christopher Larson
2016-06-07 20:48   ` Joshua G Lock
2016-06-07 16:59 ` Richard Purdie
2016-06-07 20:50   ` Joshua G Lock

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox