Migrate cleanup-stale-volumes cron script 56/13456/1
authorThanh Ha <thanh.ha@linuxfoundation.org>
Mon, 12 Nov 2018 07:48:45 +0000 (15:48 +0800)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Mon, 12 Nov 2018 07:48:45 +0000 (15:48 +0800)
Generalize the cleanup script for general use in global-jjb.

Issue: RELENG-1435
Change-Id: If84c0f4341386ed758ce9d8556d4c4e574601797
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
.jjb-test/lf-ci-jobs/openstack-cron-full.yaml
docs/jjb/lf-ci-jobs.rst
jjb/lf-ci-jobs.yaml
shell/openstack-cleanup-orphaned-volumes.sh [new file with mode: 0644]

index 0dc4aaa..f0724fa 100644 (file)
@@ -9,3 +9,4 @@
     openstack-image-cleanup: false
     openstack-image-cleanup-age: 42
     openstack-image-protect: false
+    openstack-volume-cleanup: false
index 57aebc6..3ab71f2 100644 (file)
@@ -576,6 +576,8 @@ containing the credentials for the cloud.
         removal. (default: 30)
     :openstack-image-protect: Whether or not to run the image protect script.
         (default: true)
+    :openstack-volume-cleanup: Whether or not to run the volume cleanup script.
+        (default: true)
     :stream: Keyword that can be used to represent a release code-name.
         Often the same as the branch. (default: master)
     :submodule-recursive: Whether to checkout submodules recursively.
index 2ede3e7..b639775 100644 (file)
     openstack-image-cleanup: true
     openstack-image-cleanup-age: 30
     openstack-image-protect: true
+    openstack-volume-cleanup: true
     stream: master
     submodule-timeout: 10
 
       - lf-infra-pre-build
       - inject:
           properties-content: OS_CLOUD={openstack-cloud}
+      # Volumes
+      - conditional-step:
+          condition-kind: boolean-expression
+          condition-expression: '{openstack-volume-cleanup}'
+          steps:
+            - shell: !include-raw-escape: ../shell/openstack-cleanup-orphaned-volumes.sh
       # Images
       - conditional-step:
           condition-kind: boolean-expression
diff --git a/shell/openstack-cleanup-orphaned-volumes.sh b/shell/openstack-cleanup-orphaned-volumes.sh
new file mode 100644 (file)
index 0000000..51b4e58
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/bash -l
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2018 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+# Scans OpenStack for orphaned volumes
+echo "---> Orphaned volumes"
+
+os_cloud="${OS_CLOUD:-vex}"
+
+set -eux -o pipefail
+
+mapfile -t os_volumes < <(openstack --os-cloud "$os_cloud" volume list -f value -c ID --status Available)
+
+if [ ${#os_volumes[@]} -eq 0 ]; then
+    echo "No orphaned volumes found."
+else
+    for volume in "${os_volumes[@]}"; do
+        echo "Removing volume $volume"
+        lftools openstack --os-cloud "$os_cloud" volume remove --minutes 15 "$volume"
+    done
+fi