Re-enable orphaned nodes cleanup script 41/68241/3
authorThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 14 Feb 2018 13:33:48 +0000 (08:33 -0500)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 14 Feb 2018 13:42:41 +0000 (08:42 -0500)
With lftools v0.12.0 now available we can switch this script
back on. Improve the script to remove servers only if they are
15 minutes old to give them time to connect to Jenkins.

Change-Id: Ia5792a937e41f4da73188b4b38f95028f689345c
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
jjb/odl-openstack-cleanup-orphaned-nodes.sh
jjb/releng-jobs.yaml

index 953dadc81cded07e11715ce8beb1f77d54e9fa56..1b7f0c68e47389c6ab0d7cd2f2d63f12bf48b0f2 100644 (file)
@@ -10,9 +10,6 @@
 ##############################################################################
 echo "---> Cleanup orphaned servers"
 
-# shellcheck source=/tmp/v/openstack/bin/activate disable=SC1091
-source "/tmp/v/openstack/bin/activate"
-
 minion_in_jenkins() {
     # Usage: check_stack_in_jenkins STACK_NAME JENKINS_URL [JENKINS_URL...]
     # Returns: 0 If stack is in Jenkins and 1 if stack is not in Jenkins.
@@ -46,13 +43,22 @@ minion_in_jenkins() {
 # Fetch server list before fetching active minions to minimize race condition
 # where we might be trying to delete servers while jobs are trying to start
 
+# shellcheck source=/tmp/v/openstack/bin/activate disable=SC1091
+source "/tmp/v/openstack/bin/activate"
+
 # We purposely need word splitting here to create the OS_SERVERS array.
 # shellcheck disable=SC2207
-OS_SERVERS=($(openstack server list -f value -c "Name" | grep -E 'prd|snd'))
+mapfile -t OS_SERVERS < <(openstack server list -f value -c "Name" | grep -E 'prd|snd')
+
+deactivate
 
 #############################
 ## DELETE ORPHANED SERVERS ##
 #############################
+
+# shellcheck source=/tmp/v/lftools/bin/activate disable=SC1091
+source "/tmp/v/lftools/bin/activate"
+
 # Search for servers that are not in use by either releng or sandbox silos and
 # delete them.
 for server in "${OS_SERVERS[@]}"; do
@@ -64,6 +70,9 @@ for server in "${OS_SERVERS[@]}"; do
         continue
     else
         echo "Deleting $server"
-        openstack server delete "$server"
+        lftools openstack --os-cloud vex \
+            server remove --minutes 15 "$server"
     fi
 done
+
+deactivate
index 6ae1b9ea347ce085a7a40d77685dfea6ab314a95..c1f41b551893eb4f417825a15077a9884d40de90 100644 (file)
       # Servers
       - odl-openstack-cleanup-stale-stacks
       - odl-openstack-cleanup-stale-nodes
-      # Disable orphaned nodes script. See:
-      #   https://jira.linuxfoundation.org/browse/RELENG-780
-      # - odl-openstack-cleanup-orphaned-nodes
+      - odl-openstack-cleanup-orphaned-nodes
       # Images
       - odl-openstack-check-image-protection
       - odl-openstack-cleanup-old-images