From 5b1cd2b1c50d99a68b162abfea7b4985e37c771e Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Fri, 8 Oct 2021 14:54:46 +0000 Subject: [PATCH] schema/v2: make mount source and target optional The previous commit gave the individual mounts more control over the source and target properties. Do not require them at the global schema but hand the control if they are optional over to the modules. --- osbuild/formats/v2.py | 12 +++++++----- osbuild/mounts.py | 6 ++++-- schemas/osbuild2.json | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/osbuild/formats/v2.py b/osbuild/formats/v2.py index 4b5190e7..94da3a7f 100644 --- a/osbuild/formats/v2.py +++ b/osbuild/formats/v2.py @@ -274,14 +274,16 @@ def load_mount(description: Dict, index: Index, stage: Stage): if name in stage.mounts: raise ValueError(f"Duplicated mount '{name}'") - source = description["source"] - target = description["target"] + source = description.get("source") + target = description.get("target") options = description.get("options", {}) - device = stage.devices.get(source) - if not device: - raise ValueError(f"Unknown device '{source}' for mount '{name}'") + device = None + if source: + device = stage.devices.get(source) + if not device: + raise ValueError(f"Unknown device '{source}' for mount '{name}'") stage.add_mount(name, info, device, target, options) diff --git a/osbuild/mounts.py b/osbuild/mounts.py index 346a7a35..519fc743 100644 --- a/osbuild/mounts.py +++ b/osbuild/mounts.py @@ -35,8 +35,10 @@ class Mount: def calc_id(self): m = hashlib.sha256() m.update(json.dumps(self.info.name, sort_keys=True).encode()) - m.update(json.dumps(self.device.id, sort_keys=True).encode()) - m.update(json.dumps(self.target, sort_keys=True).encode()) + if self.device: + m.update(json.dumps(self.device.id, sort_keys=True).encode()) + if self.target: + m.update(json.dumps(self.target, sort_keys=True).encode()) m.update(json.dumps(self.options, sort_keys=True).encode()) return m.hexdigest() diff --git a/schemas/osbuild2.json b/schemas/osbuild2.json index 4d66c1bc..f08996c0 100644 --- a/schemas/osbuild2.json +++ b/schemas/osbuild2.json @@ -71,7 +71,7 @@ "mount": { "title": "Mount point for a stage", "additionalProperties": false, - "required": ["name", "type", "source", "target"], + "required": ["name", "type"], "properties": { "name": { "type": "string" }, "type": { "type": "string" },