From eada2456afdf5e248c14a2727149dfa8f9248cc8 Mon Sep 17 00:00:00 2001 From: Manasvini B Suryanarayana Date: Wed, 3 Apr 2024 23:29:18 +0000 Subject: [PATCH] Add integtest.sh script for build to trigger Dahsboards cypress tests Signed-off-by: Manasvini B Suryanarayana --- .../workflows/release_cypress_workflow.yml | 4 +- integtest.sh | 135 ++++++++++++++++++ scripts/cypress_tests.sh | 5 +- 3 files changed, 142 insertions(+), 2 deletions(-) create mode 100755 integtest.sh diff --git a/.github/workflows/release_cypress_workflow.yml b/.github/workflows/release_cypress_workflow.yml index f58757b23f9f..656b55bf67c4 100644 --- a/.github/workflows/release_cypress_workflow.yml +++ b/.github/workflows/release_cypress_workflow.yml @@ -2,6 +2,8 @@ name: Orchestrator cypress workflow run-name: release_cypress_workflow ${{ inputs.UNIQUE_ID != '' && inputs.UNIQUE_ID || '' }} # Unique id number appended to the workflow run-name to reference the run within the orchestrator. # Trigger on dispatch event sent from FT repo orchestrator on: + push: + branches: [ '**' ] workflow_dispatch: inputs: test_repo: @@ -47,7 +49,7 @@ env: DASHBOARDS: ${{ inputs.OSD_URL != '' && inputs.OSD_URL || 'https://ci.opensearch.org/ci/dbc/distribution-build-opensearch-dashboards/$VERSION/latest/linux/x64/tar/dist/opensearch-dashboards/opensearch-dashboards-$VERSION-linux-x64.tar.gz' }} OPENSEARCH_DIR: 'cypress/opensearch' DASHBOARDS_DIR: 'cypress/opensearch-dashboards' - SECURITY_ENABLED: ${{ inputs.SECURITY_ENABLED != '' && inputs.SECURITY_ENABLED || 'false' }} + SECURITY_ENABLED: ${{ inputs.SECURITY_ENABLED != '' && inputs.SECURITY_ENABLED || 'true' }} jobs: Get-CI-Image-Tag: diff --git a/integtest.sh b/integtest.sh new file mode 100755 index 000000000000..3ccb976ab1b5 --- /dev/null +++ b/integtest.sh @@ -0,0 +1,135 @@ +#!/bin/bash + +set -e + +OSD_TEST_PATH='cypress/integration/core_opensearch_dashboards' +OSD_BUILD_MANIFEST='../local-test-cluster/opensearch-dashboards-*/manifest.yml' + +echo -e "*** Execute integtest.sh script ****" + +function usage() { + echo "" + echo "This script is used to run integration tests for OpenSearch Dashboards cypress tests on a remote OpenSearch/Dashboards cluster on a Build CI." + echo "--------------------------------------------------------------------------" + echo "Usage: $0 [args]" + echo "" + echo "Required arguments:" + echo "None" + echo "" + echo "Optional arguments:" + echo -e "-b 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 "-s SECURITY_ENABLED\t(true | false), defaults to false. Specify the OpenSearch/Dashboards have security enabled or not." + echo -e "-c CREDENTIAL\t(usename:password), no defaults, effective when SECURITY_ENABLED=true." + echo -e "-t TEST_COMPONENTS\t(OpenSearch-Dashboards reportsDashboards etc.), optional, specify test components, separate with space, else test everything." + echo -e "-v VERSION\t, no defaults, indicates the OpenSearch version to test." + echo -e "-o OPTION\t, no defaults, determine the TEST_TYPE value among(default, manifest) in test_finder.sh, optional." + echo -e "-h\tPrint this message." + echo "--------------------------------------------------------------------------" +} + +while getopts ":hb:p:s:c:t:v:o:" arg; do + case $arg in + h) + usage + exit 1 + ;; + b) + BIND_ADDRESS=$OPTARG + ;; + p) + BIND_PORT=$OPTARG + ;; + s) + SECURITY_ENABLED=$OPTARG + ;; + c) + CREDENTIAL=$OPTARG + ;; + t) + TEST_COMPONENTS=$OPTARG + ;; + v) + VERSION=$OPTARG + ;; + o) + OPTION=$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 [ -z "$SECURITY_ENABLED" ] +then + SECURITY_ENABLED="true" +fi + +if [ -z "$CREDENTIAL" ] +then + # Starting in 2.12.0, security demo configuration script requires an initial admin password + CREDENTIAL="admin:myStrongPassword123!" +fi + +USERNAME=`echo $CREDENTIAL | awk -F ':' '{print $1}'` +PASSWORD=`echo $CREDENTIAL | awk -F ':' '{print $2}'` + +# Set environment variable +export OPENSEARCH_INITIAL_ADMIN_PASSWORD="$PASSWORD" + +# User can send custom browser path through env variable +if [ -z "$BROWSER_PATH" ] +then + # chromium@1108766 is version 112 with revision r1108766 + # Please keep this version until cypress upgrade or test will freeze: https://github.com/opensearch-project/opensearch-build/issues/4241 + # BROWSER_PATH=`download_chromium | head -n 1 | cut -d ' ' -f1` + BROWSER_PATH=$CYPRESS_BROWSER +fi + + +# npm install + +TEST_TYPE=$OPTION +TEST_FILES_EXT_LOCAL="**/*.js" +TEST_FILES="$OSD_TEST_PATH/$TEST_FILES_EXT_LOCAL" +echo -e "Test Files List:" +echo $TEST_FILES | tr ',' '\n' +echo "BROWSER_PATH: $BROWSER_PATH" + +if [ -z $TEST_TYPE ]; then + [ -f $OSD_BUILD_MANIFEST ] && TEST_TYPE="manifest" || TEST_TYPE="default" +fi + +## WARNING: THIS LOGIC NEEDS TO BE THE LAST IN THIS FILE! ## +# Cypress returns back the test failure count in the error code +# The CI outputs the error code as test failure count. +# +# We need to ensure the cypress tests are the last execute process to +# the error code gets passed to the CI. + +if [ "$SECURITY_ENABLED" = "true" ] +then + echo "run security enabled tests" + yarn cypress:run-with-security --browser "$BROWSER_PATH" --spec "$TEST_FILES" +else + echo "run security disabled tests" + yarn cypress:run-without-security --browser "$BROWSER_PATH" --spec "$TEST_FILES" +fi diff --git a/scripts/cypress_tests.sh b/scripts/cypress_tests.sh index 93e58664f438..d72c353ed958 100644 --- a/scripts/cypress_tests.sh +++ b/scripts/cypress_tests.sh @@ -82,7 +82,10 @@ function run_dashboards_cypress_tests() { check_status $DASHBOARDS_URL $DASHBOARDS_MSG # Run cypress tests cd "$CWD"/osd - run_cypress + ls -l + ./integtest.sh + # run_cypress + } function run_cypress() {