[node-patches] Change in ovirt-node[master]: add return value when persist command does not return an err...

baichm at linux.vnet.ibm.com baichm at linux.vnet.ibm.com
Thu May 23 09:40:45 UTC 2013


Changming Bai has uploaded a new change for review.

Change subject: add return value when persist command does not return an error code on failure
......................................................................

add return value when persist command does not return an error code on failure

move the ovirt_store_config code into a new function "ovirt_store_config_atomic"
Have it return different error number consist with the different error case
The "ovirt_store_config" function will invoked the new function "ovirt_store_config_atomic"
The ovirt_store_config will judge the error number from the ovirt_store_config_atomic
and ovirt_store_config will also return True/False value from the judgement error number
In the shell script ovirt-functions.in, invoked the ovirt_store_config_atomic directly

Change-Id: I6a36ac8c1a2c7e31b09614da1dae9d59b9ea7f45
Signed-off-by: Changming Bai <baichm at linux.vnet.ibm.com>
---
M scripts/ovirt-functions.in
M src/ovirtnode/ovirtfunctions.py
2 files changed, 27 insertions(+), 75 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/15/15015/1

diff --git a/scripts/ovirt-functions.in b/scripts/ovirt-functions.in
index 55a92f0..64294f1 100644
--- a/scripts/ovirt-functions.in
+++ b/scripts/ovirt-functions.in
@@ -650,73 +650,8 @@
 #   ovirt_store_config /etc/config /etc/config2 ...
 #   copy to /config and bind-mount back
 ovirt_store_config() {
-    rc=0
-    if is_stateless; then
-        # no need to do anything
-        return 0;
-    fi
-    if grep -q " /config ext[234]" /proc/mounts; then
-        for p in "$@"; do
-            local filename=$(readlink -f $p)
-            local persist_it=true
-            if [[ "$filename" =~ ^/[^/]*$ ]]; then
-                # persisting top-level folder makes trouble rhbz#611617
-                printf "Cannot persist system folder: ${filename}\n"
-                persist_it=false
-            elif [ -d $filename ]; then
-                if [ -d /config$filename ]; then
-                    printf "Directory already persisted: ${filename}\n"
-                    printf "You need to unpersist its child directories and/or files and try again.\n"
-                    persist_it=false
-                fi
-            elif [ -f $filename ]; then
-                if [ -f /config$filename ]; then
-                    local md5root=$(md5 $filename)
-                    local md5stored=$(md5 /config$filename)
-                    if [ "$md5root" = "$md5stored" ]; then
-                        printf "File already persisted: ${filename}\n"
-                        persist_it=false
-                    else
-                        # persistent copy needs refresh
-                        umount -n $filename 2> /dev/null || :
-                        rm -f /config$filename
-                    fi
-                fi
-            else
-                printf "Cannot persist: ${filename}\n"
-                persist_it=false
-            fi
-
-            if $persist_it; then
-                # skip if file does not exist
-                if [ ! -e "${filename}" ]; then
-                    printf " Skipping, file '${filename}' does not exist\n"
-                    continue
-                fi
-                # skip if already bind-mounted
-                if ! grep -q " $filename ext[234]" /proc/mounts ; then
-                    mkdir -p /config$(dirname $filename)
-                    cp -a $filename /config$filename \
-                        && mount -n --bind /config$filename $filename
-                    if [ $? -ne 0 ]; then
-                        printf " Failed to persist\n"
-                        rc=1
-                    else
-                        printf " File persisted\n"
-                    fi
-                fi
-                # register in /config/files used by rc.sysinit
-                if ! grep -q "^${filename}$" /config/files 2> /dev/null ; then
-                    printf "${filename}\n" >> /config/files
-                fi
-                printf "\nSuccessfully persisted ${filename}\n"
-            fi
-        done
-        echo
-    else
-        printf "WARNING: persistent config storage not available\n"
-        rc=2
-    fi
+    python -c "import ovirtnode.ovirtfunctions; import sys; sys.exit(ovirt_store_config_retnum(sys.argv[1:], retNumber=True))" "$@"
+    rc=$?
     return $rc
 }
 
diff --git a/src/ovirtnode/ovirtfunctions.py b/src/ovirtnode/ovirtfunctions.py
index ee47286..0ca744f 100644
--- a/src/ovirtnode/ovirtfunctions.py
+++ b/src/ovirtnode/ovirtfunctions.py
@@ -743,14 +743,28 @@
 #   copy to /config and bind-mount back
 
 def ovirt_store_config(files):
-    rc = True
-    if is_stateless():
+    rc = ovirt_store_config_retnum(files)
+    if rc == 1 or rc == 2:
+        return False
+    else:
         return True
+    
+# persist configuration to /config
+# ovirt_store_config_retnum /etc/config /etc/config2 ...
+# copy to /config and bind-mount back
+# this function can be invoked by shell script and function ovirt_store_config
+# this function will return the different error number consist with different error case.
+
+def ovirt_store_config_retnum(files):
+    rc = 0 
+    if is_stateless():
+        return rc 
     if not os.path.ismount("/config"):
         logger.error("/config is not mounted")
-        return False
+        rc = 2
+        return rc 
     if isinstance(files,STRING_TYPE):
-        files_list = []
+        files_list = [] 
         files_list.append(files)
     else:
         files_list=files
@@ -766,6 +780,7 @@
                 logger.warn("You need to unpersist its child directories " +
                             "and/or files and try again.")
                 persist_it=False
+                rc = 3
         elif os.path.isfile(filename):
             # if it's a file then make sure it's not already persisted
             if os.path.isfile("/config/" + filename):
@@ -774,6 +789,7 @@
                 if cksumroot == cksumstored:
                     logger.warn("File already persisted: " + filename)
                     persist_it=False
+                    rc = 4
                 else:
                     # persistent copy needs refresh
                     if system("umount -n " + filename + " 2> /dev/null"):
@@ -781,6 +797,7 @@
         else:
             # skip if file does not exist
             logger.warn("Skipping, file '" + filename + "' does not exist")
+            rc = 5
             continue
 
         if persist_it:
@@ -792,22 +809,22 @@
                     if not system("mount -n --bind /config"+filename+ " " + \
                                   filename):
                         logger.error("Failed to persist: " + filename)
-                        rc = False
+                        rc = 1
                     else:
                         logger.info("File: " + filename + " persisted")
-                        rc = rc and True
+                        rc = 0
             # register in /config/files used by rc.sysinit
             ret = system_closefds("grep -q \"^$" + filename +"$\" " + \
                                   " /config/files 2> /dev/null")
             if ret > 0:
                 system_closefds("echo "+filename+" >> /config/files")
                 logger.info("Successfully persisted: " + filename)
-                rc = rc and True
+                rc = 0
         else:
             logger.warn(filename + " Already persisted")
-            rc = rc and True
     return rc
 
+
 def ovirt_store_config_atomic(filename, source=None):
     rc = True
     persist_it = True


--
To view, visit http://gerrit.ovirt.org/15015
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6a36ac8c1a2c7e31b09614da1dae9d59b9ea7f45
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Changming Bai <baichm at linux.vnet.ibm.com>



More information about the node-patches mailing list