summaryrefslogtreecommitdiff
path: root/nova/tests/unit/virt/vmwareapi/test_volumeops.py
diff options
context:
space:
mode:
authorjaveme <javaloveme@gmail.com>2015-03-10 00:53:02 +0800
committerJaveme <zhangmei.li@easystack.cn>2015-08-28 13:33:27 +0800
commit1e457566210559650b37095f9086557ffbf694e8 (patch)
tree97225f750e8fd1f015c6cac49198fdffdf4e267f /nova/tests/unit/virt/vmwareapi/test_volumeops.py
parent5d54e3d14939e03df662bcc11be14364b7f246bc (diff)
downloadnova-1e457566210559650b37095f9086557ffbf694e8.tar.gz
VMware: Update to return the correct ESX iqn
By default, the return value of method get_volume_connector is the first ESX's connection info. This patch will update it to return the connection info of the host running the VM. Closes-Bug: #1429581 Change-Id: Iac4f199632a0196f7cb8e1e50b7c7c4bb285d97d
Diffstat (limited to 'nova/tests/unit/virt/vmwareapi/test_volumeops.py')
-rw-r--r--nova/tests/unit/virt/vmwareapi/test_volumeops.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/nova/tests/unit/virt/vmwareapi/test_volumeops.py b/nova/tests/unit/virt/vmwareapi/test_volumeops.py
index 1fb015f438..544de0a01f 100644
--- a/nova/tests/unit/virt/vmwareapi/test_volumeops.py
+++ b/nova/tests/unit/virt/vmwareapi/test_volumeops.py
@@ -27,6 +27,7 @@ from nova.tests.unit.virt.vmwareapi import fake as vmwareapi_fake
from nova.tests.unit.virt.vmwareapi import stubs
from nova.virt.vmwareapi import constants
from nova.virt.vmwareapi import driver
+from nova.virt.vmwareapi import vim_util
from nova.virt.vmwareapi import vm_util
from nova.virt.vmwareapi import volumeops
@@ -438,3 +439,78 @@ class VMwareVolumeOpsTestCase(test.NoDBTestCase):
attach_disk_to_vm.assert_called_once_with(
volume_ref, instance, adapter_type, disk_type,
vmdk_path=new_file_name)
+
+ def test_iscsi_get_host_iqn(self):
+ host_mor = mock.Mock()
+ iqn = 'iscsi-name'
+ hba = vmwareapi_fake.HostInternetScsiHba(iqn)
+ hbas = mock.MagicMock(HostHostBusAdapter=[hba])
+
+ with contextlib.nested(
+ mock.patch.object(vm_util, 'get_host_ref_for_vm',
+ return_value=host_mor),
+ mock.patch.object(self._volumeops._session, '_call_method',
+ return_value=hbas)
+ ) as (fake_get_host_ref_for_vm, fake_call_method):
+ result = self._volumeops._iscsi_get_host_iqn(self._instance)
+
+ fake_get_host_ref_for_vm.assert_called_once_with(
+ self._volumeops._session, self._instance)
+ fake_call_method.assert_called_once_with(vim_util,
+ "get_dynamic_property",
+ host_mor, "HostSystem",
+ "config.storageDevice.hostBusAdapter")
+
+ self.assertEqual(iqn, result)
+
+ def test_iscsi_get_host_iqn_instance_not_found(self):
+ host_mor = mock.Mock()
+ iqn = 'iscsi-name'
+ hba = vmwareapi_fake.HostInternetScsiHba(iqn)
+ hbas = mock.MagicMock(HostHostBusAdapter=[hba])
+
+ with contextlib.nested(
+ mock.patch.object(vm_util, 'get_host_ref_for_vm',
+ side_effect=exception.InstanceNotFound('fake')),
+ mock.patch.object(vm_util, 'get_host_ref',
+ return_value=host_mor),
+ mock.patch.object(self._volumeops._session, '_call_method',
+ return_value=hbas)
+ ) as (fake_get_host_ref_for_vm,
+ fake_get_host_ref,
+ fake_call_method):
+ result = self._volumeops._iscsi_get_host_iqn(self._instance)
+
+ fake_get_host_ref_for_vm.assert_called_once_with(
+ self._volumeops._session, self._instance)
+ fake_get_host_ref.assert_called_once_with(
+ self._volumeops._session, self._volumeops._cluster)
+ fake_call_method.assert_called_once_with(vim_util,
+ "get_dynamic_property",
+ host_mor, "HostSystem",
+ "config.storageDevice.hostBusAdapter")
+
+ self.assertEqual(iqn, result)
+
+ def test_get_volume_connector(self):
+ vm_id = 'fake-vm'
+ vm_ref = mock.MagicMock(value=vm_id)
+ iqn = 'iscsi-name'
+ url = 'test_url'
+ self.flags(host_ip=url, group='vmware')
+
+ with contextlib.nested(
+ mock.patch.object(vm_util, 'get_vm_ref', return_value=vm_ref),
+ mock.patch.object(self._volumeops, '_iscsi_get_host_iqn',
+ return_value=iqn)
+ ) as (fake_get_vm_ref, fake_iscsi_get_host_iqn):
+ connector = self._volumeops.get_volume_connector(self._instance)
+
+ fake_get_vm_ref.assert_called_once_with(self._volumeops._session,
+ self._instance)
+ fake_iscsi_get_host_iqn.assert_called_once_with(self._instance)
+
+ self.assertEqual(url, connector['ip'])
+ self.assertEqual(url, connector['host'])
+ self.assertEqual(iqn, connector['initiator'])
+ self.assertEqual(vm_id, connector['instance'])