Skip to content

Commit

Permalink
Updating the logic for New Duffy reservation
Browse files Browse the repository at this point in the history
  • Loading branch information
rakshithakamath94 committed Feb 13, 2023
1 parent d313e1e commit ee34888
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 44 deletions.
1 change: 0 additions & 1 deletion jobs/scripts/common/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -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" ];
Expand Down
89 changes: 53 additions & 36 deletions jobs/scripts/common/get-node.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
client:
url: https://duffy.ci.centos.org/api/v1
auth:
name: gluster
key: ${CICO_API_KEY}
EOF

case "${CENTOS_VERSION}" in
7)
VERSION_STRING="7"
;;
8-stream)
VERSION_STRING="8s"
;;
9-stream)
VERSION_STRING="9s"
;;
esac

POOL_MATCH="^(metal-ec2)(.*)(centos-${VERSION_STRING}-x86_64)$"

readarray -t POOLS < <(duffy client list-pools | jq -r '.pools[].name')

for i in "${POOLS[@]}"
do
host=$(echo "${node}" |cut -f1 -d " ")
address=$(echo "${node}" |cut -f2 -d " ")
ssid=$(echo "${node}" |cut -f3 -d " ")
if [[ $i =~ ${POOL_MATCH} ]]; then
POOL_FOUND=$i
break
fi
done

if [ -z "${POOL_FOUND}" ]; then
echo "No matching pool found"
exit 1
fi

line="${address}"
echo "${line}" >> ${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
10 changes: 3 additions & 7 deletions jobs/scripts/common/return-node.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ee34888

Please sign in to comment.