VMware: revert deletion of cleanup_host

Commit 1deb31f85a removes cleanup_host
by mistake. This adds the missing method back.

Related-Bug: #1355875

Change-Id: If695bf00613fe389af91f453dbc8191698d95a94
This commit is contained in:
Davanum Srinivas 2014-08-12 17:13:59 -04:00
parent c2ee61e595
commit 49d4defee6
3 changed files with 55 additions and 1 deletions

View File

@ -1010,6 +1010,21 @@ class FakeFactory(object):
return DataObject(obj_name)
class FakeService(DataObject):
"""Fake service class."""
def Logout(self, session_manager):
pass
class FakeClient(DataObject):
"""Fake client class."""
def __init__(self):
"""Creates a namespace object."""
self.service = FakeService()
class FakeSession(object):
"""Fake Session Class."""
@ -1052,7 +1067,7 @@ class FakeVim(object):
contents and the cookies for the session.
"""
self._session = None
self.client = DataObject()
self.client = FakeClient()
self.client.factory = FakeFactory()
transport = DataObject()

View File

@ -383,6 +383,33 @@ class VMwareAPIVMTestCase(test.NoDBTestCase):
self.task_ref = None
self.exception = False
def test_cleanup_host(self):
self.conn.init_host("fake_host")
try:
self.conn.cleanup_host("fake_host")
except Exception as ex:
self.fail("cleanup_host raised: %s" % ex)
@mock.patch('nova.virt.vmwareapi.driver.VMwareVCDriver.__init__')
def test_cleanup_host_direct(self, mock_init):
mock_init.return_value = None
vcdriver = driver.VMwareVCDriver(None, False)
vcdriver._session = mock.Mock()
vcdriver.cleanup_host("foo")
vcdriver._session.vim.get_service_content.assert_called_once_with()
vcdriver._session.vim.client.service.Logout.assert_called_once_with(
vcdriver._session.vim.get_service_content().sessionManager
)
@mock.patch('nova.virt.vmwareapi.driver.VMwareVCDriver.__init__')
def test_cleanup_host_direct_with_bad_logout(self, mock_init):
mock_init.return_value = None
vcdriver = driver.VMwareVCDriver(None, False)
vcdriver._session = mock.Mock()
fault = suds.WebFault(mock.Mock(), mock.Mock())
vcdriver._session.vim.client.service.Logout.side_effect = fault
vcdriver.cleanup_host("foo")
def test_driver_capabilities(self):
self.assertTrue(self.conn.capabilities['has_imagecache'])
self.assertFalse(self.conn.capabilities['supports_recreate'])

View File

@ -25,6 +25,7 @@ import time
from eventlet import event
from oslo.config import cfg
import suds
from nova import exception
from nova.i18n import _, _LC, _LW
@ -169,6 +170,17 @@ class VMwareVCDriver(driver.ComputeDriver):
if vim is None:
self._session._create_session()
def cleanup_host(self, host):
# NOTE(hartsocks): we lean on the init_host to force the vim object
# to not be None.
vim = self._session.vim
service_content = vim.get_service_content()
session_manager = service_content.sessionManager
try:
vim.client.service.Logout(session_manager)
except suds.WebFault:
LOG.debug("No vSphere session was open during cleanup_host.")
def cleanup(self, context, instance, network_info, block_device_info=None,
destroy_disks=True, migrate_data=None, destroy_vifs=True):
"""Cleanup after instance being destroyed by Hypervisor."""