From 989920268501bcee081d9e86f1a855ef3156644d Mon Sep 17 00:00:00 2001 From: FrantiĊĦek Zatloukal Date: Oct 08 2020 09:16:12 +0000 Subject: Improve user experience when testcloud fails because of missing group --- diff --git a/testcloud/cli.py b/testcloud/cli.py index 4ed40bf..ae64903 100644 --- a/testcloud/cli.py +++ b/testcloud/cli.py @@ -15,7 +15,7 @@ import libvirt from . import config from . import image from . import instance -from .exceptions import TestcloudCliError +from .exceptions import TestcloudCliError, TestcloudPermissionsError config_data = config.get_config() @@ -63,7 +63,16 @@ def _create_instance(args): log.debug("create instance") tc_image = image.Image(args.url) - tc_image.prepare() + try: + tc_image.prepare() + except TestcloudPermissionsError as error: + # User might not be part of testcloud group, print user friendly message how to fix this + print(error) + print("") + print("You should be able to fix this by calling following commands:") + print("sudo usermod -a -G testcloud $USER") + print("su - $USER") + sys.exit(1) existing_instance = instance.find_instance(args.name, image=tc_image, connection=args.connection) diff --git a/testcloud/exceptions.py b/testcloud/exceptions.py index a2e73b3..3944491 100644 --- a/testcloud/exceptions.py +++ b/testcloud/exceptions.py @@ -22,6 +22,9 @@ class TestcloudImageError(TestcloudException): """Exception for errors having to do with images and image fetching""" pass +class TestcloudPermissionsError(TestcloudException): + """Exception for errors from insufficient permissions on the file system.""" + pass class TestcloudInstanceError(TestcloudException): """Exception for errors having to do with instances and instance prep""" diff --git a/testcloud/image.py b/testcloud/image.py index 1e2cd26..b52c4b5 100644 --- a/testcloud/image.py +++ b/testcloud/image.py @@ -17,7 +17,7 @@ import logging import requests from . import config -from .exceptions import TestcloudImageError +from .exceptions import TestcloudImageError, TestcloudPermissionsError config_data = config.get_config() @@ -155,7 +155,7 @@ class Image(object): except OSError: # note: suppress inside exception warnings - raise TestcloudImageError( + raise TestcloudPermissionsError( 'Problem writing to {}. Are you in group testcloud?'.format(local_path) ) from None diff --git a/testcloud/instance.py b/testcloud/instance.py index 63e6014..111eff4 100644 --- a/testcloud/instance.py +++ b/testcloud/instance.py @@ -533,7 +533,7 @@ class Instance(object): else: raise TestcloudInstanceError( "Cannot remove running instance {}. Please stop the " - "instance before removing.".format(self.name)) + "instance before removing or use '-f' parameter.".format(self.name)) # remove from libvirt, assuming that it's stopped already if domain_state is not None: