Improve handling of mountpoint, support pe_helper mounting

main
svalouch 4 years ago
parent 7d2e6e2a0d
commit 115f3fdb7f

@ -20,10 +20,10 @@ class PEHelperBase:
def __repr__(self) -> str:
return '<PEHelperBase>'
def zfs_mount(self, fileset: str, mountpoint: Optional[str] = None) -> None:
def zfs_mount(self, fileset: str) -> None:
'''
Tries to mount ``fileset``. An optional ``mountpoint`` can be given, otherwise it relies on inheritance to set
the mountpoint. Note that some implementations may need an explicit mountpoint.
Tries to mount ``fileset`` to the location its ``mountpoint`` property points to. It does **not** check if the
fileset has a valid mountpoint property.
:raises ValidationError: If parameters do not validate.
:raises PEHelperException: If errors are encountered when running the helper.
@ -157,6 +157,14 @@ class SudoPEHelper(PEHelperBase):
raise PEHelperException(f'Error running command {" ".join(args)}: {proc.stderr}')
self.log.debug(f'pe helper command successful. stout: {proc.stdout}')
def zfs_mount(self, fileset: str) -> None:
if '/' in fileset:
validate_dataset_path(fileset)
else:
validate_pool_name(fileset)
self._execute_cmd(['zfs', 'mount', fileset])
def zfs_set_mountpoint(self, fileset: str, mountpoint: str) -> None:
if '/' in fileset:
validate_dataset_path(fileset)

@ -267,8 +267,18 @@ class ZFSCli(ZFS):
if properties and 'mountpoint' in properties:
mp = properties['mountpoint']
if self.pe_helper is not None:
log.info(f'Fileset {name} was created, using pe_helper to set the mountpoint')
self.pe_helper.zfs_set_mountpoint(name, mp)
test_prop = self.get_property(dataset=name, key='mountpoint', metadata=False)
if test_prop.value == mp:
log.info(f'Fileset {name} was created with mountpoint set')
else:
log.info(f'Fileset {name} was created, using pe_helper to set the mountpoint')
self.pe_helper.zfs_set_mountpoint(name, mp)
test_prop = self.get_property(dataset=name, key='mounted', metadata=False)
if test_prop.value == 'yes':
log.info(f'Fileset {name} is mounted')
else:
log.info(f'Using pe_helper to mount fileset {name}')
self.pe_helper.zfs_mount(name)
log.info(f'Fileset {name} created successfully (using pe_helper)')
return self.get_dataset_info(name)
else:

Loading…
Cancel
Save