from cinder.openstack.common import log as logging
from cinder import test
from cinder import units
+from cinder import utils
from cinder.volume import configuration as conf
from cinder.volume.drivers import coraid
from cinder.volume import volume_types
connector.get_connector_properties(root_helper).\
AndReturn({})
- self.mox.StubOutWithMock(connector.InitiatorConnector, 'factory')
+ self.mox.StubOutWithMock(utils, 'brick_get_connector')
aoe_initiator = self.mox.CreateMockAnything()
- connector.InitiatorConnector.factory('aoe', root_helper,
- use_multipath=False).\
+ utils.brick_get_connector('aoe',
+ use_multipath=False).\
AndReturn(aoe_initiator)
aoe_initiator\
import hashlib
import os
import paramiko
+import socket
import StringIO
import tempfile
import uuid
from oslo.config import cfg
import cinder
+from cinder.brick.initiator import connector
+from cinder.brick.initiator import linuxfc
from cinder import exception
+from cinder.openstack.common import processutils as putils
from cinder.openstack.common import timeutils
from cinder import test
from cinder import utils
third_id = ssh.id
self.assertNotEqual(first_id, third_id)
+
+
+class BrickUtils(test.TestCase):
+ """Unit test to test the brick utility
+ wrapper functions.
+ """
+
+ def test_brick_get_connector_properties(self):
+
+ self.mox.StubOutWithMock(socket, 'gethostname')
+ socket.gethostname().AndReturn('fakehost')
+
+ self.mox.StubOutWithMock(connector.ISCSIConnector, 'get_initiator')
+ connector.ISCSIConnector.get_initiator().AndReturn('fakeinitiator')
+
+ self.mox.StubOutWithMock(linuxfc.LinuxFibreChannel, 'get_fc_wwpns')
+ linuxfc.LinuxFibreChannel.get_fc_wwpns().AndReturn(None)
+
+ self.mox.StubOutWithMock(linuxfc.LinuxFibreChannel, 'get_fc_wwnns')
+ linuxfc.LinuxFibreChannel.get_fc_wwnns().AndReturn(None)
+
+ props = {'initiator': 'fakeinitiator',
+ 'host': 'fakehost',
+ 'ip': CONF.my_ip,
+ }
+
+ self.mox.ReplayAll()
+ props_actual = utils.brick_get_connector_properties()
+ self.assertEqual(props, props_actual)
+ self.mox.VerifyAll()
+
+ def test_brick_get_connector(self):
+
+ root_helper = utils.get_root_helper()
+
+ self.mox.StubOutClassWithMocks(connector, 'ISCSIConnector')
+ connector.ISCSIConnector(execute=putils.execute,
+ driver=None,
+ root_helper=root_helper,
+ use_multipath=False)
+
+ self.mox.StubOutClassWithMocks(connector, 'FibreChannelConnector')
+ connector.FibreChannelConnector(execute=putils.execute,
+ driver=None,
+ root_helper=root_helper,
+ use_multipath=False)
+
+ self.mox.StubOutClassWithMocks(connector, 'AoEConnector')
+ connector.AoEConnector(execute=putils.execute,
+ driver=None,
+ root_helper=root_helper)
+
+ self.mox.ReplayAll()
+ utils.brick_get_connector('iscsi')
+ utils.brick_get_connector('fibre_channel')
+ utils.brick_get_connector('aoe')
+ self.mox.VerifyAll()
from oslo.config import cfg
+from cinder.brick.initiator import connector
from cinder import exception
from cinder.openstack.common import excutils
from cinder.openstack.common import gettextutils
def execute(*cmd, **kwargs):
"""Convenience wrapper around oslo's execute() method."""
if 'run_as_root' in kwargs and not 'root_helper' in kwargs:
- kwargs['root_helper'] =\
- 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
+ kwargs['root_helper'] = get_root_helper()
try:
(stdout, stderr) = processutils.execute(*cmd, **kwargs)
except processutils.ProcessExecutionError as ex:
def trycmd(*args, **kwargs):
"""Convenience wrapper around oslo's trycmd() method."""
if 'run_as_root' in kwargs and not 'root_helper' in kwargs:
- kwargs['root_helper'] =\
- 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
+ kwargs['root_helper'] = get_root_helper()
try:
(stdout, stderr) = processutils.trycmd(*args, **kwargs)
except processutils.ProcessExecutionError as ex:
LOG.exception(msg, **kwargs)
self._rollback()
+
+
+def get_root_helper():
+ return 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
+
+
+def brick_get_connector_properties():
+ """wrapper for the brick calls to automatically set
+ the root_helper needed for cinder.
+ """
+
+ root_helper = get_root_helper()
+ return connector.get_connector_properties(root_helper)
+
+
+def brick_get_connector(protocol, driver=None,
+ execute=processutils.execute,
+ use_multipath=False):
+ """Wrapper to get a brick connector object.
+ This automatically populates the required protocol as well
+ as the root_helper needed to execute commands.
+ """
+
+ root_helper = get_root_helper()
+ return connector.InitiatorConnector.factory(protocol, root_helper,
+ driver=driver,
+ execute=execute,
+ use_multipath=use_multipath)
LOG.debug(_('copy_data_between_volumes %(src)s -> %(dest)s.')
% {'src': src_vol['name'], 'dest': dest_vol['name']})
- root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
- properties = initiator.get_connector_properties(root_helper)
+ properties = utils.brick_get_connector_properties()
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'])
- root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
- properties = initiator.get_connector_properties(root_helper)
+ properties = utils.brick_get_connector_properties()
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'])
- root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
- properties = initiator.get_connector_properties(root_helper)
+ properties = utils.brick_get_connector_properties()
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, root_helper, use_multipath=use_multipath)
+ connector = utils.brick_get_connector(protocol,
+ use_multipath=use_multipath)
device = connector.connect_volume(conn['data'])
host_device = device['path']