]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Correct IetAdm remove_iscsi_target
authorJohn Griffith <john.griffith@solidfire.com>
Wed, 19 Sep 2012 17:18:51 +0000 (11:18 -0600)
committerJohn Griffith <john.griffith@solidfire.com>
Wed, 19 Sep 2012 21:52:56 +0000 (15:52 -0600)
Remove logical units should be done before delete the target while
unexport iSCSI volume. Or ietd will show "No such file or directory"
error.

Fix bug 1043107

Change-Id: Iab5b97044c5a30c788fcabce827923ff82a84b91
(cherry picked from commit f14e955735065a998cd78280661f6d33c850d9e2)

cinder/tests/test_iscsi.py
cinder/utils.py
cinder/volume/iscsi.py

index 32a1309dd7160096936223cd8ed5c83b053c0f15..04ebf233e41828da58e5048630c1e0693077d5f7 100644 (file)
@@ -118,5 +118,5 @@ class IetAdmTestCase(test.TestCase, TargetAdminTestCase):
         'ietadm --op new --tid=%(tid)s --lun=%(lun)s '
                 '--params Path=%(path)s,Type=fileio',
         'ietadm --op show --tid=%(tid)s',
-        'ietadm --op delete --tid=%(tid)s',
-        'ietadm --op delete --tid=%(tid)s --lun=%(lun)s'])
+        'ietadm --op delete --tid=%(tid)s --lun=%(lun)s',
+        'ietadm --op delete --tid=%(tid)s'])
index 87b59ae642207a29107549d7191dd1dbc9bf159e..bfcda366a2b3feedbd4f0cebd9411959d61aa2ac 100644 (file)
@@ -1029,3 +1029,18 @@ class UndoManager(object):
                 LOG.exception(msg, **kwargs)
 
             self._rollback()
+
+
+def ensure_tree(path):
+    """Create a directory (and any ancestor directories required)
+
+    :param path: Directory to create
+    """
+    try:
+        os.makedirs(path)
+    except OSError as exc:
+        if exc.errno == errno.EEXIST:
+            if not os.path.isdir(path):
+                raise
+        else:
+            raise
index 2bdf0dc350b58775e35355d61adb3eea509f9a93..ec6e408946e09ea336feacaf32857f30e070d7b0 100644 (file)
@@ -109,8 +109,7 @@ class TgtAdm(TargetAdmin):
         # Note(jdg) tid and lun aren't used by TgtAdm but remain for
         # compatibility
 
-        if not os.path.exists(FLAGS.volumes_dir):
-            os.makedirs(FLAGS.volumes_dir)
+        utils.ensure_tree(FLAGS.volumes_dir)
 
         vol_id = name.split(':')[1]
         volume_conf = """
@@ -194,8 +193,8 @@ class IetAdm(TargetAdmin):
 
     def remove_iscsi_target(self, tid, lun, vol_id, **kwargs):
         LOG.info(_('Removing volume: %s') % vol_id)
-        self._delete_target(tid, **kwargs)
         self._delete_logicalunit(tid, lun, **kwargs)
+        self._delete_target(tid, **kwargs)
 
     def _new_target(self, name, tid, **kwargs):
         self._run('--op', 'new',