blob: 2906f157365752debb018f13de2f03b2077a78cf [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
Sean Daguef3b2f4c2017-04-13 10:11:48 -040061if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -040062 Q_PROTOCOL="https"
63fi
64
65
Mark McClainb05c8762013-07-06 23:29:39 -040066# Set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050067GITDIR["python-neutronclient"]=$DEST/python-neutronclient
Sean Dague5cb19062014-11-01 01:37:45 +010068
Doug Wiegley93e682c2015-03-03 10:31:30 -070069
Mark McClainb05c8762013-07-06 23:29:39 -040070NEUTRON_DIR=$DEST/neutron
Kyle Mestery20b839f2014-12-08 06:17:27 +000071NEUTRON_FWAAS_DIR=$DEST/neutron-fwaas
Mark McClainb05c8762013-07-06 23:29:39 -040072
73# Support entry points installation of console scripts
74if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
75 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
Sean Dague3bdb9222013-10-22 08:36:16 -040076else
77 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
Mark McClainb05c8762013-07-06 23:29:39 -040078fi
79
80NEUTRON_CONF_DIR=/etc/neutron
81NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
82export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
83
Kevin Benton66b361b2017-06-13 00:31:01 -070084# NEUTRON_DEPLOY_MOD_WSGI defines how neutron is deployed, allowed values:
85# - False (default) : Run neutron under Eventlet
86# - True : Run neutron under uwsgi
87# TODO(annp): Switching to uwsgi in next cycle if things turn out to be stable
88# enough
Jens Harbott3492fee2018-11-30 13:57:17 +000089NEUTRON_DEPLOY_MOD_WSGI=$(trueorfalse False NEUTRON_DEPLOY_MOD_WSGI)
Kevin Benton66b361b2017-06-13 00:31:01 -070090
91NEUTRON_UWSGI_CONF=$NEUTRON_CONF_DIR/neutron-api-uwsgi.ini
92
Adam Gandelman7614d212014-08-11 14:27:50 -070093# Agent binaries. Note, binary paths for other agents are set in per-service
94# scripts in lib/neutron_plugins/services/
95AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
96AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
97AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
98
99# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
100# loaded from per-plugin scripts in lib/neutron_plugins/
101Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
102Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
Adam Gandelman7614d212014-08-11 14:27:50 -0700103Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
104
Henry Gessau0fc1cc22014-07-06 22:54:34 -0400105# Default name for Neutron database
106Q_DB_NAME=${Q_DB_NAME:-neutron}
Mark McClainb05c8762013-07-06 23:29:39 -0400107# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +0000108Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -0400109# Default Neutron Port
110Q_PORT=${Q_PORT:-9696}
Rob Crittenden18d47782014-03-19 17:47:42 -0400111# Default Neutron Internal Port when using TLS proxy
112Q_PORT_INT=${Q_PORT_INT:-19696}
Mark McClainb05c8762013-07-06 23:29:39 -0400113# Default Neutron Host
114Q_HOST=${Q_HOST:-$SERVICE_HOST}
Rob Crittenden18d47782014-03-19 17:47:42 -0400115# Default protocol
116Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
Brian Haley180f5eb2015-06-16 13:14:31 -0400117# Default listen address
Jens Harbottdc7b4292017-09-19 10:52:32 +0000118Q_LISTEN_ADDRESS=${Q_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)}
Mark McClainb05c8762013-07-06 23:29:39 -0400119# Default admin username
120Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
121# Default auth strategy
122Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
Mark McClainb05c8762013-07-06 23:29:39 -0400123# RHEL's support for namespaces requires using veths with ovs
124Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
125Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
Yuriy Taraday26623952014-07-16 17:41:53 +0400126Q_USE_ROOTWRAP_DAEMON=$(trueorfalse True Q_USE_ROOTWRAP_DAEMON)
Mark McClainb05c8762013-07-06 23:29:39 -0400127# Meta data IP
Jens Harbottdc7b4292017-09-19 10:52:32 +0000128Q_META_DATA_IP=${Q_META_DATA_IP:-$(ipv6_unquote $SERVICE_HOST)}
Mark McClainb05c8762013-07-06 23:29:39 -0400129# Allow Overlapping IP among subnets
130Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
Terry Wilsonf06c4432014-05-20 10:54:51 -0500131Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
132Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
Aaron Rosencea32b12014-03-04 16:20:14 -0800133VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
134VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Aaron Rosen4540d002013-10-24 13:59:33 -0700135
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900136# The directory which contains files for Q_PLUGIN_EXTRA_CONF_FILES.
137# /etc/neutron is assumed by many of devstack plugins. Do not change.
138_Q_PLUGIN_EXTRA_CONF_PATH=/etc/neutron
139
Mark McClainb05c8762013-07-06 23:29:39 -0400140# List of config file names in addition to the main plugin config file
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900141# To add additional plugin config files, use ``neutron_server_config_add``
142# utility function. For example:
143#
144# ``neutron_server_config_add file1``
145#
146# These config files are relative to ``/etc/neutron``. The above
147# example would specify ``--config-file /etc/neutron/file1`` for
148# neutron server.
Sean Dagueafef8bf2017-03-06 14:07:23 -0500149declare -a -g Q_PLUGIN_EXTRA_CONF_FILES
Mark McClainb05c8762013-07-06 23:29:39 -0400150
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900151# same as Q_PLUGIN_EXTRA_CONF_FILES, but with absolute path.
Sean Dagueafef8bf2017-03-06 14:07:23 -0500152declare -a -g _Q_PLUGIN_EXTRA_CONF_FILES_ABS
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900153
Mark McClainb05c8762013-07-06 23:29:39 -0400154
Dean Troyere2907b42014-02-26 17:35:37 -0600155Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
156if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
157 Q_RR_COMMAND="sudo"
158else
159 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
160 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
Yuriy Taraday26623952014-07-16 17:41:53 +0400161 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
162 Q_RR_DAEMON_COMMAND="sudo $NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
163 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400164fi
165
Brian Haleyeea76212014-06-27 11:45:50 -0400166
167# Distributed Virtual Router (DVR) configuration
168# Can be:
Dean Troyer3324f192014-09-18 09:26:39 -0500169# - ``legacy`` - No DVR functionality
170# - ``dvr_snat`` - Controller or single node DVR
171# - ``dvr`` - Compute node in multi-node DVR
172#
Brian Haleyeea76212014-06-27 11:45:50 -0400173Q_DVR_MODE=${Q_DVR_MODE:-legacy}
174if [[ "$Q_DVR_MODE" != "legacy" ]]; then
Brian Haleye43dfdd2017-09-12 16:13:26 -0600175 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,l2population
Brian Haleyeea76212014-06-27 11:45:50 -0400176fi
177
Dean Troyere2907b42014-02-26 17:35:37 -0600178# Provider Network Configurations
179# --------------------------------
180
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900181# The following variables control the Neutron ML2 plugins' allocation
182# of tenant networks and availability of provider networks. If these
183# are not configured in ``localrc``, tenant networks will be local to
184# the host (with no remote connectivity), and no physical resources
185# will be available for the allocation of provider networks.
Dean Troyere2907b42014-02-26 17:35:37 -0600186
Attila Fazekas8feaf6c2014-07-27 20:47:04 +0200187# To disable tunnels (GRE or VXLAN) for tenant networks,
188# set to False in ``local.conf``.
189# GRE tunnels are only supported by the openvswitch.
190ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
Dean Troyere2907b42014-02-26 17:35:37 -0600191
Richard Theis8906b482016-06-08 10:28:37 -0500192# If using GRE, VXLAN or GENEVE tunnels for tenant networks,
193# specify the range of IDs from which tenant networks are
194# allocated. Can be overridden in ``localrc`` if necessary.
Anant Patil3827dc02014-07-03 21:38:16 +0530195TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
Dean Troyere2907b42014-02-26 17:35:37 -0600196
197# To use VLANs for tenant networks, set to True in localrc. VLANs
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900198# are supported by the ML2 plugins, requiring additional configuration
199# described below.
Dean Troyere2907b42014-02-26 17:35:37 -0600200ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
201
202# If using VLANs for tenant networks, set in ``localrc`` to specify
203# the range of VLAN VIDs from which tenant networks are
204# allocated. An external network switch must be configured to
205# trunk these VLANs between hosts for multi-host connectivity.
206#
207# Example: ``TENANT_VLAN_RANGE=1000:1999``
208TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
209
210# If using VLANs for tenant networks, or if using flat or VLAN
211# provider networks, set in ``localrc`` to the name of the physical
212# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
213# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
214# agent, as described below.
215#
216# Example: ``PHYSICAL_NETWORK=default``
Kevin Benton1554ade2016-07-22 09:40:19 -0700217PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-public}
Dean Troyere2907b42014-02-26 17:35:37 -0600218
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900219# With the openvswitch agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600220# or if using flat or VLAN provider networks, set in ``localrc`` to
221# the name of the OVS bridge to use for the physical network. The
222# bridge will be created if it does not already exist, but a
223# physical interface must be manually added to the bridge as a
224# port for external connectivity.
225#
226# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
Kevin Benton1554ade2016-07-22 09:40:19 -0700227OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-br-ex}
Dean Troyere2907b42014-02-26 17:35:37 -0600228
Clark Boylan95469032016-09-08 17:08:36 -0700229default_route_dev=$(ip route | grep ^default | awk '{print $5}')
230die_if_not_set $LINENO default_route_dev "Failure retrieving default route device"
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900231# With the linuxbridge agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600232# or if using flat or VLAN provider networks, set in ``localrc`` to
233# the name of the network interface to use for the physical
234# network.
235#
236# Example: ``LB_PHYSICAL_INTERFACE=eth1``
Clark Boylan95469032016-09-08 17:08:36 -0700237LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-$default_route_dev}
Dean Troyere2907b42014-02-26 17:35:37 -0600238
Edgar Magana6f335b92014-07-10 15:42:44 -0700239# When Neutron tunnels are enabled it is needed to specify the
240# IP address of the end point in the local server. This IP is set
241# by default to the same IP address that the HOST IP.
242# This variable can be used to specify a different end point IP address
243# Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1``
244TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP}
245
Dean Troyere2907b42014-02-26 17:35:37 -0600246# With the openvswitch plugin, set to True in ``localrc`` to enable
247# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
248#
249# Example: ``OVS_ENABLE_TUNNELING=True``
250OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
251
Tan Lin27a196e2014-10-31 15:44:34 +0800252# Use DHCP agent for providing metadata service in the case of
253# without L3 agent (No Route Agent), set to True in localrc.
254ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
255
256# Add a static route as dhcp option, so the request to 169.254.169.254
257# will be able to reach through a route(DHCP agent)
258# This option require ENABLE_ISOLATED_METADATA = True
259ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
Mark McClainb05c8762013-07-06 23:29:39 -0400260# Neutron plugin specific functions
261# ---------------------------------
262
263# Please refer to ``lib/neutron_plugins/README.md`` for details.
Hirofumi Ichihara36daecd2015-07-23 17:50:40 +0900264if [ -f $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN ]; then
265 source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
266fi
Mark McClainb05c8762013-07-06 23:29:39 -0400267
Emilien Macchi40546f72013-09-24 15:10:25 +0200268# Agent metering service plugin functions
269# -------------------------------------------
270
271# Hardcoding for 1 service plugin for now
272source $TOP_DIR/lib/neutron_plugins/services/metering
273
Sean M. Collins2a242512016-05-03 09:03:09 -0400274# L3 Service functions
275source $TOP_DIR/lib/neutron_plugins/services/l3
Mark McClainb05c8762013-07-06 23:29:39 -0400276# Use security group or not
277if has_neutron_plugin_security_group; then
278 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
279else
280 Q_USE_SECGROUP=False
281fi
282
Dean Troyere2907b42014-02-26 17:35:37 -0600283# Save trace setting
Ian Wienand523f4882015-10-13 11:03:03 +1100284_XTRACE_NEUTRON=$(set +o | grep xtrace)
Dean Troyere2907b42014-02-26 17:35:37 -0600285set +o xtrace
286
287
Mark McClainb05c8762013-07-06 23:29:39 -0400288# Functions
289# ---------
290
Adam Gandelman7614d212014-08-11 14:27:50 -0700291function _determine_config_server {
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900292 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" != '' ]]; then
293 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" = "$_Q_PLUGIN_EXTRA_CONF_PATH" ]]; then
294 deprecated "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
295 else
296 die $LINENO "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
297 fi
298 fi
299 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 ]]; then
300 deprecated "Q_PLUGIN_EXTRA_CONF_FILES is deprecated. Use neutron_server_config_add instead."
301 fi
302 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
303 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($_Q_PLUGIN_EXTRA_CONF_PATH/$cfg_file)
304 done
305
Adam Gandelman7614d212014-08-11 14:27:50 -0700306 local cfg_file
307 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900308 for cfg_file in ${_Q_PLUGIN_EXTRA_CONF_FILES_ABS[@]}; do
Tom Patzig73467042016-04-19 17:02:34 +0200309 opts+=" --config-file $cfg_file"
Adam Gandelman7614d212014-08-11 14:27:50 -0700310 done
311 echo "$opts"
312}
313
Adam Gandelman7614d212014-08-11 14:27:50 -0700314function _determine_config_l3 {
Angus Leesa1c70f22016-05-31 14:43:14 +1000315 local opts="--config-file $NEUTRON_CONF --config-file $Q_L3_CONF_FILE"
Adam Gandelman7614d212014-08-11 14:27:50 -0700316 echo "$opts"
317}
318
319# For services and agents that require it, dynamically construct a list of
320# --config-file arguments that are passed to the binary.
321function determine_config_files {
322 local opts=""
323 case "$1" in
324 "neutron-server") opts="$(_determine_config_server)" ;;
Adam Gandelman7614d212014-08-11 14:27:50 -0700325 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
326 esac
327 if [ -z "$opts" ] ; then
328 die $LINENO "Could not determine config files for $1."
329 fi
330 echo "$opts"
331}
332
Sean M. Collins2a242512016-05-03 09:03:09 -0400333# configure_mutnauq()
Mark McClainb05c8762013-07-06 23:29:39 -0400334# Set common config for all neutron server and agents.
Sean M. Collins2a242512016-05-03 09:03:09 -0400335function configure_mutnauq {
Mark McClainb05c8762013-07-06 23:29:39 -0400336 _configure_neutron_common
Brant Knudson2dd110c2015-03-14 12:39:14 -0500337 iniset_rpc_backend neutron $NEUTRON_CONF
Mark McClainb05c8762013-07-06 23:29:39 -0400338
Emilien Macchi40546f72013-09-24 15:10:25 +0200339 if is_service_enabled q-metering; then
340 _configure_neutron_metering
341 fi
Stephen Ma9b38eb22014-04-02 02:13:09 +0000342 if is_service_enabled q-agt q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -0400343 _configure_neutron_service
344 fi
345 if is_service_enabled q-agt; then
346 _configure_neutron_plugin_agent
347 fi
348 if is_service_enabled q-dhcp; then
349 _configure_neutron_dhcp_agent
350 fi
351 if is_service_enabled q-l3; then
352 _configure_neutron_l3_agent
353 fi
354 if is_service_enabled q-meta; then
355 _configure_neutron_metadata_agent
356 fi
357
Brian Haleyeea76212014-06-27 11:45:50 -0400358 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
359 _configure_dvr
360 fi
Dina Belova58adaa62014-07-11 18:18:12 +0400361 if is_service_enabled ceilometer; then
362 _configure_neutron_ceilometer_notifications
363 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400364
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100365 if [[ $Q_AGENT == "ovn" ]]; then
366 configure_ovn
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100367 configure_ovn_plugin
368 fi
369
armando-migliaccioe155b892015-06-12 08:55:02 -0700370 iniset $NEUTRON_CONF DEFAULT api_workers "$API_WORKERS"
Armando Migliaccio06f2ea22017-02-02 16:47:00 -0800371 # devstack is not a tool for running uber scale OpenStack
372 # clouds, therefore running without a dedicated RPC worker
373 # for state reports is more than adequate.
374 iniset $NEUTRON_CONF DEFAULT rpc_state_report_workers 0
Mark McClainb05c8762013-07-06 23:29:39 -0400375}
376
Ian Wienandaee18c72014-02-21 15:35:08 +1100377function create_nova_conf_neutron {
Lucas Alvares Gomese6385932018-06-28 11:00:28 +0100378 local conf=${1:-$NOVA_CONF}
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400379 iniset $conf neutron auth_type "password"
Jens Harbott32c00892019-04-10 10:33:39 +0000380 iniset $conf neutron auth_url "$KEYSTONE_SERVICE_URI"
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400381 iniset $conf neutron username "$Q_ADMIN_USERNAME"
382 iniset $conf neutron password "$SERVICE_PASSWORD"
383 iniset $conf neutron user_domain_name "$SERVICE_DOMAIN_NAME"
384 iniset $conf neutron project_name "$SERVICE_PROJECT_NAME"
385 iniset $conf neutron project_domain_name "$SERVICE_DOMAIN_NAME"
386 iniset $conf neutron auth_strategy "$Q_AUTH_STRATEGY"
387 iniset $conf neutron region_name "$REGION_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400388
Matt Riedemann925c2562015-08-25 13:40:25 -0700389 # optionally set options in nova_conf
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400390 neutron_plugin_create_nova_conf $conf
Mark McClainb05c8762013-07-06 23:29:39 -0400391
Mark McClainb05c8762013-07-06 23:29:39 -0400392 if is_service_enabled q-meta; then
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400393 iniset $conf neutron service_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400394 fi
Aaron Rosencea32b12014-03-04 16:20:14 -0800395
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400396 iniset $conf DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
397 iniset $conf DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Mark McClainb05c8762013-07-06 23:29:39 -0400398}
399
Sean M. Collins2a242512016-05-03 09:03:09 -0400400# create_mutnauq_accounts() - Set up common required neutron accounts
Mark McClainb05c8762013-07-06 23:29:39 -0400401
402# Tenant User Roles
403# ------------------------------------------------------------------
404# service neutron admin # if enabled
405
406# Migrated from keystone_data.sh
Sean M. Collins2a242512016-05-03 09:03:09 -0400407function create_mutnauq_accounts {
Kevin Benton66b361b2017-06-13 00:31:01 -0700408 local neutron_url
409 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
410 neutron_url=$Q_PROTOCOL://$SERVICE_HOST/networking/
411 else
412 neutron_url=$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/
413 fi
414
Mark McClainb05c8762013-07-06 23:29:39 -0400415 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100416
Jamie Lennox85ff5322015-01-28 14:28:01 +1000417 create_service_user "neutron"
Bartosz Górski0abde392014-02-28 14:15:19 +0100418
Sean Dague985e9582016-02-10 07:25:24 -0500419 get_or_create_service "neutron" "network" "Neutron Service"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000420 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500421 "network" \
Kevin Benton66b361b2017-06-13 00:31:01 -0700422 "$REGION_NAME" "$neutron_url"
Mark McClainb05c8762013-07-06 23:29:39 -0400423 fi
424}
425
Sean M. Collins2a242512016-05-03 09:03:09 -0400426# init_mutnauq() - Initialize databases, etc.
427function init_mutnauq {
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200428 recreate_database $Q_DB_NAME
Clark Boylan633dbc32017-06-14 12:09:21 -0700429 time_start "dbsync"
Salvatore Orlandodd649882013-08-05 08:56:17 -0700430 # Run Neutron db migrations
431 $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 -0700432 time_stop "dbsync"
Mark McClainb05c8762013-07-06 23:29:39 -0400433}
434
Sean M. Collins2a242512016-05-03 09:03:09 -0400435# install_mutnauq() - Collect source and prepare
436function install_mutnauq {
Doug Wiegley86561c32016-02-10 18:37:21 -0700437 # Install neutron-lib from git so we make sure we're testing
438 # the latest code.
439 if use_library_from_git "neutron-lib"; then
440 git_clone_by_name "neutron-lib"
441 setup_dev_lib "neutron-lib"
442 fi
443
Mark McClainb05c8762013-07-06 23:29:39 -0400444 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
445 setup_develop $NEUTRON_DIR
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100446
447 if [[ $Q_AGENT == "ovn" ]]; then
448 install_ovn
449 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400450}
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
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100471# Start running OVN processes
472function start_ovn_services {
473 if [[ $Q_AGENT == "ovn" ]]; then
474 init_ovn
475 start_ovn
476 if [[ "$OVN_L3_CREATE_PUBLIC_NETWORK" == "True" ]]; then
477 if [[ "$NEUTRON_CREATE_INITIAL_NETWORKS" != "True" ]]; then
478 echo "OVN_L3_CREATE_PUBLIC_NETWORK=True is being ignored "
479 echo "because NEUTRON_CREATE_INITIAL_NETWORKS is set to False"
480 else
481 create_public_bridge
482 fi
483 fi
484 fi
485}
486
Sean Dague0eebeb42017-08-30 14:16:58 -0400487# Start running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100488function start_neutron_service_and_check {
Rob Crittenden18d47782014-03-19 17:47:42 -0400489 local service_port=$Q_PORT
490 local service_protocol=$Q_PROTOCOL
Ian Wienand7ae97292016-02-16 14:50:53 +1100491 local cfg_file_options
Kevin Benton66b361b2017-06-13 00:31:01 -0700492 local neutron_url
Ian Wienand7ae97292016-02-16 14:50:53 +1100493
494 cfg_file_options="$(determine_config_files neutron-server)"
495
Rob Crittenden18d47782014-03-19 17:47:42 -0400496 if is_service_enabled tls-proxy; then
497 service_port=$Q_PORT_INT
498 service_protocol="http"
499 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400500 # Start the Neutron service
Kevin Benton66b361b2017-06-13 00:31:01 -0700501 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
502 enable_service neutron-api
Ian Wienand312517d2018-06-22 22:23:29 +1000503 run_process neutron-api "$(which uwsgi) --procname-prefix neutron-api --ini $NEUTRON_UWSGI_CONF"
Kevin Benton66b361b2017-06-13 00:31:01 -0700504 neutron_url=$Q_PROTOCOL://$Q_HOST/networking/
505 enable_service neutron-rpc-server
506 run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $cfg_file_options"
507 else
508 run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
509 neutron_url=$service_protocol://$Q_HOST:$service_port
510 # Start proxy if enabled
511 if is_service_enabled tls-proxy; then
512 start_tls_proxy neutron '*' $Q_PORT $Q_HOST $Q_PORT_INT
513 fi
514 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400515 echo "Waiting for Neutron to start..."
Sean Dague442e4e92015-06-24 13:24:02 -0400516
Kevin Benton66b361b2017-06-13 00:31:01 -0700517 local testcmd="wget ${ssl_ca} --no-proxy -q -O- $neutron_url"
Sean Dague442e4e92015-06-24 13:24:02 -0400518 test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
Mark McClainb05c8762013-07-06 23:29:39 -0400519}
520
Russell Bryant09b94602015-06-08 15:25:43 -0400521# Control of the l2 agent is separated out to make it easier to test partial
522# upgrades (everything upgraded except the L2 agent)
Sean M. Collins2a242512016-05-03 09:03:09 -0400523function start_mutnauq_l2_agent {
Davanum Srinivas59756e92015-09-23 17:42:54 -0400524 run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
Nachi Ueno584750f2013-07-15 18:22:21 -0700525
Kahou Leid663e292015-10-24 12:18:57 -0700526 if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then
Zhongyue Luo56b7efb2014-12-16 11:36:49 +0800527 sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400528 sudo ip link set $OVS_PHYSICAL_BRIDGE up
529 sudo ip link set br-int up
530 sudo ip link set $PUBLIC_INTERFACE up
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700531 if is_ironic_hardware; then
532 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
533 sudo ip addr del $IP dev $PUBLIC_INTERFACE
534 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
535 done
gong yong sheng348c6ac2015-06-23 14:03:47 +0800536 sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700537 fi
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400538 fi
Russell Bryant09b94602015-06-08 15:25:43 -0400539}
540
Sean M. Collins2a242512016-05-03 09:03:09 -0400541function start_mutnauq_other_agents {
Angus Leesa1c70f22016-05-31 14:43:14 +1000542 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 -0400543
Paul Michalie4289c82015-08-14 11:49:27 -0400544 if is_service_enabled neutron-vpnaas; then
545 : # Started by plugin
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700546 else
Davanum Srinivas59756e92015-09-23 17:42:54 -0400547 run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700548 fi
549
Angus Leesa1c70f22016-05-31 14:43:14 +1000550 run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file $Q_META_CONF_FILE"
Davanum Srinivas59756e92015-09-23 17:42:54 -0400551 run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400552}
553
Russell Bryant09b94602015-06-08 15:25:43 -0400554# Start running processes, including screen
555function start_neutron_agents {
556 # Start up the neutron agents if enabled
Sean M. Collins2a242512016-05-03 09:03:09 -0400557 start_mutnauq_l2_agent
558 start_mutnauq_other_agents
Russell Bryant09b94602015-06-08 15:25:43 -0400559}
560
Sean M. Collins2a242512016-05-03 09:03:09 -0400561function stop_mutnauq_l2_agent {
Russell Bryant09b94602015-06-08 15:25:43 -0400562 stop_process q-agt
563}
564
Sean Dague0eebeb42017-08-30 14:16:58 -0400565# stop_mutnauq_other() - Stop running processes
Sean M. Collins2a242512016-05-03 09:03:09 -0400566function stop_mutnauq_other {
Mark McClainb05c8762013-07-06 23:29:39 -0400567 if is_service_enabled q-dhcp; then
Chris Dent36891dc2015-02-03 16:22:44 +0000568 stop_process q-dhcp
Mark McClainb05c8762013-07-06 23:29:39 -0400569 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
570 [ ! -z "$pid" ] && sudo kill -9 $pid
571 fi
Chris Dent36891dc2015-02-03 16:22:44 +0000572
Kevin Benton66b361b2017-06-13 00:31:01 -0700573 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
574 stop_process neutron-rpc-server
575 stop_process neutron-api
576 else
577 stop_process q-svc
578 fi
Li Maa15d9de2016-01-19 19:11:51 +0800579
580 if is_service_enabled q-l3; then
581 sudo pkill -f "radvd -C $DATA_DIR/neutron/ra"
582 stop_process q-l3
583 fi
Chris Dent36891dc2015-02-03 16:22:44 +0000584
Mark McClainb05c8762013-07-06 23:29:39 -0400585 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100586 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Chris Dent36891dc2015-02-03 16:22:44 +0000587 stop_process q-meta
Mark McClainb05c8762013-07-06 23:29:39 -0400588 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900589
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900590 if is_service_enabled q-metering; then
591 neutron_metering_stop
592 fi
Li Ma50120fa2015-12-13 10:41:34 +0800593
594 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
595 sudo pkill -9 -f $NEUTRON_ROOTWRAP-daemon || :
596 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400597}
598
Russell Bryant09b94602015-06-08 15:25:43 -0400599# stop_neutron() - Stop running processes (non-screen)
Sean M. Collins2a242512016-05-03 09:03:09 -0400600function stop_mutnauq {
601 stop_mutnauq_other
602 stop_mutnauq_l2_agent
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100603
604 if [[ $Q_AGENT == "ovn" ]]; then
605 stop_ovn
606 fi
Russell Bryant09b94602015-06-08 15:25:43 -0400607}
608
Sean M. Collins00e16a92015-02-20 11:45:21 -0500609# _move_neutron_addresses_route() - Move the primary IP to the OVS bridge
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600610# on startup, or back to the public interface on cleanup. If no IP is
611# configured on the interface, just add it as a port to the OVS bridge.
Sean M. Collins00e16a92015-02-20 11:45:21 -0500612function _move_neutron_addresses_route {
613 local from_intf=$1
614 local to_intf=$2
615 local add_ovs_port=$3
Brian Haleya0d1b012015-11-16 17:30:48 -0500616 local del_ovs_port=$4
617 local af=$5
Sean M. Collins00e16a92015-02-20 11:45:21 -0500618
619 if [[ -n "$from_intf" && -n "$to_intf" ]]; then
620 # Remove the primary IP address from $from_intf and add it to $to_intf,
621 # along with the default route, if it exists. Also, when called
622 # on configure we will also add $from_intf as a port on $to_intf,
623 # assuming it is an OVS bridge.
624
Matt McEuene24707b2016-07-11 08:37:59 -0500625 local IP_REPLACE=""
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600626 local IP_DEL=""
Shinobu KINJOf95315b2015-11-07 10:21:08 +0900627 local IP_UP=""
Ian Wienandada886d2015-10-07 14:06:26 +1100628 local DEFAULT_ROUTE_GW
Andreas Scheuring92e6b1a2017-04-26 13:40:42 +0200629 DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf\s/ { print \$3; exit }")
Sean M. Collins00e16a92015-02-20 11:45:21 -0500630 local ADD_OVS_PORT=""
Brian Haleya0d1b012015-11-16 17:30:48 -0500631 local DEL_OVS_PORT=""
Sean M. Collins17398a32016-05-11 18:24:46 +0000632 local ARP_CMD=""
Sean M. Collins00e16a92015-02-20 11:45:21 -0500633
Brian Haleybb9caea2015-11-16 17:18:42 -0500634 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 -0600635
Sean M. Collins00e16a92015-02-20 11:45:21 -0500636 if [ "$DEFAULT_ROUTE_GW" != "" ]; then
Sean M. Collins59e86a32015-11-09 11:06:39 -0500637 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 -0500638 fi
639
640 if [[ "$add_ovs_port" == "True" ]]; then
Raman Budnydb02bbf2015-03-31 13:09:09 +0300641 ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf"
Sean M. Collins00e16a92015-02-20 11:45:21 -0500642 fi
643
Brian Haleya0d1b012015-11-16 17:30:48 -0500644 if [[ "$del_ovs_port" == "True" ]]; then
645 DEL_OVS_PORT="sudo ovs-vsctl --if-exists del-port $from_intf $to_intf"
646 fi
647
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600648 if [[ "$IP_BRD" != "" ]]; then
Brian Haley94510212015-09-02 15:40:04 -0400649 IP_DEL="sudo ip addr del $IP_BRD dev $from_intf"
Matt McEuene24707b2016-07-11 08:37:59 -0500650 IP_REPLACE="sudo ip addr replace $IP_BRD dev $to_intf"
Shinobu KINJOf95315b2015-11-07 10:21:08 +0900651 IP_UP="sudo ip link set $to_intf up"
Sean M. Collins6d4843e2016-05-12 16:14:26 -0400652 if [[ "$af" == "inet" ]]; then
653 IP=$(echo $IP_BRD | awk '{ print $1; exit }' | grep -o -E '(.*)/' | cut -d "/" -f1)
Rodolfo Alonso Hernandezca486c52020-06-25 18:22:28 +0000654 ARP_CMD="sudo arping -A -c 3 -w 5 -I $to_intf $IP "
Sean M. Collins6d4843e2016-05-12 16:14:26 -0400655 fi
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600656 fi
657
Brian Haleya0d1b012015-11-16 17:30:48 -0500658 # The add/del OVS port calls have to happen either before or
659 # after the address is moved in order to not leave it orphaned.
Matt McEuene24707b2016-07-11 08:37:59 -0500660 $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 -0500661 fi
662}
663
Sean M. Collins2a242512016-05-03 09:03:09 -0400664# cleanup_mutnauq() - Remove residual data files, anything left over from previous
Mark McClainb05c8762013-07-06 23:29:39 -0400665# runs that a clean run would need to clean up
Sean M. Collins2a242512016-05-03 09:03:09 -0400666function cleanup_mutnauq {
Sean M. Collins00e16a92015-02-20 11:45:21 -0500667
Yalei Wang316b3482015-07-15 21:00:31 +0800668 if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then
Brian Haleya0d1b012015-11-16 17:30:48 -0500669 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False True "inet"
Adam Kacmarsky11298a02015-06-26 14:49:47 -0600670
Yalei Wang316b3482015-07-15 21:00:31 +0800671 if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then
Sean M. Collins790266f2015-11-11 13:36:35 -0500672 # ip(8) wants the prefix length when deleting
673 local v6_gateway
674 v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }')
675 sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE
Brian Haleya0d1b012015-11-16 17:30:48 -0500676 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False False "inet6"
Yalei Wang316b3482015-07-15 21:00:31 +0800677 fi
Sean M. Collins00e16a92015-02-20 11:45:21 -0500678
Yalei Wang316b3482015-07-15 21:00:31 +0800679 if is_provider_network && is_ironic_hardware; then
680 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
681 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
682 sudo ip addr add $IP dev $PUBLIC_INTERFACE
683 done
684 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
685 fi
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700686 fi
687
Mark McClainb05c8762013-07-06 23:29:39 -0400688 if is_neutron_ovs_base_plugin; then
689 neutron_ovs_base_cleanup
690 fi
691
Sean M. Collins7bc2af72015-06-08 12:36:30 -0400692 if [[ $Q_AGENT == "linuxbridge" ]]; then
693 neutron_lb_cleanup
694 fi
695
Mark McClainb05c8762013-07-06 23:29:39 -0400696 # delete all namespaces created by neutron
Doug Wiegley7e40c642016-08-20 16:32:14 +0000697 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 -0400698 sudo ip netns delete ${ns}
699 done
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100700
701 if [[ $Q_AGENT == "ovn" ]]; then
702 cleanup_ovn
703 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400704}
705
Doug Wiegley93e682c2015-03-03 10:31:30 -0700706
Maru Newby952fd902015-01-30 22:27:12 +0000707function _create_neutron_conf_dir {
Mark McClainb05c8762013-07-06 23:29:39 -0400708 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
Dean Troyer8421c2b2015-03-16 13:52:19 -0500709 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
Maru Newby952fd902015-01-30 22:27:12 +0000710}
711
712# _configure_neutron_common()
713# Set common config for all neutron server and agents.
714# This MUST be called before other ``_configure_neutron_*`` functions.
715function _configure_neutron_common {
716 _create_neutron_conf_dir
Mark McClainb05c8762013-07-06 23:29:39 -0400717
Martin Hickey30d5fae2015-11-10 13:44:15 +0000718 # Uses oslo config generator to generate core sample configuration files
719 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
720
721 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
Mark McClainb05c8762013-07-06 23:29:39 -0400722
Jerry Zhao296c1e32015-08-07 20:43:54 -0400723 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
Jerry Zhao296c1e32015-08-07 20:43:54 -0400724
725 # allow neutron user to administer neutron to match neutron account
Akihiro Motoki80769c52018-11-23 05:18:40 +0900726 # NOTE(amotoki): This is required for nova works correctly with neutron.
727 if [ -f $NEUTRON_DIR/etc/policy.json ]; then
728 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
729 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
730 else
731 echo '{"context_is_admin": "role:admin or user_name:neutron"}' > $Q_POLICY_FILE
732 fi
Jerry Zhao296c1e32015-08-07 20:43:54 -0400733
Mark McClainb05c8762013-07-06 23:29:39 -0400734 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
735 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
Mark McClainb05c8762013-07-06 23:29:39 -0400736 neutron_plugin_configure_common
737
sbauzae2c4ee22013-08-29 17:29:46 +0200738 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400739 die $LINENO "Neutron plugin not set.. exiting"
740 fi
741
742 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
743 mkdir -p /$Q_PLUGIN_CONF_PATH
744 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
Hirofumi Ichihara97cc85b2015-09-08 13:51:01 +0900745 # NOTE(hichihara): Some neutron vendor plugins were already decomposed and
746 # there is no config file in Neutron tree. They should prepare the file in each plugin.
Martin Hickey30d5fae2015-11-10 13:44:15 +0000747 if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then
748 cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE
749 elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then
Hirofumi Ichihara97cc85b2015-09-08 13:51:01 +0900750 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
751 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400752
Ihar Hrachyshkab816e5d2014-07-21 13:53:50 +0200753 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
Mark McClainb05c8762013-07-06 23:29:39 -0400754 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
salvatoree4e535b2014-10-29 18:22:46 +0100755 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
Brian Haley180f5eb2015-06-16 13:14:31 -0400756 iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS
Martin Hickey30d5fae2015-11-10 13:44:15 +0000757 iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock
758
Victor Ryzhenkin878d7d82016-04-27 15:15:52 +0300759 # NOTE(freerunner): Need to adjust Region Name for nova in multiregion installation
760 iniset $NEUTRON_CONF nova region_name $REGION_NAME
761
Joe Gordonbee5c502013-08-30 13:48:08 -0400762 if [ "$VIRT_DRIVER" = 'fake' ]; then
763 # Disable arbitrary limits
764 iniset $NEUTRON_CONF quotas quota_network -1
765 iniset $NEUTRON_CONF quotas quota_subnet -1
766 iniset $NEUTRON_CONF quotas quota_port -1
767 iniset $NEUTRON_CONF quotas quota_security_group -1
768 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
769 fi
770
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700771 # Format logging
Sean Dague9751be62016-04-05 12:08:57 -0400772 setup_logging $NEUTRON_CONF
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700773
Kevin Benton66b361b2017-06-13 00:31:01 -0700774 if is_service_enabled tls-proxy && [ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" ]; then
Rob Crittenden18d47782014-03-19 17:47:42 -0400775 # Set the service port for a proxy to take the original
776 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
Jens Harbott411c34d2017-08-29 14:40:26 +0000777 iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True
Rob Crittenden18d47782014-03-19 17:47:42 -0400778 fi
779
Mark McClainb05c8762013-07-06 23:29:39 -0400780 _neutron_setup_rootwrap
781}
782
Ian Wienandaee18c72014-02-21 15:35:08 +1100783function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400784
Martin Hickey30d5fae2015-11-10 13:44:15 +0000785 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400786
Ben Nemec03997942013-08-10 09:56:16 -0500787 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Sean Dague78801c12016-08-04 14:10:07 -0400788 # make it so we have working DNS from guests
789 iniset $Q_DHCP_CONF_FILE DEFAULT dnsmasq_local_resolv True
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700790 iniset $Q_DHCP_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400791 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700792 iniset $Q_DHCP_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400793 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400794
Tan Lin27a196e2014-10-31 15:44:34 +0800795 if ! is_service_enabled q-l3; then
796 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
797 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
798 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
799 else
800 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
801 die "$LINENO" "Enable isolated metadata is a must for metadata network"
802 fi
803 fi
804 fi
805
Mark McClainb05c8762013-07-06 23:29:39 -0400806 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
807
xurong000379977ef31d02016-07-05 11:09:40 +0800808 neutron_plugin_configure_dhcp_agent $Q_DHCP_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400809}
810
Mark McClainb05c8762013-07-06 23:29:39 -0400811
Ian Wienandaee18c72014-02-21 15:35:08 +1100812function _configure_neutron_metadata_agent {
Martin Hickey30d5fae2015-11-10 13:44:15 +0000813 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400814
Ben Nemec03997942013-08-10 09:56:16 -0500815 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Brian Haleyefc51682017-11-10 00:50:48 -0500816 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_host $Q_META_DATA_IP
Armando Migliaccio06f2ea22017-02-02 16:47:00 -0800817 iniset $Q_META_CONF_FILE DEFAULT metadata_workers $API_WORKERS
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700818 iniset $Q_META_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400819 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700820 iniset $Q_META_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400821 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400822}
823
Dina Belova58adaa62014-07-11 18:18:12 +0400824function _configure_neutron_ceilometer_notifications {
Matt Riedemann45da7772017-03-05 13:07:39 -0500825 iniset $NEUTRON_CONF oslo_messaging_notifications driver messagingv2
Dina Belova58adaa62014-07-11 18:18:12 +0400826}
827
Ian Wienandaee18c72014-02-21 15:35:08 +1100828function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +0200829 neutron_agent_metering_configure_common
830 neutron_agent_metering_configure_agent
831}
832
Brian Haleyeea76212014-06-27 11:45:50 -0400833function _configure_dvr {
834 iniset $NEUTRON_CONF DEFAULT router_distributed True
835 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
836}
837
838
Mark McClainb05c8762013-07-06 23:29:39 -0400839# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
840# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100841function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400842 # Specify the default root helper prior to agent configuration to
843 # ensure that an agent's configuration can override the default
844 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400845 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
846 iniset /$Q_PLUGIN_CONF_FILE agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
847 fi
Ben Nemec03997942013-08-10 09:56:16 -0500848 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400849
850 # Configure agent for plugin
851 neutron_plugin_configure_plugin_agent
852}
853
854# _configure_neutron_service() - Set config files for neutron service
855# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100856function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -0400857 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
Mark McClainb05c8762013-07-06 23:29:39 -0400858 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700859
Mark McClainb05c8762013-07-06 23:29:39 -0400860 # Update either configuration file with plugin
861 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
862
Ben Nemec03997942013-08-10 09:56:16 -0500863 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Chris Dent74a85b02015-04-22 18:02:39 +0000864 iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400865 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
866
867 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100868 configure_keystone_authtoken_middleware $NEUTRON_CONF $Q_ADMIN_USERNAME
Mark McClainb05c8762013-07-06 23:29:39 -0400869
Atsushi SAKAIfe7b56c2015-11-13 17:06:16 +0900870 # Configuration for neutron notifications to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -0500871 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
872 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Jamie Lennoxdc757dd2015-03-09 14:48:09 +1100873
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100874 configure_keystone_authtoken_middleware $NEUTRON_CONF nova nova
Aaron Rosencea32b12014-03-04 16:20:14 -0800875
Mark McClainb05c8762013-07-06 23:29:39 -0400876 # Configure plugin
877 neutron_plugin_configure_service
878}
879
880# Utility Functions
881#------------------
882
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900883# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +1100884function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900885 local service_plugin_class=$1
886 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
887 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
888 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
889 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
890 fi
891}
892
Ihar Hrachyshkaf511c362017-03-07 06:31:49 +0000893# _neutron_ml2_extension_driver_add_old() - add ML2 extension driver
894function _neutron_ml2_extension_driver_add_old {
895 local extension=$1
896 if [[ $Q_ML2_PLUGIN_EXT_DRIVERS == '' ]]; then
897 Q_ML2_PLUGIN_EXT_DRIVERS=$extension
898 elif [[ ! ,${Q_ML2_PLUGIN_EXT_DRIVERS}, =~ ,${extension}, ]]; then
899 Q_ML2_PLUGIN_EXT_DRIVERS="$Q_ML2_PLUGIN_EXT_DRIVERS,$extension"
900 fi
901}
902
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900903# mutnauq_server_config_add() - add server config file
904function mutnauq_server_config_add {
905 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($1)
906}
907
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100908# _neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root).
909function _neutron_deploy_rootwrap_filters {
gong yong sheng3d6eaae2015-09-15 15:00:29 +0800910 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
911 return
912 fi
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100913 local srcdir=$1
Dean Troyer8421c2b2015-03-16 13:52:19 -0500914 sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D
915 sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100916}
917
Mark McClainb05c8762013-07-06 23:29:39 -0400918# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100919function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -0400920 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
921 return
922 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400923 # Wipe any existing ``rootwrap.d`` files first
924 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
925 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
926 sudo rm -rf $Q_CONF_ROOTWRAP_D
927 fi
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100928
929 _neutron_deploy_rootwrap_filters $NEUTRON_DIR
930
Mark McClainb05c8762013-07-06 23:29:39 -0400931 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
932 # location moved in newer versions, prefer new location
933 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Dean Troyer8421c2b2015-03-16 13:52:19 -0500934 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 -0400935 else
Dean Troyer8421c2b2015-03-16 13:52:19 -0500936 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400937 fi
938 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
Robert Li2c5d4622015-04-21 15:48:22 -0400939 sudo sed -e 's:^exec_dirs=\(.*\)$:exec_dirs=\1,/usr/local/bin:' -i $Q_RR_CONF_FILE
940
Mark McClainb05c8762013-07-06 23:29:39 -0400941 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
942 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
Yuriy Taraday26623952014-07-16 17:41:53 +0400943 ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -0400944
945 # Set up the rootwrap sudoers for neutron
946 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +0100947 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Yuriy Taraday26623952014-07-16 17:41:53 +0400948 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -0400949 chmod 0440 $TEMPFILE
950 sudo chown root:root $TEMPFILE
951 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
952
953 # Update the root_helper
954 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400955 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
956 iniset $NEUTRON_CONF agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
957 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400958}
959
Ian Wienandaee18c72014-02-21 15:35:08 +1100960function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -0400961
962 # ovs_use_veth needs to be set before the plugin configuration
963 # occurs to allow plugins to override the setting.
964 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
965
966 neutron_plugin_setup_interface_driver $1
967}
Mark McClainb05c8762013-07-06 23:29:39 -0400968# Functions for Neutron Exercises
969#--------------------------------
970
Ian Wienandaee18c72014-02-21 15:35:08 +1100971function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -0400972 local from_net="$1"
973 net_id=`_get_net_id $from_net`
974 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}'`
975 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
976}
977
Ian Wienandaee18c72014-02-21 15:35:08 +1100978function _get_net_id {
Brian Haley4bc42c72017-11-07 15:22:00 -0500979 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 -0400980}
981
Ian Wienandaee18c72014-02-21 15:35:08 +1100982function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -0400983 local from_net="$1"
984 net_id=`_get_net_id $from_net`
985 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`
986 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
987}
988
Mark McClainb05c8762013-07-06 23:29:39 -0400989# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +1100990function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400991 local from_net=$1
992 local key_file=$2
993 local ip=$3
994 local user=$4
995 local timeout_sec=$5
996 local probe_cmd = ""
997 probe_cmd=`_get_probe_cmd_prefix $from_net`
Sean Dague442e4e92015-06-24 13:24:02 -0400998 local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success"
999 test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec
Mark McClainb05c8762013-07-06 23:29:39 -04001000}
1001
Mark McClainb05c8762013-07-06 23:29:39 -04001002# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +11001003$_XTRACE_NEUTRON
Mark McClainb05c8762013-07-06 23:29:39 -04001004
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001005# Tell emacs to use shell-script-mode
1006## Local variables:
1007## mode: shell-script
1008## End: