synchronized = lockutils.synchronized_with_prefix('brick-')
-def get_connector_properties():
+def get_connector_properties(root_helper):
"""Get the connection properties for all protocols."""
- iscsi = ISCSIConnector()
- fc = linuxfc.LinuxFibreChannel()
+ iscsi = ISCSIConnector(root_helper=root_helper)
+ fc = linuxfc.LinuxFibreChannel(root_helper=root_helper)
props = {}
props['ip'] = CONF.my_ip
class InitiatorConnector(executor.Executor):
- def __init__(self, driver=None, execute=putils.execute,
- root_helper="sudo", *args, **kwargs):
- super(InitiatorConnector, self).__init__(execute, root_helper,
+ def __init__(self, root_helper, driver=None,
+ execute=putils.execute, *args, **kwargs):
+ super(InitiatorConnector, self).__init__(root_helper, execute,
*args, **kwargs)
if not driver:
driver = host_driver.HostDriver()
self.driver = driver
@staticmethod
- def factory(protocol, driver=None, execute=putils.execute,
- root_helper="sudo", use_multipath=False):
+ def factory(protocol, root_helper, driver=None,
+ execute=putils.execute, use_multipath=False):
"""Build a Connector object based upon protocol."""
LOG.debug("Factory for %s" % protocol)
protocol = protocol.upper()
class ISCSIConnector(InitiatorConnector):
"""Connector class to attach/detach iSCSI volumes."""
- def __init__(self, driver=None, execute=putils.execute,
- root_helper="sudo", use_multipath=False,
+ def __init__(self, root_helper, driver=None,
+ execute=putils.execute, use_multipath=False,
*args, **kwargs):
- self._linuxscsi = linuxscsi.LinuxSCSI(execute, root_helper)
- super(ISCSIConnector, self).__init__(driver, execute, root_helper,
+ self._linuxscsi = linuxscsi.LinuxSCSI(root_helper, execute)
+ super(ISCSIConnector, self).__init__(root_helper, driver, execute,
*args, **kwargs)
self.use_multipath = use_multipath
class FibreChannelConnector(InitiatorConnector):
"""Connector class to attach/detach Fibre Channel volumes."""
- def __init__(self, driver=None, execute=putils.execute,
- root_helper="sudo", use_multipath=False,
+ def __init__(self, root_helper, driver=None,
+ execute=putils.execute, use_multipath=False,
*args, **kwargs):
- self._linuxscsi = linuxscsi.LinuxSCSI(execute, root_helper)
- self._linuxfc = linuxfc.LinuxFibreChannel(execute, root_helper)
- super(FibreChannelConnector, self).__init__(driver, execute,
- root_helper,
- *args, **kwargs)
+ self._linuxscsi = linuxscsi.LinuxSCSI(root_helper, execute)
+ self._linuxfc = linuxfc.LinuxFibreChannel(root_helper, execute)
+ super(FibreChannelConnector, self).__init__(root_helper, driver,
+ execute, *args, **kwargs)
self.use_multipath = use_multipath
def set_execute(self, execute):
class AoEConnector(InitiatorConnector):
"""Connector class to attach/detach AoE volumes."""
- def __init__(self, driver=None, execute=putils.execute,
- root_helper="sudo", *args, **kwargs):
- super(AoEConnector, self).__init__(driver, execute, root_helper,
+ def __init__(self, root_helper, driver=None,
+ execute=putils.execute, *args, **kwargs):
+ super(AoEConnector, self).__init__(root_helper, driver, execute,
*args, **kwargs)
def _get_aoe_info(self, connection_properties):
class Executor(object):
- def __init__(self, execute=putils.execute, root_helper="sudo",
+ def __init__(self, root_helper, execute=putils.execute,
*args, **kwargs):
self.set_execute(execute)
self.set_root_helper(root_helper)
class LinuxFibreChannel(linuxscsi.LinuxSCSI):
- def __init__(self, execute=putils.execute, root_helper="sudo",
+ def __init__(self, root_helper, execute=putils.execute,
*args, **kwargs):
- super(LinuxFibreChannel, self).__init__(execute, root_helper,
+ super(LinuxFibreChannel, self).__init__(root_helper, execute,
*args, **kwargs)
def rescan_hosts(self, hbas):
class LinuxSCSI(executor.Executor):
- def __init__(self, execute=putils.execute, root_helper="sudo",
+ def __init__(self, root_helper, execute=putils.execute,
*args, **kwargs):
- super(LinuxSCSI, self).__init__(execute, root_helper,
+ super(LinuxSCSI, self).__init__(root_helper, execute,
*args, **kwargs)
def echo_scsi_command(self, path, content):
return "", None
def test_connect_volume(self):
- self.connector = connector.InitiatorConnector()
+ self.connector = connector.InitiatorConnector(None)
self.assertRaises(NotImplementedError,
self.connector.connect_volume, None)
def test_disconnect_volume(self):
- self.connector = connector.InitiatorConnector()
+ self.connector = connector.InitiatorConnector(None)
self.assertRaises(NotImplementedError,
self.connector.disconnect_volume, None, None)
def test_factory(self):
- obj = connector.InitiatorConnector.factory('iscsi')
+ obj = connector.InitiatorConnector.factory('iscsi', None)
self.assertTrue(obj.__class__.__name__,
"ISCSIConnector")
- obj = connector.InitiatorConnector.factory('fibre_channel')
+ obj = connector.InitiatorConnector.factory('fibre_channel', None)
self.assertTrue(obj.__class__.__name__,
"FibreChannelConnector")
- obj = connector.InitiatorConnector.factory('aoe')
+ obj = connector.InitiatorConnector.factory('aoe', None)
self.assertTrue(obj.__class__.__name__,
"AoEConnector")
self.assertRaises(ValueError,
connector.InitiatorConnector.factory,
- "bogus")
+ "bogus", None)
def test_check_valid_device_with_wrong_path(self):
- self.connector = connector.InitiatorConnector()
+ self.connector = connector.InitiatorConnector(None)
self.stubs.Set(self.connector,
'_execute', lambda *args, **kwargs: ("", None))
self.assertFalse(self.connector.check_valid_device('/d0v'))
def test_check_valid_device(self):
- self.connector = connector.InitiatorConnector()
+ self.connector = connector.InitiatorConnector(None)
self.stubs.Set(self.connector,
'_execute', lambda *args, **kwargs: ("", ""))
self.assertTrue(self.connector.check_valid_device('/dev'))
def test_check_valid_device_with_cmd_error(self):
def raise_except(*args, **kwargs):
raise putils.ProcessExecutionError
- self.connector = connector.InitiatorConnector()
+ self.connector = connector.InitiatorConnector(None)
self.stubs.Set(self.connector,
'_execute', raise_except)
self.assertFalse(self.connector.check_valid_device('/dev'))
def setUp(self):
super(ISCSIConnectorTestCase, self).setUp()
- self.connector = connector.ISCSIConnector(execute=self.fake_execute,
- use_multipath=False)
+ self.connector = connector.ISCSIConnector(
+ None, execute=self.fake_execute, use_multipath=False)
self.stubs.Set(self.connector._linuxscsi,
'get_name_from_path', lambda x: "/dev/sdb")
connection_properties = self.iscsi_connection(vol, location, iqn)
self.connector_with_multipath =\
- connector.ISCSIConnector(use_multipath=True)
+ connector.ISCSIConnector(None, use_multipath=True)
self.stubs.Set(self.connector_with_multipath,
'_run_iscsiadm_bare',
lambda *args, **kwargs: "%s %s" % (location, iqn))
def setUp(self):
super(FibreChannelConnectorTestCase, self).setUp()
self.connector = connector.FibreChannelConnector(
- execute=self.fake_execute, use_multipath=False)
+ None, execute=self.fake_execute, use_multipath=False)
self.assertIsNotNone(self.connector)
self.assertIsNotNone(self.connector._linuxfc)
self.assertIsNotNone(self.connector._linuxscsi)
def setUp(self):
super(AoEConnectorTestCase, self).setUp()
self.mox = mox.Mox()
- self.connector = connector.AoEConnector()
+ self.connector = connector.AoEConnector('sudo')
self.connection_properties = {'target_shelf': 'fake_shelf',
'target_lun': 'fake_lun'}
super(LinuxFCTestCase, self).setUp()
self.cmds = []
self.stubs.Set(os.path, 'exists', lambda x: True)
- self.lfc = linuxfc.LinuxFibreChannel(execute=self.fake_execute)
+ self.lfc = linuxfc.LinuxFibreChannel(None, execute=self.fake_execute)
def fake_execute(self, *cmd, **kwargs):
self.cmds.append(string.join(cmd))
super(LinuxSCSITestCase, self).setUp()
self.cmds = []
self.stubs.Set(os.path, 'realpath', lambda x: '/dev/sdc')
- self.linuxscsi = linuxscsi.LinuxSCSI(execute=self.fake_execute)
+ self.linuxscsi = linuxscsi.LinuxSCSI(None, execute=self.fake_execute)
def fake_execute(self, *cmd, **kwargs):
self.cmds.append(string.join(cmd))
self.driver.terminate_connection(fake_volume, mox.IgnoreArg())\
.AndReturn(None)
+ root_helper = 'sudo cinder-rootwrap None'
+
self.mox.StubOutWithMock(connector, 'get_connector_properties')
- connector.get_connector_properties().AndReturn({})
+ connector.get_connector_properties(root_helper).\
+ AndReturn({})
self.mox.StubOutWithMock(connector.InitiatorConnector, 'factory')
aoe_initiator = self.mox.CreateMockAnything()
- connector.InitiatorConnector.factory('aoe', use_multipath=False)\
- .AndReturn(aoe_initiator)
+ connector.InitiatorConnector.factory('aoe', root_helper,
+ use_multipath=False).\
+ AndReturn(aoe_initiator)
aoe_initiator\
.connect_volume(self.fake_connection['data'])\
LOG.debug(_('copy_data_between_volumes %(src)s -> %(dest)s.')
% {'src': src_vol['name'], 'dest': dest_vol['name']})
- properties = initiator.get_connector_properties()
+ root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
+ properties = initiator.get_connector_properties(root_helper)
dest_remote = True if remote in ['dest', 'both'] else False
dest_orig_status = dest_vol['status']
try:
"""Fetch the image from image_service and write it to the volume."""
LOG.debug(_('copy_image_to_volume %s.') % volume['name'])
- properties = initiator.get_connector_properties()
+ root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
+ properties = initiator.get_connector_properties(root_helper)
attach_info = self._attach_volume(context, volume, properties)
try:
"""Copy the volume to the specified image."""
LOG.debug(_('copy_volume_to_image %s.') % volume['name'])
- properties = initiator.get_connector_properties()
+ root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
+ properties = initiator.get_connector_properties(root_helper)
attach_info = self._attach_volume(context, volume, properties)
try:
# Use Brick's code to do attach/detach
use_multipath = self.configuration.use_multipath_for_image_xfer
protocol = conn['driver_volume_type']
+ root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
connector = initiator.InitiatorConnector.factory(
- protocol, use_multipath=use_multipath)
+ protocol, root_helper, use_multipath=use_multipath)
device = connector.connect_volume(conn['data'])
host_device = device['path']