diff options
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 | } | ||
