From d22d069117b64cee73be1165861013de9e79ab19 Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Mon, 12 Nov 2018 15:48:45 +0800 Subject: [PATCH] Migrate cleanup-stale-volumes cron script Generalize the cleanup script for general use in global-jjb. Issue: RELENG-1435 Change-Id: If84c0f4341386ed758ce9d8556d4c4e574601797 Signed-off-by: Thanh Ha --- .jjb-test/lf-ci-jobs/openstack-cron-full.yaml | 1 + docs/jjb/lf-ci-jobs.rst | 2 ++ jjb/lf-ci-jobs.yaml | 7 +++++++ shell/openstack-cleanup-orphaned-volumes.sh | 27 +++++++++++++++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 shell/openstack-cleanup-orphaned-volumes.sh diff --git a/.jjb-test/lf-ci-jobs/openstack-cron-full.yaml b/.jjb-test/lf-ci-jobs/openstack-cron-full.yaml index 0dc4aaaa..f0724fac 100644 --- a/.jjb-test/lf-ci-jobs/openstack-cron-full.yaml +++ b/.jjb-test/lf-ci-jobs/openstack-cron-full.yaml @@ -9,3 +9,4 @@ openstack-image-cleanup: false openstack-image-cleanup-age: 42 openstack-image-protect: false + openstack-volume-cleanup: false diff --git a/docs/jjb/lf-ci-jobs.rst b/docs/jjb/lf-ci-jobs.rst index 57aebc6a..3ab71f27 100644 --- a/docs/jjb/lf-ci-jobs.rst +++ b/docs/jjb/lf-ci-jobs.rst @@ -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. diff --git a/jjb/lf-ci-jobs.yaml b/jjb/lf-ci-jobs.yaml index 2ede3e7b..b6397753 100644 --- a/jjb/lf-ci-jobs.yaml +++ b/jjb/lf-ci-jobs.yaml @@ -1242,6 +1242,7 @@ openstack-image-cleanup: true openstack-image-cleanup-age: 30 openstack-image-protect: true + openstack-volume-cleanup: true stream: master submodule-timeout: 10 @@ -1286,6 +1287,12 @@ - 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 index 00000000..51b4e58a --- /dev/null +++ b/shell/openstack-cleanup-orphaned-volumes.sh @@ -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 -- 2.16.6