blob: 87edc5ab819839635ea9c5ff4c9b40ab2c4c9798 [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Mark McClainb05c8762013-07-06 23:29:39 -04003# lib/neutron
Joe Gordon23946052014-01-15 21:42:32 +00004# functions - functions specific to neutron
Mark McClainb05c8762013-07-06 23:29:39 -04005
6# Dependencies:
7# ``functions`` file
8# ``DEST`` must be defined
Stephan Renatuse578eff2013-11-19 13:31:04 +01009# ``STACK_USER`` must be defined
Mark McClainb05c8762013-07-06 23:29:39 -040010
11# ``stack.sh`` calls the entry points in this order:
12#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010013# - install_neutron_agent_packages
YAMAMOTO Takashi1a669dc2015-02-05 11:54:12 +090014# - install_neutronclient
15# - install_neutron
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010016# - install_neutron_third_party
17# - configure_neutron
18# - init_neutron
19# - configure_neutron_third_party
20# - init_neutron_third_party
21# - start_neutron_third_party
22# - create_nova_conf_neutron
YAMAMOTO Takashia1875b12017-02-23 05:44:22 +090023# - configure_neutron_after_post_config
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010024# - start_neutron_service_and_check
YAMAMOTO Takashi1a669dc2015-02-05 11:54:12 +090025# - check_neutron_third_party_integration
yunhong jiang0d6e9922014-10-10 06:12:47 -070026# - start_neutron_agents
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010027# - create_neutron_initial_network
Mark McClainb05c8762013-07-06 23:29:39 -040028#
29# ``unstack.sh`` calls the entry points in this order:
30#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010031# - stop_neutron
yunhong jiang0d6e9922014-10-10 06:12:47 -070032# - stop_neutron_third_party
33# - cleanup_neutron
Mark McClainb05c8762013-07-06 23:29:39 -040034
35# Functions in lib/neutron are classified into the following categories:
36#
37# - entry points (called from stack.sh or unstack.sh)
38# - internal functions
39# - neutron exercises
40# - 3rd party programs
41
42
43# Neutron Networking
44# ------------------
45
46# Make sure that neutron is enabled in ``ENABLED_SERVICES``. If you want
47# to run Neutron on this host, make sure that q-svc is also in
48# ``ENABLED_SERVICES``.
49#
Mark McClainb05c8762013-07-06 23:29:39 -040050# See "Neutron Network Configuration" below for additional variables
51# that must be set in localrc for connectivity across hosts with
52# Neutron.
Mark McClainb05c8762013-07-06 23:29:39 -040053
John Davidge21529a52014-06-30 09:55:11 -040054# Settings
55# --------
56
Mark McClainb05c8762013-07-06 23:29:39 -040057
58# Neutron Network Configuration
59# -----------------------------
60
Matthew Treinishabde96a2016-05-12 19:26:20 -040061deprecated "Using lib/neutron-legacy is deprecated, and it will be removed in the future"
Armando Migliaccio7dbcfae2016-02-19 14:43:42 -080062
Sean Daguef3b2f4c2017-04-13 10:11:48 -040063if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -040064 Q_PROTOCOL="https"
65fi
66
67
Mark McClainb05c8762013-07-06 23:29:39 -040068# Set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050069GITDIR["python-neutronclient"]=$DEST/python-neutronclient
Sean Dague5cb19062014-11-01 01:37:45 +010070
Doug Wiegley93e682c2015-03-03 10:31:30 -070071
Mark McClainb05c8762013-07-06 23:29:39 -040072NEUTRON_DIR=$DEST/neutron
Kyle Mestery20b839f2014-12-08 06:17:27 +000073NEUTRON_FWAAS_DIR=$DEST/neutron-fwaas
Ian Wienand1f82f432017-10-04 09:51:02 +110074NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
Mark McClainb05c8762013-07-06 23:29:39 -040075
76# Support entry points installation of console scripts
77if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
78 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
Sean Dague3bdb9222013-10-22 08:36:16 -040079else
80 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
Mark McClainb05c8762013-07-06 23:29:39 -040081fi
82
83NEUTRON_CONF_DIR=/etc/neutron
84NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
85export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
86
Kevin Benton66b361b2017-06-13 00:31:01 -070087# NEUTRON_DEPLOY_MOD_WSGI defines how neutron is deployed, allowed values:
88# - False (default) : Run neutron under Eventlet
89# - True : Run neutron under uwsgi
90# TODO(annp): Switching to uwsgi in next cycle if things turn out to be stable
91# enough
Jens Harbott3492fee2018-11-30 13:57:17 +000092NEUTRON_DEPLOY_MOD_WSGI=$(trueorfalse False NEUTRON_DEPLOY_MOD_WSGI)
Kevin Benton66b361b2017-06-13 00:31:01 -070093
94NEUTRON_UWSGI_CONF=$NEUTRON_CONF_DIR/neutron-api-uwsgi.ini
95
Adam Gandelman7614d212014-08-11 14:27:50 -070096# Agent binaries. Note, binary paths for other agents are set in per-service
97# scripts in lib/neutron_plugins/services/
98AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
99AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
100AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
101
102# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
103# loaded from per-plugin scripts in lib/neutron_plugins/
104Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
105Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
Adam Gandelman7614d212014-08-11 14:27:50 -0700106Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
107
Henry Gessau0fc1cc22014-07-06 22:54:34 -0400108# Default name for Neutron database
109Q_DB_NAME=${Q_DB_NAME:-neutron}
Mark McClainb05c8762013-07-06 23:29:39 -0400110# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +0000111Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -0400112# Default Neutron Port
113Q_PORT=${Q_PORT:-9696}
Rob Crittenden18d47782014-03-19 17:47:42 -0400114# Default Neutron Internal Port when using TLS proxy
115Q_PORT_INT=${Q_PORT_INT:-19696}
Mark McClainb05c8762013-07-06 23:29:39 -0400116# Default Neutron Host
117Q_HOST=${Q_HOST:-$SERVICE_HOST}
Rob Crittenden18d47782014-03-19 17:47:42 -0400118# Default protocol
119Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
Brian Haley180f5eb2015-06-16 13:14:31 -0400120# Default listen address
Jens Harbottdc7b4292017-09-19 10:52:32 +0000121Q_LISTEN_ADDRESS=${Q_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)}
Mark McClainb05c8762013-07-06 23:29:39 -0400122# Default admin username
123Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
124# Default auth strategy
125Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
Mark McClainb05c8762013-07-06 23:29:39 -0400126# RHEL's support for namespaces requires using veths with ovs
127Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
128Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
Yuriy Taraday26623952014-07-16 17:41:53 +0400129Q_USE_ROOTWRAP_DAEMON=$(trueorfalse True Q_USE_ROOTWRAP_DAEMON)
Mark McClainb05c8762013-07-06 23:29:39 -0400130# Meta data IP
Jens Harbottdc7b4292017-09-19 10:52:32 +0000131Q_META_DATA_IP=${Q_META_DATA_IP:-$(ipv6_unquote $SERVICE_HOST)}
Mark McClainb05c8762013-07-06 23:29:39 -0400132# Allow Overlapping IP among subnets
133Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
Terry Wilsonf06c4432014-05-20 10:54:51 -0500134Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
135Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
Aaron Rosencea32b12014-03-04 16:20:14 -0800136VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
137VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Aaron Rosen4540d002013-10-24 13:59:33 -0700138
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900139# The directory which contains files for Q_PLUGIN_EXTRA_CONF_FILES.
140# /etc/neutron is assumed by many of devstack plugins. Do not change.
141_Q_PLUGIN_EXTRA_CONF_PATH=/etc/neutron
142
Mark McClainb05c8762013-07-06 23:29:39 -0400143# List of config file names in addition to the main plugin config file
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900144# To add additional plugin config files, use ``neutron_server_config_add``
145# utility function. For example:
146#
147# ``neutron_server_config_add file1``
148#
149# These config files are relative to ``/etc/neutron``. The above
150# example would specify ``--config-file /etc/neutron/file1`` for
151# neutron server.
Sean Dagueafef8bf2017-03-06 14:07:23 -0500152declare -a -g Q_PLUGIN_EXTRA_CONF_FILES
Mark McClainb05c8762013-07-06 23:29:39 -0400153
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900154# same as Q_PLUGIN_EXTRA_CONF_FILES, but with absolute path.
Sean Dagueafef8bf2017-03-06 14:07:23 -0500155declare -a -g _Q_PLUGIN_EXTRA_CONF_FILES_ABS
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900156
Mark McClainb05c8762013-07-06 23:29:39 -0400157
Dean Troyere2907b42014-02-26 17:35:37 -0600158Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
159if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
160 Q_RR_COMMAND="sudo"
161else
162 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
163 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
Yuriy Taraday26623952014-07-16 17:41:53 +0400164 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
165 Q_RR_DAEMON_COMMAND="sudo $NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
166 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400167fi
168
Brian Haleyeea76212014-06-27 11:45:50 -0400169
170# Distributed Virtual Router (DVR) configuration
171# Can be:
Dean Troyer3324f192014-09-18 09:26:39 -0500172# - ``legacy`` - No DVR functionality
173# - ``dvr_snat`` - Controller or single node DVR
174# - ``dvr`` - Compute node in multi-node DVR
175#
Brian Haleyeea76212014-06-27 11:45:50 -0400176Q_DVR_MODE=${Q_DVR_MODE:-legacy}
177if [[ "$Q_DVR_MODE" != "legacy" ]]; then
Brian Haleye43dfdd2017-09-12 16:13:26 -0600178 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,l2population
Brian Haleyeea76212014-06-27 11:45:50 -0400179fi
180
Dean Troyere2907b42014-02-26 17:35:37 -0600181# Provider Network Configurations
182# --------------------------------
183
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900184# The following variables control the Neutron ML2 plugins' allocation
185# of tenant networks and availability of provider networks. If these
186# are not configured in ``localrc``, tenant networks will be local to
187# the host (with no remote connectivity), and no physical resources
188# will be available for the allocation of provider networks.
Dean Troyere2907b42014-02-26 17:35:37 -0600189
Attila Fazekas8feaf6c2014-07-27 20:47:04 +0200190# To disable tunnels (GRE or VXLAN) for tenant networks,
191# set to False in ``local.conf``.
192# GRE tunnels are only supported by the openvswitch.
193ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
Dean Troyere2907b42014-02-26 17:35:37 -0600194
Richard Theis8906b482016-06-08 10:28:37 -0500195# If using GRE, VXLAN or GENEVE tunnels for tenant networks,
196# specify the range of IDs from which tenant networks are
197# allocated. Can be overridden in ``localrc`` if necessary.
Anant Patil3827dc02014-07-03 21:38:16 +0530198TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
Dean Troyere2907b42014-02-26 17:35:37 -0600199
200# To use VLANs for tenant networks, set to True in localrc. VLANs
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900201# are supported by the ML2 plugins, requiring additional configuration
202# described below.
Dean Troyere2907b42014-02-26 17:35:37 -0600203ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
204
205# If using VLANs for tenant networks, set in ``localrc`` to specify
206# the range of VLAN VIDs from which tenant networks are
207# allocated. An external network switch must be configured to
208# trunk these VLANs between hosts for multi-host connectivity.
209#
210# Example: ``TENANT_VLAN_RANGE=1000:1999``
211TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
212
213# If using VLANs for tenant networks, or if using flat or VLAN
214# provider networks, set in ``localrc`` to the name of the physical
215# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
216# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
217# agent, as described below.
218#
219# Example: ``PHYSICAL_NETWORK=default``
Kevin Benton1554ade2016-07-22 09:40:19 -0700220PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-public}
Dean Troyere2907b42014-02-26 17:35:37 -0600221
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900222# With the openvswitch agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600223# or if using flat or VLAN provider networks, set in ``localrc`` to
224# the name of the OVS bridge to use for the physical network. The
225# bridge will be created if it does not already exist, but a
226# physical interface must be manually added to the bridge as a
227# port for external connectivity.
228#
229# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
Kevin Benton1554ade2016-07-22 09:40:19 -0700230OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-br-ex}
Dean Troyere2907b42014-02-26 17:35:37 -0600231
Clark Boylan95469032016-09-08 17:08:36 -0700232default_route_dev=$(ip route | grep ^default | awk '{print $5}')
233die_if_not_set $LINENO default_route_dev "Failure retrieving default route device"
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900234# With the linuxbridge agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600235# or if using flat or VLAN provider networks, set in ``localrc`` to
236# the name of the network interface to use for the physical
237# network.
238#
239# Example: ``LB_PHYSICAL_INTERFACE=eth1``
Clark Boylan95469032016-09-08 17:08:36 -0700240LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-$default_route_dev}
Dean Troyere2907b42014-02-26 17:35:37 -0600241
Edgar Magana6f335b92014-07-10 15:42:44 -0700242# When Neutron tunnels are enabled it is needed to specify the
243# IP address of the end point in the local server. This IP is set
244# by default to the same IP address that the HOST IP.
245# This variable can be used to specify a different end point IP address
246# Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1``
247TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP}
248
Dean Troyere2907b42014-02-26 17:35:37 -0600249# With the openvswitch plugin, set to True in ``localrc`` to enable
250# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
251#
252# Example: ``OVS_ENABLE_TUNNELING=True``
253OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
254
Tan Lin27a196e2014-10-31 15:44:34 +0800255# Use DHCP agent for providing metadata service in the case of
256# without L3 agent (No Route Agent), set to True in localrc.
257ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
258
259# Add a static route as dhcp option, so the request to 169.254.169.254
260# will be able to reach through a route(DHCP agent)
261# This option require ENABLE_ISOLATED_METADATA = True
262ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
Mark McClainb05c8762013-07-06 23:29:39 -0400263# Neutron plugin specific functions
264# ---------------------------------
265
266# Please refer to ``lib/neutron_plugins/README.md`` for details.
Hirofumi Ichihara36daecd2015-07-23 17:50:40 +0900267if [ -f $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN ]; then
268 source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
269fi
Mark McClainb05c8762013-07-06 23:29:39 -0400270
Emilien Macchi40546f72013-09-24 15:10:25 +0200271# Agent metering service plugin functions
272# -------------------------------------------
273
274# Hardcoding for 1 service plugin for now
275source $TOP_DIR/lib/neutron_plugins/services/metering
276
Sean M. Collins2a242512016-05-03 09:03:09 -0400277# L3 Service functions
278source $TOP_DIR/lib/neutron_plugins/services/l3
Mark McClainb05c8762013-07-06 23:29:39 -0400279# Use security group or not
280if has_neutron_plugin_security_group; then
281 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
282else
283 Q_USE_SECGROUP=False
284fi
285
Dean Troyere2907b42014-02-26 17:35:37 -0600286# Save trace setting
Ian Wienand523f4882015-10-13 11:03:03 +1100287_XTRACE_NEUTRON=$(set +o | grep xtrace)
Dean Troyere2907b42014-02-26 17:35:37 -0600288set +o xtrace
289
290
Mark McClainb05c8762013-07-06 23:29:39 -0400291# Functions
292# ---------
293
Adam Gandelman7614d212014-08-11 14:27:50 -0700294function _determine_config_server {
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900295 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" != '' ]]; then
296 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" = "$_Q_PLUGIN_EXTRA_CONF_PATH" ]]; then
297 deprecated "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
298 else
299 die $LINENO "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
300 fi
301 fi
302 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 ]]; then
303 deprecated "Q_PLUGIN_EXTRA_CONF_FILES is deprecated. Use neutron_server_config_add instead."
304 fi
305 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
306 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($_Q_PLUGIN_EXTRA_CONF_PATH/$cfg_file)
307 done
308
Adam Gandelman7614d212014-08-11 14:27:50 -0700309 local cfg_file
310 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900311 for cfg_file in ${_Q_PLUGIN_EXTRA_CONF_FILES_ABS[@]}; do
Tom Patzig73467042016-04-19 17:02:34 +0200312 opts+=" --config-file $cfg_file"
Adam Gandelman7614d212014-08-11 14:27:50 -0700313 done
314 echo "$opts"
315}
316
Adam Gandelman7614d212014-08-11 14:27:50 -0700317function _determine_config_l3 {
Angus Leesa1c70f22016-05-31 14:43:14 +1000318 local opts="--config-file $NEUTRON_CONF --config-file $Q_L3_CONF_FILE"
Adam Gandelman7614d212014-08-11 14:27:50 -0700319 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.
324function determine_config_files {
325 local opts=""
326 case "$1" in
327 "neutron-server") opts="$(_determine_config_server)" ;;
Adam Gandelman7614d212014-08-11 14:27:50 -0700328 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
329 esac
330 if [ -z "$opts" ] ; then
331 die $LINENO "Could not determine config files for $1."
332 fi
333 echo "$opts"
334}
335
Sean M. Collins2a242512016-05-03 09:03:09 -0400336# configure_mutnauq()
Mark McClainb05c8762013-07-06 23:29:39 -0400337# Set common config for all neutron server and agents.
Sean M. Collins2a242512016-05-03 09:03:09 -0400338function configure_mutnauq {
Mark McClainb05c8762013-07-06 23:29:39 -0400339 _configure_neutron_common
Brant Knudson2dd110c2015-03-14 12:39:14 -0500340 iniset_rpc_backend neutron $NEUTRON_CONF
Mark McClainb05c8762013-07-06 23:29:39 -0400341
Emilien Macchi40546f72013-09-24 15:10:25 +0200342 if is_service_enabled q-metering; then
343 _configure_neutron_metering
344 fi
Stephen Ma9b38eb22014-04-02 02:13:09 +0000345 if is_service_enabled q-agt q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -0400346 _configure_neutron_service
347 fi
348 if is_service_enabled q-agt; then
349 _configure_neutron_plugin_agent
350 fi
351 if is_service_enabled q-dhcp; then
352 _configure_neutron_dhcp_agent
353 fi
354 if is_service_enabled q-l3; then
355 _configure_neutron_l3_agent
356 fi
357 if is_service_enabled q-meta; then
358 _configure_neutron_metadata_agent
359 fi
360
Brian Haleyeea76212014-06-27 11:45:50 -0400361 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
362 _configure_dvr
363 fi
Dina Belova58adaa62014-07-11 18:18:12 +0400364 if is_service_enabled ceilometer; then
365 _configure_neutron_ceilometer_notifications
366 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400367
armando-migliaccioe155b892015-06-12 08:55:02 -0700368 iniset $NEUTRON_CONF DEFAULT api_workers "$API_WORKERS"
Armando Migliaccio06f2ea22017-02-02 16:47:00 -0800369 # devstack is not a tool for running uber scale OpenStack
370 # clouds, therefore running without a dedicated RPC worker
371 # for state reports is more than adequate.
372 iniset $NEUTRON_CONF DEFAULT rpc_state_report_workers 0
Mark McClainb05c8762013-07-06 23:29:39 -0400373}
374
Ian Wienandaee18c72014-02-21 15:35:08 +1100375function create_nova_conf_neutron {
Lucas Alvares Gomese6385932018-06-28 11:00:28 +0100376 local conf=${1:-$NOVA_CONF}
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400377 iniset $conf DEFAULT use_neutron True
378 iniset $conf neutron auth_type "password"
379 iniset $conf neutron auth_url "$KEYSTONE_AUTH_URI"
380 iniset $conf neutron username "$Q_ADMIN_USERNAME"
381 iniset $conf neutron password "$SERVICE_PASSWORD"
382 iniset $conf neutron user_domain_name "$SERVICE_DOMAIN_NAME"
383 iniset $conf neutron project_name "$SERVICE_PROJECT_NAME"
384 iniset $conf neutron project_domain_name "$SERVICE_DOMAIN_NAME"
385 iniset $conf neutron auth_strategy "$Q_AUTH_STRATEGY"
386 iniset $conf neutron region_name "$REGION_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400387
388 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
389 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400390 iniset $conf DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
Mark McClainb05c8762013-07-06 23:29:39 -0400391 fi
392
Matt Riedemann925c2562015-08-25 13:40:25 -0700393 # optionally set options in nova_conf
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400394 neutron_plugin_create_nova_conf $conf
Mark McClainb05c8762013-07-06 23:29:39 -0400395
Mark McClainb05c8762013-07-06 23:29:39 -0400396 if is_service_enabled q-meta; then
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400397 iniset $conf neutron service_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400398 fi
Aaron Rosencea32b12014-03-04 16:20:14 -0800399
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400400 iniset $conf DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
401 iniset $conf DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Mark McClainb05c8762013-07-06 23:29:39 -0400402}
403
Sean M. Collins2a242512016-05-03 09:03:09 -0400404# create_mutnauq_accounts() - Set up common required neutron accounts
Mark McClainb05c8762013-07-06 23:29:39 -0400405
406# Tenant User Roles
407# ------------------------------------------------------------------
408# service neutron admin # if enabled
409
410# Migrated from keystone_data.sh
Sean M. Collins2a242512016-05-03 09:03:09 -0400411function create_mutnauq_accounts {
Kevin Benton66b361b2017-06-13 00:31:01 -0700412 local neutron_url
413 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
414 neutron_url=$Q_PROTOCOL://$SERVICE_HOST/networking/
415 else
416 neutron_url=$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/
417 fi
418
Mark McClainb05c8762013-07-06 23:29:39 -0400419 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100420
Jamie Lennox85ff5322015-01-28 14:28:01 +1000421 create_service_user "neutron"
Bartosz Górski0abde392014-02-28 14:15:19 +0100422
Sean Dague985e9582016-02-10 07:25:24 -0500423 get_or_create_service "neutron" "network" "Neutron Service"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000424 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500425 "network" \
Kevin Benton66b361b2017-06-13 00:31:01 -0700426 "$REGION_NAME" "$neutron_url"
Mark McClainb05c8762013-07-06 23:29:39 -0400427 fi
428}
429
Sean M. Collins2a242512016-05-03 09:03:09 -0400430# init_mutnauq() - Initialize databases, etc.
431function init_mutnauq {
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200432 recreate_database $Q_DB_NAME
Clark Boylan633dbc32017-06-14 12:09:21 -0700433 time_start "dbsync"
Salvatore Orlandodd649882013-08-05 08:56:17 -0700434 # Run Neutron db migrations
435 $NEUTRON_BIN_DIR/neutron-db-manage --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE upgrade head
Clark Boylan633dbc32017-06-14 12:09:21 -0700436 time_stop "dbsync"
Mark McClainb05c8762013-07-06 23:29:39 -0400437}
438
Sean M. Collins2a242512016-05-03 09:03:09 -0400439# install_mutnauq() - Collect source and prepare
440function install_mutnauq {
Doug Wiegley86561c32016-02-10 18:37:21 -0700441 # Install neutron-lib from git so we make sure we're testing
442 # the latest code.
443 if use_library_from_git "neutron-lib"; then
444 git_clone_by_name "neutron-lib"
445 setup_dev_lib "neutron-lib"
446 fi
447
Mark McClainb05c8762013-07-06 23:29:39 -0400448 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
449 setup_develop $NEUTRON_DIR
450}
451
Mark McClainb05c8762013-07-06 23:29:39 -0400452# install_neutron_agent_packages() - Collect source and prepare
YAMAMOTO Takashic74315e2016-07-21 17:49:43 +0900453function install_neutron_agent_packages_mutnauq {
Robert Li72b3e442014-07-17 15:04:52 -0400454 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
455 if is_service_enabled q-l3; then
456 install_package radvd
457 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400458 # install packages that are specific to plugin agent(s)
459 if is_service_enabled q-agt q-dhcp q-l3; then
460 neutron_plugin_install_agent_packages
461 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400462}
463
YAMAMOTO Takashia1875b12017-02-23 05:44:22 +0900464# Finish neutron configuration
465function configure_neutron_after_post_config {
466 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
467 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
468 fi
469}
470
Sean Dague0eebeb42017-08-30 14:16:58 -0400471# Start running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100472function start_neutron_service_and_check {
Rob Crittenden18d47782014-03-19 17:47:42 -0400473 local service_port=$Q_PORT
474 local service_protocol=$Q_PROTOCOL
Ian Wienand7ae97292016-02-16 14:50:53 +1100475 local cfg_file_options
Kevin Benton66b361b2017-06-13 00:31:01 -0700476 local neutron_url
Ian Wienand7ae97292016-02-16 14:50:53 +1100477
478 cfg_file_options="$(determine_config_files neutron-server)"
479
Rob Crittenden18d47782014-03-19 17:47:42 -0400480 if is_service_enabled tls-proxy; then
481 service_port=$Q_PORT_INT
482 service_protocol="http"
483 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400484 # Start the Neutron service
Kevin Benton66b361b2017-06-13 00:31:01 -0700485 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
486 enable_service neutron-api
487 run_process neutron-api "$NEUTRON_BIN_DIR/uwsgi --procname-prefix neutron-api --ini $NEUTRON_UWSGI_CONF"
488 neutron_url=$Q_PROTOCOL://$Q_HOST/networking/
489 enable_service neutron-rpc-server
490 run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $cfg_file_options"
491 else
492 run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
493 neutron_url=$service_protocol://$Q_HOST:$service_port
494 # Start proxy if enabled
495 if is_service_enabled tls-proxy; then
496 start_tls_proxy neutron '*' $Q_PORT $Q_HOST $Q_PORT_INT
497 fi
498 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400499 echo "Waiting for Neutron to start..."
Sean Dague442e4e92015-06-24 13:24:02 -0400500
Kevin Benton66b361b2017-06-13 00:31:01 -0700501 local testcmd="wget ${ssl_ca} --no-proxy -q -O- $neutron_url"
Sean Dague442e4e92015-06-24 13:24:02 -0400502 test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
Mark McClainb05c8762013-07-06 23:29:39 -0400503}
504
Russell Bryant09b94602015-06-08 15:25:43 -0400505# Control of the l2 agent is separated out to make it easier to test partial
506# upgrades (everything upgraded except the L2 agent)
Sean M. Collins2a242512016-05-03 09:03:09 -0400507function start_mutnauq_l2_agent {
Davanum Srinivas59756e92015-09-23 17:42:54 -0400508 run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
Nachi Ueno584750f2013-07-15 18:22:21 -0700509
Kahou Leid663e292015-10-24 12:18:57 -0700510 if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then
Zhongyue Luo56b7efb2014-12-16 11:36:49 +0800511 sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400512 sudo ip link set $OVS_PHYSICAL_BRIDGE up
513 sudo ip link set br-int up
514 sudo ip link set $PUBLIC_INTERFACE up
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700515 if is_ironic_hardware; then
516 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
517 sudo ip addr del $IP dev $PUBLIC_INTERFACE
518 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
519 done
gong yong sheng348c6ac2015-06-23 14:03:47 +0800520 sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700521 fi
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400522 fi
Russell Bryant09b94602015-06-08 15:25:43 -0400523}
524
Sean M. Collins2a242512016-05-03 09:03:09 -0400525function start_mutnauq_other_agents {
Angus Leesa1c70f22016-05-31 14:43:14 +1000526 run_process q-dhcp "$AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file $Q_DHCP_CONF_FILE"
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400527
Paul Michalie4289c82015-08-14 11:49:27 -0400528 if is_service_enabled neutron-vpnaas; then
529 : # Started by plugin
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700530 else
Davanum Srinivas59756e92015-09-23 17:42:54 -0400531 run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700532 fi
533
Angus Leesa1c70f22016-05-31 14:43:14 +1000534 run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file $Q_META_CONF_FILE"
Davanum Srinivas59756e92015-09-23 17:42:54 -0400535 run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400536}
537
Russell Bryant09b94602015-06-08 15:25:43 -0400538# Start running processes, including screen
539function start_neutron_agents {
540 # Start up the neutron agents if enabled
Sean M. Collins2a242512016-05-03 09:03:09 -0400541 start_mutnauq_l2_agent
542 start_mutnauq_other_agents
Russell Bryant09b94602015-06-08 15:25:43 -0400543}
544
Sean M. Collins2a242512016-05-03 09:03:09 -0400545function stop_mutnauq_l2_agent {
Russell Bryant09b94602015-06-08 15:25:43 -0400546 stop_process q-agt
547}
548
Sean Dague0eebeb42017-08-30 14:16:58 -0400549# stop_mutnauq_other() - Stop running processes
Sean M. Collins2a242512016-05-03 09:03:09 -0400550function stop_mutnauq_other {
Mark McClainb05c8762013-07-06 23:29:39 -0400551 if is_service_enabled q-dhcp; then
Chris Dent36891dc2015-02-03 16:22:44 +0000552 stop_process q-dhcp
Mark McClainb05c8762013-07-06 23:29:39 -0400553 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
554 [ ! -z "$pid" ] && sudo kill -9 $pid
555 fi
Chris Dent36891dc2015-02-03 16:22:44 +0000556
Kevin Benton66b361b2017-06-13 00:31:01 -0700557 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
558 stop_process neutron-rpc-server
559 stop_process neutron-api
560 else
561 stop_process q-svc
562 fi
Li Maa15d9de2016-01-19 19:11:51 +0800563
564 if is_service_enabled q-l3; then
565 sudo pkill -f "radvd -C $DATA_DIR/neutron/ra"
566 stop_process q-l3
567 fi
Chris Dent36891dc2015-02-03 16:22:44 +0000568
Mark McClainb05c8762013-07-06 23:29:39 -0400569 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100570 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Chris Dent36891dc2015-02-03 16:22:44 +0000571 stop_process q-meta
Mark McClainb05c8762013-07-06 23:29:39 -0400572 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900573
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900574 if is_service_enabled q-metering; then
575 neutron_metering_stop
576 fi
Li Ma50120fa2015-12-13 10:41:34 +0800577
578 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
579 sudo pkill -9 -f $NEUTRON_ROOTWRAP-daemon || :
580 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400581}
582
Russell Bryant09b94602015-06-08 15:25:43 -0400583# stop_neutron() - Stop running processes (non-screen)
Sean M. Collins2a242512016-05-03 09:03:09 -0400584function stop_mutnauq {
585 stop_mutnauq_other
586 stop_mutnauq_l2_agent
Russell Bryant09b94602015-06-08 15:25:43 -0400587}
588
Sean M. Collins00e16a92015-02-20 11:45:21 -0500589# _move_neutron_addresses_route() - Move the primary IP to the OVS bridge
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600590# on startup, or back to the public interface on cleanup. If no IP is
591# configured on the interface, just add it as a port to the OVS bridge.
Sean M. Collins00e16a92015-02-20 11:45:21 -0500592function _move_neutron_addresses_route {
593 local from_intf=$1
594 local to_intf=$2
595 local add_ovs_port=$3
Brian Haleya0d1b012015-11-16 17:30:48 -0500596 local del_ovs_port=$4
597 local af=$5
Sean M. Collins00e16a92015-02-20 11:45:21 -0500598
599 if [[ -n "$from_intf" && -n "$to_intf" ]]; then
600 # Remove the primary IP address from $from_intf and add it to $to_intf,
601 # along with the default route, if it exists. Also, when called
602 # on configure we will also add $from_intf as a port on $to_intf,
603 # assuming it is an OVS bridge.
604
Matt McEuene24707b2016-07-11 08:37:59 -0500605 local IP_REPLACE=""
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600606 local IP_DEL=""
Shinobu KINJOf95315b2015-11-07 10:21:08 +0900607 local IP_UP=""
Ian Wienandada886d2015-10-07 14:06:26 +1100608 local DEFAULT_ROUTE_GW
Andreas Scheuring92e6b1a2017-04-26 13:40:42 +0200609 DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf\s/ { print \$3; exit }")
Sean M. Collins00e16a92015-02-20 11:45:21 -0500610 local ADD_OVS_PORT=""
Brian Haleya0d1b012015-11-16 17:30:48 -0500611 local DEL_OVS_PORT=""
Sean M. Collins17398a32016-05-11 18:24:46 +0000612 local ARP_CMD=""
Sean M. Collins00e16a92015-02-20 11:45:21 -0500613
Brian Haleybb9caea2015-11-16 17:18:42 -0500614 IP_BRD=$(ip -f $af a s dev $from_intf scope global primary | grep inet | awk '{ print $2, $3, $4; exit }')
Adam Kacmarsky11298a02015-06-26 14:49:47 -0600615
Sean M. Collins00e16a92015-02-20 11:45:21 -0500616 if [ "$DEFAULT_ROUTE_GW" != "" ]; then
Sean M. Collins59e86a32015-11-09 11:06:39 -0500617 ADD_DEFAULT_ROUTE="sudo ip -f $af r replace default via $DEFAULT_ROUTE_GW dev $to_intf"
Sean M. Collins00e16a92015-02-20 11:45:21 -0500618 fi
619
620 if [[ "$add_ovs_port" == "True" ]]; then
Raman Budnydb02bbf2015-03-31 13:09:09 +0300621 ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf"
Sean M. Collins00e16a92015-02-20 11:45:21 -0500622 fi
623
Brian Haleya0d1b012015-11-16 17:30:48 -0500624 if [[ "$del_ovs_port" == "True" ]]; then
625 DEL_OVS_PORT="sudo ovs-vsctl --if-exists del-port $from_intf $to_intf"
626 fi
627
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600628 if [[ "$IP_BRD" != "" ]]; then
Brian Haley94510212015-09-02 15:40:04 -0400629 IP_DEL="sudo ip addr del $IP_BRD dev $from_intf"
Matt McEuene24707b2016-07-11 08:37:59 -0500630 IP_REPLACE="sudo ip addr replace $IP_BRD dev $to_intf"
Shinobu KINJOf95315b2015-11-07 10:21:08 +0900631 IP_UP="sudo ip link set $to_intf up"
Sean M. Collins6d4843e2016-05-12 16:14:26 -0400632 if [[ "$af" == "inet" ]]; then
633 IP=$(echo $IP_BRD | awk '{ print $1; exit }' | grep -o -E '(.*)/' | cut -d "/" -f1)
zhubx00759f50c72018-07-23 11:42:07 +0800634 ARP_CMD="sudo arping -A -c 3 -w 4.5 -I $to_intf $IP "
Sean M. Collins6d4843e2016-05-12 16:14:26 -0400635 fi
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600636 fi
637
Brian Haleya0d1b012015-11-16 17:30:48 -0500638 # The add/del OVS port calls have to happen either before or
639 # after the address is moved in order to not leave it orphaned.
Matt McEuene24707b2016-07-11 08:37:59 -0500640 $DEL_OVS_PORT; $IP_DEL; $IP_REPLACE; $IP_UP; $ADD_OVS_PORT; $ADD_DEFAULT_ROUTE; $ARP_CMD
Sean M. Collins00e16a92015-02-20 11:45:21 -0500641 fi
642}
643
Sean M. Collins2a242512016-05-03 09:03:09 -0400644# cleanup_mutnauq() - Remove residual data files, anything left over from previous
Mark McClainb05c8762013-07-06 23:29:39 -0400645# runs that a clean run would need to clean up
Sean M. Collins2a242512016-05-03 09:03:09 -0400646function cleanup_mutnauq {
Sean M. Collins00e16a92015-02-20 11:45:21 -0500647
Yalei Wang316b3482015-07-15 21:00:31 +0800648 if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then
Brian Haleya0d1b012015-11-16 17:30:48 -0500649 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False True "inet"
Adam Kacmarsky11298a02015-06-26 14:49:47 -0600650
Yalei Wang316b3482015-07-15 21:00:31 +0800651 if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then
Sean M. Collins790266f2015-11-11 13:36:35 -0500652 # ip(8) wants the prefix length when deleting
653 local v6_gateway
654 v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }')
655 sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE
Brian Haleya0d1b012015-11-16 17:30:48 -0500656 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False False "inet6"
Yalei Wang316b3482015-07-15 21:00:31 +0800657 fi
Sean M. Collins00e16a92015-02-20 11:45:21 -0500658
Yalei Wang316b3482015-07-15 21:00:31 +0800659 if is_provider_network && is_ironic_hardware; then
660 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
661 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
662 sudo ip addr add $IP dev $PUBLIC_INTERFACE
663 done
664 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
665 fi
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700666 fi
667
Mark McClainb05c8762013-07-06 23:29:39 -0400668 if is_neutron_ovs_base_plugin; then
669 neutron_ovs_base_cleanup
670 fi
671
Sean M. Collins7bc2af72015-06-08 12:36:30 -0400672 if [[ $Q_AGENT == "linuxbridge" ]]; then
673 neutron_lb_cleanup
674 fi
675
Mark McClainb05c8762013-07-06 23:29:39 -0400676 # delete all namespaces created by neutron
Doug Wiegley7e40c642016-08-20 16:32:14 +0000677 for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|fip|snat)-[0-9a-f-]*'); do
Mark McClainb05c8762013-07-06 23:29:39 -0400678 sudo ip netns delete ${ns}
679 done
680}
681
Doug Wiegley93e682c2015-03-03 10:31:30 -0700682
Maru Newby952fd902015-01-30 22:27:12 +0000683function _create_neutron_conf_dir {
Mark McClainb05c8762013-07-06 23:29:39 -0400684 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
Dean Troyer8421c2b2015-03-16 13:52:19 -0500685 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
Maru Newby952fd902015-01-30 22:27:12 +0000686}
687
688# _configure_neutron_common()
689# Set common config for all neutron server and agents.
690# This MUST be called before other ``_configure_neutron_*`` functions.
691function _configure_neutron_common {
692 _create_neutron_conf_dir
Mark McClainb05c8762013-07-06 23:29:39 -0400693
Martin Hickey30d5fae2015-11-10 13:44:15 +0000694 # Uses oslo config generator to generate core sample configuration files
695 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
696
697 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
Mark McClainb05c8762013-07-06 23:29:39 -0400698
Jerry Zhao296c1e32015-08-07 20:43:54 -0400699 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
Jerry Zhao296c1e32015-08-07 20:43:54 -0400700
701 # allow neutron user to administer neutron to match neutron account
Akihiro Motoki80769c52018-11-23 05:18:40 +0900702 # NOTE(amotoki): This is required for nova works correctly with neutron.
703 if [ -f $NEUTRON_DIR/etc/policy.json ]; then
704 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
705 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
706 else
707 echo '{"context_is_admin": "role:admin or user_name:neutron"}' > $Q_POLICY_FILE
708 fi
Jerry Zhao296c1e32015-08-07 20:43:54 -0400709
Mark McClainb05c8762013-07-06 23:29:39 -0400710 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
711 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
Mark McClainb05c8762013-07-06 23:29:39 -0400712 neutron_plugin_configure_common
713
sbauzae2c4ee22013-08-29 17:29:46 +0200714 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400715 die $LINENO "Neutron plugin not set.. exiting"
716 fi
717
718 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
719 mkdir -p /$Q_PLUGIN_CONF_PATH
720 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
Hirofumi Ichihara97cc85b2015-09-08 13:51:01 +0900721 # NOTE(hichihara): Some neutron vendor plugins were already decomposed and
722 # there is no config file in Neutron tree. They should prepare the file in each plugin.
Martin Hickey30d5fae2015-11-10 13:44:15 +0000723 if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then
724 cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE
725 elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then
Hirofumi Ichihara97cc85b2015-09-08 13:51:01 +0900726 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
727 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400728
Ihar Hrachyshkab816e5d2014-07-21 13:53:50 +0200729 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
Mark McClainb05c8762013-07-06 23:29:39 -0400730 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
salvatoree4e535b2014-10-29 18:22:46 +0100731 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
Brian Haley180f5eb2015-06-16 13:14:31 -0400732 iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS
Martin Hickey30d5fae2015-11-10 13:44:15 +0000733 iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock
734
Victor Ryzhenkin878d7d82016-04-27 15:15:52 +0300735 # NOTE(freerunner): Need to adjust Region Name for nova in multiregion installation
736 iniset $NEUTRON_CONF nova region_name $REGION_NAME
737
Joe Gordonbee5c502013-08-30 13:48:08 -0400738 if [ "$VIRT_DRIVER" = 'fake' ]; then
739 # Disable arbitrary limits
740 iniset $NEUTRON_CONF quotas quota_network -1
741 iniset $NEUTRON_CONF quotas quota_subnet -1
742 iniset $NEUTRON_CONF quotas quota_port -1
743 iniset $NEUTRON_CONF quotas quota_security_group -1
744 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
745 fi
746
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700747 # Format logging
Sean Dague9751be62016-04-05 12:08:57 -0400748 setup_logging $NEUTRON_CONF
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700749
Kevin Benton66b361b2017-06-13 00:31:01 -0700750 if is_service_enabled tls-proxy && [ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" ]; then
Rob Crittenden18d47782014-03-19 17:47:42 -0400751 # Set the service port for a proxy to take the original
752 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
Jens Harbott411c34d2017-08-29 14:40:26 +0000753 iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True
Rob Crittenden18d47782014-03-19 17:47:42 -0400754 fi
755
Mark McClainb05c8762013-07-06 23:29:39 -0400756 _neutron_setup_rootwrap
757}
758
Ian Wienandaee18c72014-02-21 15:35:08 +1100759function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400760
Martin Hickey30d5fae2015-11-10 13:44:15 +0000761 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400762
Ben Nemec03997942013-08-10 09:56:16 -0500763 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Sean Dague78801c12016-08-04 14:10:07 -0400764 # make it so we have working DNS from guests
765 iniset $Q_DHCP_CONF_FILE DEFAULT dnsmasq_local_resolv True
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700766 iniset $Q_DHCP_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400767 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700768 iniset $Q_DHCP_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400769 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400770
Tan Lin27a196e2014-10-31 15:44:34 +0800771 if ! is_service_enabled q-l3; then
772 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
773 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
774 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
775 else
776 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
777 die "$LINENO" "Enable isolated metadata is a must for metadata network"
778 fi
779 fi
780 fi
781
Mark McClainb05c8762013-07-06 23:29:39 -0400782 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
783
xurong000379977ef31d02016-07-05 11:09:40 +0800784 neutron_plugin_configure_dhcp_agent $Q_DHCP_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400785}
786
Mark McClainb05c8762013-07-06 23:29:39 -0400787
Ian Wienandaee18c72014-02-21 15:35:08 +1100788function _configure_neutron_metadata_agent {
Martin Hickey30d5fae2015-11-10 13:44:15 +0000789 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400790
Ben Nemec03997942013-08-10 09:56:16 -0500791 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Brian Haleyefc51682017-11-10 00:50:48 -0500792 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_host $Q_META_DATA_IP
Armando Migliaccio06f2ea22017-02-02 16:47:00 -0800793 iniset $Q_META_CONF_FILE DEFAULT metadata_workers $API_WORKERS
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700794 iniset $Q_META_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400795 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700796 iniset $Q_META_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400797 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400798}
799
Dina Belova58adaa62014-07-11 18:18:12 +0400800function _configure_neutron_ceilometer_notifications {
Matt Riedemann45da7772017-03-05 13:07:39 -0500801 iniset $NEUTRON_CONF oslo_messaging_notifications driver messagingv2
Dina Belova58adaa62014-07-11 18:18:12 +0400802}
803
Ian Wienandaee18c72014-02-21 15:35:08 +1100804function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +0200805 neutron_agent_metering_configure_common
806 neutron_agent_metering_configure_agent
807}
808
Brian Haleyeea76212014-06-27 11:45:50 -0400809function _configure_dvr {
810 iniset $NEUTRON_CONF DEFAULT router_distributed True
811 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
812}
813
814
Mark McClainb05c8762013-07-06 23:29:39 -0400815# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
816# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100817function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400818 # Specify the default root helper prior to agent configuration to
819 # ensure that an agent's configuration can override the default
820 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400821 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
822 iniset /$Q_PLUGIN_CONF_FILE agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
823 fi
Ben Nemec03997942013-08-10 09:56:16 -0500824 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400825
826 # Configure agent for plugin
827 neutron_plugin_configure_plugin_agent
828}
829
830# _configure_neutron_service() - Set config files for neutron service
831# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100832function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -0400833 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
Mark McClainb05c8762013-07-06 23:29:39 -0400834 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700835
Mark McClainb05c8762013-07-06 23:29:39 -0400836 # Update either configuration file with plugin
837 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
838
Ben Nemec03997942013-08-10 09:56:16 -0500839 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Chris Dent74a85b02015-04-22 18:02:39 +0000840 iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400841 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
842
843 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
844 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
845
Atsushi SAKAIfe7b56c2015-11-13 17:06:16 +0900846 # Configuration for neutron notifications to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -0500847 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
848 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Jamie Lennoxdc757dd2015-03-09 14:48:09 +1100849
Ian Wienand1f82f432017-10-04 09:51:02 +1100850 configure_auth_token_middleware $NEUTRON_CONF nova $NEUTRON_AUTH_CACHE_DIR nova
Aaron Rosencea32b12014-03-04 16:20:14 -0800851
Mark McClainb05c8762013-07-06 23:29:39 -0400852 # Configure plugin
853 neutron_plugin_configure_service
854}
855
856# Utility Functions
857#------------------
858
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900859# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +1100860function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900861 local service_plugin_class=$1
862 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
863 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
864 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
865 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
866 fi
867}
868
Ihar Hrachyshkaf511c362017-03-07 06:31:49 +0000869# _neutron_ml2_extension_driver_add_old() - add ML2 extension driver
870function _neutron_ml2_extension_driver_add_old {
871 local extension=$1
872 if [[ $Q_ML2_PLUGIN_EXT_DRIVERS == '' ]]; then
873 Q_ML2_PLUGIN_EXT_DRIVERS=$extension
874 elif [[ ! ,${Q_ML2_PLUGIN_EXT_DRIVERS}, =~ ,${extension}, ]]; then
875 Q_ML2_PLUGIN_EXT_DRIVERS="$Q_ML2_PLUGIN_EXT_DRIVERS,$extension"
876 fi
877}
878
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900879# mutnauq_server_config_add() - add server config file
880function mutnauq_server_config_add {
881 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($1)
882}
883
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100884# _neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root).
885function _neutron_deploy_rootwrap_filters {
gong yong sheng3d6eaae2015-09-15 15:00:29 +0800886 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
887 return
888 fi
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100889 local srcdir=$1
Dean Troyer8421c2b2015-03-16 13:52:19 -0500890 sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D
891 sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100892}
893
Mark McClainb05c8762013-07-06 23:29:39 -0400894# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100895function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -0400896 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
897 return
898 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400899 # Wipe any existing ``rootwrap.d`` files first
900 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
901 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
902 sudo rm -rf $Q_CONF_ROOTWRAP_D
903 fi
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100904
905 _neutron_deploy_rootwrap_filters $NEUTRON_DIR
906
Mark McClainb05c8762013-07-06 23:29:39 -0400907 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
908 # location moved in newer versions, prefer new location
909 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Dean Troyer8421c2b2015-03-16 13:52:19 -0500910 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400911 else
Dean Troyer8421c2b2015-03-16 13:52:19 -0500912 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400913 fi
914 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
Robert Li2c5d4622015-04-21 15:48:22 -0400915 sudo sed -e 's:^exec_dirs=\(.*\)$:exec_dirs=\1,/usr/local/bin:' -i $Q_RR_CONF_FILE
916
Mark McClainb05c8762013-07-06 23:29:39 -0400917 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
918 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
Yuriy Taraday26623952014-07-16 17:41:53 +0400919 ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -0400920
921 # Set up the rootwrap sudoers for neutron
922 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +0100923 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Yuriy Taraday26623952014-07-16 17:41:53 +0400924 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -0400925 chmod 0440 $TEMPFILE
926 sudo chown root:root $TEMPFILE
927 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
928
929 # Update the root_helper
930 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400931 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
932 iniset $NEUTRON_CONF agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
933 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400934}
935
Ihar Hrachyshkabb4654b2015-10-06 18:09:07 +0200936# Configures keystone integration for neutron service
Ian Wienandaee18c72014-02-21 15:35:08 +1100937function _neutron_setup_keystone {
Mark McClainb05c8762013-07-06 23:29:39 -0400938 local conf_file=$1
939 local section=$2
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000940
Ian Wienand1f82f432017-10-04 09:51:02 +1100941 create_neutron_cache_dir
942 configure_auth_token_middleware $conf_file $Q_ADMIN_USERNAME $NEUTRON_AUTH_CACHE_DIR $section
Mark McClainb05c8762013-07-06 23:29:39 -0400943}
944
Ian Wienandaee18c72014-02-21 15:35:08 +1100945function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -0400946
947 # ovs_use_veth needs to be set before the plugin configuration
948 # occurs to allow plugins to override the setting.
949 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
950
951 neutron_plugin_setup_interface_driver $1
952}
Mark McClainb05c8762013-07-06 23:29:39 -0400953# Functions for Neutron Exercises
954#--------------------------------
955
Ian Wienandaee18c72014-02-21 15:35:08 +1100956function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -0400957 local from_net="$1"
958 net_id=`_get_net_id $from_net`
959 probe_id=`neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-list -c id -c network_id | grep $net_id | awk '{print $2}'`
960 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
961}
962
Ian Wienandaee18c72014-02-21 15:35:08 +1100963function _get_net_id {
Brian Haley4bc42c72017-11-07 15:22:00 -0500964 openstack --os-cloud devstack-admin --os-region-name="$REGION_NAME" --os-project-name admin --os-username admin --os-password $ADMIN_PASSWORD network list | grep $1 | awk '{print $2}'
Mark McClainb05c8762013-07-06 23:29:39 -0400965}
966
Ian Wienandaee18c72014-02-21 15:35:08 +1100967function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -0400968 local from_net="$1"
969 net_id=`_get_net_id $from_net`
970 probe_id=`neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-list -c id -c network_id | grep $net_id | awk '{print $2}' | head -n 1`
971 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
972}
973
Mark McClainb05c8762013-07-06 23:29:39 -0400974# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +1100975function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400976 local from_net=$1
977 local key_file=$2
978 local ip=$3
979 local user=$4
980 local timeout_sec=$5
981 local probe_cmd = ""
982 probe_cmd=`_get_probe_cmd_prefix $from_net`
Sean Dague442e4e92015-06-24 13:24:02 -0400983 local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success"
984 test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec
Mark McClainb05c8762013-07-06 23:29:39 -0400985}
986
Mark McClainb05c8762013-07-06 23:29:39 -0400987# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100988$_XTRACE_NEUTRON
Mark McClainb05c8762013-07-06 23:29:39 -0400989
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100990# Tell emacs to use shell-script-mode
991## Local variables:
992## mode: shell-script
993## End: