]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix Fibre Channel attach for single WWN
authorAvishay Traeger <avishay@il.ibm.com>
Tue, 20 Aug 2013 15:53:47 +0000 (18:53 +0300)
committerAvishay Traeger <avishay@il.ibm.com>
Tue, 20 Aug 2013 15:53:47 +0000 (18:53 +0300)
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
cinder/brick/initiator/connector.py
cinder/tests/brick/test_brick_connector.py

index 35f3775b7d42fa8ed203894769610166034d94f3..df3883cb38f97ffb2f4a99505c990ea9877b4a4c 100644 (file)
@@ -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
index 5ec9e657eff5c1fcd05adbeb11b1b7a3a45e2eea..f3988b89262eb1399983016638552d497091923c 100644 (file)
@@ -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: [])