From: Thanh Ha Date: Wed, 7 Nov 2018 20:22:55 +0000 (+0800) Subject: Migrate cleanup old images script from ODL X-Git-Tag: v0.27.0~8^2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F03%2F13403%2F6;p=releng%2Fglobal-jjb.git Migrate cleanup old images script from ODL Generalize the cleanup script for reuse in global-jjb. Issue: RELENG-1436 Change-Id: I88e1bc3136b2f9b2542e441a74f26d742679c353 Signed-off-by: Thanh Ha --- diff --git a/.jjb-test/lf-ci-jobs/openstack-cron-full.yaml b/.jjb-test/lf-ci-jobs/openstack-cron-full.yaml new file mode 100644 index 00000000..d4bc05c9 --- /dev/null +++ b/.jjb-test/lf-ci-jobs/openstack-cron-full.yaml @@ -0,0 +1,10 @@ +--- +- project: + name: openstack-cron-full-test + jobs: + - 'gerrit-openstack-cron' + + project-name: ciman-full + openstack-cloud: example-cloud + openstack-image-cleanup: false + openstack-image-cleanup-age: 42 diff --git a/.jjb-test/lf-ci-jobs/openstack-cron-minimal.yaml b/.jjb-test/lf-ci-jobs/openstack-cron-minimal.yaml new file mode 100644 index 00000000..a6fc0b46 --- /dev/null +++ b/.jjb-test/lf-ci-jobs/openstack-cron-minimal.yaml @@ -0,0 +1,7 @@ +--- +- project: + name: openstack-cron-minimal-test + jobs: + - 'gerrit-openstack-cron' + + project-name: ci-management diff --git a/docs/jjb/lf-ci-jobs.rst b/docs/jjb/lf-ci-jobs.rst index 8c0ad44b..f7686349 100644 --- a/docs/jjb/lf-ci-jobs.rst +++ b/docs/jjb/lf-ci-jobs.rst @@ -570,6 +570,10 @@ containing the credentials for the cloud. :git-url: URL clone project from. (default: $GIT_URL/$PROJECT) :openstack-cloud: OS_CLOUD setting to pass to openstack client. (default: vex) + :openstack-image-cleanup: Whether or not to run the image cleanup script. + (default: true) + :openstack-image-cleanup-age: Age in days of image before marking it for + removal. (default: 30) :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. @@ -577,6 +581,15 @@ containing the credentials for the cloud. :submodule-timeout: Timeout (in minutes) for checkout operation. (default: 10) +Minimal Example: + +.. literalinclude:: ../../.jjb-test/lf-ci-jobs/openstack-cron-minimal.yaml + +Full Example: + +.. literalinclude:: ../../.jjb-test/lf-ci-jobs/openstack-cron-full.yaml + + .. _gjjb-packer-merge: Packer Merge diff --git a/jjb/lf-ci-jobs.yaml b/jjb/lf-ci-jobs.yaml index 733def52..217879e0 100644 --- a/jjb/lf-ci-jobs.yaml +++ b/jjb/lf-ci-jobs.yaml @@ -1239,6 +1239,8 @@ git-url: '$GIT_URL/$PROJECT' github-url: 'https://github.com' openstack-cloud: vex + openstack-image-cleanup: true + openstack-image-cleanup-age: 30 stream: master submodule-timeout: 10 @@ -1283,7 +1285,15 @@ - lf-infra-pre-build - inject: properties-content: OS_CLOUD={openstack-cloud} + # Images - shell: !include-raw-escape: ../shell/openstack-protect-in-use-images.sh + - conditional-step: + condition-kind: boolean-expression + condition-expression: '{openstack-image-cleanup}' + steps: + - inject: + properties-content: OS_IMAGE_CLEANUP_AGE={openstack-image-cleanup-age} + - shell: !include-raw-escape: ../shell/openstack-cleanup-old-images.sh publishers: - lf-infra-publish diff --git a/releasenotes/notes/migrate-heat-old-images-3850b6ecef04366c.yaml b/releasenotes/notes/migrate-heat-old-images-3850b6ecef04366c.yaml new file mode 100644 index 00000000..42b780f0 --- /dev/null +++ b/releasenotes/notes/migrate-heat-old-images-3850b6ecef04366c.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + The **openstack-cron** job now has the ability to remove images older than + a specified age (default: 30). diff --git a/shell/openstack-cleanup-old-images.sh b/shell/openstack-cleanup-old-images.sh new file mode 100644 index 00000000..cbb2ef8e --- /dev/null +++ b/shell/openstack-cleanup-old-images.sh @@ -0,0 +1,19 @@ +#!/bin/bash -l +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2017, 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 +############################################################################## +# Removes openstack images older than X days in the cloud +echo "---> Cleanup old images" + +os_cloud="${OS_CLOUD:-vex}" +os_image_cleanup_age="${OS_IMAGE_CLEANUP_AGE:-30}" + +set -eux -o pipefail + +lftools openstack --os-cloud "${os_cloud}" image cleanup --days="${os_image_cleanup_age}"