From 0a28edbe3b5d04f3cee437af678448bb76cb99dd Mon Sep 17 00:00:00 2001 From: sourabh_sourabh Date: Tue, 3 Jun 2025 15:16:31 +0100 Subject: [PATCH] Refactor the container startup process - Echo build information of DMI container before proceeding. - This enhances script efficiency and reduces unnecessary output, improving readability and maintainability. Issue-ID: 2690 Change-Id: I3bda6433bd2126e180017db7d349fa1eeb33526a Signed-off-by: sourabh_sourabh --- k6-tests/setup.sh | 57 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/k6-tests/setup.sh b/k6-tests/setup.sh index 3d486a92c4..6a233ce1f2 100755 --- a/k6-tests/setup.sh +++ b/k6-tests/setup.sh @@ -16,21 +16,46 @@ # testProfile=$1 -echo "Spinning off the CPS and NCMP containers for $testProfile testing..." - ENV_FILE="../docker-compose/env/${testProfile}.env" -docker-compose \ - --file "../docker-compose/cps-base.yml" \ - --env-file "$ENV_FILE" \ - --project-name "$testProfile" \ - up --quiet-pull --detach --wait || exit 1 - -if [[ "$testProfile" == "kpi" ]]; then - ACTUATOR_PORT=8883 -elif [[ "$testProfile" == "endurance" ]]; then - ACTUATOR_PORT=8884 -fi - -echo "Build information:" -curl --silent --show-error http://localhost:$ACTUATOR_PORT/actuator/info +COMPOSE_FILE="../docker-compose/cps-base.yml" + +# Define a function to encapsulate docker-compose command +compose() { + docker-compose \ + --file "$COMPOSE_FILE" \ + --env-file "$ENV_FILE" \ + --project-name "$testProfile" "$@" +} + +# Start the containers echo +echo "Spinning off the following containers for '$testProfile'..." +echo +compose up --quiet-pull --detach --wait || { echo "Failed to start containers."; exit 1; } + +# Define port mappings based on the test profile +declare -A CPS_PORTS=( ["kpi"]=8883 ["endurance"]=8884 ) +declare -A DMI_DEMO_STUB_PORTS=( ["kpi"]=8784 ["endurance"]=8787 ) + +CPS_ACTUATOR_PORT="${CPS_PORTS[$testProfile]}" +DMI_DEMO_STUB_ACTUATOR_PORT="${DMI_DEMO_STUB_PORTS[$testProfile]}" + +# Function to fetch and display build information +fetch_build_info() { + local service_name="$1" + local port="$2" + local url="http://localhost:${port}/actuator/info" + + echo -e "\n${service_name} Build Information:" + if curl --silent --show-error "$url"; then + echo + else + echo "Error: Unable to retrieve ${service_name} build information from ${url}" + exit 1 + fi +} + +# Fetch and display build information for CPS and DMI +fetch_build_info "CPS and NCMP" "$CPS_ACTUATOR_PORT" +fetch_build_info "DMI" "$DMI_DEMO_STUB_ACTUATOR_PORT" +echo \ No newline at end of file -- 2.16.6