Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the error logging for once and for all #150

Merged
merged 1 commit into from
Jul 7, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions wrapanapi/virtualcenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@
]


def get_task_error_message(task):
"""Depending on the error type, a different attribute may contain the error message. This
function will figure out the error message.
"""
if hasattr(task.info.error, 'message'):
message = str(task.info.error.message)
elif hasattr(task.info.error, 'localizedMessage'):
message = str(task.info.error.localizedMessage)
elif hasattr(task.info.error, 'msg'):
message = str(task.info.error.msg)
else:
message = 'Unknown error type: {}'.format(task.info.error)
return message


class VMWareSystem(WrapanapiAPIBase):
"""Client to Vsphere API

Expand Down Expand Up @@ -678,13 +693,7 @@ def _check(store=[task]):
wait_for(_check, num_sec=provision_timeout, delay=4)

if task.info.state != 'success':
if hasattr(task.info.error, 'localizedMessage'):
message = str(task.info.error.localizedMessage)
elif hasattr(task.info.error, 'faultMessage'):
message = str(task.info.error.faultMessage.message)
else:
message = 'Unknown error type: {}'.format(task.info.error)
self.logger.error('Clone VM failed: %s', message)
self.logger.error('Clone VM failed: %s', get_task_error_message(task))
raise VMInstanceNotCloned(source)
else:
return destination
Expand All @@ -711,7 +720,7 @@ def remove_host_from_cluster(self, host_name):

if status != 'success':
raise HostNotRemoved("Host {} not removed: {}".format(
host_name, task.info.error.localizedMessage))
host_name, get_task_error_message(task)))

task = host.Destroy_Task()
status, t = wait_for(self._task_wait, [task], fail_condition=None)
Expand Down