[pisa-src] r2732 - in trunk/tools/testbed: plugins/actions/lock/lock plugins/actions/unlock/unlock scripts/pisa-testbed

  • From: Samuel Richter <samuel.richter@xxxxxxxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Tue, 30 Aug 2011 18:04:35 +0200

Author: richter
Date: Tue Aug 30 18:04:35 2011
New Revision: 2732

Log:
testbed interface: fix locking mechanism

Before, the unlock of a function was locked too, if the function was locked.
Unlock works now.
Also adds the possibility to give a reason for the lock, that is displayed if
the lock takes action.

Modified:
   trunk/tools/testbed/plugins/actions/lock/lock
   trunk/tools/testbed/plugins/actions/unlock/unlock
   trunk/tools/testbed/scripts/pisa-testbed

Modified: trunk/tools/testbed/plugins/actions/lock/lock
==============================================================================
--- trunk/tools/testbed/plugins/actions/lock/lock       Mon Aug 29 22:27:53 
2011        (r2731)
+++ trunk/tools/testbed/plugins/actions/lock/lock       Tue Aug 30 18:04:35 
2011        (r2732)
@@ -2,5 +2,18 @@
 
 [ "$ACTIONS" = "lock" ] && add_action deploy && add_action update
 
-PRE_CMD='touch $LOCK_PATH/$function && echo'
-
+apply_locks(){
+    function=$1; shift
+    if [ -f "$LOCK_PATH/$function" ]; then
+        echo "$function is already locked by $(stat -c %U "$LOCK_PATH/$1")"
+        if [ -s "$LOCK_PATH/$function" ]; then
+            cat "$LOCK_PATH/$function" | sed -e "s/^/  Reason: /"
+        else
+            echo "  No reason given."
+        fi
+    else
+        echo -n "$*" > "$LOCK_PATH/$function"
+        echo "$function is now locked"
+    fi
+    return 1
+}

Modified: trunk/tools/testbed/plugins/actions/unlock/unlock
==============================================================================
--- trunk/tools/testbed/plugins/actions/unlock/unlock   Mon Aug 29 22:27:53 
2011        (r2731)
+++ trunk/tools/testbed/plugins/actions/unlock/unlock   Tue Aug 30 18:04:35 
2011        (r2732)
@@ -2,4 +2,14 @@
 
 [ "$ACTIONS" = "unlock" ] && add_action deploy && add_action update
 
-PRE_CMD='rm -f $LOCK_PATH/$function && echo'
+apply_locks(){
+    function=$1; shift
+    if [ -f "$LOCK_PATH/$function" ]; then
+        rm -f "$LOCK_PATH/$function"
+        echo "$function is now unlocked"
+
+    else
+        echo "$function is not locked"
+    fi
+    return 1
+}

Modified: trunk/tools/testbed/scripts/pisa-testbed
==============================================================================
--- trunk/tools/testbed/scripts/pisa-testbed    Mon Aug 29 22:27:53 2011        
(r2731)
+++ trunk/tools/testbed/scripts/pisa-testbed    Tue Aug 30 18:04:35 2011        
(r2732)
@@ -208,9 +208,15 @@
     select_functions $1
 }
 
-check_locks(){
-    if [ -f "$LOCK_PATH/$1" ]; then
-        echo "$function is locked by $(stat -c %U "$LOCK_PATH/$1")"
+apply_locks(){
+    function=$1; shift
+    if [ -f "$LOCK_PATH/$function" ]; then
+        echo "$function is locked by $(stat -c %U "$LOCK_PATH/$function")"
+        if [ -s "$LOCK_PATH/$function" ]; then
+            cat "$LOCK_PATH/$function" | sed -e "s/^/  Reason: /" -e "s/$/\n/"
+        else
+            echo "  No reason given."
+        fi
         return 1
     fi
     return 0
@@ -224,7 +230,7 @@
         || grep -s " $function" "$TMP_PATH"/functions_replacements \
             | while read ln; do check_function_for_classes "${ln#* }"; done | 
tail -1)
     [ "$replace" ] && function="${replace#*___}"
-    if check_locks "$function"; then
+    if apply_locks "$function"; then
         if grep -q ":${NODE}___$function$" "$TMP_PATH"/functions_known; then
             eval "${NODE}___$function '$*'"
         elif grep -q ":${function}$" "$TMP_PATH"/functions_known; then
@@ -350,17 +356,17 @@
 
 for node in $(sed "s/___[a-z_]*//g" "$TMP_PATH"/functions_tsort | sort | uniq 
| tsort); do
     for function in $(egrep "${node}___.* ${node}___.*" 
"$TMP_PATH"/functions_tsort | tsort); do
-        if check_locks "$function"; then
         if ! echo "$function" | egrep -q "(^|__)($EXCLUDE)(__|$)"; then
             if echo ${function} | egrep -q "init_node|finish_node"; then
                 eval "${function#*___} ${function%%___*}"
-            elif grep -q ":${function}$" "$TMP_PATH"/functions_known; then
-                eval "$PRE_CMD $function ${*:+'$*'} | ${LOG_CMD:-tee 
"$LOG_PATH/$function".log}" 3>&1
-            else
-                eval "$PRE_CMD ${function#*___} ${*:+'$*'} | ${LOG_CMD:-tee 
"$LOG_PATH/$function".log}" 3>&1
+            elif apply_locks "$function" ${*:+"$*"}; then
+                if grep -q ":${function}$" "$TMP_PATH"/functions_known; then
+                    eval "$PRE_CMD $function ${*:+'$*'} | ${LOG_CMD:-tee 
"$LOG_PATH/$function".log}" 3>&1
+                else
+                    eval "$PRE_CMD ${function#*___} ${*:+'$*'} | 
${LOG_CMD:-tee "$LOG_PATH/$function".log}" 3>&1
+                fi
             fi
         fi
-        fi
     done
 done
 
-- 
This is the pisa developer mailing list. Please also subscribe to the main pisa 
list at:
//www.freelists.org/list/pisa

Other related posts:

  • » [pisa-src] r2732 - in trunk/tools/testbed: plugins/actions/lock/lock plugins/actions/unlock/unlock scripts/pisa-testbed - Samuel Richter