Merge "Improve logging for task updates"

This commit is contained in:
Jenkins 2017-02-27 14:34:06 +00:00 committed by Gerrit Code Review
commit 26154eca0d
2 changed files with 20 additions and 3 deletions

View File

@ -419,13 +419,25 @@ class VMwareAPISession(object):
"task: %s."),
task)
else:
task_detail = {'id': task.value}
# some internal tasks do not have 'name' set
if getattr(task_info, 'name', None):
task_detail['name'] = task_info.name
if task_info.state in ['queued', 'running']:
if hasattr(task_info, 'progress'):
LOG.debug("Task: %(task)s progress is %(progress)s%%.",
{'task': task,
{'task': task_detail,
'progress': task_info.progress})
elif task_info.state == 'success':
LOG.debug("Task: %s status is success.", task)
def get_completed_task():
complete_time = getattr(task_info, 'completeTime', None)
if complete_time:
duration = complete_time - task_info.queueTime
task_detail['duration_secs'] = duration.total_seconds()
return task_detail
LOG.debug("Task: %s completed successfully.",
get_completed_task())
raise loopingcall.LoopingCallDone(task_info)
else:
error_msg = six.text_type(task_info.error.localizedMessage)

View File

@ -18,6 +18,7 @@
Unit tests for session management and API invocation classes.
"""
from datetime import datetime
from eventlet import greenthread
import mock
import six
@ -401,6 +402,8 @@ class VMwareAPISessionTest(base.TestCase):
(state, progress) = task_info_list.pop(0)
task_info = mock.Mock()
task_info.progress = progress
task_info.queueTime = datetime(2016, 12, 6, 15, 29, 43, 79060)
task_info.completeTime = datetime(2016, 12, 6, 15, 29, 50, 79060)
task_info.state = state
return task_info
@ -546,9 +549,11 @@ class VMwareAPISessionTest(base.TestCase):
with (
mock.patch.object(api_session, 'invoke_api', fake_invoke_api)
):
fake_task = mock.Mock()
fake_task.value = 'task-1'
self.assertRaises(expected_exception,
api_session._poll_task,
'fake-task')
fake_task)
def test_poll_task_well_known_exceptions(self):
for k, v in six.iteritems(exceptions._fault_classes_registry):