From: Avishay Traeger Date: Tue, 20 Aug 2013 15:53:47 +0000 (+0300) Subject: Fix Fibre Channel attach for single WWN X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=8bd26071418c26ccaa40423b75750fa3bab1fa22;p=openstack-build%2Fcinder-build.git Fix Fibre Channel attach for single WWN 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 --- diff --git a/cinder/brick/initiator/connector.py b/cinder/brick/initiator/connector.py index 35f3775b7..df3883cb3 100644 --- a/cinder/brick/initiator/connector.py +++ b/cinder/brick/initiator/connector.py @@ -518,9 +518,9 @@ class FibreChannelConnector(InitiatorConnector): # 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 diff --git a/cinder/tests/brick/test_brick_connector.py b/cinder/tests/brick/test_brick_connector.py index 5ec9e657e..f3988b892 100644 --- a/cinder/tests/brick/test_brick_connector.py +++ b/cinder/tests/brick/test_brick_connector.py @@ -308,18 +308,28 @@ class FibreChannelConnectorTestCase(ConnectorTestCase): 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: [])