Skip to content

Commit

Permalink
Merge "Add root_helper param to get_connector_properties"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Aug 20, 2013
2 parents a75901c + 2584b30 commit 64cad73
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 50 deletions.
43 changes: 21 additions & 22 deletions cinder/brick/initiator/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
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
Expand All @@ -71,9 +71,9 @@ def get_connector_properties():


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()
Expand All @@ -85,8 +85,8 @@ def set_driver(self, driver):
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()
Expand Down Expand Up @@ -148,11 +148,11 @@ def disconnect_volume(self, connection_properties, device_info):
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

Expand Down Expand Up @@ -486,14 +486,13 @@ def _rescan_multipath(self):
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):
Expand Down Expand Up @@ -658,9 +657,9 @@ def _get_pci_num(self, hba):

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):
Expand Down
2 changes: 1 addition & 1 deletion cinder/brick/initiator/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


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)
Expand Down
4 changes: 2 additions & 2 deletions cinder/brick/initiator/linuxfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@


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):
Expand Down
4 changes: 2 additions & 2 deletions cinder/brick/initiator/linuxscsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@


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):
Expand Down
28 changes: 14 additions & 14 deletions cinder/tests/brick/test_brick_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,48 +44,48 @@ def fake_execute(self, *cmd, **kwargs):
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'))
Expand All @@ -109,8 +109,8 @@ class ISCSIConnectorTestCase(ConnectorTestCase):

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")

Expand Down Expand Up @@ -196,7 +196,7 @@ def test_connect_volume_with_multipath(self):
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))
Expand Down Expand Up @@ -239,7 +239,7 @@ class FibreChannelConnectorTestCase(ConnectorTestCase):
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)
Expand Down Expand Up @@ -335,7 +335,7 @@ class AoEConnectorTestCase(ConnectorTestCase):
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'}

Expand Down
2 changes: 1 addition & 1 deletion cinder/tests/brick/test_brick_linuxfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setUp(self):
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))
Expand Down
2 changes: 1 addition & 1 deletion cinder/tests/brick/test_brick_linuxscsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setUp(self):
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))
Expand Down
10 changes: 7 additions & 3 deletions cinder/tests/test_coraid.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,15 +773,19 @@ def setUp(self):
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'])\
Expand Down
12 changes: 8 additions & 4 deletions cinder/volume/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ def copy_volume_data(self, context, src_vol, dest_vol, remote=None):
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:
Expand Down Expand Up @@ -290,7 +291,8 @@ def copy_image_to_volume(self, context, volume, image_service, image_id):
"""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:
Expand All @@ -306,7 +308,8 @@ def copy_volume_to_image(self, context, volume, image_service, image_meta):
"""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:
Expand All @@ -329,8 +332,9 @@ def _attach_volume(self, context, volume, properties, remote=False):
# 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']

Expand Down

0 comments on commit 64cad73

Please sign in to comment.