File 0018-lio_node-Make-add-idempotent.patch of Package lio-utils.216

From d16a16f730c179ad0fb1d88f650c63017e28c247 Mon Sep 17 00:00:00 2001
From: Hannes Reinecke <hare@suse.de>
Date: Fri, 1 Feb 2013 14:49:03 +0100
Subject: lio_node: Make 'add' idempotent

We can be called with the same argument twice; that should not
resort in an error.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 lio-py/lio_node.py | 34 ++++++++++++++++------------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/lio-py/lio_node.py b/lio-py/lio_node.py
index d047fc1..d1cf7ee 100755
--- a/lio-py/lio_node.py
+++ b/lio-py/lio_node.py
@@ -319,13 +319,12 @@ def lio_target_add_port(option, opt_str, value, parser):
 
 	lun_dir = lio_root + "/" + iqn + "/tpgt_" + tpgt + "/lun/lun_" + lun
 	if os.path.isdir(lun_dir):
-		lio_err("iSCSI Target Logical Unit ConfigFS directory already exists")
-
-	mkdir_op = "mkdir -p " + lun_dir
-#	print "mkdir_op: " + mkdir_op
-	ret = os.system(mkdir_op)
-	if ret:
-		lio_err("Unable to create iSCSI Target Logical Unit ConfigFS directory")
+		lio_dbg("iSCSI Target Logical Unit ConfigFS directory already exists")
+	else:
+		mkdir_op = "mkdir -p " + lun_dir
+		ret = os.system(mkdir_op)
+		if ret:
+			lio_err("Unable to create iSCSI Target Logical Unit ConfigFS directory")
 
 	port_src = tcm_root + "/" + tcm_obj
 	port_dst = lio_root + "/" + iqn + "/tpgt_" + tpgt + "/lun/lun_" + lun + "/" + port_name
@@ -349,16 +348,15 @@ def lio_target_add_tpg(option, opt_str, value, parser):
 
 	tpg_dir = lio_root + "/" + iqn + "/tpgt_" + tpgt
 	if os.path.isdir(tpg_dir):
-		lio_err("iSCSI Target Portal Group directory already exists")
-
-	mkdir_op = "mkdir -p " + tpg_dir
-	ret = os.system(mkdir_op)
-	if ret:
-		lio_err("Unable to create iSCSI Target Portal Group ConfigFS directory")
-	else:
-		lio_dbg("Successfully created iSCSI Target Portal Group")
-		lio_alua_check_secondary_md(iqn, tpgt)
-
+		lio_dbg("iSCSI Target Portal Group directory already exists")
+        else:
+		mkdir_op = "mkdir -p " + tpg_dir
+		ret = os.system(mkdir_op)
+		if ret:
+			lio_err("Unable to create iSCSI Target Portal Group ConfigFS directory")
+		else:
+			lio_dbg("Successfully created iSCSI Target Portal Group")
+        lio_alua_check_secondary_md(iqn, tpgt)
 	return
 
 def __lio_target_del_port(option, opt_str, value, parser):
@@ -407,7 +405,7 @@ def lio_target_del_port(option, opt_str, value, parser):
 
 	lun_dir = lio_root + "/" + iqn + "/tpgt_" + tpgt + "/lun/lun_" + lun
 	if os.path.isdir(lun_dir) == False:
-		lio_err("LIO-Target Port/LUN directory: " + lun_dir + " does not exist")
+		lio_err("LIO-Target Port/LUN directory: " + lun_dir + " does not  exist")
 
 	__lio_target_del_port(option, opt_str, value, parser)
 	# Delete the ALUA secondary metadata file for this Port/LUN
-- 
1.8.1.4

openSUSE Build Service is sponsored by