From e97975d6113ca1ffa6cbe9b005bd518bd146fd9c Mon Sep 17 00:00:00 2001 From: Ming Liu Date: Tue, 20 Nov 2018 09:03:25 +0100 Subject: image_types_ostree/ota.bbclass: refactor ostree task There are several flaws with ostree tasks, as follows: - ${IMAGE_NAME}.rootfs.ostree.tar.bz2 is generated, but it's not being used during ostree commit, so it should be removed if it's just a intermittent artifact. Or if we intend to deploy this tar.bz2 file, it should be tracked by sstate cache, that is to day, it should be generated in ${IMGDEPLOYDIR} rather than in ${DEPLOY_DIR_IMAGE}. - There are quite a few redundant code like mktemp/cd/rm a directory, which can be replaced by setting 'dirs', 'cleandirs' varflags. - There are some redundant variable check logic in image_types_ostree and image_types_ota bbclass. To fix the above, we make the following changes: - Introduce a new conversion image type 'tar', it could convert ostree and ota to ostree.tar, ota.tar, hence we can drop the code generating ostree.tar.bz2 in image_types_ostree.bbclass, and also drop the do_image_ota-tar task. To let this conversion type take effect, the otasetup task needs to be changed to ota. - Introduce BUILD_OSTREE_TARBALL variable, when being set to 1, a ostree.tar.bz2 tarball would be built, BUILD_OSTREE_TARBALL defaults to be 1, to be consistent with original behavior. - Replace 'ota-tar ota-tar.xz' with ota.tar.xz in IMAGE_FSTYPES. - Add a sanity check bbclass sota_sanity.bbclass, to ensure ostree or ota is not in OVERRIDES, this is to prevent potential naming pollution with other meta layers, and also check the required variables are not empty. This sota_sanity.bbclass is a common class that could be extended easily in furture, and one of its most advantages is that all the check are done in bb.event.SanityCheck event handler, so the end users could get the error message at very beginning of the recipe parsing time. Signed-off-by: Ming Liu --- classes/sota_sanity.bbclass | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 classes/sota_sanity.bbclass (limited to 'classes/sota_sanity.bbclass') diff --git a/classes/sota_sanity.bbclass b/classes/sota_sanity.bbclass new file mode 100644 index 0000000..e47de19 --- /dev/null +++ b/classes/sota_sanity.bbclass @@ -0,0 +1,54 @@ +# Sanity check the sota setup for common misconfigurations + +def sota_check_overrides(status, d): + for var in (d.getVar('SOTA_OVERRIDES_BLACKLIST', True) or "").split(): + if var in d.getVar('OVERRIDES', True).split(':'): + status.addresult("%s should not be a overrides, because it is a image fstype in updater layer, please check your OVERRIDES setting.\n" % var) + +def sota_check_required_variables(status, d): + for var in (d.getVar('SOTA_REQUIRED_VARIABLES', True) or "").split(): + if not d.getVar(var, True): + status.addresult("%s should be set in your local.conf.\n" % var) + +def sota_raise_sanity_error(msg, d): + if d.getVar("SANITY_USE_EVENTS", True) == "1": + bb.event.fire(bb.event.SanityCheckFailed(msg), d) + return + + bb.fatal("Sota's config sanity checker detected a potential misconfiguration.\n" + "Please fix the cause of this error then you can continue to build.\n" + "Following is the list of potential problems / advisories:\n" + "\n%s" % msg) + +def sota_check_sanity(sanity_data): + class SanityStatus(object): + def __init__(self): + self.messages = "" + self.reparse = False + + def addresult(self, message): + if message: + self.messages = self.messages + message + + status = SanityStatus() + + sota_check_overrides(status, sanity_data) + sota_check_required_variables(status, sanity_data) + + if status.messages != "": + sota_raise_sanity_error(sanity_data.expand(status.messages), sanity_data) + +addhandler sota_check_sanity_eventhandler +sota_check_sanity_eventhandler[eventmask] = "bb.event.SanityCheck" + +python sota_check_sanity_eventhandler() { + if bb.event.getName(e) == "SanityCheck": + sanity_data = copy_data(e) + if e.generateevents: + sanity_data.setVar("SANITY_USE_EVENTS", "1") + reparse = sota_check_sanity(sanity_data) + e.data.setVar("BB_INVALIDCONF", reparse) + bb.event.fire(bb.event.SanityCheckPassed(), e.data) + + return +} -- cgit v1.2.3-54-g00ecf