self.target._get_target_chap_auth(ctx, test_vol))
self.assertTrue(mock_open.called)
+ def test_get_target_chap_auth_negative(self):
+ test_vol =\
+ 'iqn.2010-10.org.openstack:'\
+ 'volume-83c2e877-feed-46be-8435-77884fe55b45'
+ with mock.patch('__builtin__.open') as mock_open:
+ e = IOError()
+ e.errno = 123
+ mock_open.side_effect = e
+ ctxt = context.get_admin_context()
+ self.assertRaises(IOError,
+ self.target._get_target_chap_auth,
+ ctxt, test_vol)
+ mock_open.side_effect = StandardError()
+ self.assertRaises(StandardError,
+ self.target._get_target_chap_auth,
+ ctxt, test_vol)
+
@mock.patch('cinder.volume.targets.cxt.CxtAdm._get_target',
return_value=1)
@mock.patch('cinder.utils.execute')
self.assertEqual(expected,
self.target._get_target_chap_auth(ctxt, test_vol))
+ def test_get_target_chap_auth_negative(self):
+ test_vol =\
+ 'iqn.2010-10.org.openstack:'\
+ 'volume-83c2e877-feed-46be-8435-77884fe55b45'
+ with mock.patch('__builtin__.open') as mock_open:
+ e = IOError()
+ e.errno = 123
+ mock_open.side_effect = e
+ ctxt = context.get_admin_context()
+ self.assertRaises(IOError,
+ self.target._get_target_chap_auth,
+ ctxt, test_vol)
+ mock_open.side_effect = StandardError()
+ self.assertRaises(StandardError,
+ self.target._get_target_chap_auth,
+ ctxt, test_vol)
+
def test_create_iscsi_target(self):
def _fake_execute(*args, **kwargs):
from oslo_concurrency import processutils as putils
from oslo_utils import netutils
-import six
from cinder import exception
from cinder.openstack.common import fileutils
volume_conf = f.read()
except IOError as e_fnf:
LOG.debug('Failed to open config for %(vol_id)s: %(e)s',
- {'vol_id': vol_id, 'e':
- six.text_type(e_fnf)})
+ {'vol_id': vol_id, 'e': e_fnf})
# We don't run on anything non-linux
if e_fnf.errno == 2:
return None
else:
raise
except Exception as e_vol:
- LOG.debug('Failed to open config for %(vol_id)s: %(e)s',
- {'vol_id': vol_id, 'e':
- six.text_type(e_vol)})
+ LOG.error(_LE('Failed to open config for %(vol_id)s: %(e)s'),
+ {'vol_id': vol_id, 'e': e_vol})
raise
m = re.search('Auth_CHAP_Initiator="(\w+)":"(\w+)"', volume_conf)
import time
from oslo_concurrency import processutils as putils
-import six
from cinder import exception
from cinder.openstack.common import fileutils
except putils.ProcessExecutionError as e:
LOG.error(_LE("Failed recovery attempt to create "
"iscsi backing lun for Volume "
- "id:%(vol_id)s: %(e)s"),
- {'vol_id': name, 'e': six.text_type(e)})
+ "ID:%(vol_id)s: %(e)s"),
+ {'vol_id': name, 'e': e})
finally:
LOG.debug('StdOut from recreate backing lun: %s', out)
LOG.debug('StdErr from recreate backing lun: %s', err)
try:
with open(volume_path, 'r') as f:
volume_conf = f.read()
- except Exception as e:
+ except IOError as e_fnf:
LOG.debug('Failed to open config for Volume %(vol_id)s: %(e)s',
- {'vol_id': vol_id, 'e': six.text_type(e)})
- return None
+ {'vol_id': vol_id, 'e': e_fnf})
+ # tgt is linux specific
+ if e_fnf.errno == 2:
+ return None
+ else:
+ raise
+ except Exception as e_vol:
+ LOG.error(_LE('Failed to open config for %(vol_id)s: %(e)s'),
+ {'vol_id': vol_id, 'e': e_vol})
+ raise
m = re.search('incominguser (\w+) (\w+)', volume_conf)
if m:
# ER marker (Ref bug: #1398078).
LOG.warning(_LW('Could not create target because '
'it already exists for volume: %s'), vol_id)
- LOG.debug('Exception was: %s', six.text_type(e))
+ LOG.debug('Exception was: %s', e)
- LOG.error(_LE("Failed to create iscsi target for Volume "
- "ID: %(vol_id)s: %(e)s"),
- {'vol_id': vol_id, 'e': six.text_type(e)})
+ else:
+ LOG.error(_LE("Failed to create iscsi target for Volume "
+ "ID: %(vol_id)s: %(e)s"),
+ {'vol_id': vol_id, 'e': e})
# Don't forget to remove the persistent file we created
os.unlink(volume_path)
LOG.warning(_LW("Failed target removal because target "
"couldn't be found for iqn: %s."), iqn)
else:
- LOG.error(_LE("Failed to remove iscsi target for volume "
+ LOG.error(_LE("Failed to remove iscsi target for Volume "
"ID: %(vol_id)s: %(e)s"),
- {'vol_id': vol_id, 'e': six.text_type(e)})
+ {'vol_id': vol_id, 'e': e})
raise exception.ISCSITargetRemoveFailed(volume_id=vol_id)
# NOTE(jdg): There's a bug in some versions of tgt that
# will sometimes fail silently when using the force flag
except putils.ProcessExecutionError as e:
LOG.error(_LE("Failed to remove iscsi target for Volume "
"ID: %(vol_id)s: %(e)s"),
- {'vol_id': vol_id, 'e': six.text_type(e)})
+ {'vol_id': vol_id, 'e': e})
raise exception.ISCSITargetRemoveFailed(volume_id=vol_id)
# NOTE(jdg): This *should* be there still but incase