Skip to content

Commit 43fe5b1

Browse files
committed
Select one of the existing RMQ deploymens to diagnose
Rather than using a deployment configuration to run diagnostics, choose from the existing RabbitMQ deployments on the BOSH director. Fix shellcheck warnings
1 parent 03ac51c commit 43fe5b1

File tree

3 files changed

+30
-35
lines changed

3 files changed

+30
-35
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ update: ## Deploy an existing RabbitMQ cluster configuration - CONFIG is optiona
189189
submodules: $(GIT)
190190
@$(GIT) submodule update --init
191191

192-
diagnostics: ## Run diagnostics on an existing RabbitMQ cluster
192+
diagnostics: ## Run diagnostics on an existing RabbitMQ deployment
193193
@diagnostics
194194

195-
diagnostics-recent: ## Display outcome from the last diagnostics (executed after `bosh deploy|restart` commands)
195+
diagnostics-recent: ## Show most recent diagnostics for an existing RabbitMQ deployment
196196
@diagnostics "--recent"

script/_rabbitmq-server_deployments

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
set -o pipefail
4+
5+
bosh deployments --json |
6+
jq --raw-output '.Tables[].Rows[] | select(.release_s | contains("rabbitmq-server")) | .name'

script/diagnostics

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,39 @@
22

33
set -e
44

5-
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
5+
[ -n "$SCRIPT" ] || SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
66

7-
if [ ! -e "$DEPLOYMENT_CONFIGURATION" ]
8-
then
9-
pushd "$SCRIPT"/../deployment_configurations &> /dev/null
10-
shopt -s nullglob
11-
deployment_configurations=( *.yml )
12-
if [ ${#deployment_configurations[@]} != 0 ]
13-
then
14-
echo "Which configuration do you want to deploy?"
15-
select deployment_configuration in "${deployment_configurations[@]}"
16-
do
17-
DEPLOYMENT_CONFIGURATION="$SCRIPT"/../deployment_configurations/"$deployment_configuration"
18-
break
19-
done
20-
else
21-
echo "There are no deployment configurations, you can create one by running: deploy"
22-
exit 1
23-
fi
24-
popd &> /dev/null
25-
fi
7+
echo "Select which RabbitMQ deployment to run diagnostics against:"
8+
select RMQ_DEPLOYMENT in $("$SCRIPT"/_rabbitmq-server_deployments)
9+
do
10+
export RMQ_DEPLOYMENT
11+
break
12+
done
2613

27-
_BOSH_DEPLOYMENT="${DEPLOYMENT_CONFIGURATION/.yml}"
28-
BOSH_DEPLOYMENT="${_BOSH_DEPLOYMENT##*/}"
14+
RMQ_INSTANCE_COUNT=$(bosh -d "$RMQ_DEPLOYMENT" instances | grep -c rmq)
2915

30-
RMQ_INSTANCE_COUNT=$(bosh -d $BOSH_DEPLOYMENT instances | grep rmq | wc -l)
31-
32-
if [[ $1 = "--recent" ]]; then
33-
echo "Displaying diagnostics on ${BOSH_DEPLOYMENT} ..."
34-
for (( i=0; i<$RMQ_INSTANCE_COUNT; i++ )) ; do
16+
if [[ $1 = --recent ]]
17+
then
18+
echo "Displaying diagnostics on $RMQ_DEPLOYMENT ..."
19+
for (( i=0; i<RMQ_INSTANCE_COUNT; i++ ))
20+
do
3521
echo "Displaying tests on rmq/$i ..."
36-
bosh -d $BOSH_DEPLOYMENT ssh rmq/$i -r -c "sudo -i bash -c 'cat \$(ls -rt /var/vcap/sys/log/diagnostics/diagnostics-*.report | tail -1)'"
22+
bosh -d "$RMQ_DEPLOYMENT" ssh rmq/$i -r -c "sudo -i bash -c 'cat \$(ls -rt /var/vcap/sys/log/diagnostics/diagnostics-*.report | tail -1)'"
3723
done
3824
else
39-
echo "Running diagnostics on ${BOSH_DEPLOYMENT} ..."
40-
LOG_FILE="/tmp/$BOSH_DEPLOYMENT-$(date -u +'%Y-%m-%dT%H:%M:%SZ').log"
25+
echo "Running diagnostics on $RMQ_DEPLOYMENT ..."
26+
LOG_FILE="/tmp/$RMQ_DEPLOYMENT-$(date -u +'%Y-%m-%dT%H:%M:%SZ').log"
4127
echo "Check out output at $LOG_FILE"
4228

43-
for (( i=0; i<$RMQ_INSTANCE_COUNT; i++ )) ; do
29+
for (( i=0; i<RMQ_INSTANCE_COUNT; i++ ))
30+
do
4431
echo "Running tests on rmq/$i ..."
45-
bosh -d $BOSH_DEPLOYMENT ssh rmq/$i -c "sudo -i bash -c 'DEBUG=false diagnostics'" 2>&1 | tee -a $LOG_FILE | awk '/^--- (FAIL|PASS|::)/ { print $5 " " $6 }'
32+
bosh -d "$RMQ_DEPLOYMENT" ssh rmq/$i -c "sudo -i bash -c 'DEBUG=false diagnostics'" 2>&1 |
33+
tee -a "$LOG_FILE" |
34+
awk '/^--- (FAIL|PASS|::)/ { print $5 " " $6 }'
4635
done
4736

4837
# exit 0 -> no failures
4938
# exit 5 -> 5 tests failed
50-
exit "$(grep '\| FAIL' $LOG_FILE | wc -l)"
39+
exit "$(grep -c '\| FAIL' "$LOG_FILE" )"
5140
fi

0 commit comments

Comments
 (0)