blob: b906a1b2ff71127e814e816c21500e9d3026dcb6 [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
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +020093# If NEUTRON_ENFORCE_SCOPE == True, it will set "enforce_scope"
94# and "enforce_new_defaults" to True in the Neutron's config to enforce usage
95# of the new RBAC policies and scopes.
96NEUTRON_ENFORCE_SCOPE=$(trueorfalse False NEUTRON_ENFORCE_SCOPE)
97
Adam Gandelman7614d212014-08-11 14:27:50 -070098# Agent binaries. Note, binary paths for other agents are set in per-service
99# scripts in lib/neutron_plugins/services/
100AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
101AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
102AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
103
104# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
105# loaded from per-plugin scripts in lib/neutron_plugins/
106Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
107Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
Adam Gandelman7614d212014-08-11 14:27:50 -0700108Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
109
Henry Gessau0fc1cc22014-07-06 22:54:34 -0400110# Default name for Neutron database
111Q_DB_NAME=${Q_DB_NAME:-neutron}
Mark McClainb05c8762013-07-06 23:29:39 -0400112# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +0000113Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -0400114# Default Neutron Port
115Q_PORT=${Q_PORT:-9696}
Rob Crittenden18d47782014-03-19 17:47:42 -0400116# Default Neutron Internal Port when using TLS proxy
117Q_PORT_INT=${Q_PORT_INT:-19696}
Mark McClainb05c8762013-07-06 23:29:39 -0400118# Default Neutron Host
119Q_HOST=${Q_HOST:-$SERVICE_HOST}
Rob Crittenden18d47782014-03-19 17:47:42 -0400120# Default protocol
121Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
Brian Haley180f5eb2015-06-16 13:14:31 -0400122# Default listen address
Jens Harbottdc7b4292017-09-19 10:52:32 +0000123Q_LISTEN_ADDRESS=${Q_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)}
Mark McClainb05c8762013-07-06 23:29:39 -0400124# Default admin username
125Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
126# Default auth strategy
127Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
Mark McClainb05c8762013-07-06 23:29:39 -0400128# RHEL's support for namespaces requires using veths with ovs
129Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
130Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
Yuriy Taraday26623952014-07-16 17:41:53 +0400131Q_USE_ROOTWRAP_DAEMON=$(trueorfalse True Q_USE_ROOTWRAP_DAEMON)
Mark McClainb05c8762013-07-06 23:29:39 -0400132# Meta data IP
Jens Harbottdc7b4292017-09-19 10:52:32 +0000133Q_META_DATA_IP=${Q_META_DATA_IP:-$(ipv6_unquote $SERVICE_HOST)}
Mark McClainb05c8762013-07-06 23:29:39 -0400134# Allow Overlapping IP among subnets
135Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
Terry Wilsonf06c4432014-05-20 10:54:51 -0500136Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
137Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
Aaron Rosencea32b12014-03-04 16:20:14 -0800138VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
139VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Aaron Rosen4540d002013-10-24 13:59:33 -0700140
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900141# The directory which contains files for Q_PLUGIN_EXTRA_CONF_FILES.
142# /etc/neutron is assumed by many of devstack plugins. Do not change.
143_Q_PLUGIN_EXTRA_CONF_PATH=/etc/neutron
144
Mark McClainb05c8762013-07-06 23:29:39 -0400145# List of config file names in addition to the main plugin config file
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900146# To add additional plugin config files, use ``neutron_server_config_add``
147# utility function. For example:
148#
149# ``neutron_server_config_add file1``
150#
151# These config files are relative to ``/etc/neutron``. The above
152# example would specify ``--config-file /etc/neutron/file1`` for
153# neutron server.
Sean Dagueafef8bf2017-03-06 14:07:23 -0500154declare -a -g Q_PLUGIN_EXTRA_CONF_FILES
Mark McClainb05c8762013-07-06 23:29:39 -0400155
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900156# same as Q_PLUGIN_EXTRA_CONF_FILES, but with absolute path.
Sean Dagueafef8bf2017-03-06 14:07:23 -0500157declare -a -g _Q_PLUGIN_EXTRA_CONF_FILES_ABS
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900158
Mark McClainb05c8762013-07-06 23:29:39 -0400159
Dean Troyere2907b42014-02-26 17:35:37 -0600160Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
161if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
162 Q_RR_COMMAND="sudo"
163else
164 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
165 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
Yuriy Taraday26623952014-07-16 17:41:53 +0400166 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
167 Q_RR_DAEMON_COMMAND="sudo $NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
168 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400169fi
170
Brian Haleyeea76212014-06-27 11:45:50 -0400171
172# Distributed Virtual Router (DVR) configuration
173# Can be:
Dean Troyer3324f192014-09-18 09:26:39 -0500174# - ``legacy`` - No DVR functionality
175# - ``dvr_snat`` - Controller or single node DVR
176# - ``dvr`` - Compute node in multi-node DVR
177#
Brian Haleyeea76212014-06-27 11:45:50 -0400178Q_DVR_MODE=${Q_DVR_MODE:-legacy}
179if [[ "$Q_DVR_MODE" != "legacy" ]]; then
Brian Haleye43dfdd2017-09-12 16:13:26 -0600180 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,l2population
Brian Haleyeea76212014-06-27 11:45:50 -0400181fi
182
Dean Troyere2907b42014-02-26 17:35:37 -0600183# Provider Network Configurations
184# --------------------------------
185
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900186# The following variables control the Neutron ML2 plugins' allocation
187# of tenant networks and availability of provider networks. If these
188# are not configured in ``localrc``, tenant networks will be local to
189# the host (with no remote connectivity), and no physical resources
190# will be available for the allocation of provider networks.
Dean Troyere2907b42014-02-26 17:35:37 -0600191
Attila Fazekas8feaf6c2014-07-27 20:47:04 +0200192# To disable tunnels (GRE or VXLAN) for tenant networks,
193# set to False in ``local.conf``.
194# GRE tunnels are only supported by the openvswitch.
195ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
Dean Troyere2907b42014-02-26 17:35:37 -0600196
Richard Theis8906b482016-06-08 10:28:37 -0500197# If using GRE, VXLAN or GENEVE tunnels for tenant networks,
198# specify the range of IDs from which tenant networks are
199# allocated. Can be overridden in ``localrc`` if necessary.
Anant Patil3827dc02014-07-03 21:38:16 +0530200TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
Dean Troyere2907b42014-02-26 17:35:37 -0600201
202# To use VLANs for tenant networks, set to True in localrc. VLANs
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900203# are supported by the ML2 plugins, requiring additional configuration
204# described below.
Dean Troyere2907b42014-02-26 17:35:37 -0600205ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
206
207# If using VLANs for tenant networks, set in ``localrc`` to specify
208# the range of VLAN VIDs from which tenant networks are
209# allocated. An external network switch must be configured to
210# trunk these VLANs between hosts for multi-host connectivity.
211#
212# Example: ``TENANT_VLAN_RANGE=1000:1999``
213TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
214
215# If using VLANs for tenant networks, or if using flat or VLAN
216# provider networks, set in ``localrc`` to the name of the physical
217# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
218# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
219# agent, as described below.
220#
221# Example: ``PHYSICAL_NETWORK=default``
Kevin Benton1554ade2016-07-22 09:40:19 -0700222PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-public}
Dean Troyere2907b42014-02-26 17:35:37 -0600223
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900224# With the openvswitch agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600225# or if using flat or VLAN provider networks, set in ``localrc`` to
226# the name of the OVS bridge to use for the physical network. The
227# bridge will be created if it does not already exist, but a
228# physical interface must be manually added to the bridge as a
229# port for external connectivity.
230#
231# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
Kevin Benton1554ade2016-07-22 09:40:19 -0700232OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-br-ex}
Dean Troyere2907b42014-02-26 17:35:37 -0600233
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``
Jens Harbott47f76ac2020-10-29 10:42:38 +0000240if [[ $Q_AGENT == "linuxbridge" && -z ${LB_PHYSICAL_INTERFACE} ]]; then
Nate Johnstonefc04ee2020-11-03 10:04:26 -0500241 default_route_dev=$( (ip route; ip -6 route) | grep ^default | head -n 1 | awk '{print $5}')
Jens Harbott47f76ac2020-10-29 10:42:38 +0000242 die_if_not_set $LINENO default_route_dev "Failure retrieving default route device"
243 LB_PHYSICAL_INTERFACE=$default_route_dev
244fi
Dean Troyere2907b42014-02-26 17:35:37 -0600245
Edgar Magana6f335b92014-07-10 15:42:44 -0700246# When Neutron tunnels are enabled it is needed to specify the
247# IP address of the end point in the local server. This IP is set
248# by default to the same IP address that the HOST IP.
249# This variable can be used to specify a different end point IP address
250# Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1``
251TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP}
252
Dean Troyere2907b42014-02-26 17:35:37 -0600253# With the openvswitch plugin, set to True in ``localrc`` to enable
254# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
255#
256# Example: ``OVS_ENABLE_TUNNELING=True``
257OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
258
Tan Lin27a196e2014-10-31 15:44:34 +0800259# Use DHCP agent for providing metadata service in the case of
260# without L3 agent (No Route Agent), set to True in localrc.
261ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
262
263# Add a static route as dhcp option, so the request to 169.254.169.254
264# will be able to reach through a route(DHCP agent)
265# This option require ENABLE_ISOLATED_METADATA = True
266ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
Mark McClainb05c8762013-07-06 23:29:39 -0400267# Neutron plugin specific functions
268# ---------------------------------
269
270# Please refer to ``lib/neutron_plugins/README.md`` for details.
Hirofumi Ichihara36daecd2015-07-23 17:50:40 +0900271if [ -f $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN ]; then
272 source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
273fi
Mark McClainb05c8762013-07-06 23:29:39 -0400274
Emilien Macchi40546f72013-09-24 15:10:25 +0200275# Agent metering service plugin functions
276# -------------------------------------------
277
278# Hardcoding for 1 service plugin for now
279source $TOP_DIR/lib/neutron_plugins/services/metering
280
Sean M. Collins2a242512016-05-03 09:03:09 -0400281# L3 Service functions
282source $TOP_DIR/lib/neutron_plugins/services/l3
Slawek Kaplonskif758b602021-10-06 12:02:22 +0200283
284# Additional Neutron service plugins
Slawek Kaplonski7f6d9282021-10-27 16:40:30 +0200285source $TOP_DIR/lib/neutron_plugins/services/placement
Slawek Kaplonskif758b602021-10-06 12:02:22 +0200286source $TOP_DIR/lib/neutron_plugins/services/trunk
Slawek Kaplonskif9a896c2021-10-27 16:50:11 +0200287source $TOP_DIR/lib/neutron_plugins/services/qos
Slawek Kaplonskif758b602021-10-06 12:02:22 +0200288
Mark McClainb05c8762013-07-06 23:29:39 -0400289# Use security group or not
290if has_neutron_plugin_security_group; then
291 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
292else
293 Q_USE_SECGROUP=False
294fi
295
Dean Troyere2907b42014-02-26 17:35:37 -0600296# Save trace setting
Ian Wienand523f4882015-10-13 11:03:03 +1100297_XTRACE_NEUTRON=$(set +o | grep xtrace)
Dean Troyere2907b42014-02-26 17:35:37 -0600298set +o xtrace
299
300
Mark McClainb05c8762013-07-06 23:29:39 -0400301# Functions
302# ---------
303
Adam Gandelman7614d212014-08-11 14:27:50 -0700304function _determine_config_server {
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900305 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" != '' ]]; then
306 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" = "$_Q_PLUGIN_EXTRA_CONF_PATH" ]]; then
307 deprecated "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
308 else
309 die $LINENO "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
310 fi
311 fi
312 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 ]]; then
313 deprecated "Q_PLUGIN_EXTRA_CONF_FILES is deprecated. Use neutron_server_config_add instead."
314 fi
315 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
316 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($_Q_PLUGIN_EXTRA_CONF_PATH/$cfg_file)
317 done
318
Adam Gandelman7614d212014-08-11 14:27:50 -0700319 local cfg_file
320 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900321 for cfg_file in ${_Q_PLUGIN_EXTRA_CONF_FILES_ABS[@]}; do
Tom Patzig73467042016-04-19 17:02:34 +0200322 opts+=" --config-file $cfg_file"
Adam Gandelman7614d212014-08-11 14:27:50 -0700323 done
324 echo "$opts"
325}
326
Adam Gandelman7614d212014-08-11 14:27:50 -0700327function _determine_config_l3 {
Angus Leesa1c70f22016-05-31 14:43:14 +1000328 local opts="--config-file $NEUTRON_CONF --config-file $Q_L3_CONF_FILE"
Adam Gandelman7614d212014-08-11 14:27:50 -0700329 echo "$opts"
330}
331
332# For services and agents that require it, dynamically construct a list of
333# --config-file arguments that are passed to the binary.
334function determine_config_files {
335 local opts=""
336 case "$1" in
337 "neutron-server") opts="$(_determine_config_server)" ;;
Adam Gandelman7614d212014-08-11 14:27:50 -0700338 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
339 esac
340 if [ -z "$opts" ] ; then
341 die $LINENO "Could not determine config files for $1."
342 fi
343 echo "$opts"
344}
345
Sean M. Collins2a242512016-05-03 09:03:09 -0400346# configure_mutnauq()
Mark McClainb05c8762013-07-06 23:29:39 -0400347# Set common config for all neutron server and agents.
Sean M. Collins2a242512016-05-03 09:03:09 -0400348function configure_mutnauq {
Mark McClainb05c8762013-07-06 23:29:39 -0400349 _configure_neutron_common
Brant Knudson2dd110c2015-03-14 12:39:14 -0500350 iniset_rpc_backend neutron $NEUTRON_CONF
Mark McClainb05c8762013-07-06 23:29:39 -0400351
Emilien Macchi40546f72013-09-24 15:10:25 +0200352 if is_service_enabled q-metering; then
353 _configure_neutron_metering
354 fi
Stephen Ma9b38eb22014-04-02 02:13:09 +0000355 if is_service_enabled q-agt q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -0400356 _configure_neutron_service
357 fi
358 if is_service_enabled q-agt; then
359 _configure_neutron_plugin_agent
360 fi
361 if is_service_enabled q-dhcp; then
362 _configure_neutron_dhcp_agent
363 fi
364 if is_service_enabled q-l3; then
365 _configure_neutron_l3_agent
366 fi
367 if is_service_enabled q-meta; then
368 _configure_neutron_metadata_agent
369 fi
370
Brian Haleyeea76212014-06-27 11:45:50 -0400371 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
372 _configure_dvr
373 fi
Dina Belova58adaa62014-07-11 18:18:12 +0400374 if is_service_enabled ceilometer; then
375 _configure_neutron_ceilometer_notifications
376 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400377
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100378 if [[ $Q_AGENT == "ovn" ]]; then
379 configure_ovn
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100380 configure_ovn_plugin
381 fi
382
Slawek Kaplonskif758b602021-10-06 12:02:22 +0200383 # Configure Neutron's advanced services
Slawek Kaplonski7f6d9282021-10-27 16:40:30 +0200384 if is_service_enabled q-placement neutron-placement; then
385 configure_placement_extension
386 fi
Slawek Kaplonskif758b602021-10-06 12:02:22 +0200387 if is_service_enabled q-trunk neutron-trunk; then
388 configure_trunk_extension
389 fi
Slawek Kaplonskif9a896c2021-10-27 16:50:11 +0200390 if is_service_enabled q-qos neutron-qos; then
391 configure_qos
392 if is_service_enabled q-l3 neutron-l3; then
393 configure_l3_agent_extension_fip_qos
394 configure_l3_agent_extension_gateway_ip_qos
395 fi
396 fi
Slawek Kaplonskif758b602021-10-06 12:02:22 +0200397
armando-migliaccioe155b892015-06-12 08:55:02 -0700398 iniset $NEUTRON_CONF DEFAULT api_workers "$API_WORKERS"
Armando Migliaccio06f2ea22017-02-02 16:47:00 -0800399 # devstack is not a tool for running uber scale OpenStack
400 # clouds, therefore running without a dedicated RPC worker
401 # for state reports is more than adequate.
402 iniset $NEUTRON_CONF DEFAULT rpc_state_report_workers 0
Mark McClainb05c8762013-07-06 23:29:39 -0400403}
404
Ian Wienandaee18c72014-02-21 15:35:08 +1100405function create_nova_conf_neutron {
Lucas Alvares Gomese6385932018-06-28 11:00:28 +0100406 local conf=${1:-$NOVA_CONF}
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400407 iniset $conf neutron auth_type "password"
Jens Harbott32c00892019-04-10 10:33:39 +0000408 iniset $conf neutron auth_url "$KEYSTONE_SERVICE_URI"
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400409 iniset $conf neutron username "$Q_ADMIN_USERNAME"
410 iniset $conf neutron password "$SERVICE_PASSWORD"
411 iniset $conf neutron user_domain_name "$SERVICE_DOMAIN_NAME"
412 iniset $conf neutron project_name "$SERVICE_PROJECT_NAME"
413 iniset $conf neutron project_domain_name "$SERVICE_DOMAIN_NAME"
414 iniset $conf neutron auth_strategy "$Q_AUTH_STRATEGY"
415 iniset $conf neutron region_name "$REGION_NAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400416
Matt Riedemann925c2562015-08-25 13:40:25 -0700417 # optionally set options in nova_conf
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400418 neutron_plugin_create_nova_conf $conf
Mark McClainb05c8762013-07-06 23:29:39 -0400419
Mark McClainb05c8762013-07-06 23:29:39 -0400420 if is_service_enabled q-meta; then
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400421 iniset $conf neutron service_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400422 fi
Aaron Rosencea32b12014-03-04 16:20:14 -0800423
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400424 iniset $conf DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
425 iniset $conf DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Mark McClainb05c8762013-07-06 23:29:39 -0400426}
427
Sean M. Collins2a242512016-05-03 09:03:09 -0400428# create_mutnauq_accounts() - Set up common required neutron accounts
Mark McClainb05c8762013-07-06 23:29:39 -0400429
430# Tenant User Roles
431# ------------------------------------------------------------------
432# service neutron admin # if enabled
433
434# Migrated from keystone_data.sh
Sean M. Collins2a242512016-05-03 09:03:09 -0400435function create_mutnauq_accounts {
Kevin Benton66b361b2017-06-13 00:31:01 -0700436 local neutron_url
437 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
438 neutron_url=$Q_PROTOCOL://$SERVICE_HOST/networking/
439 else
440 neutron_url=$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/
441 fi
442
Mark McClainb05c8762013-07-06 23:29:39 -0400443 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100444
Jamie Lennox85ff5322015-01-28 14:28:01 +1000445 create_service_user "neutron"
Bartosz Górski0abde392014-02-28 14:15:19 +0100446
Sean Dague985e9582016-02-10 07:25:24 -0500447 get_or_create_service "neutron" "network" "Neutron Service"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000448 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500449 "network" \
Kevin Benton66b361b2017-06-13 00:31:01 -0700450 "$REGION_NAME" "$neutron_url"
Mark McClainb05c8762013-07-06 23:29:39 -0400451 fi
452}
453
Sean M. Collins2a242512016-05-03 09:03:09 -0400454# init_mutnauq() - Initialize databases, etc.
455function init_mutnauq {
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200456 recreate_database $Q_DB_NAME
Clark Boylan633dbc32017-06-14 12:09:21 -0700457 time_start "dbsync"
Salvatore Orlandodd649882013-08-05 08:56:17 -0700458 # Run Neutron db migrations
459 $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 -0700460 time_stop "dbsync"
Mark McClainb05c8762013-07-06 23:29:39 -0400461}
462
Sean M. Collins2a242512016-05-03 09:03:09 -0400463# install_mutnauq() - Collect source and prepare
464function install_mutnauq {
Doug Wiegley86561c32016-02-10 18:37:21 -0700465 # Install neutron-lib from git so we make sure we're testing
466 # the latest code.
467 if use_library_from_git "neutron-lib"; then
468 git_clone_by_name "neutron-lib"
469 setup_dev_lib "neutron-lib"
470 fi
471
Mark McClainb05c8762013-07-06 23:29:39 -0400472 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
473 setup_develop $NEUTRON_DIR
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100474
475 if [[ $Q_AGENT == "ovn" ]]; then
476 install_ovn
477 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400478}
479
Mark McClainb05c8762013-07-06 23:29:39 -0400480# install_neutron_agent_packages() - Collect source and prepare
YAMAMOTO Takashic74315e2016-07-21 17:49:43 +0900481function install_neutron_agent_packages_mutnauq {
Robert Li72b3e442014-07-17 15:04:52 -0400482 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
483 if is_service_enabled q-l3; then
484 install_package radvd
485 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400486 # install packages that are specific to plugin agent(s)
487 if is_service_enabled q-agt q-dhcp q-l3; then
488 neutron_plugin_install_agent_packages
489 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400490}
491
YAMAMOTO Takashia1875b12017-02-23 05:44:22 +0900492# Finish neutron configuration
493function configure_neutron_after_post_config {
494 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
495 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
496 fi
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +0200497 configure_rbac_policies
498}
499
500# configure_rbac_policies() - Configure Neutron to enforce new RBAC
501# policies and scopes if NEUTRON_ENFORCE_SCOPE == True
502function configure_rbac_policies {
503 if [ "$NEUTRON_ENFORCE_SCOPE" == "True" ]; then
504 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults True
505 iniset $NEUTRON_CONF oslo_policy enforce_scope True
506 else
507 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults False
508 iniset $NEUTRON_CONF oslo_policy enforce_scope False
509 fi
YAMAMOTO Takashia1875b12017-02-23 05:44:22 +0900510}
511
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100512# Start running OVN processes
513function start_ovn_services {
514 if [[ $Q_AGENT == "ovn" ]]; then
515 init_ovn
516 start_ovn
517 if [[ "$OVN_L3_CREATE_PUBLIC_NETWORK" == "True" ]]; then
518 if [[ "$NEUTRON_CREATE_INITIAL_NETWORKS" != "True" ]]; then
519 echo "OVN_L3_CREATE_PUBLIC_NETWORK=True is being ignored "
520 echo "because NEUTRON_CREATE_INITIAL_NETWORKS is set to False"
521 else
522 create_public_bridge
523 fi
524 fi
525 fi
526}
527
Sean Dague0eebeb42017-08-30 14:16:58 -0400528# Start running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100529function start_neutron_service_and_check {
Rob Crittenden18d47782014-03-19 17:47:42 -0400530 local service_port=$Q_PORT
531 local service_protocol=$Q_PROTOCOL
Ian Wienand7ae97292016-02-16 14:50:53 +1100532 local cfg_file_options
Kevin Benton66b361b2017-06-13 00:31:01 -0700533 local neutron_url
Ian Wienand7ae97292016-02-16 14:50:53 +1100534
535 cfg_file_options="$(determine_config_files neutron-server)"
536
Rob Crittenden18d47782014-03-19 17:47:42 -0400537 if is_service_enabled tls-proxy; then
538 service_port=$Q_PORT_INT
539 service_protocol="http"
540 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400541 # Start the Neutron service
Kevin Benton66b361b2017-06-13 00:31:01 -0700542 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
543 enable_service neutron-api
Ian Wienand312517d2018-06-22 22:23:29 +1000544 run_process neutron-api "$(which uwsgi) --procname-prefix neutron-api --ini $NEUTRON_UWSGI_CONF"
Kevin Benton66b361b2017-06-13 00:31:01 -0700545 neutron_url=$Q_PROTOCOL://$Q_HOST/networking/
546 enable_service neutron-rpc-server
547 run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $cfg_file_options"
548 else
549 run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
550 neutron_url=$service_protocol://$Q_HOST:$service_port
551 # Start proxy if enabled
552 if is_service_enabled tls-proxy; then
553 start_tls_proxy neutron '*' $Q_PORT $Q_HOST $Q_PORT_INT
554 fi
555 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400556 echo "Waiting for Neutron to start..."
Sean Dague442e4e92015-06-24 13:24:02 -0400557
Kevin Benton66b361b2017-06-13 00:31:01 -0700558 local testcmd="wget ${ssl_ca} --no-proxy -q -O- $neutron_url"
Sean Dague442e4e92015-06-24 13:24:02 -0400559 test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
Mark McClainb05c8762013-07-06 23:29:39 -0400560}
561
Russell Bryant09b94602015-06-08 15:25:43 -0400562# Control of the l2 agent is separated out to make it easier to test partial
563# upgrades (everything upgraded except the L2 agent)
Sean M. Collins2a242512016-05-03 09:03:09 -0400564function start_mutnauq_l2_agent {
Davanum Srinivas59756e92015-09-23 17:42:54 -0400565 run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
Nachi Ueno584750f2013-07-15 18:22:21 -0700566
Kahou Leid663e292015-10-24 12:18:57 -0700567 if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then
Zhongyue Luo56b7efb2014-12-16 11:36:49 +0800568 sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400569 sudo ip link set $OVS_PHYSICAL_BRIDGE up
570 sudo ip link set br-int up
571 sudo ip link set $PUBLIC_INTERFACE up
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700572 if is_ironic_hardware; then
573 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
574 sudo ip addr del $IP dev $PUBLIC_INTERFACE
575 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
576 done
gong yong sheng348c6ac2015-06-23 14:03:47 +0800577 sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700578 fi
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400579 fi
Russell Bryant09b94602015-06-08 15:25:43 -0400580}
581
Sean M. Collins2a242512016-05-03 09:03:09 -0400582function start_mutnauq_other_agents {
Angus Leesa1c70f22016-05-31 14:43:14 +1000583 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 -0400584
YAMAMOTO Takashi6839d422017-10-17 12:58:18 +0900585 run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700586
Angus Leesa1c70f22016-05-31 14:43:14 +1000587 run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file $Q_META_CONF_FILE"
Davanum Srinivas59756e92015-09-23 17:42:54 -0400588 run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400589}
590
Russell Bryant09b94602015-06-08 15:25:43 -0400591# Start running processes, including screen
592function start_neutron_agents {
593 # Start up the neutron agents if enabled
Sean M. Collins2a242512016-05-03 09:03:09 -0400594 start_mutnauq_l2_agent
595 start_mutnauq_other_agents
Russell Bryant09b94602015-06-08 15:25:43 -0400596}
597
Sean M. Collins2a242512016-05-03 09:03:09 -0400598function stop_mutnauq_l2_agent {
Russell Bryant09b94602015-06-08 15:25:43 -0400599 stop_process q-agt
600}
601
Sean Dague0eebeb42017-08-30 14:16:58 -0400602# stop_mutnauq_other() - Stop running processes
Sean M. Collins2a242512016-05-03 09:03:09 -0400603function stop_mutnauq_other {
Mark McClainb05c8762013-07-06 23:29:39 -0400604 if is_service_enabled q-dhcp; then
Chris Dent36891dc2015-02-03 16:22:44 +0000605 stop_process q-dhcp
Mark McClainb05c8762013-07-06 23:29:39 -0400606 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
607 [ ! -z "$pid" ] && sudo kill -9 $pid
608 fi
Chris Dent36891dc2015-02-03 16:22:44 +0000609
Kevin Benton66b361b2017-06-13 00:31:01 -0700610 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
611 stop_process neutron-rpc-server
612 stop_process neutron-api
613 else
614 stop_process q-svc
615 fi
Li Maa15d9de2016-01-19 19:11:51 +0800616
617 if is_service_enabled q-l3; then
618 sudo pkill -f "radvd -C $DATA_DIR/neutron/ra"
619 stop_process q-l3
620 fi
Chris Dent36891dc2015-02-03 16:22:44 +0000621
Mark McClainb05c8762013-07-06 23:29:39 -0400622 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100623 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Chris Dent36891dc2015-02-03 16:22:44 +0000624 stop_process q-meta
Mark McClainb05c8762013-07-06 23:29:39 -0400625 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900626
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900627 if is_service_enabled q-metering; then
628 neutron_metering_stop
629 fi
Li Ma50120fa2015-12-13 10:41:34 +0800630
631 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
632 sudo pkill -9 -f $NEUTRON_ROOTWRAP-daemon || :
633 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400634}
635
Russell Bryant09b94602015-06-08 15:25:43 -0400636# stop_neutron() - Stop running processes (non-screen)
Sean M. Collins2a242512016-05-03 09:03:09 -0400637function stop_mutnauq {
638 stop_mutnauq_other
639 stop_mutnauq_l2_agent
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100640
641 if [[ $Q_AGENT == "ovn" ]]; then
642 stop_ovn
643 fi
Russell Bryant09b94602015-06-08 15:25:43 -0400644}
645
Sean M. Collins00e16a92015-02-20 11:45:21 -0500646# _move_neutron_addresses_route() - Move the primary IP to the OVS bridge
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600647# on startup, or back to the public interface on cleanup. If no IP is
648# configured on the interface, just add it as a port to the OVS bridge.
Sean M. Collins00e16a92015-02-20 11:45:21 -0500649function _move_neutron_addresses_route {
650 local from_intf=$1
651 local to_intf=$2
652 local add_ovs_port=$3
Brian Haleya0d1b012015-11-16 17:30:48 -0500653 local del_ovs_port=$4
654 local af=$5
Sean M. Collins00e16a92015-02-20 11:45:21 -0500655
656 if [[ -n "$from_intf" && -n "$to_intf" ]]; then
657 # Remove the primary IP address from $from_intf and add it to $to_intf,
658 # along with the default route, if it exists. Also, when called
659 # on configure we will also add $from_intf as a port on $to_intf,
660 # assuming it is an OVS bridge.
661
Matt McEuene24707b2016-07-11 08:37:59 -0500662 local IP_REPLACE=""
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600663 local IP_DEL=""
Shinobu KINJOf95315b2015-11-07 10:21:08 +0900664 local IP_UP=""
Ian Wienandada886d2015-10-07 14:06:26 +1100665 local DEFAULT_ROUTE_GW
Andreas Scheuring92e6b1a2017-04-26 13:40:42 +0200666 DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf\s/ { print \$3; exit }")
Sean M. Collins00e16a92015-02-20 11:45:21 -0500667 local ADD_OVS_PORT=""
Brian Haleya0d1b012015-11-16 17:30:48 -0500668 local DEL_OVS_PORT=""
Sean M. Collins17398a32016-05-11 18:24:46 +0000669 local ARP_CMD=""
Sean M. Collins00e16a92015-02-20 11:45:21 -0500670
Brian Haleybb9caea2015-11-16 17:18:42 -0500671 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 -0600672
Sean M. Collins00e16a92015-02-20 11:45:21 -0500673 if [ "$DEFAULT_ROUTE_GW" != "" ]; then
Sean M. Collins59e86a32015-11-09 11:06:39 -0500674 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 -0500675 fi
676
677 if [[ "$add_ovs_port" == "True" ]]; then
Raman Budnydb02bbf2015-03-31 13:09:09 +0300678 ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf"
Sean M. Collins00e16a92015-02-20 11:45:21 -0500679 fi
680
Brian Haleya0d1b012015-11-16 17:30:48 -0500681 if [[ "$del_ovs_port" == "True" ]]; then
682 DEL_OVS_PORT="sudo ovs-vsctl --if-exists del-port $from_intf $to_intf"
683 fi
684
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600685 if [[ "$IP_BRD" != "" ]]; then
Brian Haley94510212015-09-02 15:40:04 -0400686 IP_DEL="sudo ip addr del $IP_BRD dev $from_intf"
Matt McEuene24707b2016-07-11 08:37:59 -0500687 IP_REPLACE="sudo ip addr replace $IP_BRD dev $to_intf"
Shinobu KINJOf95315b2015-11-07 10:21:08 +0900688 IP_UP="sudo ip link set $to_intf up"
Sean M. Collins6d4843e2016-05-12 16:14:26 -0400689 if [[ "$af" == "inet" ]]; then
690 IP=$(echo $IP_BRD | awk '{ print $1; exit }' | grep -o -E '(.*)/' | cut -d "/" -f1)
Rodolfo Alonso Hernandezca486c52020-06-25 18:22:28 +0000691 ARP_CMD="sudo arping -A -c 3 -w 5 -I $to_intf $IP "
Sean M. Collins6d4843e2016-05-12 16:14:26 -0400692 fi
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600693 fi
694
Brian Haleya0d1b012015-11-16 17:30:48 -0500695 # The add/del OVS port calls have to happen either before or
696 # after the address is moved in order to not leave it orphaned.
Matt McEuene24707b2016-07-11 08:37:59 -0500697 $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 -0500698 fi
699}
700
Slawek Kaplonskib1a89eb2021-08-26 21:42:32 +0200701# _configure_public_network_connectivity() - Configures connectivity to the
702# external network using $PUBLIC_INTERFACE or NAT on the single interface
703# machines
704function _configure_public_network_connectivity {
705 # If we've given a PUBLIC_INTERFACE to take over, then we assume
706 # that we can own the whole thing, and privot it into the OVS
707 # bridge. If we are not, we're probably on a single interface
708 # machine, and we just setup NAT so that fixed guests can get out.
709 if [[ -n "$PUBLIC_INTERFACE" ]]; then
710 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" True False "inet"
711
712 if [[ $(ip -f inet6 a s dev "$PUBLIC_INTERFACE" | grep -c 'global') != 0 ]]; then
713 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" False False "inet6"
714 fi
715 else
716 for d in $default_v4_route_devs; do
717 sudo iptables -t nat -A POSTROUTING -o $d -s $FLOATING_RANGE -j MASQUERADE
718 done
719 fi
720}
721
Sean M. Collins2a242512016-05-03 09:03:09 -0400722# cleanup_mutnauq() - Remove residual data files, anything left over from previous
Mark McClainb05c8762013-07-06 23:29:39 -0400723# runs that a clean run would need to clean up
Sean M. Collins2a242512016-05-03 09:03:09 -0400724function cleanup_mutnauq {
Sean M. Collins00e16a92015-02-20 11:45:21 -0500725
Yalei Wang316b3482015-07-15 21:00:31 +0800726 if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then
Brian Haleya0d1b012015-11-16 17:30:48 -0500727 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False True "inet"
Adam Kacmarsky11298a02015-06-26 14:49:47 -0600728
Yalei Wang316b3482015-07-15 21:00:31 +0800729 if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then
Sean M. Collins790266f2015-11-11 13:36:35 -0500730 # ip(8) wants the prefix length when deleting
731 local v6_gateway
732 v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }')
733 sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE
Brian Haleya0d1b012015-11-16 17:30:48 -0500734 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False False "inet6"
Yalei Wang316b3482015-07-15 21:00:31 +0800735 fi
Sean M. Collins00e16a92015-02-20 11:45:21 -0500736
Yalei Wang316b3482015-07-15 21:00:31 +0800737 if is_provider_network && is_ironic_hardware; then
738 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
739 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
740 sudo ip addr add $IP dev $PUBLIC_INTERFACE
741 done
742 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
743 fi
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700744 fi
745
Mark McClainb05c8762013-07-06 23:29:39 -0400746 if is_neutron_ovs_base_plugin; then
747 neutron_ovs_base_cleanup
748 fi
749
Sean M. Collins7bc2af72015-06-08 12:36:30 -0400750 if [[ $Q_AGENT == "linuxbridge" ]]; then
751 neutron_lb_cleanup
752 fi
753
Mark McClainb05c8762013-07-06 23:29:39 -0400754 # delete all namespaces created by neutron
Doug Wiegley7e40c642016-08-20 16:32:14 +0000755 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 -0400756 sudo ip netns delete ${ns}
757 done
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100758
759 if [[ $Q_AGENT == "ovn" ]]; then
760 cleanup_ovn
761 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400762}
763
Doug Wiegley93e682c2015-03-03 10:31:30 -0700764
Maru Newby952fd902015-01-30 22:27:12 +0000765function _create_neutron_conf_dir {
Mark McClainb05c8762013-07-06 23:29:39 -0400766 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
Dean Troyer8421c2b2015-03-16 13:52:19 -0500767 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
Maru Newby952fd902015-01-30 22:27:12 +0000768}
769
770# _configure_neutron_common()
771# Set common config for all neutron server and agents.
772# This MUST be called before other ``_configure_neutron_*`` functions.
773function _configure_neutron_common {
774 _create_neutron_conf_dir
Mark McClainb05c8762013-07-06 23:29:39 -0400775
Martin Hickey30d5fae2015-11-10 13:44:15 +0000776 # Uses oslo config generator to generate core sample configuration files
777 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
778
779 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
Mark McClainb05c8762013-07-06 23:29:39 -0400780
Jerry Zhao296c1e32015-08-07 20:43:54 -0400781 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
Jerry Zhao296c1e32015-08-07 20:43:54 -0400782
783 # allow neutron user to administer neutron to match neutron account
Akihiro Motoki80769c52018-11-23 05:18:40 +0900784 # NOTE(amotoki): This is required for nova works correctly with neutron.
785 if [ -f $NEUTRON_DIR/etc/policy.json ]; then
786 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
787 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
788 else
789 echo '{"context_is_admin": "role:admin or user_name:neutron"}' > $Q_POLICY_FILE
790 fi
Jerry Zhao296c1e32015-08-07 20:43:54 -0400791
Mark McClainb05c8762013-07-06 23:29:39 -0400792 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
793 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
Mark McClainb05c8762013-07-06 23:29:39 -0400794 neutron_plugin_configure_common
795
sbauzae2c4ee22013-08-29 17:29:46 +0200796 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400797 die $LINENO "Neutron plugin not set.. exiting"
798 fi
799
800 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
801 mkdir -p /$Q_PLUGIN_CONF_PATH
802 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
Hirofumi Ichihara97cc85b2015-09-08 13:51:01 +0900803 # NOTE(hichihara): Some neutron vendor plugins were already decomposed and
804 # there is no config file in Neutron tree. They should prepare the file in each plugin.
Martin Hickey30d5fae2015-11-10 13:44:15 +0000805 if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then
806 cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE
807 elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then
Hirofumi Ichihara97cc85b2015-09-08 13:51:01 +0900808 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
809 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400810
Ihar Hrachyshkab816e5d2014-07-21 13:53:50 +0200811 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
Mark McClainb05c8762013-07-06 23:29:39 -0400812 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
salvatoree4e535b2014-10-29 18:22:46 +0100813 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
Brian Haley180f5eb2015-06-16 13:14:31 -0400814 iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS
Martin Hickey30d5fae2015-11-10 13:44:15 +0000815 iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock
816
Victor Ryzhenkin878d7d82016-04-27 15:15:52 +0300817 # NOTE(freerunner): Need to adjust Region Name for nova in multiregion installation
818 iniset $NEUTRON_CONF nova region_name $REGION_NAME
819
Joe Gordonbee5c502013-08-30 13:48:08 -0400820 if [ "$VIRT_DRIVER" = 'fake' ]; then
821 # Disable arbitrary limits
822 iniset $NEUTRON_CONF quotas quota_network -1
823 iniset $NEUTRON_CONF quotas quota_subnet -1
824 iniset $NEUTRON_CONF quotas quota_port -1
825 iniset $NEUTRON_CONF quotas quota_security_group -1
826 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
827 fi
828
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700829 # Format logging
Sean Dague9751be62016-04-05 12:08:57 -0400830 setup_logging $NEUTRON_CONF
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700831
Kevin Benton66b361b2017-06-13 00:31:01 -0700832 if is_service_enabled tls-proxy && [ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" ]; then
Rob Crittenden18d47782014-03-19 17:47:42 -0400833 # Set the service port for a proxy to take the original
834 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
Jens Harbott411c34d2017-08-29 14:40:26 +0000835 iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True
Rob Crittenden18d47782014-03-19 17:47:42 -0400836 fi
837
Mark McClainb05c8762013-07-06 23:29:39 -0400838 _neutron_setup_rootwrap
839}
840
Ian Wienandaee18c72014-02-21 15:35:08 +1100841function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400842
Martin Hickey30d5fae2015-11-10 13:44:15 +0000843 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400844
Ben Nemec03997942013-08-10 09:56:16 -0500845 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Sean Dague78801c12016-08-04 14:10:07 -0400846 # make it so we have working DNS from guests
847 iniset $Q_DHCP_CONF_FILE DEFAULT dnsmasq_local_resolv True
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700848 iniset $Q_DHCP_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400849 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700850 iniset $Q_DHCP_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400851 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400852
Tan Lin27a196e2014-10-31 15:44:34 +0800853 if ! is_service_enabled q-l3; then
854 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
855 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
856 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
857 else
858 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
859 die "$LINENO" "Enable isolated metadata is a must for metadata network"
860 fi
861 fi
862 fi
863
Mark McClainb05c8762013-07-06 23:29:39 -0400864 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
865
xurong000379977ef31d02016-07-05 11:09:40 +0800866 neutron_plugin_configure_dhcp_agent $Q_DHCP_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400867}
868
Mark McClainb05c8762013-07-06 23:29:39 -0400869
Ian Wienandaee18c72014-02-21 15:35:08 +1100870function _configure_neutron_metadata_agent {
Martin Hickey30d5fae2015-11-10 13:44:15 +0000871 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400872
Ben Nemec03997942013-08-10 09:56:16 -0500873 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Brian Haleyefc51682017-11-10 00:50:48 -0500874 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_host $Q_META_DATA_IP
Armando Migliaccio06f2ea22017-02-02 16:47:00 -0800875 iniset $Q_META_CONF_FILE DEFAULT metadata_workers $API_WORKERS
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700876 iniset $Q_META_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400877 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700878 iniset $Q_META_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400879 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400880}
881
Dina Belova58adaa62014-07-11 18:18:12 +0400882function _configure_neutron_ceilometer_notifications {
Matt Riedemann45da7772017-03-05 13:07:39 -0500883 iniset $NEUTRON_CONF oslo_messaging_notifications driver messagingv2
Dina Belova58adaa62014-07-11 18:18:12 +0400884}
885
Ian Wienandaee18c72014-02-21 15:35:08 +1100886function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +0200887 neutron_agent_metering_configure_common
888 neutron_agent_metering_configure_agent
889}
890
Brian Haleyeea76212014-06-27 11:45:50 -0400891function _configure_dvr {
892 iniset $NEUTRON_CONF DEFAULT router_distributed True
893 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
894}
895
896
Mark McClainb05c8762013-07-06 23:29:39 -0400897# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
898# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100899function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400900 # Specify the default root helper prior to agent configuration to
901 # ensure that an agent's configuration can override the default
902 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400903 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
904 iniset /$Q_PLUGIN_CONF_FILE agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
905 fi
Ben Nemec03997942013-08-10 09:56:16 -0500906 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400907
908 # Configure agent for plugin
909 neutron_plugin_configure_plugin_agent
910}
911
912# _configure_neutron_service() - Set config files for neutron service
913# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100914function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -0400915 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
Mark McClainb05c8762013-07-06 23:29:39 -0400916 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700917
Mark McClainb05c8762013-07-06 23:29:39 -0400918 # Update either configuration file with plugin
919 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
920
Ben Nemec03997942013-08-10 09:56:16 -0500921 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Chris Dent74a85b02015-04-22 18:02:39 +0000922 iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400923 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
924
925 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100926 configure_keystone_authtoken_middleware $NEUTRON_CONF $Q_ADMIN_USERNAME
Mark McClainb05c8762013-07-06 23:29:39 -0400927
Atsushi SAKAIfe7b56c2015-11-13 17:06:16 +0900928 # Configuration for neutron notifications to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -0500929 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
930 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Jamie Lennoxdc757dd2015-03-09 14:48:09 +1100931
Dirk Mueller8ab64b32017-11-17 19:52:29 +0100932 configure_keystone_authtoken_middleware $NEUTRON_CONF nova nova
Aaron Rosencea32b12014-03-04 16:20:14 -0800933
Mark McClainb05c8762013-07-06 23:29:39 -0400934 # Configure plugin
935 neutron_plugin_configure_service
936}
937
938# Utility Functions
939#------------------
940
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900941# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +1100942function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900943 local service_plugin_class=$1
944 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
945 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
946 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
947 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
948 fi
949}
950
Ihar Hrachyshkaf511c362017-03-07 06:31:49 +0000951# _neutron_ml2_extension_driver_add_old() - add ML2 extension driver
952function _neutron_ml2_extension_driver_add_old {
953 local extension=$1
954 if [[ $Q_ML2_PLUGIN_EXT_DRIVERS == '' ]]; then
955 Q_ML2_PLUGIN_EXT_DRIVERS=$extension
956 elif [[ ! ,${Q_ML2_PLUGIN_EXT_DRIVERS}, =~ ,${extension}, ]]; then
957 Q_ML2_PLUGIN_EXT_DRIVERS="$Q_ML2_PLUGIN_EXT_DRIVERS,$extension"
958 fi
959}
960
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900961# mutnauq_server_config_add() - add server config file
962function mutnauq_server_config_add {
963 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($1)
964}
965
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100966# _neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root).
967function _neutron_deploy_rootwrap_filters {
gong yong sheng3d6eaae2015-09-15 15:00:29 +0800968 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
969 return
970 fi
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100971 local srcdir=$1
Dean Troyer8421c2b2015-03-16 13:52:19 -0500972 sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D
973 sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100974}
975
Mark McClainb05c8762013-07-06 23:29:39 -0400976# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100977function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -0400978 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
979 return
980 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400981 # Wipe any existing ``rootwrap.d`` files first
982 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
983 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
984 sudo rm -rf $Q_CONF_ROOTWRAP_D
985 fi
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100986
987 _neutron_deploy_rootwrap_filters $NEUTRON_DIR
988
Mark McClainb05c8762013-07-06 23:29:39 -0400989 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
990 # location moved in newer versions, prefer new location
991 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Dean Troyer8421c2b2015-03-16 13:52:19 -0500992 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 -0400993 else
Dean Troyer8421c2b2015-03-16 13:52:19 -0500994 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400995 fi
996 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
Robert Li2c5d4622015-04-21 15:48:22 -0400997 sudo sed -e 's:^exec_dirs=\(.*\)$:exec_dirs=\1,/usr/local/bin:' -i $Q_RR_CONF_FILE
998
Mark McClainb05c8762013-07-06 23:29:39 -0400999 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
1000 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
Yuriy Taraday26623952014-07-16 17:41:53 +04001001 ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -04001002
1003 # Set up the rootwrap sudoers for neutron
1004 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +01001005 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Yuriy Taraday26623952014-07-16 17:41:53 +04001006 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -04001007 chmod 0440 $TEMPFILE
1008 sudo chown root:root $TEMPFILE
1009 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
1010
1011 # Update the root_helper
1012 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +04001013 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
1014 iniset $NEUTRON_CONF agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
1015 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001016}
1017
Ian Wienandaee18c72014-02-21 15:35:08 +11001018function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -04001019
1020 # ovs_use_veth needs to be set before the plugin configuration
1021 # occurs to allow plugins to override the setting.
1022 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1023
1024 neutron_plugin_setup_interface_driver $1
1025}
Mark McClainb05c8762013-07-06 23:29:39 -04001026# Functions for Neutron Exercises
1027#--------------------------------
1028
Ian Wienandaee18c72014-02-21 15:35:08 +11001029function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -04001030 local from_net="$1"
1031 net_id=`_get_net_id $from_net`
1032 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}'`
1033 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
1034}
1035
Ian Wienandaee18c72014-02-21 15:35:08 +11001036function _get_net_id {
Brian Haley4bc42c72017-11-07 15:22:00 -05001037 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 -04001038}
1039
Ian Wienandaee18c72014-02-21 15:35:08 +11001040function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -04001041 local from_net="$1"
1042 net_id=`_get_net_id $from_net`
1043 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`
1044 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
1045}
1046
Mark McClainb05c8762013-07-06 23:29:39 -04001047# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +11001048function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001049 local from_net=$1
1050 local key_file=$2
1051 local ip=$3
1052 local user=$4
1053 local timeout_sec=$5
1054 local probe_cmd = ""
1055 probe_cmd=`_get_probe_cmd_prefix $from_net`
Sean Dague442e4e92015-06-24 13:24:02 -04001056 local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success"
1057 test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec
Mark McClainb05c8762013-07-06 23:29:39 -04001058}
1059
Slawek Kaplonskifaed11d2021-11-18 10:36:57 +01001060function plugin_agent_add_l2_agent_extension {
1061 local l2_agent_extension=$1
1062 if [[ -z "$L2_AGENT_EXTENSIONS" ]]; then
1063 L2_AGENT_EXTENSIONS=$l2_agent_extension
1064 elif [[ ! ,${L2_AGENT_EXTENSIONS}, =~ ,${l2_agent_extension}, ]]; then
1065 L2_AGENT_EXTENSIONS+=",$l2_agent_extension"
1066 fi
1067}
1068
Mark McClainb05c8762013-07-06 23:29:39 -04001069# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +11001070$_XTRACE_NEUTRON
Mark McClainb05c8762013-07-06 23:29:39 -04001071
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001072# Tell emacs to use shell-script-mode
1073## Local variables:
1074## mode: shell-script
1075## End: