# Restart dhcpd so servers PXE boot to FOG server
ssh ubuntu@store01.front.sepia.ceph.com "sudo service dhcpd restart"
+# Get FOG 'Deploy' TaskID
+fogdeployid=$(curl -s -k -H "fog-api-token: ${FOG_API_TOKEN}" -H "fog-user-token: ${FOG_USER_TOKEN}" http://fog.front.sepia.ceph.com/fog/tasktype -d '{"name": "Deploy"}' -X GET | jq -r '.tasktypes[0].id')
+
+# Check for scheduled deploy tasks
+deploytasks=$(curl -s -k -H "fog-api-token: ${FOG_API_TOKEN}" -H "fog-user-token: ${FOG_USER_TOKEN}" http://fog.front.sepia.ceph.com/fog/task/active -d '{"typeID": "'${fogdeployid}'"}' -X GET | jq -r '.count')
+
+# If there are scheduled or active deploy tasks, pause the queue and let them finish.
+# Capturing a new OS image can interrupt active OS deployments.
+if [ $deploytasks -gt 0 ]; then
+ for type in $MACHINETYPES; do
+ # Only pause the queue for 20 minutes just in case anything goes wrong with the Jenkins job.
+ teuthology-queue --pause 1200 --machine_type $type
+ done
+ pausedqueue=true
+ while [ $deploytasks -gt 0 ]; do
+ echo "$(date) -- $deploytasks FOG deploy tasks still queued. Sleeping 10sec"
+ sleep 10
+ deploytasks=$(curl -s -k -H "fog-api-token: ${FOG_API_TOKEN}" -H "fog-user-token: ${FOG_USER_TOKEN}" http://fog.front.sepia.ceph.com/fog/task/active -d '{"typeID": "'${fogdeployid}'"}' -X GET | jq -r '.count')
+ done
+fi
+
# Reboot all hosts so FOG can capture their OSes
for host in $allhosts; do
funPowerCycle $host
done
-set +x
-
# Wait for Capture tasks to finish
capturetasks=$(curl -s -k -H "fog-api-token: ${FOG_API_TOKEN}" -H "fog-user-token: ${FOG_USER_TOKEN}" http://fog.front.sepia.ceph.com/fog/task/active -d '{"typeID": "'${fogcaptureid}'"}' -X GET | jq -r '.count')
while [ $capturetasks -gt 0 ]; do
capturetasks=$(curl -s -k -H "fog-api-token: ${FOG_API_TOKEN}" -H "fog-user-token: ${FOG_USER_TOKEN}" http://fog.front.sepia.ceph.com/fog/task/active -d '{"typeID": "'${fogcaptureid}'"}' -X GET | jq -r '.count')
done
-set -ex
+# Unpause the queue if we paused it earlier
+if [ "$pausedqueue" = true ]; then
+ for type in $MACHINETYPES; do
+ teuthology-queue --pause 0 --machine_type $type
+ done
+fi
# Unlock all machines after all capture images are finished
for host in $allhosts; do