Raise exception when import without properties
exception.Invalid will be raised when use task-create to import image without properties, as task-create is a asynchronous action, so we change task status to failure, and save the exception msg to the task msg, the end users can get the msg when they use "task-show". Change-Id: I08c26fd073e643d6ae7fef3475343442d24831b5 Closes-bug: #1580848
This commit is contained in:
parent
24fae90c17
commit
bcf372288d
@ -97,7 +97,7 @@ class TaskExecutor(glance.async.TaskExecutor):
|
||||
invoke_kwds=kwds).driver
|
||||
except urllib.error.URLError as exc:
|
||||
raise exception.ImportTaskError(message=exc.reason)
|
||||
except exception.BadStoreUri as exc:
|
||||
except (exception.BadStoreUri, exception.Invalid) as exc:
|
||||
raise exception.ImportTaskError(message=exc.msg)
|
||||
except RuntimeError:
|
||||
raise NotImplementedError()
|
||||
|
@ -407,6 +407,28 @@ class TestTasksController(test_utils.BaseTestCase):
|
||||
"%(supported)s") % {'supported': supported}
|
||||
self.assertEqual(msg, final_task.message)
|
||||
|
||||
def test_create_with_properties_missed(self):
|
||||
request = unit_test_utils.get_fake_request()
|
||||
executor_factory = self.gateway.get_task_executor_factory(
|
||||
request.context)
|
||||
task_repo = self.gateway.get_task_repo(request.context)
|
||||
|
||||
task = {
|
||||
"type": "import",
|
||||
"input": {
|
||||
"import_from": "swift://cloud.foo/myaccount/mycontainer/path",
|
||||
"import_from_format": "qcow2",
|
||||
}
|
||||
}
|
||||
new_task = self.controller.create(request, task=task)
|
||||
task_executor = executor_factory.new_task_executor(request.context)
|
||||
task_executor.begin_processing(new_task.task_id)
|
||||
final_task = task_repo.get(new_task.task_id)
|
||||
|
||||
self.assertEqual('failure', final_task.status)
|
||||
msg = "Input does not contain 'image_properties' field"
|
||||
self.assertEqual(msg, final_task.message)
|
||||
|
||||
@mock.patch.object(glance.gateway.Gateway, 'get_task_factory')
|
||||
def test_notifications_on_create(self, mock_get_task_factory):
|
||||
request = unit_test_utils.get_fake_request()
|
||||
|
Loading…
Reference in New Issue
Block a user