Remove unused variables from ensure_export()
After introducing commit 9651f54714
,
these three variables are obsolete in ensure_export().
By remaining these variable, ensure_export() fails to export
volumes after c-vol service is restart because the caller of
ensure_export() in lvm driver does not pass these variables.
- iscsi_name, volume_group, config
Main clean up is done by commit Ibfd1feefd72c43ef316b267e9d6645f2e67e2558.
This patch adds some tests for tgt, lio, and iser targets.
And also adds initialization of chap_auth_userid and chap_auth_password
in create_iscsi_target() because these variables might be referred
before definition.
Closes-bug: 1408121
Related-bug: 1408171
Change-Id: I8766eee33ae07fea71873809bfec37b8352c3a89
This commit is contained in:
parent
c705d398f6
commit
73363c1cac
|
@ -27,9 +27,7 @@ class FakeDriver(iscsi.ISCSITarget):
|
|||
def create_export(self, context, vref):
|
||||
pass
|
||||
|
||||
def ensure_export(self, context, vref,
|
||||
iscsi_name, vol_path,
|
||||
vol_group, cfg):
|
||||
def ensure_export(self, context, vref, vol_path):
|
||||
pass
|
||||
|
||||
def remove_export(self, context, vref):
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from cinder.tests.targets import test_tgt_driver as test_tgt
|
||||
from cinder import utils
|
||||
from cinder.volume.targets import iser
|
||||
|
||||
|
||||
class TestIserAdmDriver(test_tgt.TestTgtAdmDriver):
|
||||
|
||||
def setUp(self):
|
||||
super(TestIserAdmDriver, self).setUp()
|
||||
self.configuration.iser_ip_address = '10.9.8.7'
|
||||
self.configuration.iser_target_prefix = 'iqn.2010-10.org.openstack:'
|
||||
self.target = iser.ISERTgtAdm(root_helper=utils.get_root_helper(),
|
||||
configuration=self.configuration)
|
|
@ -0,0 +1,89 @@
|
|||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
from oslo_concurrency import processutils as putils
|
||||
|
||||
from cinder import context
|
||||
from cinder import exception
|
||||
from cinder.tests.targets import test_tgt_driver as test_tgt
|
||||
from cinder import utils
|
||||
from cinder.volume.targets import lio
|
||||
|
||||
|
||||
class TestLioAdmDriver(test_tgt.TestTgtAdmDriver):
|
||||
|
||||
def setUp(self):
|
||||
super(TestLioAdmDriver, self).setUp()
|
||||
self.target = lio.LioAdm(root_helper=utils.get_root_helper(),
|
||||
configuration=self.configuration)
|
||||
self.fake_iscsi_scan = ('iqn.2010-10.org.openstack:'
|
||||
'volume-83c2e877-feed-46be-8435-77884fe55b45')
|
||||
self.target.db = mock.MagicMock(
|
||||
volume_get=lambda x, y: {'provider_auth': 'IncomingUser foo bar'})
|
||||
|
||||
def test_get_target(self):
|
||||
|
||||
def _fake_execute(*args, **kwargs):
|
||||
return self.fake_iscsi_scan, None
|
||||
|
||||
self.stubs.Set(utils,
|
||||
'execute',
|
||||
_fake_execute)
|
||||
|
||||
self.assertEqual('iqn.2010-10.org.openstack:'
|
||||
'volume-83c2e877-feed-46be-8435-77884fe55b45',
|
||||
self.target._get_target('iqn.2010-10.org.openstack:'
|
||||
'volume-83c2e877-feed-46be-'
|
||||
'8435-77884fe55b45'))
|
||||
|
||||
def test_verify_backing_lun(self):
|
||||
pass
|
||||
|
||||
def test_create_iscsi_target_already_exists(self):
|
||||
def _fake_execute(*args, **kwargs):
|
||||
raise putils.ProcessExecutionError(exit_code=1)
|
||||
|
||||
self.stubs.Set(utils,
|
||||
'execute',
|
||||
_fake_execute)
|
||||
|
||||
self.stubs.Set(self.target,
|
||||
'_get_target',
|
||||
lambda x: 1)
|
||||
|
||||
self.stubs.Set(self.target,
|
||||
'_verify_backing_lun',
|
||||
lambda x, y: True)
|
||||
|
||||
test_vol = 'iqn.2010-10.org.openstack:'\
|
||||
'volume-83c2e877-feed-46be-8435-77884fe55b45'
|
||||
chap_auth = 'chap foo bar'
|
||||
self.assertRaises(exception.ISCSITargetCreateFailed,
|
||||
self.target.create_iscsi_target,
|
||||
test_vol,
|
||||
1,
|
||||
0,
|
||||
self.fake_volumes_dir,
|
||||
chap_auth)
|
||||
|
||||
@mock.patch.object(lio.LioAdm, 'create_iscsi_target')
|
||||
def test_ensure_export(self, _mock_create):
|
||||
|
||||
ctxt = context.get_admin_context()
|
||||
self.target.ensure_export(ctxt,
|
||||
self.testvol_1,
|
||||
self.fake_volumes_dir)
|
||||
self.target.create_iscsi_target.assert_called_once_with(
|
||||
'iqn.2010-10.org.openstack:testvol',
|
||||
1, 0, self.fake_volumes_dir, 'IncomingUser foo bar',
|
||||
check_exit_code=False)
|
|
@ -9,6 +9,7 @@
|
|||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
|
@ -228,7 +229,7 @@ class TestTgtAdmDriver(test.TestCase):
|
|||
0,
|
||||
self.fake_volumes_dir))
|
||||
|
||||
def test_create_create_export(self):
|
||||
def test_create_export(self):
|
||||
|
||||
def _fake_execute(*args, **kwargs):
|
||||
return '', ''
|
||||
|
@ -262,3 +263,16 @@ class TestTgtAdmDriver(test.TestCase):
|
|||
self.target.create_export(ctxt,
|
||||
self.testvol_1,
|
||||
self.fake_volumes_dir))
|
||||
|
||||
def test_ensure_export(self):
|
||||
ctxt = context.get_admin_context()
|
||||
with mock.patch.object(self.target, 'create_iscsi_target'):
|
||||
self.target.ensure_export(ctxt,
|
||||
self.testvol_1,
|
||||
self.fake_volumes_dir)
|
||||
self.target.create_iscsi_target.assert_called_once_with(
|
||||
'iqn.2010-10.org.openstack:testvol',
|
||||
1, 0, self.fake_volumes_dir, None,
|
||||
iscsi_write_cache='on',
|
||||
check_exit_code=False,
|
||||
old_name=None)
|
||||
|
|
|
@ -95,6 +95,8 @@ class LioAdm(TgtAdm):
|
|||
|
||||
LOG.info(_LI('Creating iscsi_target for volume: %s') % vol_id)
|
||||
|
||||
chap_auth_userid = ""
|
||||
chap_auth_password = ""
|
||||
if chap_auth is not None:
|
||||
(chap_auth_userid, chap_auth_password) = chap_auth.split(' ')[1:]
|
||||
|
||||
|
|
Loading…
Reference in New Issue