forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bash scripts for MVP validation tests (#482)
* Add MVP validation tests bash scripts * Add validations for generated index-patterns * Update scripts to support debian ARM * Update validations scripts to be able to use the generated package name * Add argument to define certificates path * Update OS detection on scripts * Add dependencies validations * Add usage description to each script and a simple README * Add dependencies validations * Fix typos * Apply SpellCheck linter recommendations * Skip checks related to SC2181 where the fix is not applicable * Remove unnecesary double quotes from certificates generation script * Update variable quoting * Provision VMs with dependencies for the testing scripts Copy the scripts to the VMs auto. * Merge scripts 00 and 01 making it easier to get the package from GHA artifacts Update the tests scripts README * Optimize test scripts * Add sleep after clister initialization * Update README and improve scripts output logs Fix script 00 to work on any node Remove unwanted outputs from executed commands * Update execution guide on README * Add conditional to remove certs directory if already exists Update default IP detection * Add sleep to avoid requesting to the API before cluster is initialized * Add index force merge for the command_manager plugin index * Avoid errors due to race conditions --------- Co-authored-by: Álex Ruiz <[email protected]>
- Loading branch information
Showing
12 changed files
with
1,082 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/bin/bash | ||
|
||
# Prompt the user for GitHub Token and artifact details securely | ||
if [ -z "$GITHUB_TOKEN" ]; then | ||
read -rsp 'Enter GitHub Token: ' GITHUB_TOKEN | ||
echo "" | ||
fi | ||
export GITHUB_TOKEN | ||
|
||
if [ -z "$RUN_ID" ]; then | ||
read -rp 'Enter Action Run ID: ' RUN_ID | ||
fi | ||
export RUN_ID | ||
|
||
if [ -z "$ARTIFACT_NAME" ]; then | ||
read -rp 'Enter Artifact Name: ' ARTIFACT_NAME | ||
fi | ||
export ARTIFACT_NAME | ||
|
||
# Define environment variables with default values if not provided | ||
read -rp "Enter current node name (default: 'node-1'): " NODE_NAME | ||
export NODE_NAME=${NODE_NAME:-"node-1"} | ||
|
||
IP_ADDRESS=$(ip addr show eth1 2>/dev/null | grep 'inet ' | awk '{print $2}' | cut -d/ -f1) | ||
if [ -z "$IP_ADDRESS" ]; then | ||
IP_ADDRESS="127.0.0.1" | ||
fi | ||
read -rp "Enter IP of current node (default: '$IP_ADDRESS'): " NODE_IP | ||
export NODE_IP=${NODE_IP:-$IP_ADDRESS} | ||
|
||
export CERTS_PATH=${CERTS_PATH:-"/home/vagrant/wazuh-certificates.tar"} | ||
|
||
# Optional variables for Node 2 | ||
read -rp 'Enter secondary Node name (optional): ' NODE_2 | ||
read -rp 'Enter IP of secondary Node (optional): ' IP_NODE_2 | ||
|
||
# Logging function with timestamps | ||
log() { | ||
echo "$(date +'%Y-%m-%d %H:%M:%S') - $1" | ||
} | ||
|
||
# Function to run a command and check for errors | ||
run_command() { | ||
local cmd=$1 | ||
log "Executing: $cmd" | ||
if ! eval "$cmd"; then | ||
log "Error executing: $cmd" | ||
exit 1 | ||
else | ||
log "Successfully executed: $cmd" | ||
fi | ||
} | ||
|
||
# Main execution | ||
log "Starting the script execution" | ||
|
||
run_command "bash 01_download_and_install_package.sh -id $RUN_ID -n $ARTIFACT_NAME" | ||
|
||
# Apply certificates | ||
if [ -n "$NODE_2" ] && [ -n "$IP_NODE_2" ]; then | ||
run_command "sudo bash 02_apply_certificates.sh -p $CERTS_PATH -n $NODE_NAME -nip $NODE_IP -s $NODE_2 -sip $IP_NODE_2" | ||
else | ||
run_command "sudo bash 02_apply_certificates.sh -p $CERTS_PATH -n $NODE_NAME -nip $NODE_IP" | ||
fi | ||
|
||
# Start indexer service | ||
run_command "sudo bash 03_manage_indexer_service.sh -a start" | ||
|
||
# Initialize cluster (assumes this step doesn't depend on Node 2 presence) | ||
run_command "sudo bash 04_initialize_cluster.sh" | ||
sleep 10 | ||
|
||
# Validate installed plugins | ||
if [ -n "$NODE_2" ]; then | ||
run_command "bash 05_validate_installed_plugins.sh -n $NODE_NAME -n $NODE_2" | ||
else | ||
run_command "bash 05_validate_installed_plugins.sh -n $NODE_NAME" | ||
fi | ||
|
||
# Validate setup and command manager | ||
run_command "bash 06_validate_setup.sh" | ||
run_command "bash 07_validate_command_manager.sh" | ||
|
||
# Uninstall indexer | ||
log "Running 08_uninstall_indexer.sh" | ||
run_command "sudo bash 08_uninstall_indexer.sh" | ||
|
||
log "All tasks completed successfully." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
#!/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. | ||
|
||
# Tool dependencies | ||
DEPENDENCIES=(curl jq unzip) | ||
# Default package revision | ||
PKG_REVISION="0" | ||
# Wazuh indexer repository | ||
REPO="wazuh/wazuh-indexer" | ||
|
||
# Function to display usage help | ||
usage() { | ||
echo "Usage: $0 --run-id <RUN_ID> [-v <PKG_VERSION>] [-r <PKG_REVISION>] [-n <PKG_NAME>]" | ||
echo | ||
echo "Parameters:" | ||
echo " -id, --run-id The GHA workflow execution ID." | ||
echo " -v, --version (Optional) The version of the wazuh-indexer package." | ||
echo " -r, --revision (Optional) The revision of the package. Defaults to '0' if not provided." | ||
echo " -n, --name (Optional) The package name. If not provided, it will be configured based on version and revision." | ||
echo | ||
echo "Please ensure you have the GITHUB_TOKEN environment variable set to access the GitHub repository, and all the dependencies installed: " "${DEPENDENCIES[@]}" | ||
exit 1 | ||
} | ||
|
||
# Parse named parameters | ||
while [[ "$#" -gt 0 ]]; do | ||
case $1 in | ||
--artifact-id|-id) RUN_ID="$2"; shift ;; | ||
--version|-v) PKG_VERSION="$2"; shift ;; | ||
--revision|-r) PKG_REVISION="$2"; shift ;; | ||
--name|-n) PKG_NAME="$2"; shift ;; | ||
-h|--help) usage ;; | ||
*) echo "Unknown parameter passed: $1"; usage ;; | ||
esac | ||
shift | ||
done | ||
|
||
# Validate all dependencies are installed | ||
for dep in "${DEPENDENCIES[@]}" | ||
do | ||
if ! command -v "${dep}" &> /dev/null | ||
then | ||
echo "Error: Dependency '$dep' is not installed. Please install $dep and try again." >&2 | ||
exit 1 | ||
fi | ||
done | ||
|
||
# Check if RUN_ID is provided | ||
if [ -z "$RUN_ID" ]; then | ||
echo "Error: RUN_ID is required." | ||
usage | ||
fi | ||
|
||
# Validate GITHUB_TOKEN environment variable | ||
if [ -z "$GITHUB_TOKEN" ]; then | ||
echo "Please ensure you have the GITHUB_TOKEN environment variable set to access the GitHub repository." | ||
exit 1 | ||
fi | ||
|
||
# Ensure either PKG_NAME or both PKG_VERSION and PKG_REVISION are provided | ||
if [ -z "$PKG_NAME" ] && { [ -z "$PKG_VERSION" ] || [ -z "$PKG_REVISION" ]; }; then | ||
echo "Error: Either a package name (--name) or both a version (--version) and revision (--revision) must be provided." | ||
usage | ||
fi | ||
|
||
# Detect OS and architecture | ||
if [ -f /etc/os-release ]; then | ||
. /etc/os-release | ||
OS=$(echo "$NAME" | tr '[:upper:]' '[:lower:]') | ||
else | ||
echo "Unsupported OS." | ||
exit 1 | ||
fi | ||
|
||
# Determine package type if PKG_NAME is not provided | ||
ARCH=$(uname -m) | ||
case "$OS" in | ||
*ubuntu* | *debian*) | ||
PKG_FORMAT="deb" | ||
if [ -z "$PKG_NAME" ]; then | ||
[ "$ARCH" == "x86_64" ] && ARCH="amd64" | ||
[ "$ARCH" == "aarch64" ] && ARCH="arm64" | ||
PKG_NAME="wazuh-indexer_${PKG_VERSION}-${PKG_REVISION}_${ARCH}.${PKG_FORMAT}" | ||
fi | ||
;; | ||
*centos* | *fedora* | *rhel* | *"red hat"* | *alma*) | ||
PKG_FORMAT="rpm" | ||
if [ -z "$PKG_NAME" ]; then | ||
PKG_NAME="wazuh-indexer-${PKG_VERSION}-${PKG_REVISION}.${ARCH}.${PKG_FORMAT}" | ||
fi | ||
;; | ||
*) | ||
echo "Unsupported OS." | ||
exit 1 | ||
;; | ||
esac | ||
|
||
# Check if the package is already present | ||
if [ -f "$PKG_NAME" ]; then | ||
echo "Package $PKG_NAME found locally. Reusing existing package." | ||
else | ||
# Fetch the list of artifacts | ||
echo "Fetching artifacts list..." | ||
RUN_URL="https://api.github.com/repos/${REPO}/actions/artifacts" | ||
RESPONSE=$(curl -s -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $GITHUB_TOKEN" -H "X-GitHub-Api-Version: 2022-11-28" "$RUN_URL?name=$PKG_NAME") | ||
|
||
# Check if the curl command was successful | ||
if [ $? -ne 0 ]; then | ||
echo "Error: Failed to fetch artifacts." | ||
exit 1 | ||
fi | ||
|
||
# Check if the artifact from the specified workflow run ID exists | ||
echo "Checking ${PKG_NAME} package is generated for workflow run ${RUN_ID}" | ||
ARTIFACT=$(echo "$RESPONSE" | jq -e ".artifacts[] | select(.workflow_run.id == $RUN_ID)") | ||
|
||
if [ -z "$ARTIFACT" ]; then | ||
echo "Error: Wazuh indexer package not found." | ||
exit 1 | ||
fi | ||
|
||
ARTIFACT_ID=$(echo "$ARTIFACT" | jq -r '.id') | ||
echo "Wazuh indexer artifact detected. Artifact ID: $ARTIFACT_ID" | ||
|
||
# Download the package | ||
ARTIFACT_URL="https://api.github.com/repos/${REPO}/actions/artifacts/${ARTIFACT_ID}/zip" | ||
echo "Downloading wazuh-indexer package from GitHub artifactory..." | ||
echo "(It could take a couple of minutes)" | ||
|
||
if ! curl -L -H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: Bearer $GITHUB_TOKEN" \ | ||
-H "X-GitHub-Api-Version: 2022-11-28" \ | ||
"$ARTIFACT_URL" -o package.zip > /dev/null 2>&1; then | ||
echo "Error downloading package." | ||
exit 1 | ||
fi | ||
echo "Package downloaded successfully" | ||
|
||
# Unzip the package | ||
echo "Decompressing wazuh-indexer package..." | ||
unzip ./package.zip | ||
rm package.zip | ||
|
||
# shellcheck disable=SC2181 | ||
if [ $? -ne 0 ]; then | ||
echo "Error unzipping package." | ||
exit 1 | ||
fi | ||
echo "Package decompressed" | ||
fi | ||
|
||
# Install the package | ||
echo "Installing wazuh-indexer package..." | ||
case "$PKG_FORMAT" in | ||
"deb") | ||
sudo dpkg -i "$PKG_NAME" > /dev/null 2>&1 | ||
;; | ||
"rpm") | ||
sudo rpm -i "$PKG_NAME" > /dev/null 2>&1 | ||
;; | ||
esac | ||
|
||
# shellcheck disable=SC2181 | ||
if [ $? -ne 0 ]; then | ||
echo "Error installing package." | ||
exit 1 | ||
fi | ||
|
||
echo "Package installed successfully." |
Oops, something went wrong.