Skip to content

Commit 4703c1c

Browse files
Merge pull request #13847 from rabbitmq/mergify/bp/v4.1.x/pr-13843
Launch another rabbitmq server from a Selenium test suite (backport #13843)
2 parents fc350e4 + 01d520f commit 4703c1c

File tree

14 files changed

+267
-34
lines changed

14 files changed

+267
-34
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
6+
init_other_rabbitmq() {
7+
RABBITMQ_CONFIG_DIR=${TEST_CONFIG_DIR}
8+
RABBITMQ_DOCKER_IMAGE=${RABBITMQ_DOCKER_IMAGE:-rabbitmq}
9+
OTHER_RABBITMQ_HOSTNAME=${OTHER_RABBITMQ_HOSTNAME:-other-rabbitmq}
10+
11+
print "> RABBITMQ_CONFIG_DIR: ${RABBITMQ_CONFIG_DIR}"
12+
print "> RABBITMQ_DOCKER_IMAGE: ${RABBITMQ_DOCKER_IMAGE}"
13+
print "> OTHER_RABBITMQ_HOSTNAME: ${OTHER_RABBITMQ_HOSTNAME}"
14+
15+
[[ -z "${OAUTH_SERVER_CONFIG_BASEDIR}" ]] || print "> OAUTH_SERVER_CONFIG_BASEDIR: ${OAUTH_SERVER_CONFIG_BASEDIR}"
16+
[[ -z "${OAUTH_SERVER_CONFIG_DIR}" ]] || print "> OAUTH_SERVER_CONFIG_DIR: ${OAUTH_SERVER_CONFIG_DIR}"
17+
18+
if [[ ! -d "${RABBITMQ_CONFIG_DIR}/certs" ]]; then
19+
mkdir ${RABBITMQ_CONFIG_DIR}/certs
20+
fi
21+
generate-ca-server-client-kpi ${OTHER_RABBITMQ_HOSTNAME} $RABBITMQ_CONFIG_DIR/certs
22+
generate-server-keystore-if-required ${OTHER_RABBITMQ_HOSTNAME} $RABBITMQ_CONFIG_DIR/certs
23+
generate-client-keystore-if-required ${OTHER_RABBITMQ_HOSTNAME} $RABBITMQ_CONFIG_DIR/certs
24+
generate-truststore-if-required ${OTHER_RABBITMQ_HOSTNAME} $RABBITMQ_CONFIG_DIR/certs
25+
}
26+
27+
start_other_rabbitmq() {
28+
if [[ "$PROFILES_FOR_OTHER" == *"docker"* ]]; then
29+
start_docker_other_rabbitmq
30+
else
31+
start_local_rabbitmq
32+
fi
33+
}
34+
stop_other_rabbitmq() {
35+
if [[ "$PROFILES_FOR_OTHER" == *"docker"* ]]; then
36+
kill_container_if_exist "$component"
37+
else
38+
stop_local_rabbitmq
39+
fi
40+
}
41+
42+
save_logs_other_rabbitmq() {
43+
if [[ "$PROFILES_FOR_OTHER" == *"docker"* ]]; then
44+
if [[ "$PROFILES_FOR_OTHER" == *"cluster"* ]]; then
45+
docker compose -f $CONF_DIR/rabbitmq/other-compose.yml logs > $LOGS/other-rabbitmq.log
46+
else
47+
save_container_logs "other-rabbitmq"
48+
fi
49+
fi
50+
}
51+
stop_local_other_rabbitmq() {
52+
RABBITMQ_SERVER_ROOT=$(realpath ../)
53+
gmake --directory=${RABBITMQ_SERVER_ROOT} stop-node
54+
}
55+
56+
start_local_other_rabbitmq() {
57+
begin "Starting ${OTHER_RABBITMQ_HOSTNAME} rabbitmq ..."
58+
59+
init_other_rabbitmq
60+
61+
RABBITMQ_SERVER_ROOT=$(realpath ../)
62+
63+
MOUNT_RABBITMQ_CONF="/etc/rabbitmq/rabbitmq.conf"
64+
MOUNT_ADVANCED_CONFIG="/etc/rabbitmq/advanced.config"
65+
66+
RABBITMQ_TEST_DIR="${RABBITMQ_CONFIG_DIR}"
67+
68+
${BIN_DIR}/gen-rabbitmq-conf "${PROFILES_FOR_OTHER}" ${RABBITMQ_CONFIG_DIR} $OTHER_ENV_FILE /tmp/other$MOUNT_RABBITMQ_CONF
69+
70+
print "> EFFECTIVE RABBITMQ_CONFIG_FILE: /tmp/other$MOUNT_RABBITMQ_CONF"
71+
cp ${RABBITMQ_CONFIG_DIR}/enabled_plugins /tmp/other/etc/rabbitmq/
72+
RABBITMQ_ENABLED_PLUGINS=`cat /tmp/other/etc/rabbitmq/enabled_plugins | tr -d " \t\n\r" | awk -F'[][]' '{print $2}'`
73+
print "> EFFECTIVE PLUGINS: $RABBITMQ_ENABLED_PLUGINS"
74+
75+
${BIN_DIR}/gen-advanced-config "${PROFILES_FOR_OTHER}" ${RABBITMQ_CONFIG_DIR} $OTHER_ENV_FILE /tmp/other$MOUNT_ADVANCED_CONFIG
76+
RESULT=$?
77+
if [ $RESULT -eq 0 ]; then
78+
print "> EFFECTIVE RABBITMQ_CONFIG_FILE: /tmp/other$MOUNT_ADVANCED_CONFIG"
79+
gmake --directory=${RABBITMQ_SERVER_ROOT} \
80+
RABBITMQ_NODENAME=${OTHER_RABBITMQ_NODENAME} \
81+
RABBITMQ_DIST_PORT=7001 \
82+
RABBITMQ_ENABLED_PLUGINS="$RABBITMQ_ENABLED_PLUGINS" \
83+
RABBITMQ_CONFIG_FILE=/tmp/other$MOUNT_RABBITMQ_CONF \
84+
RABBITMQ_ADVANCED_CONFIG_FILE=/tmp/other$MOUNT_ADVANCED_CONFIG run-broker
85+
else
86+
gmake --directory=${RABBITMQ_SERVER_ROOT} \
87+
RABBITMQ_NODENAME=${OTHER_RABBITMQ_NODENAME} \
88+
RABBITMQ_DIST_PORT=7001 \
89+
RABBITMQ_ENABLED_PLUGINS="$RABBITMQ_ENABLED_PLUGINS" \
90+
RABBITMQ_CONFIG_FILE=/tmp/other$MOUNT_RABBITMQ_CONF run-broker
91+
fi
92+
print "> RABBITMQ_TEST_DIR: ${RABBITMQ_CONFIG_DIR}"
93+
94+
95+
}
96+
start_docker_other_rabbitmq() {
97+
begin "Starting other-rabbitmq in docker ..."
98+
99+
init_other_rabbitmq
100+
kill_container_if_exist other_rabbitmq
101+
102+
mkdir -pv $CONF_DIR/other-rabbitmq/conf.d/
103+
104+
RABBITMQ_TEST_DIR="/var/rabbitmq"
105+
${BIN_DIR}/gen-rabbitmq-conf "${PROFILES_FOR_OTHER}" ${RABBITMQ_CONFIG_DIR} $OTHER_ENV_FILE $CONF_DIR/other-rabbitmq/rabbitmq.conf
106+
print "> EFFECTIVE RABBITMQ_CONFIG_FILE: $CONF_DIR/other-rabbitmq/rabbitmq.conf"
107+
${BIN_DIR}/gen-advanced-config "${PROFILES_FOR_OTHER}" ${RABBITMQ_CONFIG_DIR} $OTHER_ENV_FILE $CONF_DIR/other-rabbitmq/advanced.config
108+
RESULT=$?
109+
if [ $RESULT -eq 0 ]; then
110+
if [ -s $RESULT ]; then
111+
print "> EFFECTIVE ADVANCED_CONFIG_FILE: $CONF_DIR/other-rabbitmq/advanced.config"
112+
else
113+
rm $CONF_DIR/rabbitmq/advanced.config
114+
fi
115+
fi
116+
if [ -f ${RABBITMQ_CONFIG_DIR}/logging.conf ]; then
117+
cp ${RABBITMQ_CONFIG_DIR}/logging.conf $CONF_DIR/other-rabbitmq/conf.d/
118+
fi
119+
if [ -f ${RABBITMQ_CONFIG_DIR}/enabled_plugins ]; then
120+
cp ${RABBITMQ_CONFIG_DIR}/enabled_plugins $CONF_DIR/other-rabbitmq
121+
fi
122+
if [ -d "${RABBITMQ_CONFIG_DIR}/certs" ]; then
123+
cp -r ${RABBITMQ_CONFIG_DIR}/certs $CONF_DIR/other-rabbitmq
124+
fi
125+
if [ -d ${RABBITMQ_CONFIG_DIR}/imports ]; then
126+
cp -r ${RABBITMQ_CONFIG_DIR}/imports $CONF_DIR/other-rabbitmq
127+
fi
128+
129+
print "> RABBITMQ_TEST_DIR: /var/rabbitmq"
130+
131+
docker run \
132+
--detach \
133+
--name ${OTHER_RABBITMQ_HOSTNAME} \
134+
--net ${DOCKER_NETWORK} \
135+
-p 5674:5672 \
136+
-p 5673:5671 \
137+
-p 15674:15672 \
138+
-p 15673:15671 \
139+
-v $CONF_DIR/other-rabbitmq/:/etc/rabbitmq \
140+
-v $CONF_DIR/other-rabbitmq/imports:/var/rabbitmq/imports \
141+
-v ${TEST_DIR}:/config \
142+
${RABBITMQ_DOCKER_IMAGE}
143+
144+
wait_for_message ${OTHER_RABBITMQ_HOSTNAME} "Server startup complete"
145+
end "RabbitMQ ${OTHER_RABBITMQ_HOSTNAME} ready"
146+
}

selenium/bin/components/rabbitmq

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,25 @@ start_local_rabbitmq() {
6666
MOUNT_RABBITMQ_CONF="/etc/rabbitmq/rabbitmq.conf"
6767
MOUNT_ADVANCED_CONFIG="/etc/rabbitmq/advanced.config"
6868

69-
RABBITMQ_TEST_DIR="${RABBITMQ_CONFIG_DIR}" ${BIN_DIR}/gen-rabbitmq-conf ${RABBITMQ_CONFIG_DIR} $ENV_FILE /tmp$MOUNT_RABBITMQ_CONF
69+
RABBITMQ_TEST_DIR="${RABBITMQ_CONFIG_DIR}" ${BIN_DIR}/gen-rabbitmq-conf "${PROFILES}" ${RABBITMQ_CONFIG_DIR} $ENV_FILE /tmp$MOUNT_RABBITMQ_CONF
7070

7171
print "> EFFECTIVE RABBITMQ_CONFIG_FILE: /tmp$MOUNT_RABBITMQ_CONF"
7272
cp ${RABBITMQ_CONFIG_DIR}/enabled_plugins /tmp/etc/rabbitmq/
7373
RABBITMQ_ENABLED_PLUGINS=`cat /tmp/etc/rabbitmq/enabled_plugins | tr -d " \t\n\r" | awk -F'[][]' '{print $2}'`
7474
print "> EFFECTIVE PLUGINS: $RABBITMQ_ENABLED_PLUGINS"
7575

76-
${BIN_DIR}/gen-advanced-config ${RABBITMQ_CONFIG_DIR} $ENV_FILE /tmp$MOUNT_ADVANCED_CONFIG
76+
${BIN_DIR}/gen-advanced-config "${PROFILES}" ${RABBITMQ_CONFIG_DIR} $ENV_FILE /tmp$MOUNT_ADVANCED_CONFIG
7777
RESULT=$?
7878
if [ $RESULT -eq 0 ]; then
7979
print "> EFFECTIVE RABBITMQ_CONFIG_FILE: /tmp$MOUNT_ADVANCED_CONFIG"
8080
gmake --directory=${RABBITMQ_SERVER_ROOT} \
81+
RABBITMQ_NODENAME="$RABBITMQ_NODENAME" \
8182
RABBITMQ_ENABLED_PLUGINS="$RABBITMQ_ENABLED_PLUGINS" \
8283
RABBITMQ_CONFIG_FILE=/tmp$MOUNT_RABBITMQ_CONF \
8384
RABBITMQ_ADVANCED_CONFIG_FILE=/tmp$MOUNT_ADVANCED_CONFIG run-broker
8485
else
8586
gmake --directory=${RABBITMQ_SERVER_ROOT} \
87+
RABBITMQ_NODENAME="$RABBITMQ_NODENAME" \
8688
RABBITMQ_ENABLED_PLUGINS="$RABBITMQ_ENABLED_PLUGINS" \
8789
RABBITMQ_CONFIG_FILE=/tmp$MOUNT_RABBITMQ_CONF run-broker
8890
fi
@@ -99,9 +101,10 @@ start_docker_cluster_rabbitmq() {
99101

100102
mkdir -pv $CONF_DIR/rabbitmq/conf.d/
101103

102-
RABBITMQ_TEST_DIR="/var/rabbitmq" ${BIN_DIR}/gen-rabbitmq-conf ${RABBITMQ_CONFIG_DIR} $ENV_FILE $CONF_DIR/rabbitmq/rabbitmq.conf
104+
RABBITMQ_TEST_DIR="/var/rabbitmq"
105+
${BIN_DIR}/gen-rabbitmq-conf "${PROFILES}" ${RABBITMQ_CONFIG_DIR} $ENV_FILE $CONF_DIR/rabbitmq/rabbitmq.conf
103106
print "> EFFECTIVE RABBITMQ_CONFIG_FILE: $CONF_DIR/rabbitmq/rabbitmq.conf"
104-
${BIN_DIR}/gen-advanced-config ${RABBITMQ_CONFIG_DIR} $ENV_FILE $CONF_DIR/rabbitmq/advanced.config
107+
${BIN_DIR}/gen-advanced-config "${PROFILES}" ${RABBITMQ_CONFIG_DIR} $ENV_FILE $CONF_DIR/rabbitmq/advanced.config
105108
RESULT=$?
106109
if [ $RESULT -eq 0 ]; then
107110
if [ -s $RESULT ]; then
@@ -150,9 +153,10 @@ start_docker_rabbitmq() {
150153

151154
mkdir -pv $CONF_DIR/rabbitmq/conf.d/
152155

153-
RABBITMQ_TEST_DIR="/var/rabbitmq" ${BIN_DIR}/gen-rabbitmq-conf ${RABBITMQ_CONFIG_DIR} $ENV_FILE $CONF_DIR/rabbitmq/rabbitmq.conf
156+
RABBITMQ_TEST_DIR="/var/rabbitmq"
157+
${BIN_DIR}/gen-rabbitmq-conf "${PROFILES}" ${RABBITMQ_CONFIG_DIR} $ENV_FILE $CONF_DIR/rabbitmq/rabbitmq.conf
154158
print "> EFFECTIVE RABBITMQ_CONFIG_FILE: $CONF_DIR/rabbitmq/rabbitmq.conf"
155-
${BIN_DIR}/gen-advanced-config ${RABBITMQ_CONFIG_DIR} $ENV_FILE $CONF_DIR/rabbitmq/advanced.config
159+
${BIN_DIR}/gen-advanced-config "${PROFILES}" ${RABBITMQ_CONFIG_DIR} $ENV_FILE $CONF_DIR/rabbitmq/advanced.config
156160
RESULT=$?
157161
if [ $RESULT -eq 0 ]; then
158162
if [ -s $RESULT ]; then

selenium/bin/find-template-files

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
#!/usr/bin/env bash
22

3-
TEST_PATH=${1:?"First parameter must be the test path"}
4-
TEMPLATE_FILE_PREFIX=${2:?"Second parameter must be the template file prefix"}
5-
TEMPLATE_FILE_SUFFIX=${3:-""}
3+
PROFILES=${1:?"First parameter must be a space-separated list of profiles"}
4+
TEST_PATH=${2:?"First parameter must be the test path"}
5+
TEMPLATE_FILE_PREFIX=${3:?"Second parameter must be the template file prefix"}
6+
TEMPLATE_FILE_SUFFIX=${4:-""}
67
TEST_PARENT_PATH="$(dirname "$TEST_PATH")"
78

9+
if [[ ! -z "${DEBUG}" ]]; then
10+
set -x
11+
fi
12+
813
find_templates_files() {
914
find_template_files_in $TEST_PARENT_PATH
1015
find_template_files_in $TEST_PATH

selenium/bin/gen-advanced-config

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
33

44
#set -x
55

6-
TEST_PATH=${1:?First parameter is the directory env and config files are relative to}
7-
ENV_FILE=${2:?Second parameter is a comma-separated list of .env file which has exported template variables}
8-
FINAL_CONFIG_FILE=${3:?Forth parameter is the name of the final config file. It is relative to where this script is run from}
6+
PROFILES=${1:?First parameter is a string of comma separated list of profiles}
7+
TEST_PATH=${2:?First parameter is the directory env and config files are relative to}
8+
ENV_FILE=${3:?Second parameter is a comma-separated list of .env file which has exported template variables}
9+
FINAL_CONFIG_FILE=${4:?Forth parameter is the name of the final config file. It is relative to where this script is run from}
910

1011
source $ENV_FILE
1112

@@ -15,7 +16,7 @@ mkdir -p $parentdir
1516
echo "" > $FINAL_CONFIG_FILE
1617

1718
FOUND_TEMPLATES_COUNT=0
18-
for f in $($SCRIPT/find-template-files $TEST_PATH "advanced" "config")
19+
for f in $($SCRIPT/find-template-files "${PROFILES}" $TEST_PATH "advanced" "config")
1920
do
2021
envsubst < $f >> $FINAL_CONFIG_FILE
2122
FOUND_TEMPLATES_COUNT+=1

selenium/bin/gen-env-file

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ fi
77

88

99
ENV_FILE="/tmp/rabbitmq/.env"
10-
FIND_PATH=$1
11-
ENV_FILE=$2
10+
PROFILES=$1
11+
FIND_PATH=$2
12+
ENV_FILE=$3
1213
FIND_PARENT_PATH="$(dirname "$FIND_PATH")"
1314

1415
generate_env_file() {
@@ -20,7 +21,7 @@ generate_env_file() {
2021
echo "export TEST_CONFIG_PATH=${FIND_PATH}" >> $ENV_FILE
2122

2223
declare -a FILE_ARRAY
23-
for f in $($SCRIPT/find-template-files $FIND_PATH "env")
24+
for f in $($SCRIPT/find-template-files "${PROFILES}" $FIND_PATH "env")
2425
do
2526
FILE_ARRAY+=($f)
2627
done

selenium/bin/gen-httpd-conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mkdir -p $parentdir
1414

1515
echo "" > $FINAL_CONFIG_FILE
1616

17-
for f in $($SCRIPT/find-template-files $TEST_PATH "httpd" "conf")
17+
for f in $($SCRIPT/find-template-files "${PROFILES}" $TEST_PATH "httpd" "conf")
1818
do
1919
envsubst < $f >> $FINAL_CONFIG_FILE
2020
done

selenium/bin/gen-json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
#set -x
6+
7+
JSON_FILE_PATH=${1:?First parameter is the directory env and config files are relative to}
8+
JSON_FILENAME=${2:?Second parameter is the json filename of the realm without extension}
9+
ENV_FILE=${3:?Second parameter is a comma-separated list of .env file which has exported template variables}
10+
FINAL_CONFIG_FILE=${4:?Forth parameter is the name of the final config file. It is relative to where this script is run from}
11+
12+
source $ENV_FILE
13+
14+
parentdir="$(dirname "$FINAL_CONFIG_FILE")"
15+
mkdir -p $parentdir
16+
17+
echo "" > $FINAL_CONFIG_FILE
18+
19+
for f in $($SCRIPT/find-template-files "${PROFILES}" $JSON_FILE_PATH $JSON_FILENAME "json")
20+
do
21+
envsubst < $f >> $FINAL_CONFIG_FILE
22+
done

selenium/bin/gen-keycloak-json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mkdir -p $parentdir
1616

1717
echo "" > $FINAL_CONFIG_FILE
1818

19-
for f in $($SCRIPT/find-template-files $KEYCLOAK_PATH $KEYCLOAK_FILENAME "json")
19+
for f in $($SCRIPT/find-template-files "${PROFILES}" $KEYCLOAK_PATH $KEYCLOAK_FILENAME "json")
2020
do
2121
envsubst < $f >> $FINAL_CONFIG_FILE
2222
done

selenium/bin/gen-rabbitmq-conf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
33

44
#set -x
55

6-
TEST_PATH=${1:?First parameter is the directory env and config files are relative to}
7-
ENV_FILE=${2:?Second parameter is a comma-separated list of .env file which has exported template variables}
8-
FINAL_CONFIG_FILE=${3:?Forth parameter is the name of the final config file. It is relative to where this script is run from}
6+
PROFILES=${1:?First parameter is a string with a comma-separated list of profiles}
7+
TEST_PATH=${2:?First parameter is the directory env and config files are relative to}
8+
ENV_FILE=${3:?Second parameter is a comma-separated list of .env file which has exported template variables}
9+
FINAL_CONFIG_FILE=${4:?Forth parameter is the name of the final config file. It is relative to where this script is run from}
910

1011
source $ENV_FILE
1112

@@ -14,7 +15,7 @@ mkdir -p $parentdir
1415

1516
echo "" > $FINAL_CONFIG_FILE
1617

17-
for f in $($SCRIPT/find-template-files $TEST_PATH "rabbitmq" "conf")
18+
for f in $($SCRIPT/find-template-files "${PROFILES}" $TEST_PATH "rabbitmq" "conf")
1819
do
1920
envsubst < $f >> $FINAL_CONFIG_FILE
2021
done

selenium/bin/gen-uaa-yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mkdir -p $parentdir
1414

1515
echo "" > $FINAL_CONFIG_FILE
1616

17-
for f in $($SCRIPT/find-template-files $UAA_PATH "uaa" "yml")
17+
for f in $($SCRIPT/find-template-files "${PROFILES}" $UAA_PATH "uaa" "yml")
1818
do
1919
envsubst < $f >> $FINAL_CONFIG_FILE
2020
done

0 commit comments

Comments
 (0)