From: Anil Belur Date: Mon, 8 Jul 2019 09:40:31 +0000 (+1000) Subject: Remove orphaned ports on the cloud env X-Git-Tag: v0.40.0~23 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F18%2F16118%2F2;p=releng%2Fglobal-jjb.git Remove orphaned ports on the cloud env Issue: RELENG-2059 Change-Id: I0ce6e5c832d5d9481ae1f13d85716da4cab774f8 Signed-off-by: Anil Belur --- diff --git a/jjb/lf-ci-jobs.yaml b/jjb/lf-ci-jobs.yaml index 2545a6be..a70e8938 100644 --- a/jjb/lf-ci-jobs.yaml +++ b/jjb/lf-ci-jobs.yaml @@ -1291,6 +1291,7 @@ openstack-image-cleanup: true openstack-image-cleanup-age: 30 openstack-image-protect: true + openstack-port-cleanup: true openstack-server-cleanup: true openstack-stack-cleanup: true openstack-volume-cleanup: true @@ -1355,6 +1356,12 @@ condition-expression: '{openstack-server-cleanup}' steps: - shell: !include-raw-escape: ../shell/openstack-cleanup-orphaned-servers.sh + # Ports + - conditional-step: + condition-kind: boolean-expression + condition-expression: '{openstack-port-cleanup}' + steps: + - shell: !include-raw-escape: ../shell/openstack-cleanup-orphaned-ports.sh # Volumes - conditional-step: condition-kind: boolean-expression diff --git a/releasenotes/notes/openstack-cleanup-orphaned-ports-2619454ce4d083e3.yaml b/releasenotes/notes/openstack-cleanup-orphaned-ports-2619454ce4d083e3.yaml new file mode 100644 index 00000000..77c24c22 --- /dev/null +++ b/releasenotes/notes/openstack-cleanup-orphaned-ports-2619454ce4d083e3.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + Remove orphaned ports from the openstack cloud environment. These orphaned + ports are residue of CSIT jobs that needs to be purged, as a part of the + openstack cron job. A large number of stale jobs could cause IP address + allocation failures. diff --git a/shell/openstack-cleanup-orphaned-ports.sh b/shell/openstack-cleanup-orphaned-ports.sh new file mode 100644 index 00000000..fac8d202 --- /dev/null +++ b/shell/openstack-cleanup-orphaned-ports.sh @@ -0,0 +1,27 @@ +#!/bin/bash -l +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2019 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 ports +echo "---> Orphaned ports" + +os_cloud="${OS_CLOUD:-vex}" + +set -eux -o pipefail + +mapfile -t os_ports < <(openstack --os-cloud "$os_cloud" port list -f value -c ID -c status | egrep DOWN | awk '{print $1}') + +if [ ${#os_ports[@]} -eq 0 ]; then + echo "No orphaned ports found." +else + for port in "${os_ports[@]}"; do + echo "Removing orphaned port $port" + openstack --os-cloud "$os_cloud" port delete "$port" + done +fi