diff --git a/jobs/scripts/common/bootstrap.sh b/jobs/scripts/common/bootstrap.sh index 894220d..86f292e 100755 --- a/jobs/scripts/common/bootstrap.sh +++ b/jobs/scripts/common/bootstrap.sh @@ -1,7 +1,6 @@ #!/bin/bash set -e -set -x EXEC_BIN="$(basename $1)" scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$1" "root@$(cat $WORKSPACE/hosts):$EXEC_BIN" if [ -z "$2" ]; diff --git a/jobs/scripts/common/get-node.sh b/jobs/scripts/common/get-node.sh index 02c87d9..f43b9c3 100644 --- a/jobs/scripts/common/get-node.sh +++ b/jobs/scripts/common/get-node.sh @@ -1,42 +1,59 @@ -# Inspired by cico-node-get-to-ansible.sh -# A script that provisions nodes and writes them to a file +#!/bin/bash + set +x -NODE_COUNT=${NODE_COUNT:-1} -ANSIBLE_HOSTS=${ANSIBLE_HOSTS:-$WORKSPACE/hosts} -SSID_FILE=${SSID_FILE:-$WORKSPACE/cico-ssid} - -# Delete the host file if it exists -rm -rf $ANSIBLE_HOSTS - -# Get nodes -nodes=$(cico -q node get --count ${NODE_COUNT} --column hostname --release ${CENTOS_VERSION} --column ip_address --column comment -f value) -cico_ret=$? - -# Fail in case cico returned an error, or no nodes at all -if [ ${cico_ret} -ne 0 ] -then - echo "cico returned an error (${cico_ret})" - exit 2 -elif [ -z "${nodes}" ] -then - echo "cico failed to return any systems" - exit 2 -fi -# Write nodes to inventory file and persist the SSID separately for simplicity -touch ${SSID_FILE} -IFS=$'\n' -for node in ${nodes} +cat > ~/.config/duffy <> ${ANSIBLE_HOSTS} +for i in {1..30} +do + NODES_READY=$(duffy client show-pool "${POOL_FOUND}" | jq -r '.pool.levels.ready') + if [ "${NODES_READY}" -ge 1 ]; then + SESSION=$(duffy client request-session pool="${POOL_FOUND}",quantity=1) + echo "${SESSION}" | jq -r '.session.nodes[].ipaddr' > "${WORKSPACE}"/hosts + echo "${SESSION}" | jq -r '.session.id' > "${WORKSPACE}"/session_id + break + fi - # Write unique SSIDs to the SSID file - if ! grep -q ${ssid} ${SSID_FILE}; then - echo ${ssid} >> ${SSID_FILE} - fi + sleep 60 + echo -n "." done + +if [ -z "${SESSION}" ]; then + echo "Failed to reserve node" + exit 1 +fi diff --git a/jobs/scripts/common/return-node.sh b/jobs/scripts/common/return-node.sh index 22a5222..4a6c7ea 100644 --- a/jobs/scripts/common/return-node.sh +++ b/jobs/scripts/common/return-node.sh @@ -1,9 +1,5 @@ -# cico-node-done-from-ansible.sh -# A script that releases nodes from a SSID file written by set +x -SSID_FILE=${SSID_FILE:-$WORKSPACE/cico-ssid} -for ssid in $(cat ${SSID_FILE}) -do - cico -q node done $ssid -done +SESSION_ID=$(cat "${WORKSPACE}"/session_id) + +duffy client retire-session "${SESSION_ID}" > /dev/null