From 2572a0046fc0c7ccf58e9b8d82c0c4a9b3a40e1a Mon Sep 17 00:00:00 2001 From: Anan Zhuang Date: Thu, 11 Nov 2021 19:42:44 +0000 Subject: [PATCH] Add a script to use one command to run all bwc tests 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: ./cypress/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 Partically Resolved: https://github.com/opensearch-project/opensearch-build/issues/705 Signed-off-by: Anan Zhuang --- cypress/bwctest-osd.sh | 177 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100755 cypress/bwctest-osd.sh diff --git a/cypress/bwctest-osd.sh b/cypress/bwctest-osd.sh new file mode 100755 index 000000000000..64f3bdae4ced --- /dev/null +++ b/cypress/bwctest-osd.sh @@ -0,0 +1,177 @@ +#!/bin/bash + +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" \ No newline at end of file