Skip to content

Commit

Permalink
Change method to input parameters for script (#677)
Browse files Browse the repository at this point in the history
* Change default vm spec for script

* Add init.sh for script initialization

* Apply named param and merge cmd scripts

* Apply named param for mcis create scripts

* Apply named param for mcis clean scripts

* Apply named param for mcis wv deploy script
  • Loading branch information
seokho-son authored Aug 19, 2021
1 parent 17f70e8 commit 19f3fd5
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 258 deletions.
49 changes: 49 additions & 0 deletions src/testclient/scripts/common-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,55 @@ function dozing() {
echo "(Finish dozing. Back to work)"
}

function readParametersByName() {
CSP="all"
REGION="1"
POSTFIX="user"
TestSetFile="../testSet.env"
OPTION01=""
OPTION02=""
OPTION03=""

# Update values for network parameters by named input parameters (i, c)
while getopts ":f:n:x:y:z:h:" opt; do
case $opt in
f)
TestSetFile="$OPTARG"
;;
n)
POSTFIX="$OPTARG"
;;
x)
OPTION01="$OPTARG"
;;
y)
OPTION02="$OPTARG"
;;
z)
OPTION03="$OPTARG"
;;
h)
echo "How to use '-h' (ex: ./${0##*/} -c ../testSet.env -n myname)"
exit 0
;;
\?)
echo "Invalid option -$OPTARG (Use: -i for NETWORK_INTERFACE, -c for POD_NETWORK_CIDR)" >&2
exit 0
;;
esac
done

echo "[Input parameters]"
echo "CSP: $CSP"
echo "REGION: $REGION"
echo "POSTFIX: $POSTFIX"
echo "OPTION01: $OPTION01"
echo "OPTION02: $OPTION02"
echo "OPTION03: $OPTION03"


}

function readParameters() {
CSP=${1}
REGION=${2:-1}
Expand Down
6 changes: 3 additions & 3 deletions src/testclient/scripts/conf.env
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ RegionVal01[$IX,$IY]=ap-southeast-1
RegionKey02[$IX,$IY]=Zone
RegionVal02[$IX,$IY]=ap-southeast-1a
CONN_CONFIG[$IX,$IY]=aws-ap-se-1
IMAGE_NAME[$IX,$IY]=ami-061eb2b23f9f8839c
SPEC_NAME[$IX,$IY]=m4.4xlarge #t3.xlarge t3.medium
IMAGE_NAME[$IX,$IY]=ami-061eb2b23f9f8839c #Ubuntu 18.04
SPEC_NAME[$IX,$IY]=m4.4xlarge # t2.micro t3.xlarge t3.medium

# region02
IY=$AwsCaCentral1
Expand Down Expand Up @@ -239,7 +239,7 @@ RegionKey02[$IX,$IY]=Zone
RegionVal02[$IX,$IY]=ap-northeast-2a
CONN_CONFIG[$IX,$IY]=aws-ap-ne-2
IMAGE_NAME[$IX,$IY]=ami-00379ec40a3e30f87
SPEC_NAME[$IX,$IY]=m4.4xlarge
SPEC_NAME[$IX,$IY]=t2.micro # m4.4xlarge

# region18
IY=$AwsApEast1
Expand Down
25 changes: 25 additions & 0 deletions src/testclient/scripts/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

source ../common-functions.sh
readParametersByName "$@"
set -- "$CSP" "$REGION" "$POSTFIX" "$TestSetFile" "$OPTION01" "$OPTION02" "$OPTION03"

FILE=../credentials.conf
if [ ! -f "$FILE" ]; then
echo "$FILE does not exist."
exit
fi

if [ ! -f "$TestSetFile" ]; then
echo "$TestSetFile does not exist."
exit
fi
source $TestSetFile
source ../conf.env
source ../credentials.conf

getCloudIndex $CSP
MCISID=${MCISPREFIX}-${POSTFIX}

echo "[Check jq package (if not, install)]"
if ! dpkg-query -W -f='${Status}' jq | grep "ok installed"; then sudo apt install -y jq; fi
47 changes: 18 additions & 29 deletions src/testclient/scripts/sequentialFullTest/change-mcis-hostname.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,47 @@

SECONDS=0

echo "[Check jq package (if not, install)]"
if ! dpkg-query -W -f='${Status}' jq | grep "ok installed"; then sudo apt install -y jq; fi

TestSetFile=${4:-../testSet.env}
if [ ! -f "$TestSetFile" ]; then
echo "$TestSetFile does not exist."
exit
fi
source $TestSetFile
source ../conf.env

echo "####################################################################"
echo "## Command (SSH) to MCIS to change-mcis-hostname"
echo "####################################################################"

CSP=${1}
REGION=${2:-1}
POSTFIX=${3:-developer}

source ../common-functions.sh
getCloudIndex $CSP

MCISID=${CONN_CONFIG[$INDEX,$REGION]}-${POSTFIX}
source ../init.sh

if [ "${INDEX}" == "0" ]; then
# MCISPREFIX=avengers
MCISID=${MCISPREFIX}-${POSTFIX}
# MCISPREFIX=avengers
MCISID=${MCISPREFIX}-${POSTFIX}
fi

MCISINFO=$(curl -H "${AUTH}" -sX GET http://$TumblebugServer/tumblebug/ns/$NSID/mcis/${MCISID})
VMARRAY=$(jq -r '.vm' <<<"$MCISINFO")

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

VMID=$(_jq '.id')
connectionName=$(_jq '.connectionName')
connectionName=$(_jq '.connectionName')
publicIP=$(_jq '.publicIP')
cloudType=$(_jq '.location.cloudType')

echo "VMID: $VMID"
echo "connectionName: $connectionName"
echo "publicIP: $publicIP"

getCloudIndexGeneral $cloudType

# ChangeHostCMD="sudo hostnamectl set-hostname ${GeneralINDEX}-${connectionName}-${publicIP}; sudo hostname -f"
ChangeHostCMD="sudo hostnamectl set-hostname ${GeneralINDEX}-${VMID}; sudo hostname -f"
./command-mcis-vm-custom.sh "${1}" "${2}" "${3}" "${4}" "${VMID}" "${ChangeHostCMD}" &
USERCMD="sudo hostnamectl set-hostname ${GeneralINDEX}-${VMID}; echo -n [Public IP: ; curl https://api.ipify.org ; echo -n ], [Hostname: ; hostname -f; echo -n ]"
VAR1=$(
curl -H "${AUTH}" -sX POST http://$TumblebugServer/tumblebug/ns/$NSID/cmd/mcis/$MCISID/vm/$VMID -H 'Content-Type: application/json' -d @- <<EOF
{
"command" : "${USERCMD}"
}
EOF
)
echo "${VAR1}" | jq ''

done
wait

Expand All @@ -62,4 +52,3 @@ duration=$SECONDS
printElapsed $@
echo ""

./command-mcis.sh "$@"
21 changes: 1 addition & 20 deletions src/testclient/scripts/sequentialFullTest/clean-mcir-ns-cloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,12 @@ function clean_sequence() {

SECONDS=0

FILE=../credentials.conf
if [ ! -f "$FILE" ]; then
echo "$FILE does not exist."
exit
fi

TestSetFile=${4:-../testSet.env}
if [ ! -f "$TestSetFile" ]; then
echo "$TestSetFile does not exist."
exit
fi
source $TestSetFile
source ../conf.env
source ../credentials.conf

echo "####################################################################"
echo "## Remove mcir-ns-cloud"
echo "####################################################################"

CSP=${1}
REGION=${2:-1}
POSTFIX=${3:-developer}
source ../init.sh

source ../common-functions.sh
getCloudIndex $CSP

if [ "${INDEX}" == "0" ]; then
echo "[Parallel excution for all CSP regions]"
Expand Down
22 changes: 1 addition & 21 deletions src/testclient/scripts/sequentialFullTest/clean-mcis-only.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,11 @@ function clean_mcis_sequence() {

SECONDS=0

FILE=../credentials.conf
if [ ! -f "$FILE" ]; then
echo "$FILE does not exist."
exit
fi

TestSetFile=${4:-../testSet.env}
if [ ! -f "$TestSetFile" ]; then
echo "$TestSetFile does not exist."
exit
fi
source $TestSetFile
source ../conf.env
source ../credentials.conf

echo "####################################################################"
echo "## Remove MCIS only"
echo "####################################################################"

CSP=${1}
REGION=${2:-1}
POSTFIX=${3:-developer}

source ../common-functions.sh
getCloudIndex $CSP
source ../init.sh

if [ "${INDEX}" == "0" ]; then
echo "[Parallel excution for all CSP regions]"
Expand Down
50 changes: 21 additions & 29 deletions src/testclient/scripts/sequentialFullTest/command-mcis-custom.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,36 @@
#!/bin/bash

#function command_mcis_custom() {

TestSetFile=${4:-../testSet.env}
if [ ! -f "$TestSetFile" ]; then
echo "$TestSetFile does not exist."
exit
fi
source $TestSetFile
source ../conf.env

echo "####################################################################"
echo "## Command (SSH) to MCIS "
echo "## Command (SSH) to MCIS with a user command"
echo "####################################################################"

CSP=${1}
REGION=${2:-1}
POSTFIX=${3:-developer}

source ../common-functions.sh
getCloudIndex $CSP
source ../init.sh

USERCMD=${5}
USERCMD=$OPTION01
VMID=$OPTION02

MCISID=${CONN_CONFIG[$INDEX,$REGION]}-${POSTFIX}

if [ "${INDEX}" == "0" ]; then
# MCISPREFIX=avengers
MCISID=${MCISPREFIX}-${POSTFIX}
if [ -z "$USERCMD" ]; then
USERCMD="echo -n [Public IP: ; curl https://api.ipify.org ; echo -n ], [Hostname: ; hostname ; echo -n ]"
fi

VAR1=$(
curl -H "${AUTH}" -sX POST http://$TumblebugServer/tumblebug/ns/$NSID/cmd/mcis/$MCISID -H 'Content-Type: application/json' -d @- <<EOF
if [ -z "$VMID" ]; then

VAR1=$(
curl -H "${AUTH}" -sX POST http://$TumblebugServer/tumblebug/ns/$NSID/cmd/mcis/$MCISID -H 'Content-Type: application/json' -d @- <<EOF
{
"command" : "${USERCMD}"
}
EOF
)
echo "${VAR1}" | jq ''
)
else
VAR1=$(
curl -H "${AUTH}" -sX POST http://$TumblebugServer/tumblebug/ns/$NSID/cmd/mcis/$MCISID/vm/$VMID -H 'Content-Type: application/json' -d @- <<EOF
{
"command" : "${USERCMD}"
}
EOF
)

#}
fi

#command_mcis_custom
echo "${VAR1}" | jq ''

This file was deleted.

Loading

0 comments on commit 19f3fd5

Please sign in to comment.