[openstack-nova/f16] Use tgtadm instead of ietadm (#737046)

Mark McLoughlin markmc at fedoraproject.org
Mon Sep 19 10:13:47 UTC 2011


commit 77e03c14261015d71efefee377123c7eab52e8e6
Author: Mark McLoughlin <markmc at redhat.com>
Date:   Mon Sep 19 11:11:32 2011 +0100

    Use tgtadm instead of ietadm (#737046)

 nova-iscsi-choice.patch |  459 +++++++++++++++++++++++++++++++++++++++++++++++
 nova.conf               |    1 +
 openstack-nova.spec     |    7 +-
 3 files changed, 466 insertions(+), 1 deletions(-)
---
diff --git a/nova-iscsi-choice.patch b/nova-iscsi-choice.patch
new file mode 100644
index 0000000..81e6b38
--- /dev/null
+++ b/nova-iscsi-choice.patch
@@ -0,0 +1,459 @@
+Backported from:
+
+  https://code.launchpad.net/~markmc/nova/iscsi-tgtadm-choice/+merge/75906
+
+diff -up nova-2011.3/nova/tests/test_iscsi.py.iscsi-choice nova-2011.3/nova/tests/test_iscsi.py
+--- nova-2011.3/nova/tests/test_iscsi.py.iscsi-choice	2011-09-18 16:18:31.460605846 +0100
++++ nova-2011.3/nova/tests/test_iscsi.py	2011-09-18 16:18:31.460605846 +0100
+@@ -0,0 +1,116 @@
++# vim: tabstop=4 shiftwidth=4 softtabstop=4
++
++# Copyright 2011 Red Hat, Inc.
++#
++#    Licensed under the Apache License, Version 2.0 (the "License"); you may
++#    not use this file except in compliance with the License. You may obtain
++#    a copy of the License at
++#
++#         http://www.apache.org/licenses/LICENSE-2.0
++#
++#    Unless required by applicable law or agreed to in writing, software
++#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
++#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
++#    License for the specific language governing permissions and limitations
++#    under the License.
++
++import string
++
++from nova import test
++from nova.volume import iscsi
++
++
++class TargetAdminTestCase(object):
++
++    def setUp(self):
++        self.cmds = []
++
++        self.tid = 1
++        self.target_name = 'iqn.2011-09.org.foo.bar:blaa'
++        self.lun = 10
++        self.path = '/foo/bar/blaa'
++
++        self.script_template = None
++
++    def get_script_params(self):
++        return {'tid': self.tid,
++                'target_name': self.target_name,
++                'lun': self.lun,
++                'path': self.path}
++
++    def get_script(self):
++        return self.script_template % self.get_script_params()
++
++    def fake_execute(self, *cmd, **kwargs):
++        self.cmds.append(string.join(cmd))
++        return "", None
++
++    def clear_cmds(self):
++        cmds = []
++
++    def verify_cmds(self, cmds):
++        self.assertEqual(len(cmds), len(self.cmds))
++        for a, b in zip(cmds, self.cmds):
++            self.assertEqual(a, b)
++
++    def verify(self):
++        script = self.get_script()
++        cmds = []
++        for line in script.split('\n'):
++            if not line.strip():
++                continue
++            cmds.append(line)
++        self.verify_cmds(cmds)
++
++    def run_commands(self):
++        tgtadm = iscsi.get_target_admin()
++        tgtadm.set_execute(self.fake_execute)
++        tgtadm.new_target(self.target_name, self.tid)
++        tgtadm.show_target(self.tid)
++        tgtadm.new_logicalunit(self.tid, self.lun, self.path)
++        tgtadm.delete_logicalunit(self.tid, self.lun)
++        tgtadm.delete_target(self.tid)
++
++    def test_target_admin(self):
++        self.clear_cmds()
++        self.run_commands()
++        self.verify()
++
++
++class TgtAdmTestCase(test.TestCase, TargetAdminTestCase):
++
++    def setUp(self):
++        super(TgtAdmTestCase, self).setUp()
++        TargetAdminTestCase.setUp(self)
++        self.flags(iscsi_helper='tgtadm')
++        self.script_template = """
++tgtadm --op new --lld=iscsi --mode=target --tid=%(tid)s \
++--targetname=%(target_name)s
++tgtadm --op bind --lld=iscsi --mode=target --initiator-address=ALL \
++--tid=%(tid)s
++tgtadm --op show --lld=iscsi --mode=target --tid=%(tid)s
++tgtadm --op new --lld=iscsi --mode=logicalunit --tid=%(tid)s --lun=%(lun)d \
++--backing-store=%(path)s
++tgtadm --op delete --lld=iscsi --mode=logicalunit --tid=%(tid)s --lun=%(lun)d
++tgtadm --op delete --lld=iscsi --mode=target --tid=%(tid)s
++"""
++
++    def get_script_params(self):
++        params = super(TgtAdmTestCase, self).get_script_params()
++        params['lun'] += 1
++        return params
++
++
++class IetAdmTestCase(test.TestCase, TargetAdminTestCase):
++
++    def setUp(self):
++        super(IetAdmTestCase, self).setUp()
++        TargetAdminTestCase.setUp(self)
++        self.flags(iscsi_helper='ietadm')
++        self.script_template = """
++ietadm --op new --tid=%(tid)s --params Name=%(target_name)s
++ietadm --op show --tid=%(tid)s
++ietadm --op new --tid=%(tid)s --lun=%(lun)d --params Path=%(path)s,Type=fileio
++ietadm --op delete --tid=%(tid)s --lun=%(lun)d
++ietadm --op delete --tid=%(tid)s
++"""
+diff -up nova-2011.3/nova/tests/test_volume.py.iscsi-choice nova-2011.3/nova/tests/test_volume.py
+--- nova-2011.3/nova/tests/test_volume.py.iscsi-choice	2011-09-18 16:18:09.762267246 +0100
++++ nova-2011.3/nova/tests/test_volume.py	2011-09-18 16:18:31.462605870 +0100
+@@ -270,8 +270,7 @@ class DriverTestCase(test.TestCase):
+         def _fake_execute(_command, *_args, **_kwargs):
+             """Fake _execute."""
+             return self.output, None
+-        self.volume.driver._execute = _fake_execute
+-        self.volume.driver._sync_execute = _fake_execute
++        self.volume.driver.set_execute(_fake_execute)
+ 
+         log = logging.getLogger()
+         self.stream = cStringIO.StringIO()
+@@ -411,12 +410,10 @@ class ISCSITestCase(DriverTestCase):
+         """No log message when all the vblade processes are running."""
+         volume_id_list = self._attach_volume()
+ 
+-        self.mox.StubOutWithMock(self.volume.driver, '_execute')
++        self.mox.StubOutWithMock(self.volume.driver.tgtadm, 'show_target')
+         for i in volume_id_list:
+             tid = db.volume_get_iscsi_target_num(self.context, i)
+-            self.volume.driver._execute("ietadm", "--op", "show",
+-                                        "--tid=%(tid)d" % locals(),
+-                                        run_as_root=True)
++            self.volume.driver.tgtadm.show_target(tid)
+ 
+         self.stream.truncate(0)
+         self.mox.ReplayAll()
+@@ -433,11 +430,9 @@ 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",
+-                                    "--tid=%(tid)d" % locals(),
+-                                    run_as_root=True).AndRaise(
+-                                            exception.ProcessExecutionError())
++        self.mox.StubOutWithMock(self.volume.driver.tgtadm, 'show_target')
++        self.volume.driver.tgtadm.show_target(tid).AndRaise(
++            exception.ProcessExecutionError())
+ 
+         self.mox.ReplayAll()
+         self.assertRaises(exception.ProcessExecutionError,
+diff -up nova-2011.3/nova/volume/driver.py.iscsi-choice nova-2011.3/nova/volume/driver.py
+--- nova-2011.3/nova/volume/driver.py.iscsi-choice	2011-09-18 16:18:09.457262484 +0100
++++ nova-2011.3/nova/volume/driver.py	2011-09-18 16:18:31.464605905 +0100
+@@ -27,6 +27,7 @@ from nova import exception
+ from nova import flags
+ from nova import log as logging
+ from nova import utils
++from nova.volume import iscsi
+ 
+ 
+ LOG = logging.getLogger("nova.volume.driver")
+@@ -58,12 +59,13 @@ flags.DEFINE_string('rbd_pool', 'rbd',
+ 
+ class VolumeDriver(object):
+     """Executes commands relating to Volumes."""
+-    def __init__(self, execute=utils.execute,
+-                 sync_exec=utils.execute, *args, **kwargs):
++    def __init__(self, execute=utils.execute, *args, **kwargs):
+         # NOTE(vish): db is set by Manager
+         self.db = None
++        self.set_execute(execute)
++
++    def set_execute(self, execute):
+         self._execute = execute
+-        self._sync_exec = sync_exec
+ 
+     def _try_execute(self, *command, **kwargs):
+         # NOTE(vish): Volume commands can partially fail due to timing, but
+@@ -314,7 +316,6 @@ class FakeAOEDriver(AOEDriver):
+ 
+     def __init__(self, *args, **kwargs):
+         super(FakeAOEDriver, self).__init__(execute=self.fake_execute,
+-                                            sync_exec=self.fake_execute,
+                                             *args, **kwargs)
+ 
+     def check_for_setup_error(self):
+@@ -342,6 +343,14 @@ class ISCSIDriver(VolumeDriver):
+                        `CHAP` is the only auth_method in use at the moment.
+     """
+ 
++    def __init__(self, *args, **kwargs):
++        self.tgtadm = iscsi.get_target_admin()
++        super(ISCSIDriver, self).__init__(*args, **kwargs)
++
++    def set_execute(self, execute):
++        super(ISCSIDriver, self).set_execute(execute)
++        self.tgtadm.set_execute(execute)
++
+     def ensure_export(self, context, volume):
+         """Synchronously recreates an export for a logical volume."""
+         try:
+@@ -354,19 +363,10 @@ 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)
++
++        self.tgtadm.new_target(iscsi_name, iscsi_target, check_exit_code=False)
++        self.tgtadm.new_logicalunit(iscsi_target, 0, volume_path,
++                                    check_exit_code=False)
+ 
+     def _ensure_iscsi_targets(self, context, host):
+         """Ensure that target ids have been created in datastore."""
+@@ -386,13 +386,9 @@ 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)
++
++        self.tgtadm.new_target(iscsi_name, iscsi_target)
++        self.tgtadm.new_logicalunit(iscsi_target, 0, volume_path)
+ 
+     def remove_export(self, context, volume):
+         """Removes an export for a logical volume."""
+@@ -407,18 +403,14 @@ 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)
++            self.tgtadm.show_target(iscsi_target)
+         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)
++        self.tgtadm.delete_logicalunit(iscsi_target, 0)
++        self.tgtadm.delete_target(iscsi_target)
+ 
+     def _do_iscsi_discovery(self, volume):
+         #TODO(justinsb): Deprecate discovery and use stored info
+@@ -569,8 +561,7 @@ 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)
++            self.tgtadm.show_target(tid)
+         except exception.ProcessExecutionError, e:
+             # Instances remount read-only in this case.
+             # /etc/init.d/iscsitarget restart and rebooting nova-volume
+@@ -584,7 +575,6 @@ class FakeISCSIDriver(ISCSIDriver):
+     """Logs calls instead of executing."""
+     def __init__(self, *args, **kwargs):
+         super(FakeISCSIDriver, self).__init__(execute=self.fake_execute,
+-                                              sync_exec=self.fake_execute,
+                                               *args, **kwargs)
+ 
+     def check_for_setup_error(self):
+diff -up nova-2011.3/nova/volume/iscsi.py.iscsi-choice nova-2011.3/nova/volume/iscsi.py
+--- nova-2011.3/nova/volume/iscsi.py.iscsi-choice	2011-09-18 16:18:31.465605922 +0100
++++ nova-2011.3/nova/volume/iscsi.py	2011-09-18 16:18:31.466605939 +0100
+@@ -0,0 +1,156 @@
++# vim: tabstop=4 shiftwidth=4 softtabstop=4
++
++# Copyright 2010 United States Government as represented by the
++# Administrator of the National Aeronautics and Space Administration.
++# All Rights Reserved.
++#
++#    Licensed under the Apache License, Version 2.0 (the "License"); you may
++#    not use this file except in compliance with the License. You may obtain
++#    a copy of the License at
++#
++#         http://www.apache.org/licenses/LICENSE-2.0
++#
++#    Unless required by applicable law or agreed to in writing, software
++#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
++#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
++#    License for the specific language governing permissions and limitations
++#    under the License.
++"""
++Helper code for the iSCSI volume driver.
++
++"""
++
++from nova import flags
++from nova import utils
++
++
++FLAGS = flags.FLAGS
++flags.DEFINE_string('iscsi_helper', 'ietadm',
++                    'iscsi target user-land tool to use')
++
++
++class TargetAdmin(object):
++    """iSCSI target administration.
++
++    Base class for iSCSI target admin helpers.
++    """
++
++    def __init__(self, cmd, 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)
++
++    def new_target(self, name, tid, **kwargs):
++        """Create a new iSCSI target."""
++        raise NotImplementedError()
++
++    def delete_target(self, tid, **kwargs):
++        """Delete a target."""
++        raise NotImplementedError()
++
++    def show_target(self, tid, **kwargs):
++        """Query the given target ID."""
++        raise NotImplementedError()
++
++    def new_logicalunit(self, tid, lun, path, **kwargs):
++        """Create a new LUN on a target using the supplied path."""
++        raise NotImplementedError()
++
++    def delete_logicalunit(self, tid, lun, **kwargs):
++        """Delete a logical unit from a target."""
++        raise NotImplementedError()
++
++
++class TgtAdm(TargetAdmin):
++    """iSCSI target administration using tgtadm."""
++
++    def __init__(self, execute=utils.execute):
++        super(TgtAdm, self).__init__('tgtadm', execute)
++
++    def new_target(self, name, tid, **kwargs):
++        self._run('--op', 'new',
++                  '--lld=iscsi', '--mode=target',
++                  '--tid=%s' % tid,
++                  '--targetname=%s' % name,
++                  **kwargs)
++        self._run('--op', 'bind',
++                  '--lld=iscsi', '--mode=target',
++                  '--initiator-address=ALL',
++                  '--tid=%s' % tid,
++                  **kwargs)
++
++    def delete_target(self, tid, **kwargs):
++        self._run('--op', 'delete',
++                  '--lld=iscsi', '--mode=target',
++                  '--tid=%s' % tid,
++                  **kwargs)
++
++    def show_target(self, tid, **kwargs):
++        self._run('--op', 'show',
++                  '--lld=iscsi', '--mode=target',
++                  '--tid=%s' % tid,
++                  **kwargs)
++
++    def new_logicalunit(self, tid, lun, path, **kwargs):
++        self._run('--op', 'new',
++                  '--lld=iscsi', '--mode=logicalunit',
++                  '--tid=%s' % tid,
++                  '--lun=%d' % (lun + 1),  # lun0 is reserved
++                  '--backing-store=%s' % path,
++                  **kwargs)
++
++    def delete_logicalunit(self, tid, lun, **kwargs):
++        self._run('--op', 'delete',
++                  '--lld=iscsi', '--mode=logicalunit',
++                  '--tid=%s' % tid,
++                  '--lun=%d' % (lun + 1),
++                  **kwargs)
++
++
++class IetAdm(TargetAdmin):
++    """iSCSI target administration using ietadm."""
++
++    def __init__(self, execute=utils.execute):
++        super(IetAdm, self).__init__('ietadm', execute)
++
++    def new_target(self, name, tid, **kwargs):
++        self._run('--op', 'new',
++                  '--tid=%s' % tid,
++                  '--params', 'Name=%s' % name,
++                  **kwargs)
++
++    def delete_target(self, tid, **kwargs):
++        self._run('--op', 'delete',
++                  '--tid=%s' % tid,
++                  **kwargs)
++
++    def show_target(self, tid, **kwargs):
++        self._run('--op', 'show',
++                  '--tid=%s' % tid,
++                  **kwargs)
++
++    def new_logicalunit(self, tid, lun, path, **kwargs):
++        self._run('--op', 'new',
++                  '--tid=%s' % tid,
++                  '--lun=%d' % lun,
++                  '--params', 'Path=%s,Type=fileio' % path,
++                  **kwargs)
++
++    def delete_logicalunit(self, tid, lun, **kwargs):
++        self._run('--op', 'delete',
++                  '--tid=%s' % tid,
++                  '--lun=%d' % lun,
++                  **kwargs)
++
++
++def get_target_admin():
++    if FLAGS.iscsi_helper == 'tgtadm':
++        return TgtAdm()
++    else:
++        return IetAdm()
diff --git a/nova.conf b/nova.conf
index 07f5f87..d088827 100644
--- a/nova.conf
+++ b/nova.conf
@@ -8,3 +8,4 @@
 --vpn_client_template=/usr/share/nova/client.ovpn.template
 --credentials_template=/usr/share/nova/novarc.template
 --network_manager=nova.network.manager.FlatDHCPManager
+--iscsi_helper=tgtadm
diff --git a/openstack-nova.spec b/openstack-nova.spec
index da05fc7..ce6f2c7 100644
--- a/openstack-nova.spec
+++ b/openstack-nova.spec
@@ -4,7 +4,7 @@
 
 Name:             openstack-nova
 Version:          2011.3
-Release:          0.9.%{milestone}%{?dist}
+Release:          0.10.%{milestone}%{?dist}
 Summary:          OpenStack Compute (nova)
 
 Group:            Applications/System
@@ -33,6 +33,7 @@ Patch2:           nova-fix-quotas-migration-failure.patch
 Patch3:           nova-do-not-require-bridge_interface-for-flatdhcpmanager.patch
 Patch4:           nova-add-filter-rules-for-dnsmasq-dhcp.patch
 Patch5:           nova-add-input-chain-rule-for-ec2-metadata-requests.patch
+Patch6:           nova-iscsi-choice.patch
 
 BuildArch:        noarch
 BuildRequires:    intltool
@@ -164,6 +165,7 @@ This package contains documentation files for nova.
 %patch3 -p1
 %patch4 -p1
 %patch5 -p1
+%patch6 -p1
 
 find . \( -name .gitignore -o -name .placeholder \) -delete
 
@@ -351,6 +353,9 @@ fi
 %endif
 
 %changelog
+* Mon Sep 19 2011 Mark McLoughlin <markmc at redhat.com> - 2011.3-0.10.d4
+- Use tgtadm instead of ietadm (#737046)
+
 * Wed Sep 14 2011 Mark McLoughlin <markmc at redhat.com> - 2011.3-0.9.d4
 - Remove python-libguestfs dependency (#738187)
 


More information about the scm-commits mailing list