From 1ba3dfec786c60e53ceb3b682bcf927224102a0b Mon Sep 17 00:00:00 2001 From: Chuck Short Date: Fri, 27 Jul 2012 10:25:51 -0500 Subject: Add persistent volumes for tgtd. Currently if you restart the server running nova-volume or restart tgt, you will loose your iscsi targets that have been created. This is not good. In order for iscsi targets to be persistent across reboots or restarts, one has to have the target's configuration information in /etc/tgt/targets.conf or /etc/tgt/conf.d. So when tgtd is restarted then the iscsi targets will be there as expected. This patch will add a configuration file to $state_path/volumes when the volume is created. The configuration file is identified by the volume uuid. It creates a logicalunit when the volume is created as well. The iscsi target and configuration file will be removed once the volume has been removed as well. In order to use this, you have to include the following in your /etc/tgt/targets.conf include $state_path/volumes/* For upgrades, it will just re-create the volumes already in the volumes table. Fixes LP: #1011159 Change-Id: I38fc096ab881ccb52cb688ae46d9d36b0a7b3a45 Signed-off-by: Chuck Short --- nova/tests/test_iscsi.py | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/test_iscsi.py b/nova/tests/test_iscsi.py index 1008a9a0c..df619f28c 100644 --- a/nova/tests/test_iscsi.py +++ b/nova/tests/test_iscsi.py @@ -28,7 +28,8 @@ class TargetAdminTestCase(object): self.tid = 1 self.target_name = 'iqn.2011-09.org.foo.bar:blaa' self.lun = 10 - self.path = '/foo/bar/blaa' + self.path = '/foo' + self.vol_id = 'blaa' self.script_template = None @@ -65,11 +66,10 @@ class TargetAdminTestCase(object): def run_commands(self): tgtadm = iscsi.get_target_admin() tgtadm.set_execute(self.fake_execute) - tgtadm.new_target(self.target_name, self.tid) + tgtadm.create_iscsi_target(self.target_name, self.tid, + self.lun, self.path) 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) + tgtadm.remove_iscsi_target(self.tid, self.lun, self.vol_id) def test_target_admin(self): self.clear_cmds() @@ -83,22 +83,11 @@ class TgtAdmTestCase(test.TestCase, TargetAdminTestCase): super(TgtAdmTestCase, self).setUp() TargetAdminTestCase.setUp(self) self.flags(iscsi_helper='tgtadm') + self.flags(volumes_dir="./") self.script_template = "\n".join([ - "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 + "/usr/sbin/tgt-admin --conf ./blaa --update blaa", + "tgtadm --op show --lld=iscsi --mode=target --tid=1", + "/usr/bin/tgt-admin --conf ./blaa --delete blaa"]) class IetAdmTestCase(test.TestCase, TargetAdminTestCase): @@ -109,8 +98,8 @@ class IetAdmTestCase(test.TestCase, TargetAdminTestCase): self.flags(iscsi_helper='ietadm') self.script_template = "\n".join([ "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 " + "ietadm --op new --tid=%(tid)s --lun=%(lun)s " "--params Path=%(path)s,Type=fileio", - "ietadm --op delete --tid=%(tid)s --lun=%(lun)d", - "ietadm --op delete --tid=%(tid)s"]) + "ietadm --op show --tid=%(tid)s", + "ietadm --op delete --tid=%(tid)s", + "ietadm --op delete --tid=%(tid)s --lun=%(lun)s"]) -- cgit