Merge ~jslarraz/review-tools:schema-split-definitions into review-tools:master

Proposed by Jorge Sancho Larraz
Status: Work in progress
Proposed branch: ~jslarraz/review-tools:schema-split-definitions
Merge into: review-tools:master
Diff against target: 97 lines (+28/-15)
4 files modified
bin/store-query (+4/-10)
reviewtools/schemas/definitions.json (+9/-0)
reviewtools/schemas/snap.json (+9/-2)
reviewtools/tests/schemas/test_schema_snap.py (+6/-3)
Reviewer Review Type Date Requested Status
Alex Murray Approve
Review via email: mp+466423@code.launchpad.net

Commit message

rt/schemas,bin/store-query: move architectures list to a new definitions.json

To post a comment you must log in.
Revision history for this message
Jorge Sancho Larraz (jslarraz) wrote (last edit ):

Stripping some value definitions from the snap.yaml schema will allow us to reuse them in the project (architectures, types, etc. in snap.yaml and snapcraft.yaml) or among projects (title, summary, etc. for snaps, rocks, etc.)

Reference to documents in local filesystem does not work on focal. This approach would require to move to a newer release or to place schemas in a publicly accessible location under a stable url pattern or ideally both.

Thoughts about it?

Revision history for this message
Alex Murray (alexmurray) wrote :

Perhaps I am missing something, but is it possible to load the schema and use the values directly from it rather than storing them in a separate file?

Revision history for this message
Jorge Sancho Larraz (jslarraz) wrote :

That's certainly possible as done in https://git.launchpad.net/~jslarraz/review-tools/commit/?id=22827dce8143d4e685f992c049a2935a744285ba.

However, it brings no re usability benefit. For example, looking at this MR https://code.launchpad.net/~jslarraz/review-tools/+git/review-tools/+merge/466454, ideally at some point we would like to validate that the declaration is properly formatted using a declaration schema rather than in code. In such a situation, I think it will be better (for the maintainability) to define the snap types in a separate file that can be imported by both snap.json and declaration.json rather than two separate list.

Revision history for this message
Alex Murray (alexmurray) wrote :

Ah right - so since we want to have separate JSON schemas for validating the snap declaration and for validating the snap yaml, we want to then share common type definitions between the two - this was the context I was missing.

So I am not against this change then but as we don't yet have a snap declaration schema, I think it seems a bit like premature optimisation to split out the types into a separate json schema at this time - however, since you are leading this work I am happy to go with your preferred approach. Feel free to go forward with this separate definitions.json approach :)

LGTM!

review: Approve

Unmerged commits

46940fd... by Jorge Sancho Larraz

rt/schemas,bin/store-query: move architectures list to a new definitions.json

Failed
[FAILED] test:0 (build)
[WAITING] coverage:0 (build)
12 of 2 results

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/store-query b/bin/store-query
2index e6b22b8..e1938c5 100755
3--- a/bin/store-query
4+++ b/bin/store-query
5@@ -220,20 +220,14 @@ def _get_snap_yaml(snap_name, channel=None, arch=None):
6 headers = {"Snap-Device-Series": snap_device_series}
7 res = _fetch(url, headers)
8
9+ with open("reviewtools/schemas/definitions.json") as fd:
10+ definitions = json.loads(fd.read())
11+
12 risk = "stable"
13 track = "latest"
14 if arch is None:
15 arch = "amd64"
16- if arch not in [
17- "amd64",
18- "arm64",
19- "armhf",
20- "i386",
21- "powerpc",
22- "ppc64el",
23- "riscv64",
24- "s390x",
25- ]:
26+ if arch not in definitions["$defs"]["architecture"]["enum"]:
27 raise ValueError("Unsupported arch '%s'" % arch)
28
29 if channel is not None:
30diff --git a/reviewtools/schemas/definitions.json b/reviewtools/schemas/definitions.json
31new file mode 100644
32index 0000000..ae8b4a8
33--- /dev/null
34+++ b/reviewtools/schemas/definitions.json
35@@ -0,0 +1,9 @@
36+{
37+ "description": "snap related definitions",
38+ "$defs": {
39+ "architecture": {
40+ "type": "string",
41+ "enum": ["amd64", "arm64", "armhf", "i386", "powerpc", "ppc64el", "riscv64", "s390x"]
42+ }
43+ }
44+}
45\ No newline at end of file
46diff --git a/reviewtools/schemas/snap.json b/reviewtools/schemas/snap.json
47index 8d9c6bd..15809b5 100644
48--- a/reviewtools/schemas/snap.json
49+++ b/reviewtools/schemas/snap.json
50@@ -21,8 +21,15 @@
51 "type": "array",
52 "uniqueItems": true,
53 "items": {
54- "type": "string",
55- "enum": ["all", "amd64", "arm64", "armhf", "i386", "powerpc", "ppc64el", "riscv64", "s390x"]
56+ "anyOf": [
57+ {
58+ "type": "string",
59+ "enum": ["all"]
60+ },
61+ {
62+ "$ref": "definitions.json#/$defs/architecture"
63+ }
64+ ]
65 },
66 "minItems": 1,
67 "default": ["all"]
68diff --git a/reviewtools/tests/schemas/test_schema_snap.py b/reviewtools/tests/schemas/test_schema_snap.py
69index ed4853d..c7ff6ab 100644
70--- a/reviewtools/tests/schemas/test_schema_snap.py
71+++ b/reviewtools/tests/schemas/test_schema_snap.py
72@@ -144,19 +144,22 @@ class TestSchemaSnap(TestSchemaBase):
73 # test_check_architectures_single_ppc64el
74 (["ppc64el"], None),
75 # test_check_architectures_single_nonexistent
76- (["nonexistent"], "'nonexistent' is not one of "),
77+ (
78+ ["nonexistent"],
79+ "'nonexistent' is not valid under any of the given schemas",
80+ ),
81 # test_check_snappy_valid_arch_multi
82 (["amd64", "armhf"], None),
83 # test_check_snappy_valid_arch_multi2
84 (["armhf", "arm64", "i386"], None),
85 # test_check_architectures_bad_entry
86- ([{}], "{} is not of type 'string'"),
87+ ([{}], "{} is not valid under any of the given schemas"),
88 # ### integer
89 (2, "{value} is not of type 'array'"),
90 # ### empty TODO: snapcraft does not allow empty lists, snapd does
91 ([], "{value} is too short"),
92 # ### empty value
93- ([""], "'' is not one of "),
94+ ([""], "'' is not valid under any of the given schemas"),
95 # ### duplicated value TODO: snapcraft does not duplicated values, snapd does
96 (["amd64", "amd64"], "{value} has non-unique elements"),
97 ]:

Subscribers

People subscribed via source and target branches