diff options
author | Ming Liu <liu.ming50@gmail.com> | 2018-11-20 09:03:25 +0100 |
---|---|---|
committer | Ming Liu <liu.ming50@gmail.com> | 2018-11-24 14:24:26 +0100 |
commit | e97975d6113ca1ffa6cbe9b005bd518bd146fd9c (patch) | |
tree | 0c1df1f626bfd3d1819661dda5fb6ff7c4877210 /classes/sota_sanity.bbclass | |
parent | f4cf0698a88631af150782dce9b3dafcb0dbc5d5 (diff) | |
download | meta-updater-e97975d6113ca1ffa6cbe9b005bd518bd146fd9c.tar.gz |
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 <liu.ming50@gmail.com>
Diffstat (limited to 'classes/sota_sanity.bbclass')
-rw-r--r-- | classes/sota_sanity.bbclass | 54 |
1 files changed, 54 insertions, 0 deletions
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 @@ | |||
1 | # Sanity check the sota setup for common misconfigurations | ||
2 | |||
3 | def sota_check_overrides(status, d): | ||
4 | for var in (d.getVar('SOTA_OVERRIDES_BLACKLIST', True) or "").split(): | ||
5 | if var in d.getVar('OVERRIDES', True).split(':'): | ||
6 | status.addresult("%s should not be a overrides, because it is a image fstype in updater layer, please check your OVERRIDES setting.\n" % var) | ||
7 | |||
8 | def sota_check_required_variables(status, d): | ||
9 | for var in (d.getVar('SOTA_REQUIRED_VARIABLES', True) or "").split(): | ||
10 | if not d.getVar(var, True): | ||
11 | status.addresult("%s should be set in your local.conf.\n" % var) | ||
12 | |||
13 | def sota_raise_sanity_error(msg, d): | ||
14 | if d.getVar("SANITY_USE_EVENTS", True) == "1": | ||
15 | bb.event.fire(bb.event.SanityCheckFailed(msg), d) | ||
16 | return | ||
17 | |||
18 | bb.fatal("Sota's config sanity checker detected a potential misconfiguration.\n" | ||
19 | "Please fix the cause of this error then you can continue to build.\n" | ||
20 | "Following is the list of potential problems / advisories:\n" | ||
21 | "\n%s" % msg) | ||
22 | |||
23 | def sota_check_sanity(sanity_data): | ||
24 | class SanityStatus(object): | ||
25 | def __init__(self): | ||
26 | self.messages = "" | ||
27 | self.reparse = False | ||
28 | |||
29 | def addresult(self, message): | ||
30 | if message: | ||
31 | self.messages = self.messages + message | ||
32 | |||
33 | status = SanityStatus() | ||
34 | |||
35 | sota_check_overrides(status, sanity_data) | ||
36 | sota_check_required_variables(status, sanity_data) | ||
37 | |||
38 | if status.messages != "": | ||
39 | sota_raise_sanity_error(sanity_data.expand(status.messages), sanity_data) | ||
40 | |||
41 | addhandler sota_check_sanity_eventhandler | ||
42 | sota_check_sanity_eventhandler[eventmask] = "bb.event.SanityCheck" | ||
43 | |||
44 | python sota_check_sanity_eventhandler() { | ||
45 | if bb.event.getName(e) == "SanityCheck": | ||
46 | sanity_data = copy_data(e) | ||
47 | if e.generateevents: | ||
48 | sanity_data.setVar("SANITY_USE_EVENTS", "1") | ||
49 | reparse = sota_check_sanity(sanity_data) | ||
50 | e.data.setVar("BB_INVALIDCONF", reparse) | ||
51 | bb.event.fire(bb.event.SanityCheckPassed(), e.data) | ||
52 | |||
53 | return | ||
54 | } | ||