nfvbenchvm: fix broken build after dib update
[nfvbench.git] / nfvbenchvm / dib / build-image.sh
index c595f6b..4559bb6 100755 (executable)
@@ -3,7 +3,8 @@
 # A shell script to build the VPP VM image or NFVbench+TRex VM image using diskinage-builder
 #
 # The following packages must be installed prior to using this script:
-# sudo apt-get -y install python-virtualenv qemu-utils kpartx
+# Ubuntu: sudo apt-get -y install python3 python3-venv qemu-utils kpartx
+# CentOS: sudo yum install -y python3 qemu-img kpartx
 
 usage() {
     echo "Usage: $0 [-l] [-g] [-v]"
@@ -49,42 +50,23 @@ set -e
 gs_url=artifacts.opnfv.org/nfvbench/images
 
 # image version number
-__version__=0.13
+__version__=0.15
 loopvm_image_name=nfvbenchvm_centos-$__version__
 generator_image_name=nfvbenchvm_centos-generator-$__version__
 
-
-
-function cleanup_image {
-    # if image exists skip building
-    echo "Checking if image exists in google storage..."
-    if  command -v gsutil >/dev/null; then
-        if gsutil -q stat gs://$gs_url/$1.qcow2; then
-            gsutil rm http://$gs_url/$1.qcow2
-            echo "Image is deleted"
-            exit 0
-        fi
-        echo "Image does not exist in google storage, starting build..."
-        echo
-    else
-        echo "Cannot check image availability in OPNFV artifact repository (gsutil not available)"
-    fi
-}
-
-
 function build_image {
     # if image exists skip building
     echo "Checking if image exists in google storage..."
     if  command -v gsutil >/dev/null; then
-        if gsutil -q stat gs://$gs_url/$1.qcow2; then
-            echo "Image already exists at http://$gs_url/$1.qcow2"
-            echo "Build is skipped"
-            exit 0
-        fi
-        echo "Image does not exist in google storage, starting build..."
-        echo
+       if gsutil -q stat gs://$gs_url/$1.qcow2; then
+           echo "Image already exists at http://$gs_url/$1.qcow2"
+           echo "Build is skipped"
+           exit 0
+       fi
+       echo "Image does not exist in google storage, starting build..."
+       echo
     else
-        echo "Cannot check image availability in OPNFV artifact repository (gsutil not available)"
+       echo "Cannot check image availability in OPNFV artifact repository (gsutil not available)"
     fi
 
     # check if image is already built locally
@@ -96,9 +78,9 @@ function build_image {
         if [ -d dib-venv ]; then
            . dib-venv/bin/activate
         else
-           virtualenv dib-venv
+           python3 -m venv dib-venv
            . dib-venv/bin/activate
-           pip install diskimage-builder
+           pip install diskimage-builder==3.16.0
         fi
 
         # Add nfvbenchvm_centos elements directory to the DIB elements path
@@ -129,8 +111,11 @@ function build_image {
            export TREX_VER=$(awk '/ENV TREX_VER/ {print $3}' ../../docker/Dockerfile | sed 's/"//g' | sed 's/\r//g')
         fi
 
+        # Specify CentOS version
+        export DIB_RELEASE=7
+
         echo "Building $1.qcow2..."
-        time disk-image-create -o $1 centos7 nfvbenchvm
+        time disk-image-create -o $1 centos nfvbenchvm
     fi
 
     ls -l $1.qcow2
@@ -152,12 +137,8 @@ function build_image {
 
 
 if [ ! $generator_only -eq 1 ] && [ ! $loopvm_only -eq 1 ]; then
-   echo "cleanup old loop VM image (wrong content)"
-   cleanup_image $loopvm_image_name
    echo "Build loop VM image"
    build_image $loopvm_image_name
-   echo "cleanup old generator VM image (wrong content)"
-   cleanup_image $generator_image_name
    echo "Build generator image"
    build_image $generator_image_name
 else
@@ -169,4 +150,4 @@ else
        echo "Build generator image"
        build_image $generator_image_name
     fi
-fi
\ No newline at end of file
+fi