[Fuego] [PATCH RFC 2/2] common: add support the test tarball from URL

Liu Wenlong liuwl.fnst at cn.fujitsu.com
Mon Dec 17 01:53:18 UTC 2018


The current Fuego has supported test source code from following,
- source code from git
- source code from local tarball

Now, add support to use source code from URL.
Based on this feature, Fuego have the ability to abandon those
heavy test tarballs/packages in the upstream repo in the future.

Signed-off-by: Liu Wenlong <liuwl.fnst at cn.fujitsu.com>
---
 engine/scripts/functions.sh | 38 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/engine/scripts/functions.sh b/engine/scripts/functions.sh
index b0cdb0e..6052fbe 100755
--- a/engine/scripts/functions.sh
+++ b/engine/scripts/functions.sh
@@ -79,6 +79,25 @@ function git_clone {
     git checkout $gitref
 }
 
+# FIXTHIS: add support for other protocol, e.g. ftp
+# Download a tarball from a upstream location
+# $1 (tarball): the upstream location of tarball
+# $2 (tarball): the store location for $1
+function download_tarball {
+    local tarball_url=${1}
+    local tarball_des=${2}
+
+    is_empty "$tarball_url"
+    is_empty "$tarball_des"
+
+    echo "Downloading $tarball to $tarball_des"
+    wget $tarball_url -O $tarball_des &> /dev/null
+    if [ $? -ne 0 ]; then
+        abort_job "Downloading $tarball failed."
+        return 1
+    fi
+}
+
 # Untars a tarball in the current folder
 # $1 (tarball): file to untar
 function untar {
@@ -86,6 +105,17 @@ function untar {
 
     is_empty "$tarball"
 
+    # Check if it is a upstream tarball.
+    if [[ $tarball == http* ]]; then
+        upName=`echo "${TESTDIR^^}"| tr '.' '_'`
+        md5sum_value=$(echo ${tarball} | md5sum)
+        md5sum_value=${md5sum_value:0:7}
+        tarball_dest=${FUEGO_RW}/buildzone/${upName}-${md5sum_value}-$(basename ${tarball})
+        [[ -f ${tarball_dest} ]] && echo "Already downloaded, skip download..." \
+                                 || download_tarball ${tarball} ${tarball_dest}
+        tarball=${tarball_dest}
+    fi
+
     echo "Unpacking $tarball"
     case ${tarball/*./} in
         gz|tgz) key=z ;;
@@ -93,10 +123,14 @@ function untar {
         tar) key= ;;
         *) echo "Unknown $tarball file format. Not unpacking."; return 1;;
     esac
-    tar ${key}xf $TEST_HOME/$tarball --strip-components=1
+    if ! is_abs_path $tarball; then
+        tarball=$TEST_HOME/$tarball
+    fi
+
+    tar ${key}xf $tarball --strip-components=1
 
     # record md5sum for possible source code updates
-    md5sum $TEST_HOME/$tarball > fuego_tarball_src_md5sum
+    md5sum $tarball > fuego_tarball_src_md5sum
 }
 
 # Unpacks/clones the test source code into the current directory.
-- 
2.7.4





More information about the Fuego mailing list