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.
This commit is contained in:
Christian Kellner 2021-10-08 14:54:46 +00:00 committed by Tom Gundersen
parent 02404ced94
commit 5b1cd2b1c5
3 changed files with 12 additions and 8 deletions

View file

@ -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)

View file

@ -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()

View file

@ -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" },