import sys
-import rtslib
+# We always use rtslib-fb, but until version 2.1.52 it didn't have its own
+# namespace, so we must be backwards compatible.
+try:
+ import rtslib_fb
+except ImportError:
+ import rtslib as rtslib_fb
+
from cinder import i18n
from cinder.i18n import _
ips_allow_fail = ()
try:
- rtsroot = rtslib.root.RTSRoot()
- except rtslib.utils.RTSLibError:
+ rtsroot = rtslib_fb.root.RTSRoot()
+ except rtslib_fb.utils.RTSLibError:
print(_('Ensure that configfs is mounted at /sys/kernel/config.'))
raise
# Already exists, use this one
return
- so_new = rtslib.BlockStorageObject(name=name,
- dev=backing_device)
+ so_new = rtslib_fb.BlockStorageObject(name=name,
+ dev=backing_device)
- target_new = rtslib.Target(rtslib.FabricModule('iscsi'), name, 'create')
+ target_new = rtslib_fb.Target(rtslib_fb.FabricModule('iscsi'), name,
+ 'create')
- tpg_new = rtslib.TPG(target_new, mode='create')
+ tpg_new = rtslib_fb.TPG(target_new, mode='create')
tpg_new.set_attribute('authentication', '1')
- lun_new = rtslib.LUN(tpg_new, storage_object=so_new)
+ lun_new = rtslib_fb.LUN(tpg_new, storage_object=so_new)
if initiator_iqns:
initiator_iqns = initiator_iqns.strip(' ')
for i in initiator_iqns.split(','):
- acl_new = rtslib.NodeACL(tpg_new, i, mode='create')
+ acl_new = rtslib_fb.NodeACL(tpg_new, i, mode='create')
acl_new.chap_userid = userid
acl_new.chap_password = password
- rtslib.MappedLUN(acl_new, lun_new.lun, lun_new.lun)
+ rtslib_fb.MappedLUN(acl_new, lun_new.lun, lun_new.lun)
tpg_new.enable = 1
for ip in portals_ips:
try:
- portal = rtslib.NetworkPortal(tpg_new, ip, portals_port,
- mode='any')
- except rtslib.utils.RTSLibError:
+ portal = rtslib_fb.NetworkPortal(tpg_new, ip, portals_port,
+ mode='any')
+ except rtslib_fb.utils.RTSLibError:
raise_exc = ip not in ips_allow_fail
msg_type = 'Error' if raise_exc else 'Warning'
print(_('%(msg_type)s: creating NetworkPortal: ensure port '
try:
if iser_enabled == 'True':
portal.iser = True
- except rtslib.utils.RTSLibError:
+ except rtslib_fb.utils.RTSLibError:
print(_('Error enabling iSER for NetworkPortal: please ensure '
'that RDMA is supported on your iSCSI port %(port)d '
'on ip %(ip)s.') % {'port': portals_port, 'ip': ip})
def _lookup_target(target_iqn, initiator_iqn):
try:
- rtsroot = rtslib.root.RTSRoot()
- except rtslib.utils.RTSLibError:
+ rtsroot = rtslib_fb.root.RTSRoot()
+ except rtslib_fb.utils.RTSLibError:
print(_('Ensure that configfs is mounted at /sys/kernel/config.'))
raise
# No further action required
return
- acl_new = rtslib.NodeACL(tpg, initiator_iqn, mode='create')
+ acl_new = rtslib_fb.NodeACL(tpg, initiator_iqn, mode='create')
acl_new.chap_userid = userid
acl_new.chap_password = password
- rtslib.MappedLUN(acl_new, 0, tpg_lun=0)
+ rtslib_fb.MappedLUN(acl_new, 0, tpg_lun=0)
def delete_initiator(target_iqn, initiator_iqn):
def get_targets():
- rtsroot = rtslib.root.RTSRoot()
+ rtsroot = rtslib_fb.root.RTSRoot()
for x in rtsroot.targets:
print(x.wwn)
def delete(iqn):
- rtsroot = rtslib.root.RTSRoot()
+ rtsroot = rtslib_fb.root.RTSRoot()
for x in rtsroot.targets:
if x.wwn == iqn:
x.delete()
for member in ['BlockStorageObject', 'FabricModule', 'LUN',
'MappedLUN', 'NetworkPortal', 'NodeACL', 'root',
'Target', 'TPG']:
- if not hasattr(rtslib, member):
- raise RtstoolImportError(_("rtslib is missing member %s: "
- "You may need a newer python-rtslib.") %
+ if not hasattr(rtslib_fb, member):
+ raise RtstoolImportError(_("rtslib_fb is missing member %s: You "
+ "may need a newer python-rtslib-fb.") %
member)
def save_to_file(destination_file):
- rtsroot = rtslib.root.RTSRoot()
+ rtsroot = rtslib_fb.root.RTSRoot()
try:
rtsroot.save_to_file(destination_file)
except OSError:
elif argv[1] == 'verify':
# This is used to verify that this script can be called by cinder,
- # and that rtslib is new enough to work.
+ # and that rtslib_fb is new enough to work.
verify_rtslib()
return 0
import mock
from oslo_config import cfg
-import rtslib
+
+try:
+ import rtslib_fb
+except ImportError:
+ import rtslib as rtslib_fb
+
from cinder.cmd import all as cinder_all
from cinder.cmd import api as cinder_api
def tearDown(self):
super(TestCinderRtstoolCmd, self).tearDown()
- @mock.patch('rtslib.root.RTSRoot')
+ @mock.patch.object(rtslib_fb.root, 'RTSRoot')
def test_create_rtslib_error(self, rtsroot):
- rtsroot.side_effect = rtslib.utils.RTSLibError()
+ rtsroot.side_effect = rtslib_fb.utils.RTSLibError()
with mock.patch('sys.stdout', new=six.StringIO()):
- self.assertRaises(rtslib.utils.RTSLibError, cinder_rtstool.create,
+ self.assertRaises(rtslib_fb.utils.RTSLibError,
+ cinder_rtstool.create,
mock.sentinel.backing_device,
mock.sentinel.name,
mock.sentinel.userid,
mock.sentinel.iser_enabled)
def _test_create_rtslib_error_network_portal(self, ip):
- with mock.patch('rtslib.NetworkPortal') as network_portal, \
- mock.patch('rtslib.LUN') as lun, \
- mock.patch('rtslib.TPG') as tpg, \
- mock.patch('rtslib.FabricModule') as fabric_module, \
- mock.patch('rtslib.Target') as target, \
- mock.patch('rtslib.BlockStorageObject') as \
+ with mock.patch.object(rtslib_fb, 'NetworkPortal') as network_portal, \
+ mock.patch.object(rtslib_fb, 'LUN') as lun, \
+ mock.patch.object(rtslib_fb, 'TPG') as tpg, \
+ mock.patch.object(rtslib_fb, 'FabricModule') as fabric_module, \
+ mock.patch.object(rtslib_fb, 'Target') as target, \
+ mock.patch.object(rtslib_fb, 'BlockStorageObject') as \
block_storage_object, \
- mock.patch('rtslib.root.RTSRoot') as rts_root:
+ mock.patch.object(rtslib_fb.root, 'RTSRoot') as rts_root:
root_new = mock.MagicMock(storage_objects=mock.MagicMock())
rts_root.return_value = root_new
block_storage_object.return_value = mock.sentinel.so_new
lun.return_value = mock.sentinel.lun_new
if ip == '0.0.0.0':
- network_portal.side_effect = rtslib.utils.RTSLibError()
- self.assertRaises(rtslib.utils.RTSLibError,
+ network_portal.side_effect = rtslib_fb.utils.RTSLibError()
+ self.assertRaises(rtslib_fb.utils.RTSLibError,
cinder_rtstool.create,
mock.sentinel.backing_device,
mock.sentinel.name,
self._test_create_rtslib_error_network_portal('::0')
def _test_create(self, ip):
- with mock.patch('rtslib.NetworkPortal') as network_portal, \
- mock.patch('rtslib.LUN') as lun, \
- mock.patch('rtslib.TPG') as tpg, \
- mock.patch('rtslib.FabricModule') as fabric_module, \
- mock.patch('rtslib.Target') as target, \
- mock.patch('rtslib.BlockStorageObject') as \
+ with mock.patch.object(rtslib_fb, 'NetworkPortal') as network_portal, \
+ mock.patch.object(rtslib_fb, 'LUN') as lun, \
+ mock.patch.object(rtslib_fb, 'TPG') as tpg, \
+ mock.patch.object(rtslib_fb, 'FabricModule') as fabric_module, \
+ mock.patch.object(rtslib_fb, 'Target') as target, \
+ mock.patch.object(rtslib_fb, 'BlockStorageObject') as \
block_storage_object, \
- mock.patch('rtslib.root.RTSRoot') as rts_root:
+ mock.patch.object(rtslib_fb.root, 'RTSRoot') as rts_root:
root_new = mock.MagicMock(storage_objects=mock.MagicMock())
rts_root.return_value = root_new
block_storage_object.return_value = mock.sentinel.so_new
def network_portal_exception(*args, **kwargs):
if set([tpg_new, '::0', 3260]).issubset(list(args)):
- raise rtslib.utils.RTSLibError()
+ raise rtslib_fb.utils.RTSLibError()
else:
pass
def test_create_ipv6(self):
self._test_create('::0')
- @mock.patch.object(cinder_rtstool, 'rtslib', autospec=True)
+ @mock.patch.object(cinder_rtstool, 'rtslib_fb', autospec=True)
def test_create_ips_and_port(self, mock_rtslib):
port = 3261
ips = ['ip1', 'ip2', 'ip3']
any_order=True
)
- @mock.patch('rtslib.root.RTSRoot')
+ @mock.patch.object(rtslib_fb.root, 'RTSRoot')
def test_add_initiator_rtslib_error(self, rtsroot):
- rtsroot.side_effect = rtslib.utils.RTSLibError()
+ rtsroot.side_effect = rtslib_fb.utils.RTSLibError()
with mock.patch('sys.stdout', new=six.StringIO()):
- self.assertRaises(rtslib.utils.RTSLibError,
+ self.assertRaises(rtslib_fb.utils.RTSLibError,
cinder_rtstool.add_initiator,
mock.sentinel.target_iqn,
mock.sentinel.initiator_iqn,
mock.sentinel.userid,
mock.sentinel.password)
- @mock.patch('rtslib.root.RTSRoot')
+ @mock.patch.object(rtslib_fb.root, 'RTSRoot')
def test_add_initiator_rtstool_error(self, rtsroot):
rtsroot.targets.return_value = {}
mock.sentinel.userid,
mock.sentinel.password)
- @mock.patch('rtslib.MappedLUN')
- @mock.patch('rtslib.NodeACL')
- @mock.patch('rtslib.root.RTSRoot')
+ @mock.patch.object(rtslib_fb, 'MappedLUN')
+ @mock.patch.object(rtslib_fb, 'NodeACL')
+ @mock.patch.object(rtslib_fb.root, 'RTSRoot')
def test_add_initiator_acl_exists(self, rtsroot, node_acl, mapped_lun):
target_iqn = mock.MagicMock()
target_iqn.tpgs.return_value = \
self.assertFalse(node_acl.called)
self.assertFalse(mapped_lun.called)
- @mock.patch('rtslib.MappedLUN')
- @mock.patch('rtslib.NodeACL')
- @mock.patch('rtslib.root.RTSRoot')
+ @mock.patch.object(rtslib_fb, 'MappedLUN')
+ @mock.patch.object(rtslib_fb, 'NodeACL')
+ @mock.patch.object(rtslib_fb.root, 'RTSRoot')
def test_add_initiator(self, rtsroot, node_acl, mapped_lun):
target_iqn = mock.MagicMock()
target_iqn.tpgs.return_value = \
mode='create')
mapped_lun.assert_called_once_with(acl_new, 0, tpg_lun=0)
- @mock.patch('rtslib.root.RTSRoot')
+ @mock.patch.object(rtslib_fb.root, 'RTSRoot')
def test_get_targets(self, rtsroot):
target = mock.MagicMock()
target.dump.return_value = {'wwn': 'fake-wwn'}
self.assertEqual(str(target.wwn), fake_out.getvalue().strip())
- @mock.patch('rtslib.root.RTSRoot')
+ @mock.patch.object(rtslib_fb.root, 'RTSRoot')
def test_delete(self, rtsroot):
target = mock.MagicMock(wwn=mock.sentinel.iqn)
storage_object = mock.MagicMock()
target.delete.assert_called_once_with()
storage_object.delete.assert_called_once_with()
- @mock.patch.object(cinder_rtstool, 'rtslib', autospec=True)
+ @mock.patch.object(cinder_rtstool, 'rtslib_fb', autospec=True)
def test_save(self, mock_rtslib):
filename = mock.sentinel.filename
cinder_rtstool.save_to_file(filename)
delete.assert_called_once_with(mock.sentinel.iqn)
self.assertEqual(0, rc)
- def test_main_verify(self):
- with mock.patch('cinder.cmd.rtstool.verify_rtslib') as verify_rtslib:
- sys.argv = ['cinder-rtstool', 'verify']
+ @mock.patch.object(cinder_rtstool, 'verify_rtslib')
+ def test_main_verify(self, mock_verify_rtslib):
+ sys.argv = ['cinder-rtstool', 'verify']
- rc = cinder_rtstool.main()
+ rc = cinder_rtstool.main()
- verify_rtslib.assert_called_once_with()
- self.assertEqual(0, rc)
+ mock_verify_rtslib.assert_called_once_with()
+ self.assertEqual(0, rc)
class TestCinderVolumeUsageAuditCmd(test.TestCase):