Commit 0cd98bac authored by Nigel Kukard's avatar Nigel Kukard
Browse files

Allow duplicate efi usage devices and filesystems

parent 1531b22f
......@@ -75,7 +75,7 @@ class IliState:
_supported_kernels: List[Dict[str, str]]
# Block devices we'll be creating fileystems on, indexed by 'efi', 'boot', 'root'
_blockdevices: Dict[str, str]
_blockdevices: Dict[str, Any]
# MBR's which we'll be installing boot records on
_boot_mbrs: List[str]
......@@ -84,7 +84,7 @@ class IliState:
_boot_hint: Optional[str]
# Filesystems to install on, indexed by 'efi', 'boot', 'root'
_filesystems: Dict[str, Dict[str, str]]
_filesystems: Dict[str, Any]
# Filesystems we've mounted
_mounts: List[Mount]
......@@ -98,7 +98,7 @@ class IliState:
_target_mount: str
# Our fstab that will be written to the target system
_fstab: Dict[str, Dict[str, str]]
_fstab: Dict[str, Any]
# Sudo users
_sudo_users: List[Dict[str, Any]]
......@@ -467,10 +467,15 @@ class IliState:
if usage not in ['efi', 'boot', 'root']:
raise RuntimeError(f'Unknown blockdevice usage "{usage}"')
if usage in self._blockdevices:
raise RuntimeError(f'Blockdevice usage "{usage}" already set')
self._blockdevices[usage] = blockdevice
# Special handling for mulitple block devices
if usage == 'efi':
if usage not in self._blockdevices:
self._blockdevices[usage] = []
self._blockdevices[usage].append(blockdevice)
else:
if usage in self._blockdevices:
raise RuntimeError(f'Blockdevice usage "{usage}" already set')
self._blockdevices[usage] = blockdevice
def replace_blockdevice(self, usage: str, blockdevice: str):
"""Replace a block device."""
......@@ -478,6 +483,9 @@ class IliState:
if usage not in ['efi', 'boot', 'root']:
raise RuntimeError(f'Unknown blockdevice usage "{usage}"')
if usage == 'efi':
raise RuntimeError('Cannot replace EFI block device as it is a list')
if usage not in self._blockdevices:
raise RuntimeError(f'Blockdevice usage "{usage}" not set')
......@@ -516,10 +524,16 @@ class IliState:
if usage not in ['efi', 'boot', 'root']:
raise RuntimeError(f'Unknown filesystem usage "{usage}"')
if usage in self._filesystems:
raise RuntimeError(f'Filesystem usage "{usage}" already set')
# We treat efi slightly differently
if usage == 'efi':
if usage not in self._filesystems:
self._filesystems[usage] = []
self._filesystems[usage].append({'uuid': uuid, 'fstype': fstype, 'device': device})
self._filesystems[usage] = {'uuid': uuid, 'fstype': fstype, 'device': device}
else:
if usage in self._filesystems:
raise RuntimeError(f'Filesystem usage "{usage}" already set')
self._filesystems[usage] = {'uuid': uuid, 'fstype': fstype, 'device': device}
@property
def filesystems(self):
......@@ -539,19 +553,26 @@ class IliState:
if usage not in ['efi', 'boot', 'root']:
raise RuntimeError(f'Unknown fstab usage "{usage}"')
if usage in self._fstab:
raise RuntimeError(f'The fstab usage "{usage}" is already set')
# Add fstab entry
self._fstab[usage] = {
# Create fstab entry
entry = {
'device': device,
'mount_point': mount_point,
'fstype': fstype,
}
# Loop through optional items
# Loop through optional entry items
for option in ['options', 'fsdump', 'fspass']:
if kwargs.get(option):
self._fstab[usage][option] = str(kwargs.get(option))
entry[option] = str(kwargs.get(option))
# We treat EFI slightly differently
if usage == 'efi':
if 'efi' not in self._fstab:
self._fstab['efi'] = []
self._fstab['efi'].append(entry)
else:
if usage in self._fstab:
raise RuntimeError(f'The fstab usage "{usage}" is already set')
self._fstab[usage] = entry
@property
def fstab(self):
......
......@@ -42,7 +42,13 @@ class ConfigSystemEtcFstab(Plugin):
# Loop with each usage and add the associated entry
for usage in ['root', 'boot', 'efi']:
self._etc_fstab.add(**ili_state.fstab[usage])
if usage not in ili_state.fstab:
continue
if usage == 'efi':
for efi in ili_state.fstab['efi']:
self._etc_fstab.add(**efi)
else:
self._etc_fstab.add(**ili_state.fstab[usage])
# Write out entries
self._etc_fstab.write(ili_state.target_root)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment