]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Update Brick to use executor
authorWalter A. Boring IV <walter.boring@hp.com>
Thu, 15 Aug 2013 17:41:08 +0000 (10:41 -0700)
committerWalter A. Boring IV <walter.boring@hp.com>
Wed, 21 Aug 2013 06:00:26 +0000 (23:00 -0700)
modify existing modules in Brick
to make use of the Executor object,
so we don't replicated the same
set_execute() method everywhere.

Change-Id: Ib0363029557253ad86bae90e1db4fefd24a42df7

cinder/brick/executor.py [moved from cinder/brick/initiator/executor.py with 100% similarity]
cinder/brick/initiator/connector.py
cinder/brick/initiator/linuxscsi.py
cinder/brick/iscsi/iscsi.py
cinder/brick/iser/iser.py
cinder/brick/local_dev/lvm.py
cinder/tests/test_iscsi.py
cinder/tests/test_iser.py
cinder/volume/drivers/block_device.py
cinder/volume/drivers/lvm.py

index a5a312426d72db424ba9e0e492252d2198db96d4..755edffff67282e7c4d9530c569efd1c33e76aef 100644 (file)
@@ -22,7 +22,7 @@ import time
 from oslo.config import cfg
 
 from cinder.brick import exception
-from cinder.brick.initiator import executor
+from cinder.brick import executor
 from cinder.brick.initiator import host_driver
 from cinder.brick.initiator import linuxfc
 from cinder.brick.initiator import linuxscsi
index bb0f56f99122f675e9b4135f9b49d2b777ac1f96..70bd4d19034e56cbc32860fd5eea4e7a0724f634 100644 (file)
@@ -20,7 +20,7 @@
 """
 import os
 
-from cinder.brick.initiator import executor
+from cinder.brick import executor
 from cinder.openstack.common.gettextutils import _
 from cinder.openstack.common import log as logging
 from cinder.openstack.common import processutils as putils
index 5a3b8cc66a9a5cfed4a1e7d272d06d5d812e8337..80800032ff08866cfe03e2974a5873fcfcec3463 100644 (file)
@@ -28,6 +28,7 @@ import stat
 from oslo.config import cfg
 
 from cinder.brick import exception
+from cinder.brick import executor
 from cinder.openstack.common import fileutils
 from cinder.openstack.common.gettextutils import _
 from cinder.openstack.common import log as logging
@@ -67,19 +68,15 @@ CONF.register_opts(iscsi_helper_opt)
 CONF.import_opt('volume_name_template', 'cinder.db')
 
 
-class TargetAdmin(object):
+class TargetAdmin(executor.Executor):
     """iSCSI target administration.
 
     Base class for iSCSI target admin helpers.
     """
 
-    def __init__(self, cmd, execute):
+    def __init__(self, cmd, root_helper, execute):
+        super(TargetAdmin, self).__init__(root_helper, execute=execute)
         self._cmd = cmd
-        self.set_execute(execute)
-
-    def set_execute(self, execute):
-        """Set the function to be used to execute commands."""
-        self._execute = execute
 
     def _run(self, *args, **kwargs):
         self._execute(self._cmd, *args, run_as_root=True, **kwargs)
@@ -117,8 +114,8 @@ class TargetAdmin(object):
 class TgtAdm(TargetAdmin):
     """iSCSI target administration using tgtadm."""
 
-    def __init__(self, execute=putils.execute):
-        super(TgtAdm, self).__init__('tgtadm', execute)
+    def __init__(self, root_helper, execute=putils.execute):
+        super(TgtAdm, self).__init__('tgtadm', root_helper, execute)
 
     def _get_target(self, iqn):
         (out, err) = self._execute('tgt-admin', '--show', run_as_root=True)
@@ -234,8 +231,8 @@ class TgtAdm(TargetAdmin):
 class IetAdm(TargetAdmin):
     """iSCSI target administration using ietadm."""
 
-    def __init__(self, execute=putils.execute):
-        super(IetAdm, self).__init__('ietadm', execute)
+    def __init__(self, root_helper, execute=putils.execute):
+        super(IetAdm, self).__init__('ietadm', root_helper, execute)
 
     def _is_block(self, path):
         mode = os.stat(path).st_mode
@@ -381,8 +378,8 @@ class FakeIscsiHelper(object):
 
 class LioAdm(TargetAdmin):
     """iSCSI target administration for LIO using python-rtslib."""
-    def __init__(self, execute=putils.execute):
-        super(LioAdm, self).__init__('rtstool', execute)
+    def __init__(self, root_helper, execute=putils.execute):
+        super(LioAdm, self).__init__('rtstool', root_helper, execute)
 
         try:
             self._execute('rtstool', 'verify')
@@ -491,12 +488,12 @@ class LioAdm(TargetAdmin):
             raise exception.ISCSITargetAttachFailed(volume_id=volume['id'])
 
 
-def get_target_admin():
+def get_target_admin(root_helper):
     if CONF.iscsi_helper == 'tgtadm':
-        return TgtAdm()
+        return TgtAdm(root_helper)
     elif CONF.iscsi_helper == 'fake':
         return FakeIscsiHelper()
     elif CONF.iscsi_helper == 'lioadm':
-        return LioAdm()
+        return LioAdm(root_helper)
     else:
-        return IetAdm()
+        return IetAdm(root_helper)
index e6afa453185808dbce58b078f5abb8e5ff507970..43f66b7921e6a7f500237499f8d5e8756fd454d0 100644 (file)
@@ -24,6 +24,7 @@ import os
 from oslo.config import cfg
 
 from cinder.brick import exception
+from cinder.brick import executor
 from cinder.openstack.common import fileutils
 from cinder.openstack.common.gettextutils import _
 from cinder.openstack.common import log as logging
@@ -46,19 +47,15 @@ CONF.register_opts(iser_helper_opt)
 CONF.import_opt('volume_name_template', 'cinder.db')
 
 
-class TargetAdmin(object):
+class TargetAdmin(executor.Executor):
     """iSER target administration.
 
     Base class for iSER target admin helpers.
     """
 
-    def __init__(self, cmd, execute):
+    def __init__(self, cmd, root_helper, execute):
+        super(TargetAdmin, self).__init__(root_helper, execute=execute)
         self._cmd = cmd
-        self.set_execute(execute)
-
-    def set_execute(self, execute):
-        """Set the function to be used to execute commands."""
-        self._execute = execute
 
     def _run(self, *args, **kwargs):
         self._execute(self._cmd, *args, run_as_root=True, **kwargs)
@@ -96,8 +93,8 @@ class TargetAdmin(object):
 class TgtAdm(TargetAdmin):
     """iSER target administration using tgtadm."""
 
-    def __init__(self, execute=putils.execute):
-        super(TgtAdm, self).__init__('tgtadm', execute)
+    def __init__(self, root_helper, execute=putils.execute):
+        super(TgtAdm, self).__init__('tgtadm', root_helper, execute)
 
     def _get_target(self, iqn):
         (out, err) = self._execute('tgt-admin', '--show', run_as_root=True)
@@ -223,8 +220,8 @@ class FakeIserHelper(object):
         return self.tid
 
 
-def get_target_admin():
+def get_target_admin(root_helper):
     if CONF.iser_helper == 'fake':
         return FakeIserHelper()
     else:
-        return TgtAdm()
+        return TgtAdm(root_helper)
index 2543a8735eed8a6043b9659d82aa0ee8a955a739..dbd5d474cac1c1967d0a832c9cf3170e73010ed9 100644 (file)
@@ -25,6 +25,7 @@ import re
 from itertools import izip
 
 from cinder.brick import exception
+from cinder.brick import executor
 from cinder.openstack.common.gettextutils import _
 from cinder.openstack.common import log as logging
 from cinder.openstack.common import processutils as putils
@@ -32,7 +33,7 @@ from cinder.openstack.common import processutils as putils
 LOG = logging.getLogger(__name__)
 
 
-class LVM(object):
+class LVM(executor.Executor):
     """LVM object to enable various LVM related operations."""
 
     def __init__(self, vg_name, root_helper, create_vg=False,
@@ -53,6 +54,7 @@ class LVM(object):
         :param executor: Execute method to use, None uses common/processutils
 
         """
+        super(LVM, self).__init__(execute=executor, root_helper=root_helper)
         self.vg_name = vg_name
         self.pv_list = []
         self.lv_list = []
@@ -62,8 +64,6 @@ class LVM(object):
         self.vg_uuid = None
         self.vg_thin_pool = None
         self.vg_thin_pool_size = 0
-        self.root_helper = root_helper
-        self._set_execute(executor)
 
         if create_vg and physical_volumes is not None:
             self.pv_list = physical_volumes
@@ -109,7 +109,7 @@ class LVM(object):
         exists = False
         cmd = ['vgs', '--noheadings', '-o', 'name']
         (out, err) = self._execute(*cmd,
-                                   root_helper=self.root_helper,
+                                   root_helper=self._root_helper,
                                    run_as_root=True)
 
         if out is not None:
@@ -121,7 +121,7 @@ class LVM(object):
 
     def _create_vg(self, pv_list):
         cmd = ['vgcreate', self.vg_name, ','.join(pv_list)]
-        self._execute(*cmd, root_helper=self.root_helper, run_as_root=True)
+        self._execute(*cmd, root_helper=self._root_helper, run_as_root=True)
 
     def _get_vg_uuid(self):
         (out, err) = self._execute('vgs', '--noheadings',
@@ -192,7 +192,7 @@ class LVM(object):
         :returns: List of Dictionaries with LV info
 
         """
-        self.lv_list = self.get_all_volumes(self.root_helper, self.vg_name)
+        self.lv_list = self.get_all_volumes(self._root_helper, self.vg_name)
         return self.lv_list
 
     def get_volume(self, name):
@@ -248,7 +248,7 @@ class LVM(object):
         :returns: List of Dictionaries with PV info
 
         """
-        self.pv_list = self.get_all_physical_volumes(self.root_helper,
+        self.pv_list = self.get_all_physical_volumes(self._root_helper,
                                                      self.vg_name)
         return self.pv_list
 
@@ -299,7 +299,7 @@ class LVM(object):
         :returns: Dictionaries of VG info
 
         """
-        vg_list = self.get_all_volume_groups(self.root_helper, self.vg_name)
+        vg_list = self.get_all_volume_groups(self._root_helper, self.vg_name)
 
         if len(vg_list) != 1:
             LOG.error(_('Unable to find VG: %s') % self.vg_name)
@@ -311,7 +311,7 @@ class LVM(object):
         self.vg_uuid = vg_list[0]['uuid']
 
         if self.vg_thin_pool is not None:
-            for lv in self.get_all_volumes(self.root_helper, self.vg_name):
+            for lv in self.get_all_volumes(self._root_helper, self.vg_name):
                 if lv['name'] == self.vg_thin_pool:
                     self.vg_thin_pool_size = lv['size']
 
@@ -327,7 +327,7 @@ class LVM(object):
 
         """
 
-        if not self.supports_thin_provisioning(self.root_helper):
+        if not self.supports_thin_provisioning(self._root_helper):
             LOG.error(_('Requested to setup thin provisioning, '
                         'however current LVM version does not '
                         'support it.'))
@@ -347,7 +347,7 @@ class LVM(object):
         cmd = ['lvcreate', '-T', '-L', size_str, pool_path]
 
         self._execute(*cmd,
-                      root_helper=self.root_helper,
+                      root_helper=self._root_helper,
                       run_as_root=True)
         self.vg_thin_pool = pool_path
 
@@ -378,7 +378,7 @@ class LVM(object):
 
         try:
             self._execute(*cmd,
-                          root_helper=self.root_helper,
+                          root_helper=self._root_helper,
                           run_as_root=True)
         except putils.ProcessExecutionError as err:
             LOG.exception(_('Error creating Volume'))
@@ -407,7 +407,7 @@ class LVM(object):
 
         try:
             self._execute(*cmd,
-                          root_helper=self.root_helper,
+                          root_helper=self._root_helper,
                           run_as_root=True)
         except putils.ProcessExecutionError as err:
             LOG.exception(_('Error creating snapshot'))
@@ -425,7 +425,7 @@ class LVM(object):
         self._execute('lvremove',
                       '-f',
                       '%s/%s' % (self.vg_name, name),
-                      root_helper=self.root_helper, run_as_root=True)
+                      root_helper=self._root_helper, run_as_root=True)
 
     def revert(self, snapshot_name):
         """Revert an LV from snapshot.
@@ -434,14 +434,14 @@ class LVM(object):
 
         """
         self._execute('lvconvert', '--merge',
-                      snapshot_name, root_helper=self.root_helper,
+                      snapshot_name, root_helper=self._root_helper,
                       run_as_root=True)
 
     def lv_has_snapshot(self, name):
         out, err = self._execute('lvdisplay', '--noheading',
                                  '-C', '-o', 'Attr',
                                  '%s/%s' % (self.vg_name, name),
-                                 root_helper=self.root_helper,
+                                 root_helper=self._root_helper,
                                  run_as_root=True)
         if out:
             out = out.strip()
index d10354a725528fe0724825138827cfe52565841b..2247465e054d5dee5aa74ec017f89428d19bbe4e 100644 (file)
@@ -42,7 +42,7 @@ class TargetAdminTestCase(object):
         self.stubs.Set(iscsi.LioAdm, '_get_target', self.fake_get_target)
         self.stubs.Set(iscsi.LioAdm, '__init__', self.fake_init)
 
-    def fake_init(obj):
+    def fake_init(obj, root_helper):
         return
 
     def fake_get_target(obj, iqn):
@@ -79,7 +79,7 @@ class TargetAdminTestCase(object):
         self.verify_cmds(cmds)
 
     def run_commands(self):
-        tgtadm = iscsi.get_target_admin()
+        tgtadm = iscsi.get_target_admin(None)
         tgtadm.set_execute(self.fake_execute)
         tgtadm.create_iscsi_target(self.target_name, self.tid,
                                    self.lun, self.path)
index 789fbe36098e441358f59ecef2514cccf3d659bd..aa621bda4a52ef7887f8df1e0e3f5aef7bc0af6c 100644 (file)
@@ -77,7 +77,7 @@ class TargetAdminTestCase(object):
         self.verify_cmds(cmds)
 
     def run_commands(self):
-        tgtadm = iser.get_target_admin()
+        tgtadm = iser.get_target_admin(None)
         tgtadm.set_execute(self.fake_execute)
         tgtadm.create_iser_target(self.target_name, self.tid,
                                   self.lun, self.path)
index 1b3031add43cfc759179862316110d609fbab5f2..0272d4d08842467f08dadbe0b15abafa9938b19e 100644 (file)
@@ -44,7 +44,8 @@ class BlockDeviceDriver(driver.ISCSIDriver):
     VERSION = '1.0.0'
 
     def __init__(self, *args, **kwargs):
-        self.tgtadm = iscsi.get_target_admin()
+        root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
+        self.tgtadm = iscsi.get_target_admin(root_helper)
 
         super(BlockDeviceDriver, self).__init__(*args, **kwargs)
         self.configuration.append_config_values(volume_opts)
index 2b01cc031eb78feeb2dc8bdd9c883f6f1f1e38ef..6e6ace6256c7db38917985849a536381eff34f61 100644 (file)
@@ -372,7 +372,8 @@ class LVMISCSIDriver(LVMVolumeDriver, driver.ISCSIDriver):
     """
 
     def __init__(self, *args, **kwargs):
-        self.tgtadm = iscsi.get_target_admin()
+        root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
+        self.tgtadm = iscsi.get_target_admin(root_helper)
         super(LVMISCSIDriver, self).__init__(*args, **kwargs)
 
     def set_execute(self, execute):
@@ -723,7 +724,8 @@ class LVMISERDriver(LVMISCSIDriver, driver.ISERDriver):
     """
 
     def __init__(self, *args, **kwargs):
-        self.tgtadm = iser.get_target_admin()
+        root_helper = 'sudo cinder-rootwrap %s' % CONF.rootwrap_config
+        self.tgtadm = iser.get_target_admin(root_helper)
         LVMVolumeDriver.__init__(self, *args, **kwargs)
 
     def set_execute(self, execute):