Skip to content

Commit

Permalink
Add a script to use one command to run all bwc tests
Browse files Browse the repository at this point in the history
Currently, even we have bwc tests and data, to run bwc, we need
to copy and unzip data in opensearch, then run opensearch,
dashboards and cypress. This script will add more automation to
allow us use one command to run all the tests. Here is the cmd:

./scripts/bwctest-osd.sh
-o /path/to/opensearch.tar.gz
-d /path/to/opensearch-dashboards.tar.gz
-v versions
-b true/false

-o is the path to the tested opensearch. Here we need to rename
the folder to opensearch and zip it
-d is the path to the tested opensearch-dashboards. Also need to
rename the folder to opensearch-dashboards and zip it
-v is the optional version para. You can specify one version or
multiple versions like "odfe-1.1.0, osd-1.0.0". If no pass, it will
run all the versions defined in the script.
-b is the optional osd type para. If pass true, it will run osd bundle.
If pass false, it will run osd vanilla. The default is false.

update the usage section with new parameters
add license header and move the script in scripts folder

Partically Resolved:
opensearch-project/opensearch-build#705

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
  • Loading branch information
ananzh committed Nov 16, 2021
1 parent ff84b35 commit b4c3e66
Showing 1 changed file with 183 additions and 0 deletions.
183 changes: 183 additions & 0 deletions scripts/bwctest-osd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
#!/bin/bash

# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.s

set -e

function usage() {
echo ""
echo "This script is used to run bwc tests on a remote OpenSearch/Dashboards cluster."
echo "--------------------------------------------------------------------------"
echo "Usage: $0 [args]"
echo ""
echo "Required arguments:"
echo "None"
echo ""
echo "Optional arguments:"
echo -e "-a BIND_ADDRESS\t, defaults to localhost | 127.0.0.1, can be changed to any IP or domain name for the cluster location."
echo -e "-p BIND_PORT\t, defaults to 9200 or 5601 depends on OpenSearch or Dashboards, can be changed to any port for the cluster location."
echo -e "-b BUNDLED_OSD\t(true | false), defaults to false. Specify the usage of bundled Dashboards or not."
echo -e "-v VERSIONS\t(true | false), defaults to a defind test array in the script. Specify the versions of the tested Dashboards. It could be a single version or multiple."
echo -e "-o OPENSEARCH\t, no defaults and must provide. Specify the tested OpenSearch which must be named opensearch and formatted as tar.gz."
echo -e "-d OSD\t, no defaults and must provide. Specify the tested OpenSearch Dashboards which must be named opensearch-dashboards and formatted as tar.gz."
echo -e "-h\tPrint this message."
echo "--------------------------------------------------------------------------"
}

while getopts ":ha:p:b:v:o:d:" arg; do
case $arg in
h)
usage
exit 1
;;
a)
BIND_ADDRESS=$OPTARG
;;
p)
BIND_PORT=$OPTARG
;;
b)
BUNDLED_OSD=$OPTARG
;;
v)
VERSIONS=$OPTARG
;;
o)
OPENSEARCH=$OPTARG
;;
d)
OSD=$OPTARG
;;
:)
echo "-${OPTARG} requires an argument"
usage
exit 1
;;
?)
echo "Invalid option: -${OPTARG}"
exit 1
;;
esac
done

if [ -z "$BIND_ADDRESS" ]
then
BIND_ADDRESS="localhost"
fi

if [ -z "$BIND_PORT" ]
then
BIND_PORT="5601"
fi

if [ -v "VERSIONS" ]
then
testArray=($VERSIONS)
else
testArray=("odfe-0.10.0" "odfe-1.0.2" "odfe-1.1.0" "odfe-1.2.1" "odfe-1.3.0" "odfe-1.4.0" "odfe-1.7.0" "odfe-1.8.0" "odfe-1.9.0" "odfe-1.11.0" "odfe-1.13.2" "osd-1.0.0" "osd-1.1.0")
fi

if [ -z "$BUNDLED_OSD" ]
then
BUNDLED_OSD="false"
fi

if [ $BUNDLED_OSD == "false" ]
then
osdtype="osd"
else
osdtype="osd-bundle"
fi

#define path
cwd=$(pwd)
dir="$cwd/bwc-tmp"
testdir="$dir/test"
if [ -d "$dir" ]; then
echo "bwc-tmp exists and needs to be removed"
rm -rf "$dir"
fi
mkdir "$dir"
mkdir "$testdir"

#unzip opensearch and dashboards
cp $OPENSEARCH $dir
cp $OSD $dir
cd $dir
IFS='/' read -ra ADDR <<< "$OPENSEARCH"
opensearchtar=${ADDR[-1]}
IFS='.' read -ra ADDR <<< "$opensearchtar"
opensearch=${ADDR[0]}

IFS='/' read -ra ADDR <<< "$OSD"
osdtar=${ADDR[-1]}
IFS='.' read -ra ADDR <<< "$osdtar"
osd=${ADDR[0]}

tar -xvf $opensearchtar
tar -xvf $osdtar
opensearch_dir="$dir/$opensearch"
osd_dir="$dir/$osd"

#setup cypress test env
echo "setup cypress test env"
git clone https://github.com/opensearch-project/opensearch-dashboards-functional-test "$testdir"
rm -rf "$testdir/cypress/integration"
cp -r "$cwd/cypress/integration" "$testdir/cypress"
cd "$testdir"
npm install

#Run OpenSearch and Dashboards
cd "$testdir"
for i in ${!testArray[@]};
do
version=${testArray[$i]}
#setup opensearch
#copy and unzip data in opensearch
echo "---------------set up opensearch env for $version---------------"
rm -rf "$opensearch_dir/data"
cd $opensearch_dir
cp "$cwd/cypress/test-data/$osdtype/$version.tar.gz" .
tar -xvf "$opensearch_dir/$version.tar.gz" >> /dev/null 2>&1
rm "$version.tar.gz"
cd "$testdir"
echo "ready to test"
#run bwc tests
echo "---------------run bwc test for $version -----------------"
{
cd "$opensearch_dir"
./bin/opensearch
} >> /dev/null 2>&1 &
{
sleep 10
cd "$osd_dir"
./bin/opensearch-dashboards
} >> /dev/null 2>&1 &
sleep 20

if [ $version == "odfe-0.10.0" ]; then
npx cypress run --spec "$cwd/bwc-tmp/test/cypress/integration/$osdtype/check_loaded_data.js" || echo "bwc tests have issue"
npx cypress run --spec "$cwd/bwc-tmp/test/cypress/integration/$osdtype/check_timeline.js" || echo "bwc tests have issue"
elif [ $version == "odfe-1.0.2" ] || [ $version == "odfe-1.1.0" ] || [ $version == "odfe-1.2.1" ] || [ $version == "odfe-1.3.0" ]; then
npx cypress run --spec "$cwd/bwc-tmp/test/cypress/integration/$osdtype/check_advanced_settings.js" || echo "bwc tests have issue"
npx cypress run --spec "$cwd/bwc-tmp/test/cypress/integration/$osdtype/check_loaded_data.js" || echo "bwc tests have issue"
npx cypress run --spec "$cwd/bwc-tmp/test/cypress/integration/$osdtype/check_timeline.js" || echo "bwc tests have issue"
elif [ $version == "odfe-1.4.0" ] || [ $version == "odfe-1.7.0" ] || [ $version == "odfe-1.8.0" ] || [ $version == "odfe-1.9.0" ] || [ $version == "odfe-1.11.0" ]; then
npx cypress run --spec "$cwd/bwc-tmp/test/cypress/integration/$osdtype/check_advanced_settings.js" || echo "bwc tests have issue"
npx cypress run --spec "$cwd/bwc-tmp/test/cypress/integration/$osdtype/check_filter_and_query.js" || echo "bwc tests have issue"
npx cypress run --spec "$cwd/bwc-tmp/test/cypress/integration/$osdtype/check_loaded_data.js" || echo "bwc tests have issue"
npx cypress run --spec "$cwd/bwc-tmp/test/cypress/integration/$osdtype/check_timeline.js" || echo "bwc tests have issue"
else
npx cypress run --spec "$cwd/bwc-tmp/test/cypress/integration/$osdtype/*.js" || echo "bwc tests have issue"
fi

#kill opensearch process
process=($(ps -ef | grep "Dopensearch" | awk '{print $2}'))
kill ${process[0]}
done

rm -rf "$dir"

0 comments on commit b4c3e66

Please sign in to comment.