Skip to content

Instantly share code, notes, and snippets.

@fl64
Last active December 28, 2024 13:29
Show Gist options
  • Save fl64/65f99b9d7ebcc973d5b7d69a2cf6d15a to your computer and use it in GitHub Desktop.
Save fl64/65f99b9d7ebcc973d5b7d69a2cf6d15a to your computer and use it in GitHub Desktop.
test-vm-due-migration-issue.sh
#!/usr/bin/env bash
NAMESPACE="env-1b4119-testcases"
SCRIPT_TEMPLATE='
for VM in %%VMS%%; do
VM_NAME=$(echo ${VM} | cut -d% -f 1);
VM_NS=$(echo ${VM} | cut -d% -f 2);
VM_IP=$(echo ${VM} | cut -d% -f 3);
VM_NODE=$(echo ${VM} | cut -d% -f4);
CURL_RESULT=$(curl --connect-timeout 1 -sq ${VM_IP} 2>&1);
if [[ $? -eq 0 ]]; then
echo -n "curl: ✅, " ;
else
echo -n "curl: ❌, " ;
fi;
echo "${CURL_RESULT}" | grep -q "env-1b4119";
if [[ $? -eq 0 ]]; then
echo -n "env-1b4119 found: ✅, " ;
else
echo -n "env-1b4119 found: ❌, " ;
fi;
NC_RESULT=$(nc -zvw2 ${VM_IP} 22 2>&1);
echo "${NC_RESULT}"
echo ${NC_RESULT} | grep -q "succeeded";
if [[ $? -eq 0 ]]; then
echo -n "nc22: ✅, " ;
else
echo -n "nc22: ❌, " ;
fi;
echo "📦 ${VM_IP} ${VM_NAME}";
sleep 0.5;
done
'
VMS=$(kubectl get -n ${NAMESPACE} vms -o json | jq '[ .items[] | select(.status.phase=="Running") | .metadata.name+"%"+.metadata.namespace+"%"+.status.ipAddress+"%"+.status.nodeName ] | join(" ")' -cr)
SCRIPT=$(echo ${SCRIPT_TEMPLATE} | sed "s/%%VMS%%/${VMS}/g")
#/usr/bin/ssh -o ConnectTimeout=1 -o ConnectionAttempts=1 dev-rnd.d8-virt-node-4 "${SCRIPT}"
for NODE in $(kubectl get nodes -o name | cut -d/ -f2); do
echo "⚙️ dev-rnd.${NODE}"
#/usr/bin/ssh -o ConnectTimeout=1 -o ConnectionAttempts=1 dev-rnd.${NODE} "ip r show table 1490"
/usr/bin/ssh -o ConnectTimeout=1 -o ConnectionAttempts=1 dev-rnd.${NODE} "${SCRIPT}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment