diff --git a/scripts/bwctest-osd.sh b/scripts/bwctest-osd.sh new file mode 100755 index 000000000000..8f6c67c7412e --- /dev/null +++ b/scripts/bwctest-osd.sh @@ -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" \ No newline at end of file