Commit 843baa34 by Őry Máté

common: use humanize_exception for aborted activities

parent bb695789
...@@ -33,7 +33,9 @@ from sizefield.models import FileSizeField ...@@ -33,7 +33,9 @@ from sizefield.models import FileSizeField
from .tasks import local_tasks, storage_tasks from .tasks import local_tasks, storage_tasks
from celery.exceptions import TimeoutError from celery.exceptions import TimeoutError
from common.models import WorkerNotFound, HumanReadableException from common.models import (
WorkerNotFound, HumanReadableException, humanize_exception
)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -404,10 +406,11 @@ class Disk(TimeStampedModel): ...@@ -404,10 +406,11 @@ class Disk(TimeStampedModel):
try: try:
result = remote.get(timeout=5) result = remote.get(timeout=5)
break break
except TimeoutError: except TimeoutError as e:
if task is not None and task.is_aborted(): if task is not None and task.is_aborted():
AbortableAsyncResult(remote.id).abort() AbortableAsyncResult(remote.id).abort()
raise Exception("Download aborted by user.") raise humanize_exception(ugettext_noop(
"Operation aborted by user."), e)
disk.size = result['size'] disk.size = result['size']
disk.type = result['type'] disk.type = result['type']
disk.is_ready = True disk.is_ready = True
...@@ -477,11 +480,12 @@ class Disk(TimeStampedModel): ...@@ -477,11 +480,12 @@ class Disk(TimeStampedModel):
try: try:
remote.get(timeout=5) remote.get(timeout=5)
break break
except TimeoutError: except TimeoutError as e:
if task is not None and task.is_aborted(): if task is not None and task.is_aborted():
AbortableAsyncResult(remote.id).abort() AbortableAsyncResult(remote.id).abort()
disk.destroy() disk.destroy()
raise Exception("Save as aborted by use.") raise humanize_exception(ugettext_noop(
"Operation aborted by user."), e)
disk.is_ready = True disk.is_ready = True
disk.save() disk.save()
return disk return disk
...@@ -41,7 +41,9 @@ from model_utils.models import TimeStampedModel, StatusModel ...@@ -41,7 +41,9 @@ from model_utils.models import TimeStampedModel, StatusModel
from taggit.managers import TaggableManager from taggit.managers import TaggableManager
from acl.models import AclBase from acl.models import AclBase
from common.models import create_readable, HumanReadableException from common.models import (
create_readable, HumanReadableException, humanize_exception
)
from common.operations import OperatedMixin from common.operations import OperatedMixin
from ..tasks import vm_tasks, agent_tasks from ..tasks import vm_tasks, agent_tasks
from .activity import (ActivityInProgressError, instance_activity, from .activity import (ActivityInProgressError, instance_activity,
...@@ -877,10 +879,11 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin, ...@@ -877,10 +879,11 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
while True: while True:
try: try:
return remote.get(timeout=step) return remote.get(timeout=step)
except TimeoutError: except TimeoutError as e:
if task is not None and task.is_aborted(): if task is not None and task.is_aborted():
AbortableAsyncResult(remote.id).abort() AbortableAsyncResult(remote.id).abort()
raise Exception("Shutdown aborted by user.") raise humanize_exception(ugettext_noop(
"Operation aborted by user."), e)
def suspend_vm(self, timeout=230): def suspend_vm(self, timeout=230):
queue_name = self.get_remote_queue_name('vm', 'slow') queue_name = self.get_remote_queue_name('vm', 'slow')
......
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 sign in to comment