Migrate cleanup old images script from ODL 03/13403/6
authorThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 7 Nov 2018 20:22:55 +0000 (04:22 +0800)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 7 Nov 2018 22:48:44 +0000 (06:48 +0800)
Generalize the cleanup script for reuse in global-jjb.

Issue: RELENG-1436
Change-Id: I88e1bc3136b2f9b2542e441a74f26d742679c353
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
.jjb-test/lf-ci-jobs/openstack-cron-full.yaml [new file with mode: 0644]
.jjb-test/lf-ci-jobs/openstack-cron-minimal.yaml [new file with mode: 0644]
docs/jjb/lf-ci-jobs.rst
jjb/lf-ci-jobs.yaml
releasenotes/notes/migrate-heat-old-images-3850b6ecef04366c.yaml [new file with mode: 0644]
shell/openstack-cleanup-old-images.sh [new file with mode: 0644]

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 (file)
index 0000000..d4bc05c
--- /dev/null
@@ -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 (file)
index 0000000..a6fc0b4
--- /dev/null
@@ -0,0 +1,7 @@
+---
+- project:
+    name: openstack-cron-minimal-test
+    jobs:
+      - 'gerrit-openstack-cron'
+
+    project-name: ci-management
index 8c0ad44..f768634 100644 (file)
@@ -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
index 733def5..217879e 100644 (file)
     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
 
       - 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 (file)
index 0000000..42b780f
--- /dev/null
@@ -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 (file)
index 0000000..cbb2ef8
--- /dev/null
@@ -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}"