snapshot: Fix issue with snapshot rollbacks

Closes: #2144.

- '--ambit' seems to a required argument if there is no default subvolume set on
the filesystem. Add it to prevent error during rollback.

- Description is not a required option for rollback (anymore?) and default
descriptions for the two snapshots are more descriptive.

Tests:

- On a fresh vagrant machine, run snapshot rollback with the patch. It fails.
With the patch, rollback succeeds.

- The description created for the rollback is the default one 'rollback backup'
and 'writable copy of #x'.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2023-02-02 12:58:33 -08:00 committed by James Valleroy
parent d0ea67cde6
commit 0f484d7eaa
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -251,7 +251,12 @@ def kill_daemon():
@privileged
def rollback(number: str):
"""Rollback to snapshot."""
command = [
'snapper', 'rollback', '--description', 'created by rollback', number
]
# "ambit" is not very well documented by snapper. Default ambit is "auto"
# which errors out if default subvolume is not yet set on the filesystem.
# If set, then it acts as "transactional" ambit if the default snapshot is
# readonly, otherwise it acts as "classic". The "classic" behavior is the
# one described snapper(8) man page for rollback behavior. The classic
# behavior when a snapshot number to rollback to is provided is the
# behavior that we desire.
command = ['snapper', '--ambit', 'classic', 'rollback', number]
subprocess.run(command, check=True)