Add ToolsUnavailable exception

Some API calls that depend on VMware Tools will return a
ToolsUnavailable fault such as ShutdownGuest. This patch adds the
new fault so that callers can catch this specific fault rather
than the general one.

Change-Id: Ibe132e54dd84e12d01e32528824e6db8ec785b52
This commit is contained in:
Eric Brown
2015-05-12 20:31:01 -07:00
parent 2dfb6bae41
commit 5df9daa5a3
2 changed files with 8 additions and 0 deletions

View File

@@ -39,6 +39,7 @@ TASK_IN_PROGRESS = 'TaskInProgress'
DUPLICATE_NAME = 'DuplicateName'
SECURITY_ERROR = "SecurityError"
NO_DISK_SPACE = 'NoDiskSpace'
TOOLS_UNAVAILABLE = 'ToolsUnavailable'
class VimException(Exception):
@@ -229,6 +230,10 @@ class NoDiskSpaceException(VMwareDriverException):
msg_fmt = _("Insufficient disk space.")
class ToolsUnavailableException(VMwareDriverException):
msg_fmt = _("VMware Tools is not running.")
# Populate the fault registry with the exceptions that have
# special treatment.
_fault_classes_registry = {
@@ -245,6 +250,7 @@ _fault_classes_registry = {
TASK_IN_PROGRESS: TaskInProgress,
DUPLICATE_NAME: DuplicateName,
NO_DISK_SPACE: NoDiskSpaceException,
TOOLS_UNAVAILABLE: ToolsUnavailableException,
}

View File

@@ -106,5 +106,7 @@ class ExceptionsTest(base.TestCase):
exceptions.get_fault_class("DuplicateName"))
self.assertEqual(exceptions.NoDiskSpaceException,
exceptions.get_fault_class("NoDiskSpace"))
self.assertEqual(exceptions.ToolsUnavailableException,
exceptions.get_fault_class("ToolsUnavailable"))
# Test unknown fault.
self.assertIsNone(exceptions.get_fault_class("NotAFile"))