From: Juan Zuluaga Date: Tue, 16 Sep 2014 15:23:36 +0000 (-0400) Subject: ZFSSA iSCSI driver cannot add multple initiators to a group X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f94d671e627dd7b5143422ffe739418fcfb51a70;p=openstack-build%2Fcinder-build.git ZFSSA iSCSI driver cannot add multple initiators to a group 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 --- diff --git a/cinder/tests/test_zfssa.py b/cinder/tests/test_zfssa.py index 49a55e6f6..dd555d827 100644 --- a/cinder/tests/test_zfssa.py +++ b/cinder/tests/test_zfssa.py @@ -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 diff --git a/cinder/volume/drivers/zfssa/zfssarest.py b/cinder/volume/drivers/zfssa/zfssarest.py index b86294e4c..762951374 100644 --- a/cinder/volume/drivers/zfssa/zfssarest.py +++ b/cinder/volume/drivers/zfssa/zfssarest.py @@ -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 '