NFVBENCH-208 Fix VM images 26/72526/2
authorfmenguy <francoisregis.menguy@orange.com>
Mon, 17 May 2021 07:07:01 +0000 (09:07 +0200)
committerfmenguy <francoisregis.menguy@orange.com>
Mon, 17 May 2021 09:38:09 +0000 (11:38 +0200)
Change-Id: I9014b36b4f2e044f807a9b8a997e8c455511c046
Signed-off-by: fmenguy <francoisregis.menguy@orange.com>
nfvbenchvm/dib/build-image.sh
nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/03-copy-rc-local [changed mode: 0644->0755]
nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/04-add-execute-attribute [changed mode: 0644->0755]
nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/52-nfvbench-script [changed mode: 0644->0755]
nfvbenchvm/dib/elements/nfvbenchvm/post-install.d/53-sshd-script [changed mode: 0644->0755]

index e4b468a..c595f6b 100755 (executable)
@@ -53,6 +53,25 @@ __version__=0.13
 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..."
@@ -133,8 +152,12 @@ 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