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
--- /dev/null
+---
+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.
--- /dev/null
+#!/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