From ae5608297fb558567873b4c7a5b2a877a97bc355 Mon Sep 17 00:00:00 2001 From: Anan Zhuang Date: Thu, 14 Oct 2021 15:40:56 +0000 Subject: [PATCH] Add bwc tests for osd with bundle tests include the following cases: verify default page work verify advanced savings work verify filter and query work Disable eslint check Add eslint-disable comment Revise license content in plugins and support Simplify filter and query test modify test name and fix PR comment update license header and remove env files fix timestamp issue update eslint and license Particailly Resolved: https://github.com/opensearch-project/opensearch-build/issues/705 Signed-off-by: Anan Zhuang --- .../osd-bundle/check_advanced_settings.js | 42 +++ .../osd-bundle/check_default_page.js | 26 ++ .../osd-bundle/check_filter_and_query.js | 83 +++++ scripts/bwctest-osd.sh | 288 ++++++++++++++++++ 4 files changed, 439 insertions(+) create mode 100644 cypress/integration/osd-bundle/check_advanced_settings.js create mode 100644 cypress/integration/osd-bundle/check_default_page.js create mode 100644 cypress/integration/osd-bundle/check_filter_and_query.js create mode 100644 scripts/bwctest-osd.sh diff --git a/cypress/integration/osd-bundle/check_advanced_settings.js b/cypress/integration/osd-bundle/check_advanced_settings.js new file mode 100644 index 00000000000..12d4e56b176 --- /dev/null +++ b/cypress/integration/osd-bundle/check_advanced_settings.js @@ -0,0 +1,42 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +/* eslint-disable */ +import { + MiscUtils, + LoginPage, +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); +const loginPage = new LoginPage(cy); + +describe('verify the advanced settings are saved', () => { + beforeEach(() => { + miscUtils.visitPage('app/management/opensearch-dashboards/settings'); + loginPage.enterUserName('admin'); + loginPage.enterPassword('admin'); + loginPage.submit(); + }); + + it('the dark mode is on', () => { + cy.get('[data-test-subj="advancedSetting-editField-theme:darkMode"]') + .invoke('attr', 'aria-checked') + .should('eq', 'true'); + }); + + it('the Timeline default columns field is set to 4', () => { + cy.get('[data-test-subj="advancedSetting-editField-timeline:default_columns"]').should( + 'have.value', + 4 + ); + }); + + it('the Timeline Maximum buckets field is set to 4', () => { + cy.get('[data-test-subj="advancedSetting-editField-timeline:max_buckets"]').should( + 'have.value', + 4 + ); + }); +}); diff --git a/cypress/integration/osd-bundle/check_default_page.js b/cypress/integration/osd-bundle/check_default_page.js new file mode 100644 index 00000000000..469b80014bd --- /dev/null +++ b/cypress/integration/osd-bundle/check_default_page.js @@ -0,0 +1,26 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +/* eslint-disable */ +import { + MiscUtils, + LoginPage, +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); +const loginPage = new LoginPage(cy); + +describe('verify default landing page work for bwc', () => { + beforeEach(() => { + miscUtils.visitPage(''); + loginPage.enterUserName('admin'); + loginPage.enterPassword('admin'); + loginPage.submit(); + }); + + it('the overview page is set as the default landing page', () => { + cy.url().should('include', '/app/opensearch_dashboards_overview#/'); + }); +}); diff --git a/cypress/integration/osd-bundle/check_filter_and_query.js b/cypress/integration/osd-bundle/check_filter_and_query.js new file mode 100644 index 00000000000..04b415a5aeb --- /dev/null +++ b/cypress/integration/osd-bundle/check_filter_and_query.js @@ -0,0 +1,83 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +/* eslint-disable */ +import { + MiscUtils, + CommonUI, + LoginPage, +} from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; + +const miscUtils = new MiscUtils(cy); +const commonUI = new CommonUI(cy); +const loginPage = new LoginPage(cy); + +describe('check dashboards filter and query', () => { + beforeEach(() => { + miscUtils.visitPage('app/dashboards#'); + loginPage.enterUserName('admin'); + loginPage.enterPassword('admin'); + loginPage.submit(); + }); + + afterEach(() => { + cy.clearCookies(); + }); + + it('tenant-switch-modal page should show and be clicked', () => { + cy.get('[data-test-subj="tenant-switch-modal"]'); + cy.get('[data-test-subj="confirm"]').click(); + }); + + describe('osx filter and query should work in [Logs] Web Traffic dashboards', () => { + beforeEach(() => { + cy.get('[data-test-subj="dashboardListingTitleLink-[Logs]-Web-Traffic"]').click(); + cy.get('[data-test-subj="breadcrumb last"]') + .invoke('attr', 'title') + .should('eq', '[Logs] Web Traffic'); + }); + + it('osx filter and query should exist and be named correctly', () => { + cy.get('[data-test-subj="saved-query-management-popover-button"]').click(); + cy.get('[data-test-subj="saved-query-management-popover"]') + .find('[class="osdSavedQueryListItem__labelText"]') + .should('have.text', 'test-query') + .click(); + cy.get('[data-test-subj="queryInput"]').should('have.text', 'resp=200'); + cy.get( + '[data-test-subj="filter filter-enabled filter-key-machine.os filter-value-osx filter-unpinned "]' + ) + .should('have.text', 'osx filter') + .click(); + cy.get('[data-test-subj="editFilter"]').click(); + cy.get('[data-test-subj="filterFieldSuggestionList"]') + .find('[data-test-subj="comboBoxInput"]') + .should('have.text', 'machine.os'); + cy.get('[data-test-subj="filterOperatorList"]') + .find('[data-test-subj="comboBoxInput"]') + .should('have.text', 'is'); + cy.get('[data-test-subj="filterParams"]').find('input').should('have.value', 'osx'); + }); + + it('osx filter and query should function correctly', () => { + cy.get('[data-test-subj="saved-query-management-popover-button"]').click(); + cy.get('[data-test-subj="saved-query-management-popover"]') + .find('[class="osdSavedQueryListItem__labelText"]') + .should('have.text', 'test-query') + .click(); + commonUI.setDateRange('Dec 1, 2021 @ 00:00:00.000', 'Jan 1, 2021 @ 00:00:00.000'); + + //[Logs] vistor chart should show osx 100% + cy.get('[data-title="[Logs] Visitors by OS"]') + .find('[class="label"]') + .should('have.text', 'osx (100%)'); + + //[Logs] Response chart should show 200 label + cy.get('[data-title="[Logs] Response Codes Over Time + Annotations"]') + .find('[title="200"]') + .should('have.text', '200'); + }); + }); +}); diff --git a/scripts/bwctest-osd.sh b/scripts/bwctest-osd.sh new file mode 100644 index 00000000000..630cd0e54a1 --- /dev/null +++ b/scripts/bwctest-osd.sh @@ -0,0 +1,288 @@ +#!/bin/bash + +# Copyright OpenSearch Contributors +# SPDX-License-Identifier: Apache-2.0 + +set -e + +function usage() { + echo "" + echo "This script is used to run backwards compatibility 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_DASHBOARDS\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 DASHBOARDS\t, no defaults and must provide. Specify the tested 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_DASHBOARDS=$OPTARG + ;; + v) + VERSIONS=$OPTARG + ;; + o) + OPENSEARCH=$OPTARG + ;; + d) + DASHBOARDS=$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 + test_array=($VERSIONS) +else + test_array=("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_DASHBOARDS" ] +then + BUNDLED_DASHBOARDS="false" +fi + +if [ $BUNDLED_DASHBOARDS == "false" ] +then + dashboards_type="osd" +else + dashboards_type="osd-bundle" +fi + +# define test path +cwd=$(pwd) +dir="$cwd/bwc-tmp" +test_dir="$dir/test" +if [ -d "$dir" ]; then + echo "bwc-tmp exists and needs to be removed" + rm -rf "$dir" +fi +mkdir "$dir" +mkdir "$test_dir" + +# unzip opensearch and dashboards +echo "[ unzip opensearch and dashboards ]" +cd "$dir" +cp $OPENSEARCH $dir +cp $DASHBOARDS $dir + +IFS='/' read -ra ADDR <<< "$OPENSEARCH" +opensearch_tar=${ADDR[-1]} +tar -xvf $opensearch_tar >> /dev/null 2>&1 +IFS='.' read -ra ADDR <<< "$opensearch_tar" +opensearch=${ADDR[0]} + +IFS='/' read -ra ADDR <<< "$DASHBOARDS" +dashboards_tar=${ADDR[-1]} +tar -xvf $dashboards_tar >> /dev/null 2>&1 +IFS='.' read -ra ADDR <<< "$dashboards_tar" +dashboards=${ADDR[0]} + +# define other paths and tmp files +opensearch_dir="$dir/$opensearch" +dashboards_dir="$dir/$dashboards" +opensearch_file='opensearch.txt' +dashboards_file='dashboards.txt' +opensearch_path="$dir/$opensearch_file" +if [ $BUNDLED_DASHBOARDS == "false" ]; then opensearch_msg="\"status\":\"green\""; else opensearch_msg="\"status\":\"yellow\""; fi +dashboards_path="$dir/$dashboards_file" +dashboards_msg="\"state\":\"green\",\"title\":\"Green\",\"nickname\":\"Looking good\",\"icon\":\"success\"" +if [ $BUNDLED_DASHBOARDS == "false" ]; then opensearch_url="http://localhost:9200/_cluster/health"; else opensearch_url="https://localhost:9200/_cluster/health"; fi +if [ $BUNDLED_DASHBOARDS == "false" ]; then opensearch_args=""; else opensearch_args="-u admin:admin --insecure"; fi +dashboards_url="http://localhost:5601/api/status" + +# define test groups and suites +test_group_1="check_loaded_data,check_timeline" +test_group_2="check_advanced_settings,check_loaded_data,check_timeline" +test_group_3="check_advanced_settings,check_filter_and_query,check_loaded_data,check_timeline" +test_group_4="check_advanced_settings,check_default_page,check_filter_and_query,check_loaded_data,check_timeline" + +declare -A test_suites +test_suites=( + ["odfe-0.10.0"]=$test_group_1 + ["odfe-1.0.2"]=$test_group_2 + ["odfe-1.1.0"]=$test_group_2 + ["odfe-1.2.1"]=$test_group_2 + ["odfe-1.3.0"]=$test_group_2 + ["odfe-1.4.0"]=$test_group_3 + ["odfe-1.7.0"]=$test_group_3 + ["odfe-1.8.0"]=$test_group_3 + ["odfe-1.9.0"]=$test_group_3 + ["odfe-1.11.0"]=$test_group_3 + ["odfe-1.13.2"]=$test_group_4 + ["osd-1.0.0"]=$test_group_4 + ["osd-1.1.0"]=$test_group_4 +) + +# remove the running opensearch process +function clean { + echo "close running opensearcn" + process=($(ps -ef | grep "Dopensearch" | awk '{print $2}')) + kill ${process[0]} + echo "close any usage on port 5601" + process=($(lsof -i -P -n | grep 5601 | awk '{print $2}')) + kill ${process[0]} +} + +# this is a support funtion to print out a text file line by line +function print_txt { + while IFS= read -r line; do + echo "text read from $1: $line" + done < $1 +} + +# this function is used to check the opensearch or dashboards running status +# $1 is the path to the tmp file which saves the running status +# $2 is the error msg to check +# $3 is the url to curl +# $4 contains arguments that need to be passed to the curl command +function check_status { + while [ ! -f $1 ] || ! grep -q "$2" $1; do + if [ -f $1 ]; then rm $1; fi + curl $3 $4 > $1 || true + done + rm $1 +} + +# this function sets up the cypress env +# it first clones the opensearch-dashboards-functional-test library +# then it removes the tests into the cypress integration folder +# and copies the backwards compatibility tests into the folder +function setup_cypress { + git clone https://github.com/opensearch-project/opensearch-dashboards-functional-test "$test_dir" + rm -rf "$test_dir/cypress/integration" + cp -r "$cwd/cypress/integration" "$test_dir/cypress" + cd "$test_dir" + npm install +} + +# this function copies the tested data for the required version to the opensearch data folder +# $1 is the required version +function upload_data { + rm -rf "$opensearch_dir/data" + cd $opensearch_dir + cp "$cwd/cypress/test-data/$dashboards_type/$1.tar.gz" . + tar -xvf "$opensearch_dir/$1.tar.gz" >> /dev/null 2>&1 + rm "$1.tar.gz" + echo "ready to test" +} + +# this function starts opensearch +function run_opensearch { + cd "$opensearch_dir" + ./bin/opensearch +} + +# this function starts dashboards +function run_dashboards { + cd "$dashboards_dir" + ./bin/opensearch-dashboards +} + +# this function checks the opensearch running status +# it calls check_status and passes the opensearch tmp file path, error msg, url, and arguments +# if success, the while loop in the check_status will end and it prints out "opensearch is up" +function check_opensearch_status { + cd "$dir" + check_status $opensearch_path "$opensearch_msg" $opensearch_url "$opensearch_args" >> /dev/null 2>&1 + echo "opensearch is up" +} + +# this function checks the dashboards running status +# it calls check_status and passes the dashboards tmp file path, error msg, url, and arguments +# if success, the while loop in the check_status will end and it prints out "dashboards is up" +function check_dashboards_status { + cd "$dir" + check_status $dashboards_path "$dashboards_msg" $dashboards_url "" >> /dev/null 2>&1 + echo "dashboards is up" +} + +# this function will run backwards compatibility test using cypress for the required version +# $1 is the requested version +function run_bwc { + cd "$test_dir" + IFS=',' read -r -a tests <<< "${test_suites[$1]}" + for test in "${tests[@]}" + do + npx cypress run --spec "$cwd/bwc-tmp/test/cypress/integration/$dashboards_type/$test.js" || echo "backwards compatibility tests have issue" + done +} + +# setup the cypress test env +echo "[ setup the cypress test env ]" +setup_cypress +echo "cypress is ready" + +# for each required testing version, do the following +# first run opensearch and check the status +# second run dashboards and check the status +# run the backwards compatibility tests +for i in ${!test_array[@]}; +do + version=${test_array[$i]} + # setup the opensearch env + # copy and unzip data in the opensearch data folder + echo "[ set up the opensearch env for $version ]" + upload_data $version + + echo "[ start opensearch and wait ]" + run_opensearch >> /dev/null 2>&1 & + + echo "check the opensearch status" + check_opensearch_status + + echo "[ start dashboards and wait ]" + run_dashboards >> /dev/null 2>&1 & + + echo "check the dashboards status" + check_dashboards_status + + echo "[ run the backwards compatibility tests for $version ]" + run_bwc $version + + # kill the running opensearch process + clean +done + +rm -rf "$dir" \ No newline at end of file