Merge "VMware:Remove redundant check for usable ESX hosts"
This commit is contained in:
commit
e3b2ec32db
@ -2344,17 +2344,13 @@ class VMwareVcVmdkDriverTestCase(test.TestCase):
|
||||
host_2 = mock.sentinel.host_2
|
||||
host_3 = mock.sentinel.host_3
|
||||
vops.get_cluster_hosts.side_effect = [[host_1, host_2], [host_3]]
|
||||
# host_1 and host_3 are usable, host_2 is not usable
|
||||
vops.is_host_usable.side_effect = [True, False, True]
|
||||
|
||||
cls_1 = mock.sentinel.cls_1
|
||||
cls_2 = mock.sentinel.cls_2
|
||||
self.assertEqual([host_1, host_3],
|
||||
self.assertEqual([host_1, host_2, host_3],
|
||||
self._driver._get_hosts([cls_1, cls_2]))
|
||||
exp_calls = [mock.call(cls_1), mock.call(cls_2)]
|
||||
self.assertEqual(exp_calls, vops.get_cluster_hosts.call_args_list)
|
||||
exp_calls = [mock.call(host_1), mock.call(host_2), mock.call(host_3)]
|
||||
self.assertEqual(exp_calls, vops.is_host_usable.call_args_list)
|
||||
|
||||
@mock.patch.object(VMDK_DRIVER, '_get_hosts')
|
||||
@mock.patch.object(VMDK_DRIVER, 'ds_sel')
|
||||
|
@ -133,32 +133,6 @@ class VolumeOpsTestCase(test.TestCase):
|
||||
return mock.Mock(connectionState=connection_state,
|
||||
inMaintenanceMode=in_maintenance)
|
||||
|
||||
def test_is_host_usable(self):
|
||||
self.session.invoke_api.return_value = self._host_runtime_info()
|
||||
|
||||
self.assertTrue(self.vops.is_host_usable(mock.sentinel.host))
|
||||
self.session.invoke_api.assert_called_once_with(
|
||||
vim_util, 'get_object_property', self.session.vim,
|
||||
mock.sentinel.host, 'runtime')
|
||||
|
||||
def test_is_host_usable_with_disconnected_host(self):
|
||||
self.session.invoke_api.return_value = self._host_runtime_info(
|
||||
connection_state='disconnected')
|
||||
|
||||
self.assertFalse(self.vops.is_host_usable(mock.sentinel.host))
|
||||
self.session.invoke_api.assert_called_once_with(
|
||||
vim_util, 'get_object_property', self.session.vim,
|
||||
mock.sentinel.host, 'runtime')
|
||||
|
||||
def test_is_host_usable_with_host_in_maintenance(self):
|
||||
self.session.invoke_api.return_value = self._host_runtime_info(
|
||||
in_maintenance=True)
|
||||
|
||||
self.assertFalse(self.vops.is_host_usable(mock.sentinel.host))
|
||||
self.session.invoke_api.assert_called_once_with(
|
||||
vim_util, 'get_object_property', self.session.vim,
|
||||
mock.sentinel.host, 'runtime')
|
||||
|
||||
def test_get_hosts(self):
|
||||
hosts = mock.sentinel.hosts
|
||||
self.session.invoke_api.return_value = hosts
|
||||
|
@ -453,9 +453,7 @@ class VMwareVcVmdkDriver(driver.VolumeDriver):
|
||||
if clusters:
|
||||
for cluster in clusters:
|
||||
cluster_hosts = self.volumeops.get_cluster_hosts(cluster)
|
||||
for host in cluster_hosts:
|
||||
if self.volumeops.is_host_usable(host):
|
||||
hosts.append(host)
|
||||
hosts.extend(cluster_hosts)
|
||||
return hosts
|
||||
|
||||
def _select_datastore(self, req, host=None):
|
||||
|
@ -329,23 +329,6 @@ class VMwareVolumeOps(object):
|
||||
self._session.vim, instance,
|
||||
'runtime.host')
|
||||
|
||||
def is_host_usable(self, host):
|
||||
"""Check if the given ESX host is usable.
|
||||
|
||||
A host is usable if it is connected to vCenter server and not in
|
||||
maintenance mode.
|
||||
|
||||
:param host: Managed object reference to the ESX host
|
||||
:return: True if host is usable, False otherwise
|
||||
"""
|
||||
runtime_info = self._session.invoke_api(vim_util,
|
||||
'get_object_property',
|
||||
self._session.vim,
|
||||
host,
|
||||
'runtime')
|
||||
return (runtime_info.connectionState == 'connected' and
|
||||
not runtime_info.inMaintenanceMode)
|
||||
|
||||
def get_hosts(self):
|
||||
"""Get all host from the inventory.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user