Skip to content

Commit

Permalink
Fix Fibre Channel attach for single WWN
Browse files Browse the repository at this point in the history
The code allowed for only a string of the WWN or a list of them.
Unfortunately unicode is also returned, for which the attach fails.
This patch allows for unicode as well.

Change-Id: I1d81abc3f8569ce8b3fb25c0e9c8aefd10e9aae8
Fixes: bug 1214413
  • Loading branch information
avishay-traeger committed Aug 22, 2013
1 parent 6725c9c commit 52c0668
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
40 changes: 22 additions & 18 deletions nova/tests/virt/libvirt/test_libvirt_volume.py
Expand Up @@ -549,24 +549,28 @@ def test_libvirt_fibrechan_driver(self):
'id': 0, 'lun': 1}]}
self.stubs.Set(linuxscsi, 'find_multipath_device', lambda x: devices)
self.stubs.Set(linuxscsi, 'remove_device', lambda x: None)
wwn = '1234567890123456'
connection_info = self.fibrechan_connection(self.vol, self.location,
wwn)
mount_device = "vde"
conf = libvirt_driver.connect_volume(connection_info, self.disk_info)
tree = conf.format_dom()
dev_str = '/dev/disk/by-path/pci-0000:05:00.2-fc-0x%s-lun-1' % wwn
self.assertEqual(tree.get('type'), 'block')
self.assertEqual(tree.find('./source').get('dev'), multipath_devname)
connection_info["data"]["devices"] = devices["devices"]
libvirt_driver.disconnect_volume(connection_info, mount_device)
expected_commands = []
self.assertEqual(self.executes, expected_commands)

self.stubs.Set(libvirt_utils, 'get_fc_hbas',
lambda: [])
self.stubs.Set(libvirt_utils, 'get_fc_hbas_info',
lambda: [])
# Should work for string, unicode, and list
wwns = ['1234567890123456', unicode('1234567890123456'),
['1234567890123456', '1234567890123457']]
for wwn in wwns:
connection_info = self.fibrechan_connection(self.vol,
self.location, wwn)
mount_device = "vde"
conf = libvirt_driver.connect_volume(connection_info,
self.disk_info)
tree = conf.format_dom()
dev_str = '/dev/disk/by-path/pci-0000:05:00.2-fc-0x%s-lun-1' % wwn
self.assertEqual(tree.get('type'), 'block')
self.assertEqual(tree.find('./source').get('dev'),
multipath_devname)
connection_info["data"]["devices"] = devices["devices"]
libvirt_driver.disconnect_volume(connection_info, mount_device)
expected_commands = []
self.assertEqual(self.executes, expected_commands)

# Should not work for anything other than string, unicode, and list
connection_info = self.fibrechan_connection(self.vol,
self.location, 123)
self.assertRaises(exception.NovaException,
libvirt_driver.connect_volume,
connection_info, self.disk_info)
Expand Down
6 changes: 3 additions & 3 deletions nova/virt/libvirt/volume.py
Expand Up @@ -706,9 +706,9 @@ def connect_volume(self, connection_info, disk_info):
# we support a list of wwns or a single wwn
if isinstance(ports, list):
for wwn in ports:
wwns.append(wwn)
elif isinstance(ports, str):
wwns.append(ports)
wwns.append(str(wwn))
elif isinstance(ports, basestring):
wwns.append(str(ports))

# We need to look for wwns on every hba
# because we don't know ahead of time
Expand Down

0 comments on commit 52c0668

Please sign in to comment.