summaryrefslogtreecommitdiffstats
path: root/classes
diff options
context:
space:
mode:
authorZee314159 <252806294@qq.com>2019-11-19 08:02:50 +0100
committerLaurent Bonnans <laurent.bonnans@here.com>2019-12-12 16:39:14 +0100
commit2882c94733ca7719c22f28c825cf95b39bdbb614 (patch)
tree8f1070f13569180f39e671f91e1358d14f2318a1 /classes
parent74f66a0b136ec59618d519b89bc6b3fa6bc6b212 (diff)
downloadmeta-updater-2882c94733ca7719c22f28c825cf95b39bdbb614.tar.gz
Use regex and add some variables
Signed-off-by: Zee314159 <252806294@qq.com>
Diffstat (limited to 'classes')
-rw-r--r--classes/sota_sanity.bbclass75
1 files changed, 38 insertions, 37 deletions
diff --git a/classes/sota_sanity.bbclass b/classes/sota_sanity.bbclass
index c6665a2..3678e33 100644
--- a/classes/sota_sanity.bbclass
+++ b/classes/sota_sanity.bbclass
@@ -11,31 +11,47 @@ def sota_check_required_variables(status, d):
11 status.addresult("%s should be set in your local.conf.\n" % var) 11 status.addresult("%s should be set in your local.conf.\n" % var)
12 12
13def sota_check_variables_validity(status, d): 13def sota_check_variables_validity(status, d):
14 var = d.getVar("OSTREE_BRANCHNAME") 14 import re
15 if var != "": 15 import os.path
16 for ch in var: 16
17 if not (ch >= 'a' and ch <= 'z' or ch >= 'A' and ch <= 'Z' or ch >= '0' and ch <= '9' or ch = '_' or ch == '-'): 17 if d.getVar("OSTREE_BRANCHNAME") and re.match("^[a-zA-Z0-9_-]*$", d.getVar("OSTREE_BRANCHNAME")) is None:
18 status.addresult("OSTREE_BRANCHNAME Should only contain characters from the character set [a-zA-Z0-9_-].\n") 18 status.addresult("OSTREE_BRANCHNAME Should only contain characters from the character set [a-zA-Z0-9_-].\n")
19 if d.getVar("SOTA_HARDWARE_ID") and re.match("^[a-zA-Z0-9_-]*$", d.getVar("SOTA_HARDWARE_ID")) is None:
20 status.addresult("SOTA_HARDWARE_ID Should only contain characters from the character set [a-zA-Z0-9_-].\n")
21 if d.getVar("SOTA_CLIENT_FEATURES") is not None:
22 for feat in d.getVar("SOTA_CLIENT_FEATURES").split(' '):
23 if feat not in ("hsm", "serialcan", "ubootenv", ""):
24 status.addresult("SOTA_CLIENT_FEATURES should only include hsm, serialcan and bootenv.\n")
19 break 25 break
20 var = d.getVar("{SOTA_HARDWARE_ID") 26 if d.getVar("SOTA_CLIENT_PROV") is not None:
21 if var != "": 27 prov = d.getVar("SOTA_CLIENT_PROV").strip()
22 for ch in var: 28 if prov not in ("aktualizr-shared-prov", "aktualizr-device-prov", "aktualizr-device-prov-hsm", ""):
23 if not (ch >= 'a' and ch <= 'z' or ch >= 'A' and ch <= 'Z' or ch >= '0' and ch <= '9' or ch = '_' or ch == '-'): 29 status.addresult("Valid options for SOTA_CLIENT_PROV are aktualizr-shared-prov, aktualizr-device-prov and aktualizr-device-prov-hsm.\n")
24 status.addresult("SOTA_HARDWARE_ID Should only contain characters from the character set [a-zA-Z0-9_-].\n") 30 if d.getVar("GARAGE_TARGET_URL") and re.match("^(https?|ftp|file)://.+$", d.getVar("GARAGE_TARGET_URL")) is None:
25 break 31 status.addresult("GARAGE_TARGET_URL is set to a bad url.\n")
26 var = d.getVar("SOTA_CLIENT_FEATURES") 32 if d.getVar("SOTA_POLLING_SEC") and re.match("^(0|\+?[1-9][0-9]*)$", d.getVar("SOTA_POLLING_SEC")) is None:
27 if var != "hsm" and var != "secondary-network" and var != "": 33 status.addresult("SOTA_POLLING_SEC should be an integer.\n")
28 status.addresult("SOTA_CLIENT_FEATURES should be set to hsm or secondary-network.\n") 34 if d.getVar("OSTREE_REPO") and re.match("^\/([a-zA-Z0-9_-]+\/?)+$", d.getVar("OSTREE_REPO")) is None:
29 var = d.getVar("OSTREE_UPDATE_SUMMARY") 35 status.addresult("OSTREE_REPO is not set correctly. Path to your OSTree repository is invalid.\n")
30 if var != "0" and var != "1" and var != "": 36 config = d.getVar("SOTA_SECONDARY_CONFIG")
37 if config is not None and config != "":
38 path = os.path.abspath(config)
39 if not os.path.exists(path):
40 status.addresult("SOTA_SECONDARY_CONFIG is not set correctly. The file containing JSON configuration for secondaries does not exist.\n")
41 credentials = d.getVar("SOTA_PACKED_CREDENTIALS")
42 if credentials is not None and credentials != "":
43 path = os.path.abspath(credentials)
44 if not os.path.exists(path):
45 status.addresult("SOTA_PACKED_CREDENTIALS is not set correctly. The zipped credentials file does not exist.\n")
46 if d.getVar("OSTREE_UPDATE_SUMMARY") and d.getVar("OSTREE_UPDATE_SUMMARY") not in ("0", "1", ""):
31 status.addresult("OSTREE_UPDATE_SUMMARY should be set to 0 or 1.\n") 47 status.addresult("OSTREE_UPDATE_SUMMARY should be set to 0 or 1.\n")
32 var = d.getVar("OSTREE_DEPLOY_DEVICETREE") 48 if d.getVar("OSTREE_DEPLOY_DEVICETREE") and d.getVar("OSTREE_DEPLOY_DEVICETREE") not in ("0", "1", ""):
33 if var != "0" and var != "1" and var != "":
34 status.addresult("OSTREE_DEPLOY_DEVICETREE should be set to 0 or 1.\n") 49 status.addresult("OSTREE_DEPLOY_DEVICETREE should be set to 0 or 1.\n")
35 var = GARAGE_SIGN_AUTOVERSION 50 if d.getVar("GARAGE_SIGN_AUTOVERSION") and d.getVar("GARAGE_SIGN_AUTOVERSION") not in ("0", "1", ""):
36 if var != "0" and var != "1" and var != "":
37 status.addresult("GARAGE_SIGN_AUTOVERSION should be set to 0 or 1.\n") 51 status.addresult("GARAGE_SIGN_AUTOVERSION should be set to 0 or 1.\n")
38 52 if d.getVar("SOTA_DEPLOY_CREDENTIALS") and d.getVar("SOTA_DEPLOY_CREDENTIALS") not in ("0", "1", ""):
53 status.addresult("SOTA_DEPLOY_CREDENTIALS should be set to 0 or 1.\n")
54
39def sota_raise_sanity_error(msg, d): 55def sota_raise_sanity_error(msg, d):
40 if d.getVar("SANITY_USE_EVENTS") == "1": 56 if d.getVar("SANITY_USE_EVENTS") == "1":
41 bb.event.fire(bb.event.SanityCheckFailed(msg), d) 57 bb.event.fire(bb.event.SanityCheckFailed(msg), d)
@@ -60,6 +76,7 @@ def sota_check_sanity(sanity_data):
60 76
61 sota_check_overrides(status, sanity_data) 77 sota_check_overrides(status, sanity_data)
62 sota_check_required_variables(status, sanity_data) 78 sota_check_required_variables(status, sanity_data)
79 sota_check_variables_validity(status, sanity_data)
63 80
64 if status.messages != "": 81 if status.messages != "":
65 sota_raise_sanity_error(sanity_data.expand(status.messages), sanity_data) 82 sota_raise_sanity_error(sanity_data.expand(status.messages), sanity_data)
@@ -78,19 +95,3 @@ python sota_check_sanity_eventhandler() {
78 95
79 return 96 return
80} 97}
81
82# Translate old provisioning recipe names into the new versions.
83python () {
84 prov = d.getVar("SOTA_CLIENT_PROV")
85 if prov == "aktualizr-auto-prov":
86 bb.warn('aktualizr-auto-prov is deprecated. Please use aktualizr-shared-prov instead.')
87 d.setVar("SOTA_CLIENT_PROV", "aktualizr-shared-prov")
88 elif prov == "aktualizr-ca-implicit-prov":
89 bb.warn('aktualizr-ca-implicit-prov is deprecated. Please use aktualizr-device-prov instead.')
90 d.setVar("SOTA_CLIENT_PROV", "aktualizr-device-prov")
91 elif prov == "aktualizr-hsm-prov":
92 bb.warn('aktualizr-hsm-prov is deprecated. Please use aktualizr-device-prov-hsm instead.')
93 d.setVar("SOTA_CLIENT_PROV", "aktualizr-device-prov-hsm")
94}
95
96