Skip to content

Commit

Permalink
VMware: fix regression attaching iscsi cinder volumes
Browse files Browse the repository at this point in the history
VMware drivers fail to attach a iSCSI backed cinder volume with an
error 'unable to find iscsi targets' because the underlying
retrieval api was updated to a newer version but not it's usage in
volume_util (see commit e331287).
This is a regression over Grizzly release.

Fixes: bug #1193980

Change-Id: Ic2d1dc800fa10295a4d7312fbeeaa0e16d792755
  • Loading branch information
neosab authored and openstack-gerrit committed Oct 10, 2013
1 parent fc15452 commit e70211f
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 20 deletions.
8 changes: 8 additions & 0 deletions nova/tests/virt/vmwareapi/test_vmwareapi.py
Expand Up @@ -914,6 +914,14 @@ def test_attach_iscsi_disk_to_vm(self):
self.conn.attach_volume(None, connection_info, self.instance,
mount_point)

def test_find_st(self):
data = {'target_portal': 'fake_target_host:port',
'target_iqn': 'fake_target_iqn'}
host = vmwareapi_fake._get_objects('HostSystem').objects[0]
host._add_iscsi_target(data)
result = volume_util.find_st(self.conn._session, data)
self.assertEquals(('fake-device', 'fake-uuid'), result)

def test_detach_iscsi_disk_from_vm(self):
self._create_vm()
connection_info = self._test_vmdk_connection_info('iscsi')
Expand Down
72 changes: 63 additions & 9 deletions nova/virt/vmwareapi/fake.py
Expand Up @@ -33,7 +33,7 @@

_CLASSES = ['Datacenter', 'Datastore', 'ResourcePool', 'VirtualMachine',
'Network', 'HostSystem', 'HostNetworkSystem', 'Task', 'session',
'files', 'ClusterComputeResource']
'files', 'ClusterComputeResource', 'HostStorageSystem']

_FAKE_FILE_SIZE = 1024

Expand All @@ -59,6 +59,7 @@ def reset():
_db_content[c] = {}
create_network()
create_host_network_system()
create_host_storage_system()
create_host()
create_host()
create_datacenter()
Expand Down Expand Up @@ -243,8 +244,15 @@ def __repr__(self):
return str(self.__dict__)


class HostInternetScsiHba():
pass
class HostInternetScsiHba(DataObject):
"""
iSCSI Host Bus Adapter
"""

def __init__(self):
super(HostInternetScsiHba, self).__init__()
self.device = 'vmhba33'
self.key = 'key-vmhba33'


class VirtualDisk(DataObject):
Expand Down Expand Up @@ -504,6 +512,13 @@ def __init__(self, name="networkSystem"):
self.set("networkInfo.pnic", net_info_pnic)


class HostStorageSystem(ManagedObject):
"""HostStorageSystem class."""

def __init__(self):
super(HostStorageSystem, self).__init__("storageSystem")


class HostSystem(ManagedObject):
"""Host System class."""

Expand All @@ -512,9 +527,13 @@ def __init__(self, name="ha-host", connected=True):
self.set("name", name)
if _db_content.get("HostNetworkSystem", None) is None:
create_host_network_system()
if not _get_object_refs('HostStorageSystem'):
create_host_storage_system()
host_net_key = _db_content["HostNetworkSystem"].keys()[0]
host_net_sys = _db_content["HostNetworkSystem"][host_net_key].obj
self.set("configManager.networkSystem", host_net_sys)
host_storage_sys_key = _get_object_refs('HostStorageSystem')[0]
self.set("configManager.storageSystem", host_storage_sys_key)

summary = DataObject()
hardware = DataObject()
Expand Down Expand Up @@ -583,13 +602,43 @@ def __init__(self, name="ha-host", connected=True):
config = DataObject()
storageDevice = DataObject()

hostBusAdapter = HostInternetScsiHba()
hostBusAdapter.HostHostBusAdapter = [hostBusAdapter]
hostBusAdapter.iScsiName = "iscsi-name"
storageDevice.hostBusAdapter = hostBusAdapter
iscsi_hba = HostInternetScsiHba()
iscsi_hba.iScsiName = "iscsi-name"
host_bus_adapter_array = DataObject()
host_bus_adapter_array.HostHostBusAdapter = [iscsi_hba]
storageDevice.hostBusAdapter = host_bus_adapter_array
config.storageDevice = storageDevice
self.set("config.storageDevice.hostBusAdapter",
config.storageDevice.hostBusAdapter)
self.set("config.storageDevice.hostBusAdapter", host_bus_adapter_array)

# Set the same on the storage system managed object
host_storage_sys = _get_object(host_storage_sys_key)
host_storage_sys.set('storageDeviceInfo.hostBusAdapter',
host_bus_adapter_array)

def _add_iscsi_target(self, data):
default_lun = DataObject()
default_lun.scsiLun = 'key-vim.host.ScsiDisk-010'
default_lun.key = 'key-vim.host.ScsiDisk-010'
default_lun.deviceName = 'fake-device'
default_lun.uuid = 'fake-uuid'
scsi_lun_array = DataObject()
scsi_lun_array.ScsiLun = [default_lun]
self.set("config.storageDevice.scsiLun", scsi_lun_array)

transport = DataObject()
transport.address = [data['target_portal']]
transport.iScsiName = data['target_iqn']
default_target = DataObject()
default_target.lun = [default_lun]
default_target.transport = transport

iscsi_adapter = DataObject()
iscsi_adapter.adapter = 'key-vmhba33'
iscsi_adapter.transport = transport
iscsi_adapter.target = [default_target]
iscsi_topology = DataObject()
iscsi_topology.adapter = [iscsi_adapter]
self.set("config.storageDevice.scsiTopology", iscsi_topology)

def _add_port_group(self, spec):
"""Adds a port group to the host system object in the db."""
Expand Down Expand Up @@ -649,6 +698,11 @@ def create_host_network_system():
_create_object("HostNetworkSystem", host_net_system)


def create_host_storage_system():
host_storage_system = HostStorageSystem()
_create_object("HostStorageSystem", host_storage_system)


def create_host():
host_system = HostSystem()
_create_object('HostSystem', host_system)
Expand Down
17 changes: 6 additions & 11 deletions nova/virt/vmwareapi/volume_util.py
Expand Up @@ -68,21 +68,16 @@ def find_st(session, data, cluster=None):
lst_properties = ["config.storageDevice.hostBusAdapter",
"config.storageDevice.scsiTopology",
"config.storageDevice.scsiLun"]
props = session._call_method(vim_util, "get_object_properties",
None, host_mor, "HostSystem",
lst_properties)
prop_dict = session._call_method(vim_util, "get_dynamic_properties",
host_mor, "HostSystem", lst_properties)
result = (None, None)
hbas_ret = None
scsi_topology = None
scsi_lun_ret = None
for elem in props:
for prop in elem.propSet:
if prop.name == "config.storageDevice.hostBusAdapter":
hbas_ret = prop.val
elif prop.name == "config.storageDevice.scsiTopology":
scsi_topology = prop.val
elif prop.name == "config.storageDevice.scsiLun":
scsi_lun_ret = prop.val
if prop_dict:
hbas_ret = prop_dict.get('config.storageDevice.hostBusAdapter')
scsi_topology = prop_dict.get('config.storageDevice.scsiTopology')
scsi_lun_ret = prop_dict.get('config.storageDevice.scsiLun')

# Meaning there are no host bus adapters on the host
if hbas_ret is None:
Expand Down

0 comments on commit e70211f

Please sign in to comment.