Skip to content

Commit af5a201

Browse files
committed
Add script to migrate RabbitMQ queues
1 parent ba46f99 commit af5a201

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tools/rabbitmq-queue-migration.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#! /usr/bin/bash
2+
3+
set -ex
4+
5+
RABBITMQ_SERVICES_TO_RESTART=barbican,blazar,cinder,cloudkitty,designate,heat,ironic,keystone,magnum,manila,neutron,nova,octavia
6+
RABBITMQ_CONTAINER_NAME=rabbitmq
7+
8+
if [[ ! $KAYOBE_CONFIG_PATH ]]; then
9+
echo "Environment variable \$KAYOBE_CONFIG_PATH is not defined"
10+
echo "Ensure your environment is set up to run kayobe commands"
11+
exit 2
12+
fi
13+
14+
if [[ ! "$1" = "--skip-checks" ]]; then
15+
# Fail if clocks are not synced
16+
if ! ( kayobe overcloud host command run -l controllers -b --command "timedatectl status | grep 'synchronized: yes'" ); then
17+
echo "Failed precheck: Time not synced on controllers"
18+
echo "Use 'timedatectl status' to check sync state"
19+
echo "Either wait for sync or use 'chronyc makestep'"
20+
exit 1
21+
fi
22+
kayobe overcloud service configuration generate --node-config-dir /tmp/rabbit-migration --kolla-tags none
23+
# Fail if HA is set or quorum is not
24+
if ! ( grep 'om_enable_queue_manager: true' $KOLLA_CONFIG_PATH/globals.yml && \
25+
grep 'om_enable_rabbitmq_quorum_queues: true' $KOLLA_CONFIG_PATH/globals.yml && \
26+
grep 'om_enable_rabbitmq_transient_quorum_queue: true' $KOLLA_CONFIG_PATH/globals.yml && \
27+
grep 'om_enable_rabbitmq_stream_fanout: true' $KOLLA_CONFIG_PATH/globals.yml ); then
28+
echo "Failed precheck: The following must be enabled: om_enable_queue_manager, om_enable_rabbitmq_quorum_queues, om_enable_rabbitmq_transient_quorum_queue, om_enable_rabbitmq_stream_fanout"
29+
exit 1
30+
fi
31+
fi
32+
33+
# Generate new config, stop services using rabbit, and reset rabbit state
34+
kayobe overcloud service configuration generate --node-config-dir /etc/kolla --kolla-skip-tags rabbitmq-ha-precheck
35+
kayobe kolla ansible run "stop --yes-i-really-really-mean-it" -kt $RABBITMQ_SERVICES_TO_RESTART
36+
kayobe kolla ansible run rabbitmq-reset-state
37+
38+
if [[ ! "$1" = "--skip-checks" ]]; then
39+
# Fail if any queues still exist
40+
sleep 20
41+
if ( kayobe overcloud host command run -l controllers -b --command "docker exec $RABBITMQ_CONTAINER_NAME rabbitmqctl list_queues name --silent | grep -v '^$'" ); then
42+
echo "Failed check: RabbitMQ has not stopped properly, queues still exist"
43+
exit 1
44+
fi
45+
# Fail if any exchanges still exist (excluding those starting with 'amq.')
46+
if ( kayobe overcloud host command run -l controllers -b --command "docker exec $RABBITMQ_CONTAINER_NAME rabbitmqctl list_exchanges name --silent | grep -v '^$' | grep -v '^amq.'" ); then
47+
echo "Failed check: RabbitMQ has not stopped properly, exchanges still exist"
48+
exit 1
49+
fi
50+
fi
51+
52+
# Redeploy with quorum queues enabled
53+
kayobe kolla ansible run deploy-containers -kt $RABBITMQ_SERVICES_TO_RESTART
54+
55+
if [[ ! "$1" = "--skip-checks" ]]; then
56+
sleep 20
57+
# Assert that at least one quorum queue exists on each controller
58+
if ! ( kayobe overcloud host command run -l controllers -b --command "docker exec $RABBITMQ_CONTAINER_NAME rabbitmqctl list_queues durable --silent | grep false" ); then
59+
echo "Queues migrated successfully"
60+
else
61+
echo "Failed post-check: A controller has non-durable queues"
62+
fi
63+
fi

0 commit comments

Comments
 (0)