]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add root_helper param to get_connector_properties
authorWalter A. Boring IV <walter.boring@hp.com>
Fri, 16 Aug 2013 15:18:09 +0000 (08:18 -0700)
committerWalter A. Boring IV <walter.boring@hp.com>
Mon, 19 Aug 2013 22:39:40 +0000 (15:39 -0700)
This patch adds the ability to pass in a custom
root_helper for executing commands.  This is needed
for other projects that need a custom root-wrapper,
such as nova.

fixes Bug #1213135

Change-Id: Ie18276ae2e736bb2276d4e9c57385d2588441428

cinder/brick/initiator/connector.py
cinder/brick/initiator/executor.py
cinder/brick/initiator/linuxfc.py
cinder/brick/initiator/linuxscsi.py
cinder/tests/brick/test_brick_connector.py
cinder/tests/brick/test_brick_linuxfc.py
cinder/tests/brick/test_brick_linuxscsi.py
cinder/tests/test_coraid.py
cinder/volume/driver.py

index 35f3775b7d42fa8ed203894769610166034d94f3..a5a312426d72db424ba9e0e492252d2198db96d4 100644 (file)
@@ -48,11 +48,11 @@ CONF.register_opts(connector_opts)
 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
@@ -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()
@@ -85,8 +85,8 @@ class InitiatorConnector(executor.Executor):
         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()
@@ -148,11 +148,11 @@ class InitiatorConnector(executor.Executor):
 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
 
@@ -486,14 +486,13 @@ class ISCSIConnector(InitiatorConnector):
 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):
@@ -658,9 +657,9 @@ class FibreChannelConnector(InitiatorConnector):
 
 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):
index f70fea670ad876700ffca4a80a4ba82548c929e5..f7a44c09c90398e2bb6d96a5f3be5e8570fcc772 100644 (file)
@@ -24,7 +24,7 @@ from cinder.openstack.common import processutils as putils
 
 
 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)
index 5878bf1f5571a3c4acfc8dcadbeef50ab8b39c6f..fd53dd25984eaff9b601d4fc377b291211454a4b 100644 (file)
@@ -27,9 +27,9 @@ LOG = logging.getLogger(__name__)
 
 
 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):
index 5a4a2e65b65064b46b38b2193030df5ec30ac0aa..bb0f56f99122f675e9b4135f9b49d2b777ac1f96 100644 (file)
@@ -29,9 +29,9 @@ LOG = logging.getLogger(__name__)
 
 
 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):
index 5ec9e657eff5c1fcd05adbeb11b1b7a3a45e2eea..f40fa25b3c5c7608aff23dd4fc659ef12162fe5e 100644 (file)
@@ -44,40 +44,40 @@ class ConnectorTestCase(test.TestCase):
         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'))
@@ -85,7 +85,7 @@ class ConnectorTestCase(test.TestCase):
     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'))
@@ -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")
 
@@ -196,7 +196,7 @@ class ISCSIConnectorTestCase(ConnectorTestCase):
         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))
@@ -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)
@@ -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'}
 
index 9091dacc52d41cd7e054c607b4d9186fd03d3dcb..03864f8d16698329ff9829a1b2ebe8f8bab72c36 100644 (file)
@@ -30,7 +30,7 @@ class LinuxFCTestCase(test.TestCase):
         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))
index c1bc072e5b8dde305ea75b09bb57957fd5ec237d..9b7b0db687da2ffe64d45fb81a5d2f51b7c207c5 100644 (file)
@@ -30,7 +30,7 @@ class LinuxSCSITestCase(test.TestCase):
         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))
index f31b850847ada20602591ab3fdaaa7aea93112c6..ab3a849c57b35f591ea540d4b6587e85671c61ba 100644 (file)
@@ -773,15 +773,19 @@ class CoraidDriverImageTestCases(CoraidDriverTestCase):
         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'])\
index 0a0cd5f36f5d0ac294c9c9e3b373b5bff139634d..587ca578bfe73b5fbd9a246447ac4e58d933175a 100644 (file)
@@ -236,7 +236,8 @@ class VolumeDriver(object):
         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:
@@ -290,7 +291,8 @@ class VolumeDriver(object):
         """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:
@@ -306,7 +308,8 @@ class VolumeDriver(object):
         """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:
@@ -329,8 +332,9 @@ class VolumeDriver(object):
         # 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']