From 74762d17b92d6de563a310232fe00c1587776f7e Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Wed, 29 Jan 2014 10:45:03 -0500 Subject: [PATCH] Rename self.tgtadm to self.target_helper Using "tgtadm" for this member variable is confusing because it actually represents tgt, IET, and LIO. Rename to a more generic term to make things more readable. Also remove "tgtadm" from method names and references in tests where it is not tgtadm-specific. I'm choosing the name "target_helper" because "tgtadm" = tgtd, and "iscsi_helper" doesn't fit when using RDMA in ISERDriver. Change-Id: I73fab03eb6635be6b49950e3a0ccc0e9801697ca --- cinder/tests/test_iscsi.py | 14 +++---- cinder/volume/driver.py | 6 +-- cinder/volume/drivers/block_device.py | 52 ++++++++++++------------ cinder/volume/drivers/lvm.py | 58 ++++++++++++++------------- 4 files changed, 68 insertions(+), 62 deletions(-) diff --git a/cinder/tests/test_iscsi.py b/cinder/tests/test_iscsi.py index a4c2e0f32..99e15887d 100644 --- a/cinder/tests/test_iscsi.py +++ b/cinder/tests/test_iscsi.py @@ -89,13 +89,13 @@ class TargetAdminTestCase(object): self.verify_cmds(cmds) def run_commands(self): - tgtadm = self.driver.get_target_admin() - tgtadm.set_execute(self.fake_execute) - tgtadm.create_iscsi_target(self.target_name, self.tid, - self.lun, self.path) - tgtadm.show_target(self.tid, iqn=self.target_name) - tgtadm.remove_iscsi_target(self.tid, self.lun, self.vol_id, - self.vol_name) + target_helper = self.driver.get_target_helper() + target_helper.set_execute(self.fake_execute) + target_helper.create_iscsi_target(self.target_name, self.tid, + self.lun, self.path) + target_helper.show_target(self.tid, iqn=self.target_name) + target_helper.remove_iscsi_target(self.tid, self.lun, self.vol_id, + self.vol_name) def test_target_admin(self): self.clear_cmds() diff --git a/cinder/volume/driver.py b/cinder/volume/driver.py index 3bcc59b58..544f81bf6 100644 --- a/cinder/volume/driver.py +++ b/cinder/volume/driver.py @@ -684,7 +684,7 @@ class ISCSIDriver(VolumeDriver): """ if CONF.iscsi_helper == 'lioadm': - self.tgtadm.initialize_connection(volume, connector) + self.target_helper.initialize_connection(volume, connector) iscsi_properties = self._get_iscsi_properties(volume) return { @@ -739,7 +739,7 @@ class ISCSIDriver(VolumeDriver): data['QoS_support'] = False self._stats = data - def get_target_admin(self): + def get_target_helper(self): root_helper = utils.get_root_helper() if CONF.iscsi_helper == 'iseradm': return iscsi.ISERTgtAdm(root_helper, CONF.volumes_dir, @@ -858,7 +858,7 @@ class ISERDriver(ISCSIDriver): data['QoS_support'] = False self._stats = data - def get_target_admin(self): + def get_target_helper(self): root_helper = utils.get_root_helper() if CONF.iser_helper == 'fake': diff --git a/cinder/volume/drivers/block_device.py b/cinder/volume/drivers/block_device.py index 0cdfe506c..2150cd326 100644 --- a/cinder/volume/drivers/block_device.py +++ b/cinder/volume/drivers/block_device.py @@ -44,14 +44,14 @@ class BlockDeviceDriver(driver.ISCSIDriver): VERSION = '1.0.0' def __init__(self, *args, **kwargs): - self.tgtadm = self.get_target_admin() + self.target_helper = self.get_target_helper() super(BlockDeviceDriver, self).__init__(*args, **kwargs) self.configuration.append_config_values(volume_opts) def set_execute(self, execute): super(BlockDeviceDriver, self).set_execute(execute) - self.tgtadm.set_execute(execute) + self.target_helper.set_execute(execute) def check_for_setup_error(self): pass @@ -87,7 +87,7 @@ class BlockDeviceDriver(driver.ISCSIDriver): # TODO(jdg): In the future move all of the dependent stuff into the # corresponding target admin class - if not isinstance(self.tgtadm, iscsi.TgtAdm): + if not isinstance(self.target_helper, iscsi.TgtAdm): lun = 0 self._ensure_iscsi_targets(context, volume['host']) iscsi_target = self.db.volume_allocate_iscsi_target(context, @@ -104,11 +104,11 @@ class BlockDeviceDriver(driver.ISCSIDriver): chap_password) # NOTE(jdg): For TgtAdm case iscsi_name is the ONLY param we need # should clean this all up at some point in the future - tid = self.tgtadm.create_iscsi_target(iscsi_name, - iscsi_target, - 0, - volume_path, - chap_auth) + tid = self.target_helper.create_iscsi_target(iscsi_name, + iscsi_target, + 0, + volume_path, + chap_auth) model_update['provider_location'] = self._iscsi_location( self.configuration.iscsi_ip_address, tid, iscsi_name, lun, volume_path) @@ -122,7 +122,7 @@ class BlockDeviceDriver(driver.ISCSIDriver): # TODO(jdg): In the future move all of the dependent stuff into the # corresponding target admin class - if isinstance(self.tgtadm, iscsi.LioAdm): + if isinstance(self.target_helper, iscsi.LioAdm): try: iscsi_target = self.db.volume_get_iscsi_target_num( context, @@ -131,10 +131,12 @@ class BlockDeviceDriver(driver.ISCSIDriver): LOG.info(_("Skipping remove_export. No iscsi_target " "provisioned for volume: %s"), volume['id']) return - self.tgtadm.remove_iscsi_target(iscsi_target, 0, volume['id'], - volume['name']) + self.target_helper.remove_iscsi_target(iscsi_target, + 0, + volume['id'], + volume['name']) return - elif not isinstance(self.tgtadm, iscsi.TgtAdm): + elif not isinstance(self.target_helper, iscsi.TgtAdm): try: iscsi_target = self.db.volume_get_iscsi_target_num( context, @@ -152,13 +154,13 @@ class BlockDeviceDriver(driver.ISCSIDriver): iqn = location[1] # ietadm show will exit with an error # this export has already been removed - self.tgtadm.show_target(iscsi_target, iqn=iqn) + self.target_helper.show_target(iscsi_target, iqn=iqn) except Exception: LOG.info(_("Skipping remove_export. No iscsi_target " "is presently exported for volume: %s"), volume['id']) return - self.tgtadm.remove_iscsi_target(iscsi_target, 0, volume['id'], - volume['name']) + self.target_helper.remove_iscsi_target(iscsi_target, 0, volume['id'], + volume['name']) def ensure_export(self, context, volume): """Synchronously recreates an export for a logical volume. @@ -169,7 +171,7 @@ class BlockDeviceDriver(driver.ISCSIDriver): # TODO(jdg): In the future move all of the dependent stuff into the # corresponding target admin class - if isinstance(self.tgtadm, iscsi.LioAdm): + if isinstance(self.target_helper, iscsi.LioAdm): try: volume_info = self.db.volume_get(context, volume['id']) (auth_method, @@ -187,11 +189,11 @@ class BlockDeviceDriver(driver.ISCSIDriver): volume['name']) volume_path = self.local_path(volume) iscsi_target = 1 - self.tgtadm.create_iscsi_target(iscsi_name, iscsi_target, - 0, volume_path, chap_auth, - check_exit_code=False) + self.target_helper.create_iscsi_target(iscsi_name, iscsi_target, + 0, volume_path, chap_auth, + check_exit_code=False) return - if not isinstance(self.tgtadm, iscsi.TgtAdm): + if not isinstance(self.target_helper, iscsi.TgtAdm): try: iscsi_target = self.db.volume_get_iscsi_target_num( context, @@ -215,10 +217,10 @@ class BlockDeviceDriver(driver.ISCSIDriver): # NOTE(jdg): For TgtAdm case iscsi_name is the ONLY param we need # should clean this all up at some point in the future - self.tgtadm.create_iscsi_target(iscsi_name, iscsi_target, - 0, volume_path, chap_auth, - check_exit_code=False, - old_name=old_name) + self.target_helper.create_iscsi_target(iscsi_name, iscsi_target, + 0, volume_path, chap_auth, + check_exit_code=False, + old_name=old_name) def _iscsi_location(self, ip, target, iqn, lun=None, device=None): return "%s:%s,%s %s %s %s" % (ip, self.configuration.iscsi_port, @@ -232,7 +234,7 @@ class BlockDeviceDriver(driver.ISCSIDriver): # NOTE(jdg): tgtadm doesn't use the iscsi_targets table # TODO(jdg): In the future move all of the dependent stuff into the # corresponding target admin class - if not isinstance(self.tgtadm, iscsi.TgtAdm): + if not isinstance(self.target_helper, iscsi.TgtAdm): host_iscsi_targets = self.db.iscsi_target_count_by_host(context, host) if host_iscsi_targets >= self.configuration.iscsi_num_targets: diff --git a/cinder/volume/drivers/lvm.py b/cinder/volume/drivers/lvm.py index 352185c86..15e1df703 100644 --- a/cinder/volume/drivers/lvm.py +++ b/cinder/volume/drivers/lvm.py @@ -395,7 +395,7 @@ class LVMISCSIDriver(LVMVolumeDriver, driver.ISCSIDriver): """ def __init__(self, *args, **kwargs): - self.tgtadm = self.get_target_admin() + self.target_helper = self.get_target_helper() super(LVMISCSIDriver, self).__init__(*args, **kwargs) self.backend_name =\ self.configuration.safe_get('volume_backend_name') or 'LVM_iSCSI' @@ -403,11 +403,11 @@ class LVMISCSIDriver(LVMVolumeDriver, driver.ISCSIDriver): def set_execute(self, execute): super(LVMISCSIDriver, self).set_execute(execute) - self.tgtadm.set_execute(execute) + self.target_helper.set_execute(execute) - def _create_tgtadm_target(self, iscsi_name, iscsi_target, - volume_path, chap_auth, lun=0, - check_exit_code=False, old_name=None): + def _create_target(self, iscsi_name, iscsi_target, + volume_path, chap_auth, lun=0, + check_exit_code=False, old_name=None): # NOTE(jdg): tgt driver has an issue where with a lot of activity # (or sometimes just randomly) it will get *confused* and attempt # to reuse a target ID, resulting in a target already exists error @@ -421,7 +421,7 @@ class LVMISCSIDriver(LVMVolumeDriver, driver.ISCSIDriver): try: # NOTE(jdg): For TgtAdm case iscsi_name is all we need # should clean this all up at some point in the future - tid = self.tgtadm.create_iscsi_target( + tid = self.target_helper.create_iscsi_target( iscsi_name, iscsi_target, 0, @@ -445,7 +445,7 @@ class LVMISCSIDriver(LVMVolumeDriver, driver.ISCSIDriver): # TODO(jdg): In the future move all of the dependent stuff into the # corresponding target admin class - if isinstance(self.tgtadm, iscsi.LioAdm): + if isinstance(self.target_helper, iscsi.LioAdm): try: volume_info = self.db.volume_get(context, volume['id']) (auth_method, @@ -466,12 +466,12 @@ class LVMISCSIDriver(LVMVolumeDriver, driver.ISCSIDriver): volume['name']) iscsi_target = 1 - self._create_tgtadm_target(iscsi_name, iscsi_target, - volume_path, chap_auth) + self._create_target(iscsi_name, iscsi_target, + volume_path, chap_auth) return - if not isinstance(self.tgtadm, iscsi.TgtAdm): + if not isinstance(self.target_helper, iscsi.TgtAdm): try: iscsi_target = self.db.volume_get_iscsi_target_num( context, @@ -505,11 +505,11 @@ class LVMISCSIDriver(LVMVolumeDriver, driver.ISCSIDriver): # NOTE(jdg): For TgtAdm case iscsi_name is the ONLY param we need # should clean this all up at some point in the future - self._create_tgtadm_target(iscsi_name, iscsi_target, - volume_path, chap_auth, - lun=0, - check_exit_code=False, - old_name=old_name) + self._create_target(iscsi_name, iscsi_target, + volume_path, chap_auth, + lun=0, + check_exit_code=False, + old_name=old_name) return @@ -563,7 +563,7 @@ class LVMISCSIDriver(LVMVolumeDriver, driver.ISCSIDriver): # NOTE(jdg): tgtadm doesn't use the iscsi_targets table # TODO(jdg): In the future move all of the dependent stuff into the # corresponding target admin class - if not isinstance(self.tgtadm, iscsi.TgtAdm): + if not isinstance(self.target_helper, iscsi.TgtAdm): host_iscsi_targets = self.db.iscsi_target_count_by_host(context, host) if host_iscsi_targets >= self.configuration.iscsi_num_targets: @@ -590,7 +590,7 @@ class LVMISCSIDriver(LVMVolumeDriver, driver.ISCSIDriver): # TODO(jdg): In the future move all of the dependent stuff into the # corresponding target admin class - if not isinstance(self.tgtadm, iscsi.TgtAdm): + if not isinstance(self.target_helper, iscsi.TgtAdm): lun = 0 self._ensure_iscsi_targets(context, volume['host']) iscsi_target = self.db.volume_allocate_iscsi_target(context, @@ -606,8 +606,8 @@ class LVMISCSIDriver(LVMVolumeDriver, driver.ISCSIDriver): chap_auth = self._iscsi_authentication('IncomingUser', chap_username, chap_password) - tid = self._create_tgtadm_target(iscsi_name, iscsi_target, - volume_path, chap_auth) + tid = self._create_target(iscsi_name, iscsi_target, + volume_path, chap_auth) model_update['provider_location'] = self._iscsi_location( self.configuration.iscsi_ip_address, tid, iscsi_name, lun) @@ -621,7 +621,7 @@ class LVMISCSIDriver(LVMVolumeDriver, driver.ISCSIDriver): # TODO(jdg): In the future move all of the dependent stuff into the # corresponding target admin class - if isinstance(self.tgtadm, iscsi.LioAdm): + if isinstance(self.target_helper, iscsi.LioAdm): try: iscsi_target = self.db.volume_get_iscsi_target_num( context, @@ -631,12 +631,14 @@ class LVMISCSIDriver(LVMVolumeDriver, driver.ISCSIDriver): "provisioned for volume: %s"), volume['id']) return - self.tgtadm.remove_iscsi_target(iscsi_target, 0, volume['id'], - volume['name']) + self.target_helper.remove_iscsi_target(iscsi_target, + 0, + volume['id'], + volume['name']) return - elif not isinstance(self.tgtadm, iscsi.TgtAdm): + elif not isinstance(self.target_helper, iscsi.TgtAdm): try: iscsi_target = self.db.volume_get_iscsi_target_num( context, @@ -658,15 +660,17 @@ class LVMISCSIDriver(LVMVolumeDriver, driver.ISCSIDriver): # ietadm show will exit with an error # this export has already been removed - self.tgtadm.show_target(iscsi_target, iqn=iqn) + self.target_helper.show_target(iscsi_target, iqn=iqn) except Exception: LOG.info(_("Skipping remove_export. No iscsi_target " "is presently exported for volume: %s"), volume['id']) return - self.tgtadm.remove_iscsi_target(iscsi_target, 0, volume['name_id'], - volume['name']) + self.target_helper.remove_iscsi_target(iscsi_target, + 0, + volume['name_id'], + volume['name']) def migrate_volume(self, ctxt, volume, host, thin=False, mirror_count=0): """Optimize the migration if the destination is on the same server. @@ -747,7 +751,7 @@ class LVMISERDriver(LVMISCSIDriver, driver.ISERDriver): """ def __init__(self, *args, **kwargs): - self.tgtadm = self.get_target_admin() + self.target_helper = self.get_target_helper() LVMVolumeDriver.__init__(self, *args, **kwargs) self.backend_name =\ self.configuration.safe_get('volume_backend_name') or 'LVM_iSER' -- 2.45.2