From 0357fdee9cfd9212b3cc2a81b438769bb63b2a48 Mon Sep 17 00:00:00 2001 From: Mark McLoughlin <markmc@redhat.com> Date: Thu, 11 Aug 2011 07:44:38 -0400 Subject: [PATCH] Allow the user to choose either ietadm or tgtadm (lp:819997) (Actually authored by Chuck Short <zulcss@ubuntu.com> but Gerrit won't allow me to push it with Author: set to that) Change-Id: Ia350345a25a5f39b8aa26c8daf2a9987590d4b62 --- nova/flags.py | 3 + nova/tests/test_volume.py | 5 +- nova/volume/driver.py | 137 ++++++++++++++++++++++++++++++++++----------- 3 files changed, 111 insertions(+), 34 deletions(-) diff --git a/nova/flags.py b/nova/flags.py index 792407b..2280222 100644 --- a/nova/flags.py +++ b/nova/flags.py @@ -416,6 +416,9 @@ DEFINE_string('root_helper', 'sudo', DEFINE_string('network_driver', 'nova.network.linux_net', 'Driver to use for network creation') +DEFINE_string('iscsi_helper', 'ietadm', + 'iscsi target user-land tool to use') + DEFINE_bool('use_ipv6', False, 'use ipv6') DEFINE_bool('monkey_patch', False, diff --git a/nova/tests/test_volume.py b/nova/tests/test_volume.py index 689383c..5aa4853 100644 --- a/nova/tests/test_volume.py +++ b/nova/tests/test_volume.py @@ -442,7 +442,8 @@ class ISCSITestCase(DriverTestCase): self.mox.StubOutWithMock(self.volume.driver, '_execute') for i in volume_id_list: tid = db.volume_get_iscsi_target_num(self.context, i) - self.volume.driver._execute("ietadm", "--op", "show", + self.volume.driver._execute("%s" % FLAGS.iscsi_helper, + "--op", "show", "--tid=%(tid)d" % locals(), run_as_root=True) @@ -462,7 +463,7 @@ class ISCSITestCase(DriverTestCase): # the first vblade process isn't running tid = db.volume_get_iscsi_target_num(self.context, volume_id_list[0]) self.mox.StubOutWithMock(self.volume.driver, '_execute') - self.volume.driver._execute("ietadm", "--op", "show", + self.volume.driver._execute("%s" % FLAGS.iscsi_helper, "--op", "show", "--tid=%(tid)d" % locals(), run_as_root=True).AndRaise( exception.ProcessExecutionError()) diff --git a/nova/volume/driver.py b/nova/volume/driver.py index bb56956..781b1f2 100644 --- a/nova/volume/driver.py +++ b/nova/volume/driver.py @@ -368,19 +368,40 @@ class ISCSIDriver(VolumeDriver): iscsi_name = "%s%s" % (FLAGS.iscsi_target_prefix, volume['name']) volume_path = "/dev/%s/%s" % (FLAGS.volume_group, volume['name']) - self._sync_exec('ietadm', '--op', 'new', - "--tid=%s" % iscsi_target, - '--params', - "Name=%s" % iscsi_name, - run_as_root=True, - check_exit_code=False) - self._sync_exec('ietadm', '--op', 'new', - "--tid=%s" % iscsi_target, - '--lun=0', - '--params', - "Path=%s,Type=fileio" % volume_path, - run_as_root=True, - check_exit_code=False) + if FLAGS.iscsi_helper == 'tgtadm': + self._sync_exec('%s' % FLAGS.iscsi_helper, '--op', 'new', + '--lld=iscsi', '--mode=target', + "--tid=%s" % iscsi_target, + "--targetname=%s" % iscsi_name, + run_as_root=True, + check_exit_code=False) + self._sync_exec('%s' % FLAGS.iscsi_helper, '--op', 'bind' + '--lld=iscsi', '--mode=target', + '--initiator-address=ALL', + "--tid=%s" % iscsi_target, + run_as_root=True, + check_exit_code=False) + self._sync_exec('%s' % FLAGS.iscsi_helper, '--op', 'new', + '--lld=iscsi', '--mode=logicalunit', + "--tid=%s" % iscsi_target, + '--lun=1', + "--backing-store=%s,Type=fileio" % volume_path, + run_as_root=True, + check_exit_code=False) + else: + self._sync_exec('%s' % FLAGS.iscsi_helper, '--op', 'new', + "--tid=%s" % iscsi_target, + '--params', + "Name=%s" % iscsi_name, + run_as_root=True, + check_exit_code=False) + self._sync_exec('%s' % FLAGS.iscsi_helper, '--op', 'new', + "--tid=%s" % iscsi_target, + '--lun=0', + '--params', + "Path=%s,Type=fileio" % volume_path, + run_as_root=True, + check_exit_code=False) def _ensure_iscsi_targets(self, context, host): """Ensure that target ids have been created in datastore.""" @@ -400,13 +421,33 @@ class ISCSIDriver(VolumeDriver): volume['host']) iscsi_name = "%s%s" % (FLAGS.iscsi_target_prefix, volume['name']) volume_path = "/dev/%s/%s" % (FLAGS.volume_group, volume['name']) - self._execute('ietadm', '--op', 'new', - '--tid=%s' % iscsi_target, - '--params', 'Name=%s' % iscsi_name, run_as_root=True) - self._execute('ietadm', '--op', 'new', - '--tid=%s' % iscsi_target, - '--lun=0', '--params', - 'Path=%s,Type=fileio' % volume_path, run_as_root=True) + if FLAGS.iscsi_helper == 'tgtadm': + self._execute('%s' % FLAGS.iscsi_helper, '--op', 'new', + '--lld=iscsi', '--mode=target', + '--tid=%s' % iscsi_target, + '--params', 'Name=%s' % iscsi_name, + run_as_root=True) + self._execute('%s' % FLAGS.iscsi_helper, '--op', 'bind', + '--lld=iscsi', '--mode=target', + '--initiator-address=ALL', + "--tid=%s" % iscsi_target, + run_as_root=True) + self._execute('%s' % FLAGS.iscsi_helper, '--op', 'new', + '--ld=iscsi', '--mode=logicalunit', + '--tid=%s' % iscsi_target, + '--lun=0', '--params', + 'Path=%s,Type=fileio' % volume_path, + run_as_root=True) + else: + self._execute('%s' % FLAGS.iscsi_helper, '--op', 'new', + '--tid=%s' % iscsi_target, + '--params', 'Name=%s' % iscsi_name, + run_as_root=True) + self._execute('%s' % FLAGS.iscsi_helper, '--op', 'new', + '--tid=%s' % iscsi_target, + '--lun=0', '--params', + 'Path=%s,Type=fileio' % volume_path, + run_as_root=True) def remove_export(self, context, volume): """Removes an export for a logical volume.""" @@ -421,18 +462,38 @@ class ISCSIDriver(VolumeDriver): try: # ietadm show will exit with an error # this export has already been removed - self._execute('ietadm', '--op', 'show', - '--tid=%s' % iscsi_target, run_as_root=True) + if FLAGS.iscsi_helper == 'tgtadm': + self._execute('%s' % FLAGS.iscsi_helper, '--op', 'show', + '--lld=iscsi', '--mode=target', + '--tid=%s' % iscsi_target, + run_as_root=True) + else: + self._execute('%s' % FLAGS.iscsi_helper, '--op', 'show', + '--tid=%s' % iscsi_target, + run_as_root=True) except Exception as e: LOG.info(_("Skipping remove_export. No iscsi_target " + "is presently exported for volume: %d"), volume['id']) return - self._execute('ietadm', '--op', 'delete', - '--tid=%s' % iscsi_target, - '--lun=0', run_as_root=True) - self._execute('ietadm', '--op', 'delete', - '--tid=%s' % iscsi_target, run_as_root=True) + if FLAGS.iscsi_helper == 'tgtadm': + self._execute('%s' % FLAGS.iscsi_helper, '--op', 'delete', + '--lld=iscsi', '--mode=logicalunit', + '--tid=%s' % iscsi_target, + '--lun=1', + run_as_root=True) + self._execute('%s' % FLAGS.iscsi_helper, '--op', 'delete', + '--lld=iscsi', '--mode=target', + '--tid=%s' % iscsi_target, + run_as_root=True) + else: + self._execute('%s' % FLAGS.iscsi_helper, '--op' 'delete', + '--tid=%s' % iscsi_target, + '--lun=0', + run_as_root=True) + self._execute('%s' % FLAGS.iscsi_helper, '--op', 'delete', + '--tid=%s' % iscsi_target, + run_as_root=True) def _do_iscsi_discovery(self, volume): #TODO(justinsb): Deprecate discovery and use stored info @@ -541,9 +602,14 @@ class ISCSIDriver(VolumeDriver): self._iscsiadm_update(iscsi_properties, "node.startup", "automatic") - mount_device = ("/dev/disk/by-path/ip-%s-iscsi-%s-lun-0" % - (iscsi_properties['target_portal'], - iscsi_properties['target_iqn'])) + if FLAGS.iscsi_helper == 'tgtadm': + mount_device = ("/dev/disk/by-path/ip-%s-iscsi-%s-lun-0" % + (iscsi_properties['target_portal'], + iscsi_properties['target_iqn'])) + else: + mount_device = ("/dev/disk/by-path/ip-%s-iscsi-%s-lun-0" % + (iscsi_properties['target_portal'], + iscsi_properties['target_iqn'])) # The /dev/disk/by-path/... node is not always present immediately # TODO(justinsb): This retry-with-delay is a pattern, move to utils? @@ -583,8 +649,15 @@ class ISCSIDriver(VolumeDriver): tid = self.db.volume_get_iscsi_target_num(context, volume_id) try: - self._execute('ietadm', '--op', 'show', - '--tid=%(tid)d' % locals(), run_as_root=True) + if FLAGS.iscsi_helper == 'tgtadm': + self._execute('%s' % FLAGS.iscsi_helper, '--op', 'show' + '--lld=iscsi', '--mode=target', + '--tid=%(tid)d' % locals(), + run_as_root=True) + else: + self._execute('%s' % FLAGS.iscsi_helper, '--op', 'show', + '--tid=%(tid)d' % locals(), + run_as_root=True) except exception.ProcessExecutionError, e: # Instances remount read-only in this case. # /etc/init.d/iscsitarget restart and rebooting nova-volume