cros_sdk: Move checks for snapshot compatibility
Trying to pass a snapshot command when --nouse-image is active is an
error. With the change to making --nouse-image the default, this check
needs to be done after the automatic chroot.img detection happens so
that people don't have to explicitly pass --use-image for snapshot
operations.
BUG=chromium:1150581, chromium:1130049
TEST=cros_sdk --snapshot-list with image-backed and plain chroots
Change-Id: I70ec521ad1a8ffdd2a73284d61338f16cfd9694d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2549413
Reviewed-by: Conor McNamara <ctmcnamara@chromium.org>
Tested-by: Conor McNamara <ctmcnamara@chromium.org>
Commit-Queue: Conor McNamara <ctmcnamara@chromium.org>
diff --git a/scripts/cros_sdk.py b/scripts/cros_sdk.py
index c900294..dc87c78 100644
--- a/scripts/cros_sdk.py
+++ b/scripts/cros_sdk.py
@@ -926,9 +926,6 @@
any_snapshot_operation = (
options.snapshot_create or options.snapshot_restore or
options.snapshot_delete or options.snapshot_list)
- if any_snapshot_operation and not options.use_image:
- cros_build_lib.Die('Snapshot operations are not compatible with '
- '--nouse-image.')
if (options.snapshot_delete and
options.snapshot_delete == options.snapshot_restore):
@@ -980,6 +977,13 @@
img_path)
options.use_image = True
+ if any_snapshot_operation and not options.use_image:
+ if os.path.exists(img_path):
+ options.use_image = True
+ else:
+ cros_build_lib.Die('Snapshot operations are not compatible with '
+ '--nouse-image.')
+
# Discern if we need to create the chroot.
if (options.use_image and not chroot_exists and not options.delete and
not options.unmount and not missing_image_tools and