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: I4d2809b41b24b2240e447a5c09f14e6438304cd6
Fixes: bug 1214413
  • Loading branch information
avishay-traeger committed Aug 20, 2013
1 parent a75901c commit 8bd2607
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
6 changes: 3 additions & 3 deletions cinder/brick/initiator/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,9 @@ def connect_volume(self, connection_properties):
# 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, str) or isinstance(ports, unicode):
wwns.append(str(ports))

# We need to look for wwns on every hba
# because we don't know ahead of time
Expand Down
32 changes: 21 additions & 11 deletions cinder/tests/brick/test_brick_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,18 +308,28 @@ def test_connect_volume(self):
lambda x: devices['devices'][0])
location = '10.0.2.15:3260'
name = 'volume-00000001'
wwn = '1234567890123456'
vol = {'id': 1, 'name': name}
connection_info = self.fibrechan_connection(vol, location, wwn)
mount_device = "vde"
device_info = self.connector.connect_volume(connection_info['data'])
dev_str = '/dev/disk/by-path/pci-0000:05:00.2-fc-0x%s-lun-1' % wwn
self.assertEquals(device_info['type'], 'block')
self.assertEquals(device_info['path'], dev_str)

self.connector.disconnect_volume(connection_info['data'], device_info)
expected_commands = []
self.assertEqual(expected_commands, self.cmds)
# Should work for string, unicode, and list
wwns = ['1234567890123456', unicode('1234567890123456'),
['1234567890123456', '1234567890123457']]
for wwn in wwns:
connection_info = self.fibrechan_connection(vol, location, wwn)
dev_info = self.connector.connect_volume(connection_info['data'])
exp_wwn = wwn[0] if isinstance(wwn, list) else wwn
dev_str = ('/dev/disk/by-path/pci-0000:05:00.2-fc-0x%s-lun-1' %
exp_wwn)
self.assertEquals(dev_info['type'], 'block')
self.assertEquals(dev_info['path'], dev_str)

self.connector.disconnect_volume(connection_info['data'], dev_info)
expected_commands = []
self.assertEqual(expected_commands, self.cmds)

# Should not work for anything other than string, unicode, and list
connection_info = self.fibrechan_connection(vol, location, 123)
self.assertRaises(exception.NoFibreChannelHostsFound,
self.connector.connect_volume,
connection_info['data'])

self.stubs.Set(self.connector._linuxfc, 'get_fc_hbas',
lambda: [])
Expand Down

0 comments on commit 8bd2607

Please sign in to comment.