'safe_get',
_fake_safe_get)
- self.stubs.Set(self.target,
- '_execute',
+ self.stubs.Set(utils,
+ 'execute',
_fake_execute)
self.assertEqual(target_string,
def _fake_execute(*args, **kwargs):
return self.fake_iscsi_scan, None
- self.stubs.Set(self.target,
- '_execute',
+ self.stubs.Set(utils,
+ 'execute',
_fake_execute)
self.assertEqual('1',
def _fake_execute(*args, **kwargs):
return self.fake_iscsi_scan, None
- self.stubs.Set(self.target,
- '_execute',
+ self.stubs.Set(utils,
+ 'execute',
_fake_execute)
self.assertTrue(self.target._verify_backing_lun(
def _fake_execute_bad_lun(*args, **kwargs):
return bad_scan, None
- self.stubs.Set(self.target,
- '_execute',
+ self.stubs.Set(utils,
+ 'execute',
_fake_execute_bad_lun)
self.assertFalse(self.target._verify_backing_lun(
def _fake_execute(*args, **kwargs):
return '', ''
- self.stubs.Set(self.target,
- '_execute',
+ self.stubs.Set(utils,
+ 'execute',
_fake_execute)
self.stubs.Set(self.target,
stderr='target already exists',
cmd='tgtad --lld iscsi --op show --mode target')
- self.stubs.Set(self.target,
- '_execute',
+ self.stubs.Set(utils,
+ 'execute',
_fake_execute)
self.stubs.Set(self.target,
def _fake_execute(*args, **kwargs):
return '', ''
- self.stubs.Set(self.target,
- '_execute',
+ self.stubs.Set(utils,
+ 'execute',
_fake_execute)
self.stubs.Set(self.target,
iscsi_driver = \
cinder.volume.targets.tgt.TgtAdm(
configuration=self.configuration)
- iscsi_driver._execute = lambda *a, **kw: \
+
+ utils.execute = lambda *a, **kw: \
("%s dummy" % CONF.iscsi_ip_address, '')
volume = {"name": "dummy",
"host": "0.0.0.0",
import abc
-from oslo_concurrency import processutils as putils
+from oslo.config import cfg
import six
+CONF = cfg.CONF
+
@six.add_metaclass(abc.ABCMeta)
class Target(object):
def __init__(self, *args, **kwargs):
self.db = kwargs.get('db')
self.configuration = kwargs.get('configuration')
- self._execute = kwargs.get('executor', putils.execute)
- self._root_helper = kwargs.get('root_helper')
+ self._root_helper = kwargs.get('root_helper',
+ 'sudo cinder-rootwrap %s' %
+ CONF.rootwrap_config)
@abc.abstractmethod
def ensure_export(self, context, volume,
from cinder import exception
from cinder.i18n import _, _LW, _LE
from cinder.openstack.common import log as logging
+from cinder import utils
from cinder.volume.targets import driver
LOG = logging.getLogger(__name__)
# NOTE(griff) We're doing the split straight away which should be
# safe since using '@' in hostname is considered invalid
- (out, _err) = self._execute('iscsiadm', '-m', 'discovery',
+ (out, _err) = utils.execute('iscsiadm', '-m', 'discovery',
'-t', 'sendtargets', '-p',
volume['host'].split('@')[0],
- root_helper=self._root_helper,
run_as_root=True)
except processutils.ProcessExecutionError as ex:
LOG.error(_LE("ISCSI discovery attempt failed for:%s") %
from cinder import exception
from cinder.i18n import _, _LE, _LI, _LW
from cinder.openstack.common import log as logging
+from cinder import utils
from cinder.volume.targets.tgt import TgtAdm
LOG = logging.getLogger(__name__)
def _verify_rtstool(self):
try:
- self._execute('cinder-rtstool', 'verify')
+ utils.execute('cinder-rtstool', 'verify')
except (OSError, putils.ProcessExecutionError):
LOG.error(_LE('cinder-rtstool is not installed correctly'))
raise
def _get_target(self, iqn):
- (out, err) = self._execute('cinder-rtstool',
+ (out, err) = utils.execute('cinder-rtstool',
'get-targets',
run_as_root=True)
lines = out.split('\n')
name,
chap_auth_userid,
chap_auth_password]
- self._execute(*command_args, run_as_root=True)
+ utils.execute(*command_args, run_as_root=True)
except putils.ProcessExecutionError as e:
LOG.error(_LE("Failed to create iscsi target for volume "
"id:%s.") % vol_id)
iqn = '%s%s' % (self.iscsi_target_prefix, vol_uuid_name)
try:
- self._execute('cinder-rtstool',
+ utils.execute('cinder-rtstool',
'delete',
iqn,
run_as_root=True)
# Add initiator iqns to target ACL
try:
- self._execute('cinder-rtstool', 'add-initiator',
+ utils.execute('cinder-rtstool', 'add-initiator',
volume_iqn,
auth_user,
auth_pass,
# Delete initiator iqns from target ACL
try:
- self._execute('cinder-rtstool', 'delete-initiator',
+ utils.execute('cinder-rtstool', 'delete-initiator',
volume_iqn,
connector['initiator'],
run_as_root=True)
from cinder.openstack.common import fileutils
from cinder.i18n import _, _LI, _LW, _LE
from cinder.openstack.common import log as logging
+from cinder import utils
from cinder.volume.targets import iscsi
from cinder.volume import utils as vutils
self.volumes_dir = self.configuration.safe_get('volumes_dir')
def _get_target(self, iqn):
- (out, err) = self._execute('tgt-admin', '--show', run_as_root=True)
+ (out, err) = utils.execute('tgt-admin', '--show', run_as_root=True)
lines = out.split('\n')
for line in lines:
if iqn in line:
capture = False
target_info = []
- (out, err) = self._execute('tgt-admin', '--show', run_as_root=True)
+ (out, err) = utils.execute('tgt-admin', '--show', run_as_root=True)
lines = out.split('\n')
for line in lines:
# and error on the side of caution
time.sleep(10)
try:
- (out, err) = self._execute('tgtadm', '--lld', 'iscsi',
+ (out, err) = utils.execute('tgtadm', '--lld', 'iscsi',
'--op', 'new', '--mode',
'logicalunit', '--tid',
tid, '--lun', '1', '-b',
# by creating the entry in the persist file
# and then doing an update to get the target
# created.
- (out, err) = self._execute('tgt-admin', '--update', name,
+ (out, err) = utils.execute('tgt-admin', '--update', name,
run_as_root=True)
LOG.debug("StdOut from tgt-admin --update: %s", out)
LOG.debug("StdErr from tgt-admin --update: %s", err)
# Grab targets list for debug
# Consider adding a check for lun 0 and 1 for tgtadm
# before considering this as valid
- (out, err) = self._execute('tgtadm',
+ (out, err) = utils.execute('tgtadm',
'--lld',
'iscsi',
'--op',
try:
# NOTE(vish): --force is a workaround for bug:
# https://bugs.launchpad.net/cinder/+bug/1159948
- self._execute('tgt-admin',
+ utils.execute('tgt-admin',
'--force',
'--delete',
iqn,
try:
LOG.warning(_LW('Silent failure of target removal '
'detected, retry....'))
- self._execute('tgt-admin',
+ utils.execute('tgt-admin',
'--delete',
iqn,
run_as_root=True)