Skip to content

Commit

Permalink
Enhance massive mc-infra provisioning test script
Browse files Browse the repository at this point in the history
  • Loading branch information
seokho-son committed Oct 30, 2024
1 parent 244e427 commit 4d1ac72
Showing 1 changed file with 86 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,65 @@ echo "####################################################################"
echo "## test-mci-dynamic-all.sh (parameters: -x (create or delete) -y numVM)"
echo "####################################################################"



source ../init.sh

# create or delete
option=${OPTION01}
subGroupSizeInput=${OPTION02:-1}


PRINT="index,mciName,connectionName,specId,image,subGroupSize,startTime,endTime,elapsedTime,option"
echo "${PRINT}" >./mciTest-$option.csv


description="Made in CB-TB"
installMonAgent="no"
label="DynamicVM"

echo
maxIterations=3

specIdArray=(
aws+ap-northeast-1+t2.small
aws+ap-northeast-2+t2.small
aws+ap-northeast-3+t2.small
aws+ap-south-1+t2.small
aws+ap-southeast-1+t2.small
aws+ap-southeast-2+t2.small
aws+ca-central-1+t2.small
aws+eu-central-1+t2.small
aws+eu-west-1+t2.small
aws+eu-west-2+t2.small
aws+eu-west-3+t2.small
aws+sa-east-1+t2.small
aws+us-east-2+t2.small
aws+us-west-1+t2.small
aws+us-west-2+t2.small
gcp+asia-east1+g1-small
gcp+asia-east2+g1-small
gcp+asia-northeast1+g1-small
gcp+asia-northeast2+g1-small
gcp+asia-northeast3+g1-small
gcp+asia-south1+g1-small
gcp+asia-southeast1+g1-small
gcp+asia-southeast2+g1-small
gcp+australia-southeast1+g1-small
gcp+europe-central2+g1-small
)

specArray="[]"
for specId in "${specIdArray[@]}"; do
spec=$(curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/system/resources/spec/${specId})
specArray=$(echo "$specArray" | jq --argjson spec "$spec" '. + [$spec]')
sleep 0.1
done

echo "Number of specs: $(echo "$specArray" | jq length)"

specList=$(curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/system/resources/spec)
specArray=$(jq -r '.spec' <<<"$specList")
commonImage="ubuntu22.04"

MainMciName="allforone"
mciName=$MainMciName

i=0

for row in $(echo "${specArray}" | jq -r '.[] | @base64'); do
{
_jq() {
Expand All @@ -36,16 +72,17 @@ for row in $(echo "${specArray}" | jq -r '.[] | @base64'); do
specId=$(_jq '.id')
rootDiskType=$(_jq '.rootDiskType')
rootDiskSize=$(_jq '.rootDiskSize')
image="ubuntu18.04"
subGroupSize=$subGroupSizeInput
mciName=$specId

if [ "${option}" == "create" ]; then
echo "[$i] connection: $connectionName / specId: $specId / image: $image / replica: $subGroupSize "
echo "[$i] connection: $connectionName / specId: $specId / image: $commonImage / replica: $subGroupSizeInput "
elif [ "${option}" == "delete" ]; then
echo "[$i] mciName: $mciName / replica: $subGroupSize "
echo "[$i] mciName: $mciName "
fi
((i++))

if [ $i -ge $maxIterations ]; then
break
fi
}
done

Expand Down Expand Up @@ -75,140 +112,59 @@ done

SECONDS=0

specList=$(curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/system/resources/spec)
specArray=$(jq -r '.spec' <<<"$specList")

MainMciName="allforone"
mciName=$MainMciName
firstSpecId=""
if [ "${option}" == "delete" ]; then
echo "Terminate and Delete [$mciName]"
curl -H "${AUTH}" -sX DELETE http://$TumblebugServer/tumblebug/ns/$NSID/mci/${mciName}?option=terminate | jq '.'
elif [ "${option}" == "create" ]; then
# Initialize an empty array correctly
vmArray=$(jq -n '[]')
i=0

i=0
for row in $(echo "${specArray}" | jq -r '.[] | @base64'); do
for row in $(echo "${specArray}" | jq -r '.[] | @base64'); do
{
if [ "${i}" == "0" ]; then
connectionName=$(_jq '.connectionName')
specId=$(_jq '.id')
firstSpecId=$specId
rootDiskType=$(_jq '.rootDiskType')
rootDiskSize=$(_jq '.rootDiskSize')
image="ubuntu18.04"
subGroupSize=$subGroupSizeInput

mciName=$MainMciName

echo
echo "mciName: $mciName specId: $specId image: $image connectionName: $connectionName rootDiskType: $rootDiskType rootDiskSize: $rootDiskSize subGroupSize: $subGroupSize "

startTime=$SECONDS

echo "Creat MCI dynamic [$mciName]"
VAR1=$(curl -H "${AUTH}" -sX POST http://$TumblebugServer/tumblebug/ns/$NSID/mciDynamic -H 'Content-Type: application/json' -d @- <<EOF
{
"name": "${mciName}",
"description": "${description}",
"installMonAgent": "${installMonAgent}",
"label": "${label}",
"systemLabel": "Managed-by-Tumblebug",
"vm": [ {
"name": "${specId}",
"commonImage": "${image}",
"commonSpec": "${specId}",
"rootDiskType": "${rootDiskType}",
"rootDiskSize": "${rootDiskSize}",
"subGroupSize": "${subGroupSize}"
}
]
}
EOF
)

echo "${VAR1}" | jq '.'


endTime=$SECONDS
elapsedTime=$(($endTime-$startTime))

PRINT="${i},${mciName},${connectionName},${specId},${image},${subGroupSize},${startTime},${endTime},${elapsedTime},${option}"
echo "$PRINT"
echo "$PRINT" >>./mciTest-$option.csv
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
specId=$(_jq '.id')
echo "specId: $specId"

echo "[$i] Elapsed time: $elapsedTime s"
((i++))
# Properly append to the JSON array
vmArray=$(echo "$vmArray" | jq --arg commonImage "$commonImage" --arg specId "$specId" --arg subGroupSizeInput "$subGroupSizeInput" '. + [{"commonImage": $commonImage, "commonSpec": $specId, "subGroupSize": $subGroupSizeInput}]')
((i++))

_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}
# Break the loop when max iterations are reached
if [ $i -ge $maxIterations ]; then
break
fi

}
done

i=0
for row in $(echo "${specArray}" | jq -r '.[] | @base64'); do
{
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}

if [ "${firstSpecId}" != "$(_jq '.id')" ]; then

connectionName=$(_jq '.connectionName')

specId=$(_jq '.id')
rootDiskType=$(_jq '.rootDiskType')
rootDiskSize=$(_jq '.rootDiskSize')
image="ubuntu18.04"
subGroupSize=$subGroupSizeInput

echo
echo "mciName: $mciName specId: $specId image: $image connectionName: $connectionName rootDiskType: $rootDiskType rootDiskSize: $rootDiskSize subGroupSize: $subGroupSize "
sleepDuration=$((1 + $RANDOM% 1000))
echo "sleepDuration: $sleepDuration"
#sleep $sleepDuration

startTime=$SECONDS

echo "Creat VM dynamic [$mciName]"
VAR1=$(curl -H "${AUTH}" -sX POST http://$TumblebugServer/tumblebug/ns/$NSID/mci/$mciName/vmDynamic -H 'Content-Type: application/json' -d @- <<EOF
{
"name": "${specId}",
"commonImage": "${image}",
"commonSpec": "${specId}",
"rootDiskType": "${rootDiskType}",
"rootDiskSize": "${rootDiskSize}",
"subGroupSize": "${subGroupSize}"
}
EOF
)

echo "${VAR1}" | jq '.'
done

endTime=$SECONDS
elapsedTime=$(($endTime-$startTime))
# Construct the request body with the accumulated JSON array
requestBody=$(jq -n --arg name "$mciName" --argjson vm "$vmArray" '{name: $name, vm: $vm}')
echo "requestBody: $requestBody"

PRINT="${i},${mciName},${connectionName},${specId},${image},${subGroupSize},${startTime},${endTime},${elapsedTime},${option}"
echo "$PRINT"
echo "$PRINT" >>./mciTest-$option.csv
if [ "${option}" == "delete" ]; then
echo "Terminate and Delete [$mciName]"
curl -H "${AUTH}" -sX DELETE http://$TumblebugServer/tumblebug/ns/$NSID/mci/${mciName}?option=terminate | jq '.'
elif [ "${option}" == "create" ]; then
echo "Create MCI dynamic [$mciName]"
response=$(curl -H "${AUTH}" -sX POST http://$TumblebugServer/tumblebug/ns/$NSID/mciDynamic -H 'Content-Type: application/json' -d "$requestBody")
echo "${response}" | jq '.'

echo "[$i] Elapsed time: $elapsedTime s"
((i++))
fi
} #&

done
#wait
mciResponse=$(curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/$NSID/mci/${mciName})

echo -e "${BOLD}MCI Status Summary: ${mciName}${NC}"
echo "$mciResponse" | jq '.status'

echo -e "${BOLD}Table: All VMs in the MCI : ${mciName}${NC} ${BLUE} ${BOLD}"
echo "$mciResponse" |
jq '.vm | sort_by(.connectionName)' |
jq -r '(["CloudRegion", "SpecName", "ID(TB)", "ID(CSP)", "Status", "PublicIP", "PrivateIP", "DateTime(Created)"] |
(., map(length*"-"))),
(.[] | [.connectionName, .cspSpecName, .id, .cspResourceId, .status, .publicIP, .privateIP, .createdTime]) | @tsv' |
column -t
echo -e "${NC}"
fi



echo "Done!"

duration=$SECONDS
printElapsed $@
echo ""
Expand Down

0 comments on commit 4d1ac72

Please sign in to comment.