]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
ZFSSA iSCSI driver cannot add multple initiators to a group
authorJuan Zuluaga <juan.c.zuluaga@oracle.com>
Tue, 16 Sep 2014 15:23:36 +0000 (11:23 -0400)
committerThierry Carrez <thierry@openstack.org>
Wed, 8 Oct 2014 10:29:00 +0000 (12:29 +0200)
All initiators defined in zfssa_initiator property would be
added to the group.
Also fixed some typos related to initiators error messages.

Change-Id: Iec6c90702e5aafa153b4a7f1e429974ac450afc0
Closes-Bug: #1369750
(cherry picked from commit f94d671e627dd7b5143422ffe739418fcfb51a70)

cinder/tests/test_zfssa.py
cinder/volume/drivers/zfssa/zfssarest.py

index 49a55e6f6e460a725f3498b6a4ce053b9cc2a169..dd555d827eb0e57c1ee849d18d06287b575c2703 100644 (file)
@@ -17,11 +17,15 @@ Unit tests for Oracle's ZFSSA Cinder volume driver
 
 import mock
 
+from json import JSONEncoder
+
 from cinder.openstack.common import log as logging
 from cinder.openstack.common import units
 from cinder import test
 from cinder.volume import configuration as conf
+from cinder.volume.drivers.zfssa import restclient as client
 from cinder.volume.drivers.zfssa import zfssaiscsi as iscsi
+from cinder.volume.drivers.zfssa import zfssarest as rest
 
 
 LOG = logging.getLogger(__name__)
@@ -69,15 +73,9 @@ class FakeZFSSA(object):
         return out
 
     def add_to_initiatorgroup(self, init, initgrp):
-        out = {}
-        if not self.host or not self.user:
-            return out
-
-        out = {"href": "fake_href",
-               "name": "fake_initgrp",
-               "initiators": ["fake_iqn.1993-08.org.fake:01:000000000000"]
-               }
-        return out
+        r = rest.ZFSSAApi()
+        type(r).rclient = mock.PropertyMock(return_value=FakeAddIni2InitGrp())
+        r.add_to_initiatorgroup(init, initgrp)
 
     def create_target(self, tgtalias, inter, tchapuser, tchapsecret):
         out = {}
@@ -257,7 +255,7 @@ class TestZFSSAISCSIDriver(test.TestCase):
         self.configuration.zfssa_lun_compression = 'off'
         self.configuration.zfssa_initiator_group = 'test-init-grp1'
         self.configuration.zfssa_initiator = \
-            'iqn.1993-08.org.debian:01:daa02db2a827'
+            'iqn.1-0.org.deb:01:d7, iqn.1-0.org.deb:01:d9'
         self.configuration.zfssa_initiator_user = ''
         self.configuration.zfssa_initiator_password = ''
         self.configuration.zfssa_target_group = 'test-target-grp1'
@@ -304,3 +302,24 @@ class TestZFSSAISCSIDriver(test.TestCase):
 
     def tearDown(self):
         super(TestZFSSAISCSIDriver, self).tearDown()
+
+
+class FakeAddIni2InitGrp(object):
+
+    def get(self, path, **kwargs):
+        result = client.RestResult()
+        result.status = client.Status.OK
+        result.data = JSONEncoder().encode({'group':
+                                            {'initiators':
+                                             ['iqn.1-0.org.deb:01:d7']}})
+        return result
+
+    def put(self, path, body="", **kwargs):
+        result = client.RestResult()
+        result.status = client.Status.ACCEPTED
+        return result
+
+    def post(self, path, body="", **kwargs):
+        result = client.RestResult()
+        result.status = client.Status.CREATED
+        return result
index b86294e4cfe93fbc06056955bf43b85896a68891..762951374aea9361a058b1bd4efe45e74bdd7536 100644 (file)
@@ -149,7 +149,7 @@ class ZFSSAApi(object):
 
             ret = self.rclient.post(svc, arg)
             if ret.status != restclient.Status.CREATED:
-                exception_msg = (_('Error Creating Initator: '
+                exception_msg = (_('Error Creating Initiator: '
                                    '%(initiator)s on '
                                    'Alias: %(alias)s '
                                    'Return code: %(ret.status)d '
@@ -173,7 +173,7 @@ class ZFSSAApi(object):
             }
             ret = self.rclient.post(svc, arg)
             if ret.status != restclient.Status.CREATED:
-                exception_msg = (_('Error Adding Initator: '
+                exception_msg = (_('Error Adding Initiator: '
                                    '%(initiator)s on group'
                                    'InitiatorGroup: %(initiatorgroup)s '
                                    'Return code: %(ret.status)d '
@@ -185,13 +185,30 @@ class ZFSSAApi(object):
                 LOG.error(exception_msg)
                 raise exception.VolumeBackendAPIException(data=exception_msg)
         else:
+            val = json.loads(ret.data)
+            inits = val['group']['initiators']
+            if inits is None:
+                exception_msg = (_('Error Getting Initiators: '
+                                   'InitiatorGroup: %(initiatorgroup)s '
+                                   'Return code: %(ret.status)d '
+                                   'Message: %(ret.data)s .')
+                                 % {'initiatorgroup': initiatorgroup,
+                                    'ret.status': ret.status,
+                                    'ret.data': ret.data})
+                LOG.error(exception_msg)
+                raise exception.VolumeBackendAPIException(data=exception_msg)
+
+            if initiator in inits:
+                return
+
+            inits.append(initiator)
             svc = '/api/san/v1/iscsi/initiator-groups/' + initiatorgroup
             arg = {
-                'initiators': [initiator]
+                'initiators': inits
             }
             ret = self.rclient.put(svc, arg)
             if ret.status != restclient.Status.ACCEPTED:
-                exception_msg = (_('Error Adding Initator: '
+                exception_msg = (_('Error Adding Initiator: '
                                    '%(initiator)s on group'
                                    'InitiatorGroup: %(initiatorgroup)s '
                                    'Return code: %(ret.status)d '