From 6f0205b03630ecb308877f65ca3d4ab9020bc28d Mon Sep 17 00:00:00 2001 From: Dan Smith <dansmith@redhat.com> Date: Wed, 22 Feb 2017 05:59:30 -0800 Subject: [PATCH] Refactor rpc backend vhost creation The creation of the cellsv1 rpc vhost was buried in the restart function, which makes it hard to extend. This breaks it out into a helper method and moves the conditional logic into the nova module itself. Change-Id: Ib0e377aabe45c27bb6ce59ca275ce73085e8b9d2 --- lib/nova | 1 + lib/rpc_backend | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/nova b/lib/nova index 4c264209d5..f5ab20100e 100644 --- a/lib/nova +++ b/lib/nova @@ -644,6 +644,7 @@ function init_nova_cells { if is_service_enabled n-cell; then cp $NOVA_CONF $NOVA_CELLS_CONF iniset $NOVA_CELLS_CONF database connection `database_connection_url $NOVA_CELLS_DB` + rpc_backend_add_vhost child_cell iniset_rpc_backend nova $NOVA_CELLS_CONF DEFAULT child_cell iniset $NOVA_CELLS_CONF DEFAULT dhcpbridge_flagfile $NOVA_CELLS_CONF iniset $NOVA_CELLS_CONF cells enable True diff --git a/lib/rpc_backend b/lib/rpc_backend index a21f781b4e..3c1404e998 100644 --- a/lib/rpc_backend +++ b/lib/rpc_backend @@ -97,13 +97,20 @@ function restart_rpc_backend { break done - if is_service_enabled n-cell; then - # Add partitioned access for the child cell - if [ -z `sudo rabbitmqctl list_vhosts | grep child_cell` ]; then - sudo rabbitmqctl add_vhost child_cell - sudo rabbitmqctl set_permissions -p child_cell $RABBIT_USERID ".*" ".*" ".*" - fi + fi +} + +# adds a vhost to the rpc backend +function rpc_backend_add_vhost { + local vhost="$1" + if is_service_enabled rabbit; then + if [ -z `sudo rabbitmqctl list_vhosts | grep $vhost` ]; then + sudo rabbitmqctl add_vhost $vhost + sudo rabbitmqctl set_permissions -p $vhost $RABBIT_USERID ".*" ".*" ".*" fi + else + echo 'RPC backend does not support vhosts' + return 1 fi }