From 19f3fd54c1ae0fc0b0ed494bf5fccf3341db06e5 Mon Sep 17 00:00:00 2001 From: Seokho Son Date: Thu, 19 Aug 2021 11:03:56 +0900 Subject: [PATCH] Change method to input parameters for script (#677) * 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 --- src/testclient/scripts/common-functions.sh | 49 ++++++++++++++++++ src/testclient/scripts/conf.env | 6 +-- src/testclient/scripts/init.sh | 25 ++++++++++ .../change-mcis-hostname.sh | 47 +++++++---------- .../sequentialFullTest/clean-mcir-ns-cloud.sh | 21 +------- .../sequentialFullTest/clean-mcis-only.sh | 22 +------- .../sequentialFullTest/command-mcis-custom.sh | 50 ++++++++----------- .../command-mcis-vm-custom.sh | 45 ----------------- .../sequentialFullTest/command-mcis.sh | 41 --------------- .../create-mcir-ns-cloud.sh | 37 ++++---------- .../sequentialFullTest/create-mcis-only.sh | 26 ++-------- .../deploy-weavescope-to-mcis.sh | 22 +------- 12 files changed, 133 insertions(+), 258 deletions(-) create mode 100755 src/testclient/scripts/init.sh delete mode 100755 src/testclient/scripts/sequentialFullTest/command-mcis-vm-custom.sh delete mode 100755 src/testclient/scripts/sequentialFullTest/command-mcis.sh diff --git a/src/testclient/scripts/common-functions.sh b/src/testclient/scripts/common-functions.sh index 74dfc326f..a23ef475a 100755 --- a/src/testclient/scripts/common-functions.sh +++ b/src/testclient/scripts/common-functions.sh @@ -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} diff --git a/src/testclient/scripts/conf.env b/src/testclient/scripts/conf.env index ba7ee84b7..2a516b0da 100644 --- a/src/testclient/scripts/conf.env +++ b/src/testclient/scripts/conf.env @@ -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 @@ -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 diff --git a/src/testclient/scripts/init.sh b/src/testclient/scripts/init.sh new file mode 100755 index 000000000..c1c88c77f --- /dev/null +++ b/src/testclient/scripts/init.sh @@ -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 diff --git a/src/testclient/scripts/sequentialFullTest/change-mcis-hostname.sh b/src/testclient/scripts/sequentialFullTest/change-mcis-hostname.sh index bb7375a03..fe581f96e 100755 --- a/src/testclient/scripts/sequentialFullTest/change-mcis-hostname.sh +++ b/src/testclient/scripts/sequentialFullTest/change-mcis-hostname.sh @@ -2,48 +2,30 @@ 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" @@ -51,8 +33,16 @@ for row in $(echo "${VMARRAY}" | jq -r '.[] | @base64'); do 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 @- <