Skip to content

Commit 7614d21

Browse files
committed
Centralize neutron config file argument generation
Moves dynamic generation of the --config-file list from local functions to global utility functions. This breaks up the current non-obvious dependency between start_neutron_agents and _configure_neutron_l3_agent for setting the correct arguments for the vpn agent. This also similarly updates generation of arguments for neutron-server and neutron-l3-agent to use said functions. Finally, this cleans lib/neutron up a bit and moves all default paths to config files and binaries out of local functions and into the top-level, allowing external tools like Grenade to make use of the library for starting Neutron services and agents currently. Change-Id: I927dafca8a2047d6c0fd3c74569ed2521f124547 Closes-bug: #1355429
1 parent 84744d8 commit 7614d21

1 file changed

Lines changed: 63 additions & 32 deletions

File tree

lib/neutron

Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ NEUTRON_CONF_DIR=/etc/neutron
8585
NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
8686
export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
8787

88+
# Agent binaries. Note, binary paths for other agents are set in per-service
89+
# scripts in lib/neutron_plugins/services/
90+
AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
91+
AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
92+
AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
93+
94+
# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
95+
# loaded from per-plugin scripts in lib/neutron_plugins/
96+
Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
97+
Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
98+
Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini
99+
Q_VPN_CONF_FILE=$NEUTRON_CONF_DIR/vpn_agent.ini
100+
Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
101+
88102
# Default name for Neutron database
89103
Q_DB_NAME=${Q_DB_NAME:-neutron}
90104
# Default Neutron Plugin
@@ -275,6 +289,51 @@ set +o xtrace
275289
# Functions
276290
# ---------
277291

292+
function _determine_config_server {
293+
local cfg_file
294+
local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
295+
for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
296+
opts+=" --config-file /$cfg_file"
297+
done
298+
echo "$opts"
299+
}
300+
301+
function _determine_config_vpn {
302+
local cfg_file
303+
local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE --config-file=$Q_VPN_CONF_FILE"
304+
if is_service_enabled q-fwaas; then
305+
opts+=" --config-file $Q_FWAAS_CONF_FILE"
306+
fi
307+
for cfg_file in ${Q_VPN_EXTRA_CONF_FILES[@]}; do
308+
opts+=" --config-file $cfg_file"
309+
done
310+
echo "$opts"
311+
312+
}
313+
314+
function _determine_config_l3 {
315+
local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
316+
if is_service_enabled q-fwaas; then
317+
opts+=" --config-file $Q_FWAAS_CONF_FILE"
318+
fi
319+
echo "$opts"
320+
}
321+
322+
# For services and agents that require it, dynamically construct a list of
323+
# --config-file arguments that are passed to the binary.
324+
function determine_config_files {
325+
local opts=""
326+
case "$1" in
327+
"neutron-server") opts="$(_determine_config_server)" ;;
328+
"neutron-vpn-agent") opts="$(_determine_config_vpn)" ;;
329+
"neutron-l3-agent") opts="$(_determine_config_l3)" ;;
330+
esac
331+
if [ -z "$opts" ] ; then
332+
die $LINENO "Could not determine config files for $1."
333+
fi
334+
echo "$opts"
335+
}
336+
278337
# Test if any Neutron services are enabled
279338
# is_neutron_enabled
280339
function is_neutron_enabled {
@@ -508,14 +567,9 @@ function install_neutron_agent_packages {
508567

509568
# Start running processes, including screen
510569
function start_neutron_service_and_check {
511-
# build config-file options
512-
local cfg_file
513-
local CFG_FILE_OPTIONS="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
514-
for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
515-
CFG_FILE_OPTIONS+=" --config-file /$cfg_file"
516-
done
570+
local cfg_file_options="$(determine_config_files neutron-server)"
517571
# Start the Neutron service
518-
screen_it q-svc "cd $NEUTRON_DIR && python $NEUTRON_BIN_DIR/neutron-server $CFG_FILE_OPTIONS"
572+
screen_it q-svc "cd $NEUTRON_DIR && python $NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
519573
echo "Waiting for Neutron to start..."
520574
if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- http://$Q_HOST:$Q_PORT; do sleep 1; done"; then
521575
die $LINENO "Neutron did not start"
@@ -528,23 +582,17 @@ function start_neutron_agents {
528582
screen_it q-agt "cd $NEUTRON_DIR && python $AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
529583
screen_it q-dhcp "cd $NEUTRON_DIR && python $AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file=$Q_DHCP_CONF_FILE"
530584

531-
L3_CONF_FILES="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
532-
533585
if is_provider_network; then
534586
sudo ovs-vsctl add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
535587
sudo ip link set $OVS_PHYSICAL_BRIDGE up
536588
sudo ip link set br-int up
537589
sudo ip link set $PUBLIC_INTERFACE up
538590
fi
539591

540-
if is_service_enabled q-fwaas; then
541-
L3_CONF_FILES="$L3_CONF_FILES --config-file $Q_FWAAS_CONF_FILE"
542-
VPN_CONF_FILES="$VPN_CONF_FILES --config-file $Q_FWAAS_CONF_FILE"
543-
fi
544592
if is_service_enabled q-vpn; then
545-
screen_it q-vpn "cd $NEUTRON_DIR && $AGENT_VPN_BINARY $VPN_CONF_FILES"
593+
screen_it q-vpn "cd $NEUTRON_DIR && $AGENT_VPN_BINARY $(determine_config_files neutron-vpn-agent)"
546594
else
547-
screen_it q-l3 "cd $NEUTRON_DIR && python $AGENT_L3_BINARY $L3_CONF_FILES"
595+
screen_it q-l3 "cd $NEUTRON_DIR && python $AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
548596
fi
549597

550598
screen_it q-meta "cd $NEUTRON_DIR && python $AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file=$Q_META_CONF_FILE"
@@ -681,8 +729,6 @@ function _configure_neutron_debug_command {
681729
}
682730

683731
function _configure_neutron_dhcp_agent {
684-
AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
685-
Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
686732

687733
cp $NEUTRON_DIR/etc/dhcp_agent.ini $Q_DHCP_CONF_FILE
688734

@@ -702,20 +748,8 @@ function _configure_neutron_l3_agent {
702748
# for l3-agent, only use per tenant router if we have namespaces
703749
Q_L3_ROUTER_PER_TENANT=$Q_USE_NAMESPACE
704750

705-
AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
706-
Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
707-
708-
if is_service_enabled q-fwaas; then
709-
Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini
710-
fi
711-
712751
if is_service_enabled q-vpn; then
713-
Q_VPN_CONF_FILE=$NEUTRON_CONF_DIR/vpn_agent.ini
714752
cp $NEUTRON_DIR/etc/vpn_agent.ini $Q_VPN_CONF_FILE
715-
VPN_CONF_FILES="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE --config-file=$Q_VPN_CONF_FILE"
716-
for cfg_file in ${Q_VPN_EXTRA_CONF_FILES[@]}; do
717-
VPN_CONF_FILES+=" --config-file $cfg_file"
718-
done
719753
fi
720754

721755
cp $NEUTRON_DIR/etc/l3_agent.ini $Q_L3_CONF_FILE
@@ -731,9 +765,6 @@ function _configure_neutron_l3_agent {
731765
}
732766

733767
function _configure_neutron_metadata_agent {
734-
AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
735-
Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
736-
737768
cp $NEUTRON_DIR/etc/metadata_agent.ini $Q_META_CONF_FILE
738769

739770
iniset $Q_META_CONF_FILE DEFAULT verbose True

0 commit comments

Comments
 (0)