Remove orphaned ports on the cloud env 18/16118/2
authorAnil Belur <abelur@linuxfoundation.org>
Mon, 8 Jul 2019 09:40:31 +0000 (19:40 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Tue, 9 Jul 2019 22:12:26 +0000 (08:12 +1000)
Issue: RELENG-2059
Change-Id: I0ce6e5c832d5d9481ae1f13d85716da4cab774f8
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
jjb/lf-ci-jobs.yaml
releasenotes/notes/openstack-cleanup-orphaned-ports-2619454ce4d083e3.yaml [new file with mode: 0644]
shell/openstack-cleanup-orphaned-ports.sh [new file with mode: 0644]

index 2545a6b..a70e893 100644 (file)
     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
           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 (file)
index 0000000..77c24c2
--- /dev/null
@@ -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 (file)
index 0000000..fac8d20
--- /dev/null
@@ -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