blob: 39f41fdccc263d4f8be696e5b62a87de8e9ac4af [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.
53#
54# With Neutron networking the NETWORK_MANAGER variable is ignored.
Mark McClainb05c8762013-07-06 23:29:39 -040055
John Davidge21529a52014-06-30 09:55:11 -040056# Settings
57# --------
58
Mark McClainb05c8762013-07-06 23:29:39 -040059
60# Neutron Network Configuration
61# -----------------------------
62
Matthew Treinishabde96a2016-05-12 19:26:20 -040063deprecated "Using lib/neutron-legacy is deprecated, and it will be removed in the future"
Armando Migliaccio7dbcfae2016-02-19 14:43:42 -080064
Sean Daguef3b2f4c2017-04-13 10:11:48 -040065if is_service_enabled tls-proxy; then
Rob Crittenden18d47782014-03-19 17:47:42 -040066 Q_PROTOCOL="https"
67fi
68
69
Mark McClainb05c8762013-07-06 23:29:39 -040070# Set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050071GITDIR["python-neutronclient"]=$DEST/python-neutronclient
Sean Dague5cb19062014-11-01 01:37:45 +010072
Doug Wiegley93e682c2015-03-03 10:31:30 -070073
Mark McClainb05c8762013-07-06 23:29:39 -040074NEUTRON_DIR=$DEST/neutron
Kyle Mestery20b839f2014-12-08 06:17:27 +000075NEUTRON_FWAAS_DIR=$DEST/neutron-fwaas
Ian Wienand1f82f432017-10-04 09:51:02 +110076NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
Mark McClainb05c8762013-07-06 23:29:39 -040077
78# Support entry points installation of console scripts
79if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
80 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
Sean Dague3bdb9222013-10-22 08:36:16 -040081else
82 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
Mark McClainb05c8762013-07-06 23:29:39 -040083fi
84
85NEUTRON_CONF_DIR=/etc/neutron
86NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
87export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
88
Adam Gandelman7614d212014-08-11 14:27:50 -070089# Agent binaries. Note, binary paths for other agents are set in per-service
90# scripts in lib/neutron_plugins/services/
91AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
92AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
93AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
94
95# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
96# loaded from per-plugin scripts in lib/neutron_plugins/
97Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
98Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
Adam Gandelman7614d212014-08-11 14:27:50 -070099Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
100
Henry Gessau0fc1cc22014-07-06 22:54:34 -0400101# Default name for Neutron database
102Q_DB_NAME=${Q_DB_NAME:-neutron}
Mark McClainb05c8762013-07-06 23:29:39 -0400103# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +0000104Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -0400105# Default Neutron Port
106Q_PORT=${Q_PORT:-9696}
Rob Crittenden18d47782014-03-19 17:47:42 -0400107# Default Neutron Internal Port when using TLS proxy
108Q_PORT_INT=${Q_PORT_INT:-19696}
Mark McClainb05c8762013-07-06 23:29:39 -0400109# Default Neutron Host
110Q_HOST=${Q_HOST:-$SERVICE_HOST}
Rob Crittenden18d47782014-03-19 17:47:42 -0400111# Default protocol
112Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
Brian Haley180f5eb2015-06-16 13:14:31 -0400113# Default listen address
114Q_LISTEN_ADDRESS=${Q_LISTEN_ADDRESS:-$SERVICE_LISTEN_ADDRESS}
Mark McClainb05c8762013-07-06 23:29:39 -0400115# Default admin username
116Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
117# Default auth strategy
118Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
Mark McClainb05c8762013-07-06 23:29:39 -0400119# RHEL's support for namespaces requires using veths with ovs
120Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
121Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
Yuriy Taraday26623952014-07-16 17:41:53 +0400122Q_USE_ROOTWRAP_DAEMON=$(trueorfalse True Q_USE_ROOTWRAP_DAEMON)
Mark McClainb05c8762013-07-06 23:29:39 -0400123# Meta data IP
124Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
125# Allow Overlapping IP among subnets
126Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
Terry Wilsonf06c4432014-05-20 10:54:51 -0500127Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
128Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
Aaron Rosencea32b12014-03-04 16:20:14 -0800129VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
130VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Aaron Rosen4540d002013-10-24 13:59:33 -0700131
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900132# The directory which contains files for Q_PLUGIN_EXTRA_CONF_FILES.
133# /etc/neutron is assumed by many of devstack plugins. Do not change.
134_Q_PLUGIN_EXTRA_CONF_PATH=/etc/neutron
135
Mark McClainb05c8762013-07-06 23:29:39 -0400136# List of config file names in addition to the main plugin config file
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900137# To add additional plugin config files, use ``neutron_server_config_add``
138# utility function. For example:
139#
140# ``neutron_server_config_add file1``
141#
142# These config files are relative to ``/etc/neutron``. The above
143# example would specify ``--config-file /etc/neutron/file1`` for
144# neutron server.
Sean Dagueafef8bf2017-03-06 14:07:23 -0500145declare -a -g Q_PLUGIN_EXTRA_CONF_FILES
Mark McClainb05c8762013-07-06 23:29:39 -0400146
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900147# same as Q_PLUGIN_EXTRA_CONF_FILES, but with absolute path.
Sean Dagueafef8bf2017-03-06 14:07:23 -0500148declare -a -g _Q_PLUGIN_EXTRA_CONF_FILES_ABS
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900149
Mark McClainb05c8762013-07-06 23:29:39 -0400150
Dean Troyere2907b42014-02-26 17:35:37 -0600151Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
152if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
153 Q_RR_COMMAND="sudo"
154else
155 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
156 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
Yuriy Taraday26623952014-07-16 17:41:53 +0400157 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
158 Q_RR_DAEMON_COMMAND="sudo $NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
159 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400160fi
161
Brian Haleyeea76212014-06-27 11:45:50 -0400162
163# Distributed Virtual Router (DVR) configuration
164# Can be:
Dean Troyer3324f192014-09-18 09:26:39 -0500165# - ``legacy`` - No DVR functionality
166# - ``dvr_snat`` - Controller or single node DVR
167# - ``dvr`` - Compute node in multi-node DVR
168#
Brian Haleyeea76212014-06-27 11:45:50 -0400169Q_DVR_MODE=${Q_DVR_MODE:-legacy}
170if [[ "$Q_DVR_MODE" != "legacy" ]]; then
Brian Haleye43dfdd2017-09-12 16:13:26 -0600171 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,l2population
Brian Haleyeea76212014-06-27 11:45:50 -0400172fi
173
Dean Troyere2907b42014-02-26 17:35:37 -0600174# Provider Network Configurations
175# --------------------------------
176
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900177# The following variables control the Neutron ML2 plugins' allocation
178# of tenant networks and availability of provider networks. If these
179# are not configured in ``localrc``, tenant networks will be local to
180# the host (with no remote connectivity), and no physical resources
181# will be available for the allocation of provider networks.
Dean Troyere2907b42014-02-26 17:35:37 -0600182
Attila Fazekas8feaf6c2014-07-27 20:47:04 +0200183# To disable tunnels (GRE or VXLAN) for tenant networks,
184# set to False in ``local.conf``.
185# GRE tunnels are only supported by the openvswitch.
186ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
Dean Troyere2907b42014-02-26 17:35:37 -0600187
Richard Theis8906b482016-06-08 10:28:37 -0500188# If using GRE, VXLAN or GENEVE tunnels for tenant networks,
189# specify the range of IDs from which tenant networks are
190# allocated. Can be overridden in ``localrc`` if necessary.
Anant Patil3827dc02014-07-03 21:38:16 +0530191TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
Dean Troyere2907b42014-02-26 17:35:37 -0600192
193# To use VLANs for tenant networks, set to True in localrc. VLANs
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900194# are supported by the ML2 plugins, requiring additional configuration
195# described below.
Dean Troyere2907b42014-02-26 17:35:37 -0600196ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
197
198# If using VLANs for tenant networks, set in ``localrc`` to specify
199# the range of VLAN VIDs from which tenant networks are
200# allocated. An external network switch must be configured to
201# trunk these VLANs between hosts for multi-host connectivity.
202#
203# Example: ``TENANT_VLAN_RANGE=1000:1999``
204TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
205
206# If using VLANs for tenant networks, or if using flat or VLAN
207# provider networks, set in ``localrc`` to the name of the physical
208# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
209# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
210# agent, as described below.
211#
212# Example: ``PHYSICAL_NETWORK=default``
Kevin Benton1554ade2016-07-22 09:40:19 -0700213PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-public}
Dean Troyere2907b42014-02-26 17:35:37 -0600214
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900215# With the openvswitch agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600216# or if using flat or VLAN provider networks, set in ``localrc`` to
217# the name of the OVS bridge to use for the physical network. The
218# bridge will be created if it does not already exist, but a
219# physical interface must be manually added to the bridge as a
220# port for external connectivity.
221#
222# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
Kevin Benton1554ade2016-07-22 09:40:19 -0700223OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-br-ex}
Dean Troyere2907b42014-02-26 17:35:37 -0600224
Clark Boylan95469032016-09-08 17:08:36 -0700225default_route_dev=$(ip route | grep ^default | awk '{print $5}')
226die_if_not_set $LINENO default_route_dev "Failure retrieving default route device"
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900227# With the linuxbridge agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600228# or if using flat or VLAN provider networks, set in ``localrc`` to
229# the name of the network interface to use for the physical
230# network.
231#
232# Example: ``LB_PHYSICAL_INTERFACE=eth1``
Clark Boylan95469032016-09-08 17:08:36 -0700233LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-$default_route_dev}
Dean Troyere2907b42014-02-26 17:35:37 -0600234
Edgar Magana6f335b92014-07-10 15:42:44 -0700235# When Neutron tunnels are enabled it is needed to specify the
236# IP address of the end point in the local server. This IP is set
237# by default to the same IP address that the HOST IP.
238# This variable can be used to specify a different end point IP address
239# Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1``
240TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP}
241
Dean Troyere2907b42014-02-26 17:35:37 -0600242# With the openvswitch plugin, set to True in ``localrc`` to enable
243# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
244#
245# Example: ``OVS_ENABLE_TUNNELING=True``
246OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
247
Tan Lin27a196e2014-10-31 15:44:34 +0800248# Use DHCP agent for providing metadata service in the case of
249# without L3 agent (No Route Agent), set to True in localrc.
250ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
251
252# Add a static route as dhcp option, so the request to 169.254.169.254
253# will be able to reach through a route(DHCP agent)
254# This option require ENABLE_ISOLATED_METADATA = True
255ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
Mark McClainb05c8762013-07-06 23:29:39 -0400256# Neutron plugin specific functions
257# ---------------------------------
258
259# Please refer to ``lib/neutron_plugins/README.md`` for details.
Hirofumi Ichihara36daecd2015-07-23 17:50:40 +0900260if [ -f $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN ]; then
261 source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
262fi
Mark McClainb05c8762013-07-06 23:29:39 -0400263
Emilien Macchi40546f72013-09-24 15:10:25 +0200264# Agent metering service plugin functions
265# -------------------------------------------
266
267# Hardcoding for 1 service plugin for now
268source $TOP_DIR/lib/neutron_plugins/services/metering
269
Sean M. Collins2a242512016-05-03 09:03:09 -0400270# L3 Service functions
271source $TOP_DIR/lib/neutron_plugins/services/l3
Mark McClainb05c8762013-07-06 23:29:39 -0400272# Use security group or not
273if has_neutron_plugin_security_group; then
274 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
275else
276 Q_USE_SECGROUP=False
277fi
278
Dean Troyere2907b42014-02-26 17:35:37 -0600279# Save trace setting
Ian Wienand523f4882015-10-13 11:03:03 +1100280_XTRACE_NEUTRON=$(set +o | grep xtrace)
Dean Troyere2907b42014-02-26 17:35:37 -0600281set +o xtrace
282
283
Mark McClainb05c8762013-07-06 23:29:39 -0400284# Functions
285# ---------
286
Adam Gandelman7614d212014-08-11 14:27:50 -0700287function _determine_config_server {
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900288 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" != '' ]]; then
289 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" = "$_Q_PLUGIN_EXTRA_CONF_PATH" ]]; then
290 deprecated "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
291 else
292 die $LINENO "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
293 fi
294 fi
295 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 ]]; then
296 deprecated "Q_PLUGIN_EXTRA_CONF_FILES is deprecated. Use neutron_server_config_add instead."
297 fi
298 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
299 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($_Q_PLUGIN_EXTRA_CONF_PATH/$cfg_file)
300 done
301
Adam Gandelman7614d212014-08-11 14:27:50 -0700302 local cfg_file
303 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900304 for cfg_file in ${_Q_PLUGIN_EXTRA_CONF_FILES_ABS[@]}; do
Tom Patzig73467042016-04-19 17:02:34 +0200305 opts+=" --config-file $cfg_file"
Adam Gandelman7614d212014-08-11 14:27:50 -0700306 done
307 echo "$opts"
308}
309
Adam Gandelman7614d212014-08-11 14:27:50 -0700310function _determine_config_l3 {
Angus Leesa1c70f22016-05-31 14:43:14 +1000311 local opts="--config-file $NEUTRON_CONF --config-file $Q_L3_CONF_FILE"
Adam Gandelman7614d212014-08-11 14:27:50 -0700312 echo "$opts"
313}
314
315# For services and agents that require it, dynamically construct a list of
316# --config-file arguments that are passed to the binary.
317function determine_config_files {
318 local opts=""
319 case "$1" in
320 "neutron-server") opts="$(_determine_config_server)" ;;
Adam Gandelman7614d212014-08-11 14:27:50 -0700321 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
322 esac
323 if [ -z "$opts" ] ; then
324 die $LINENO "Could not determine config files for $1."
325 fi
326 echo "$opts"
327}
328
Sean M. Collins2a242512016-05-03 09:03:09 -0400329# configure_mutnauq()
Mark McClainb05c8762013-07-06 23:29:39 -0400330# Set common config for all neutron server and agents.
Sean M. Collins2a242512016-05-03 09:03:09 -0400331function configure_mutnauq {
Mark McClainb05c8762013-07-06 23:29:39 -0400332 _configure_neutron_common
Brant Knudson2dd110c2015-03-14 12:39:14 -0500333 iniset_rpc_backend neutron $NEUTRON_CONF
Mark McClainb05c8762013-07-06 23:29:39 -0400334
Emilien Macchi40546f72013-09-24 15:10:25 +0200335 if is_service_enabled q-metering; then
336 _configure_neutron_metering
337 fi
Stephen Ma9b38eb22014-04-02 02:13:09 +0000338 if is_service_enabled q-agt q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -0400339 _configure_neutron_service
340 fi
341 if is_service_enabled q-agt; then
342 _configure_neutron_plugin_agent
343 fi
344 if is_service_enabled q-dhcp; then
345 _configure_neutron_dhcp_agent
346 fi
347 if is_service_enabled q-l3; then
348 _configure_neutron_l3_agent
349 fi
350 if is_service_enabled q-meta; then
351 _configure_neutron_metadata_agent
352 fi
353
Brian Haleyeea76212014-06-27 11:45:50 -0400354 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
355 _configure_dvr
356 fi
Dina Belova58adaa62014-07-11 18:18:12 +0400357 if is_service_enabled ceilometer; then
358 _configure_neutron_ceilometer_notifications
359 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400360
armando-migliaccioe155b892015-06-12 08:55:02 -0700361 iniset $NEUTRON_CONF DEFAULT api_workers "$API_WORKERS"
Armando Migliaccio06f2ea22017-02-02 16:47:00 -0800362 # devstack is not a tool for running uber scale OpenStack
363 # clouds, therefore running without a dedicated RPC worker
364 # for state reports is more than adequate.
365 iniset $NEUTRON_CONF DEFAULT rpc_state_report_workers 0
Mark McClainb05c8762013-07-06 23:29:39 -0400366}
367
Ian Wienandaee18c72014-02-21 15:35:08 +1100368function create_nova_conf_neutron {
Sean Daguef21cc1f2016-03-04 11:08:32 -0500369 iniset $NOVA_CONF DEFAULT use_neutron True
Matthew Kassawara28af7962016-02-10 19:04:08 +0000370 iniset $NOVA_CONF neutron auth_type "password"
Sean Daguec13b8a12017-04-20 06:54:51 -0400371 iniset $NOVA_CONF neutron auth_url "$KEYSTONE_AUTH_URI"
Jamie Lennox394968f2015-08-28 09:18:26 +1000372 iniset $NOVA_CONF neutron username "$Q_ADMIN_USERNAME"
373 iniset $NOVA_CONF neutron password "$SERVICE_PASSWORD"
Jamie Lennoxcbcbd8f2016-01-21 16:08:14 -0600374 iniset $NOVA_CONF neutron user_domain_name "$SERVICE_DOMAIN_NAME"
Sean Dague7580a0c2016-02-17 06:23:36 -0500375 iniset $NOVA_CONF neutron project_name "$SERVICE_PROJECT_NAME"
Jamie Lennoxcbcbd8f2016-01-21 16:08:14 -0600376 iniset $NOVA_CONF neutron project_domain_name "$SERVICE_DOMAIN_NAME"
Gary Kotton13d385e2014-06-17 23:24:53 -0700377 iniset $NOVA_CONF neutron auth_strategy "$Q_AUTH_STRATEGY"
Bartosz Górski0abde392014-02-28 14:15:19 +0100378 iniset $NOVA_CONF neutron region_name "$REGION_NAME"
Rob Crittenden18d47782014-03-19 17:47:42 -0400379 iniset $NOVA_CONF neutron url "${Q_PROTOCOL}://$Q_HOST:$Q_PORT"
Mark McClainb05c8762013-07-06 23:29:39 -0400380
381 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
382 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
Jeff Peeler1143f7e2013-10-31 16:21:52 -0400383 iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
Mark McClainb05c8762013-07-06 23:29:39 -0400384 fi
385
Matt Riedemann925c2562015-08-25 13:40:25 -0700386 # optionally set options in nova_conf
Mark McClainb05c8762013-07-06 23:29:39 -0400387 neutron_plugin_create_nova_conf
388
Mark McClainb05c8762013-07-06 23:29:39 -0400389 if is_service_enabled q-meta; then
Gary Kottondd745502014-08-11 23:38:47 -0700390 iniset $NOVA_CONF neutron service_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400391 fi
Aaron Rosencea32b12014-03-04 16:20:14 -0800392
393 iniset $NOVA_CONF DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
394 iniset $NOVA_CONF DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Mark McClainb05c8762013-07-06 23:29:39 -0400395}
396
Sean M. Collins2a242512016-05-03 09:03:09 -0400397# create_mutnauq_accounts() - Set up common required neutron accounts
Mark McClainb05c8762013-07-06 23:29:39 -0400398
399# Tenant User Roles
400# ------------------------------------------------------------------
401# service neutron admin # if enabled
402
403# Migrated from keystone_data.sh
Sean M. Collins2a242512016-05-03 09:03:09 -0400404function create_mutnauq_accounts {
Mark McClainb05c8762013-07-06 23:29:39 -0400405 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100406
Jamie Lennox85ff5322015-01-28 14:28:01 +1000407 create_service_user "neutron"
Bartosz Górski0abde392014-02-28 14:15:19 +0100408
Sean Dague985e9582016-02-10 07:25:24 -0500409 get_or_create_service "neutron" "network" "Neutron Service"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000410 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500411 "network" \
412 "$REGION_NAME" \
Sean Dague985e9582016-02-10 07:25:24 -0500413 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/"
Mark McClainb05c8762013-07-06 23:29:39 -0400414 fi
415}
416
Sean M. Collins2a242512016-05-03 09:03:09 -0400417# init_mutnauq() - Initialize databases, etc.
418function init_mutnauq {
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200419 recreate_database $Q_DB_NAME
Clark Boylan633dbc32017-06-14 12:09:21 -0700420 time_start "dbsync"
Salvatore Orlandodd649882013-08-05 08:56:17 -0700421 # Run Neutron db migrations
422 $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 -0700423 time_stop "dbsync"
Mark McClainb05c8762013-07-06 23:29:39 -0400424}
425
Sean M. Collins2a242512016-05-03 09:03:09 -0400426# install_mutnauq() - Collect source and prepare
427function install_mutnauq {
Doug Wiegley86561c32016-02-10 18:37:21 -0700428 # Install neutron-lib from git so we make sure we're testing
429 # the latest code.
430 if use_library_from_git "neutron-lib"; then
431 git_clone_by_name "neutron-lib"
432 setup_dev_lib "neutron-lib"
433 fi
434
Mark McClainb05c8762013-07-06 23:29:39 -0400435 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
436 setup_develop $NEUTRON_DIR
437}
438
Mark McClainb05c8762013-07-06 23:29:39 -0400439# install_neutron_agent_packages() - Collect source and prepare
YAMAMOTO Takashic74315e2016-07-21 17:49:43 +0900440function install_neutron_agent_packages_mutnauq {
Robert Li72b3e442014-07-17 15:04:52 -0400441 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
442 if is_service_enabled q-l3; then
443 install_package radvd
444 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400445 # install packages that are specific to plugin agent(s)
446 if is_service_enabled q-agt q-dhcp q-l3; then
447 neutron_plugin_install_agent_packages
448 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400449}
450
YAMAMOTO Takashia1875b12017-02-23 05:44:22 +0900451# Finish neutron configuration
452function configure_neutron_after_post_config {
453 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
454 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
455 fi
456}
457
Sean Dague0eebeb42017-08-30 14:16:58 -0400458# Start running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100459function start_neutron_service_and_check {
Rob Crittenden18d47782014-03-19 17:47:42 -0400460 local service_port=$Q_PORT
461 local service_protocol=$Q_PROTOCOL
Ian Wienand7ae97292016-02-16 14:50:53 +1100462 local cfg_file_options
463
464 cfg_file_options="$(determine_config_files neutron-server)"
465
Rob Crittenden18d47782014-03-19 17:47:42 -0400466 if is_service_enabled tls-proxy; then
467 service_port=$Q_PORT_INT
468 service_protocol="http"
469 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400470 # Start the Neutron service
Davanum Srinivas59756e92015-09-23 17:42:54 -0400471 run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
Mark McClainb05c8762013-07-06 23:29:39 -0400472 echo "Waiting for Neutron to start..."
Sean Dague442e4e92015-06-24 13:24:02 -0400473
474 local testcmd="wget ${ssl_ca} --no-proxy -q -O- $service_protocol://$Q_HOST:$service_port"
475 test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
476
Rob Crittenden18d47782014-03-19 17:47:42 -0400477 # Start proxy if enabled
478 if is_service_enabled tls-proxy; then
Gregory Haynes4b49e402016-08-31 18:19:51 -0700479 start_tls_proxy neutron '*' $Q_PORT $Q_HOST $Q_PORT_INT
Rob Crittenden18d47782014-03-19 17:47:42 -0400480 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400481}
482
Russell Bryant09b94602015-06-08 15:25:43 -0400483# Control of the l2 agent is separated out to make it easier to test partial
484# upgrades (everything upgraded except the L2 agent)
Sean M. Collins2a242512016-05-03 09:03:09 -0400485function start_mutnauq_l2_agent {
Davanum Srinivas59756e92015-09-23 17:42:54 -0400486 run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
Nachi Ueno584750f2013-07-15 18:22:21 -0700487
Kahou Leid663e292015-10-24 12:18:57 -0700488 if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then
Zhongyue Luo56b7efb2014-12-16 11:36:49 +0800489 sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400490 sudo ip link set $OVS_PHYSICAL_BRIDGE up
491 sudo ip link set br-int up
492 sudo ip link set $PUBLIC_INTERFACE up
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700493 if is_ironic_hardware; then
494 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
495 sudo ip addr del $IP dev $PUBLIC_INTERFACE
496 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
497 done
gong yong sheng348c6ac2015-06-23 14:03:47 +0800498 sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700499 fi
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400500 fi
Russell Bryant09b94602015-06-08 15:25:43 -0400501}
502
Sean M. Collins2a242512016-05-03 09:03:09 -0400503function start_mutnauq_other_agents {
Angus Leesa1c70f22016-05-31 14:43:14 +1000504 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 -0400505
Paul Michalie4289c82015-08-14 11:49:27 -0400506 if is_service_enabled neutron-vpnaas; then
507 : # Started by plugin
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700508 else
Davanum Srinivas59756e92015-09-23 17:42:54 -0400509 run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700510 fi
511
Angus Leesa1c70f22016-05-31 14:43:14 +1000512 run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file $Q_META_CONF_FILE"
Davanum Srinivas59756e92015-09-23 17:42:54 -0400513 run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400514}
515
Russell Bryant09b94602015-06-08 15:25:43 -0400516# Start running processes, including screen
517function start_neutron_agents {
518 # Start up the neutron agents if enabled
Sean M. Collins2a242512016-05-03 09:03:09 -0400519 start_mutnauq_l2_agent
520 start_mutnauq_other_agents
Russell Bryant09b94602015-06-08 15:25:43 -0400521}
522
Sean M. Collins2a242512016-05-03 09:03:09 -0400523function stop_mutnauq_l2_agent {
Russell Bryant09b94602015-06-08 15:25:43 -0400524 stop_process q-agt
525}
526
Sean Dague0eebeb42017-08-30 14:16:58 -0400527# stop_mutnauq_other() - Stop running processes
Sean M. Collins2a242512016-05-03 09:03:09 -0400528function stop_mutnauq_other {
Mark McClainb05c8762013-07-06 23:29:39 -0400529 if is_service_enabled q-dhcp; then
Chris Dent36891dc2015-02-03 16:22:44 +0000530 stop_process q-dhcp
Mark McClainb05c8762013-07-06 23:29:39 -0400531 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
532 [ ! -z "$pid" ] && sudo kill -9 $pid
533 fi
Chris Dent36891dc2015-02-03 16:22:44 +0000534
535 stop_process q-svc
Li Maa15d9de2016-01-19 19:11:51 +0800536
537 if is_service_enabled q-l3; then
538 sudo pkill -f "radvd -C $DATA_DIR/neutron/ra"
539 stop_process q-l3
540 fi
Chris Dent36891dc2015-02-03 16:22:44 +0000541
Mark McClainb05c8762013-07-06 23:29:39 -0400542 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100543 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Chris Dent36891dc2015-02-03 16:22:44 +0000544 stop_process q-meta
Mark McClainb05c8762013-07-06 23:29:39 -0400545 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900546
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900547 if is_service_enabled q-metering; then
548 neutron_metering_stop
549 fi
Li Ma50120fa2015-12-13 10:41:34 +0800550
551 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
552 sudo pkill -9 -f $NEUTRON_ROOTWRAP-daemon || :
553 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400554}
555
Russell Bryant09b94602015-06-08 15:25:43 -0400556# stop_neutron() - Stop running processes (non-screen)
Sean M. Collins2a242512016-05-03 09:03:09 -0400557function stop_mutnauq {
558 stop_mutnauq_other
559 stop_mutnauq_l2_agent
Russell Bryant09b94602015-06-08 15:25:43 -0400560}
561
Sean M. Collins00e16a92015-02-20 11:45:21 -0500562# _move_neutron_addresses_route() - Move the primary IP to the OVS bridge
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600563# on startup, or back to the public interface on cleanup. If no IP is
564# configured on the interface, just add it as a port to the OVS bridge.
Sean M. Collins00e16a92015-02-20 11:45:21 -0500565function _move_neutron_addresses_route {
566 local from_intf=$1
567 local to_intf=$2
568 local add_ovs_port=$3
Brian Haleya0d1b012015-11-16 17:30:48 -0500569 local del_ovs_port=$4
570 local af=$5
Sean M. Collins00e16a92015-02-20 11:45:21 -0500571
572 if [[ -n "$from_intf" && -n "$to_intf" ]]; then
573 # Remove the primary IP address from $from_intf and add it to $to_intf,
574 # along with the default route, if it exists. Also, when called
575 # on configure we will also add $from_intf as a port on $to_intf,
576 # assuming it is an OVS bridge.
577
Matt McEuene24707b2016-07-11 08:37:59 -0500578 local IP_REPLACE=""
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600579 local IP_DEL=""
Shinobu KINJOf95315b2015-11-07 10:21:08 +0900580 local IP_UP=""
Ian Wienandada886d2015-10-07 14:06:26 +1100581 local DEFAULT_ROUTE_GW
Andreas Scheuring92e6b1a2017-04-26 13:40:42 +0200582 DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf\s/ { print \$3; exit }")
Sean M. Collins00e16a92015-02-20 11:45:21 -0500583 local ADD_OVS_PORT=""
Brian Haleya0d1b012015-11-16 17:30:48 -0500584 local DEL_OVS_PORT=""
Sean M. Collins17398a32016-05-11 18:24:46 +0000585 local ARP_CMD=""
Sean M. Collins00e16a92015-02-20 11:45:21 -0500586
Brian Haleybb9caea2015-11-16 17:18:42 -0500587 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 -0600588
Sean M. Collins00e16a92015-02-20 11:45:21 -0500589 if [ "$DEFAULT_ROUTE_GW" != "" ]; then
Sean M. Collins59e86a32015-11-09 11:06:39 -0500590 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 -0500591 fi
592
593 if [[ "$add_ovs_port" == "True" ]]; then
Raman Budnydb02bbf2015-03-31 13:09:09 +0300594 ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf"
Sean M. Collins00e16a92015-02-20 11:45:21 -0500595 fi
596
Brian Haleya0d1b012015-11-16 17:30:48 -0500597 if [[ "$del_ovs_port" == "True" ]]; then
598 DEL_OVS_PORT="sudo ovs-vsctl --if-exists del-port $from_intf $to_intf"
599 fi
600
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600601 if [[ "$IP_BRD" != "" ]]; then
Brian Haley94510212015-09-02 15:40:04 -0400602 IP_DEL="sudo ip addr del $IP_BRD dev $from_intf"
Matt McEuene24707b2016-07-11 08:37:59 -0500603 IP_REPLACE="sudo ip addr replace $IP_BRD dev $to_intf"
Shinobu KINJOf95315b2015-11-07 10:21:08 +0900604 IP_UP="sudo ip link set $to_intf up"
Sean M. Collins6d4843e2016-05-12 16:14:26 -0400605 if [[ "$af" == "inet" ]]; then
606 IP=$(echo $IP_BRD | awk '{ print $1; exit }' | grep -o -E '(.*)/' | cut -d "/" -f1)
607 ARP_CMD="arping -A -c 3 -w 4.5 -I $to_intf $IP "
608 fi
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600609 fi
610
Brian Haleya0d1b012015-11-16 17:30:48 -0500611 # The add/del OVS port calls have to happen either before or
612 # after the address is moved in order to not leave it orphaned.
Matt McEuene24707b2016-07-11 08:37:59 -0500613 $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 -0500614 fi
615}
616
Sean M. Collins2a242512016-05-03 09:03:09 -0400617# cleanup_mutnauq() - Remove residual data files, anything left over from previous
Mark McClainb05c8762013-07-06 23:29:39 -0400618# runs that a clean run would need to clean up
Sean M. Collins2a242512016-05-03 09:03:09 -0400619function cleanup_mutnauq {
Sean M. Collins00e16a92015-02-20 11:45:21 -0500620
Yalei Wang316b3482015-07-15 21:00:31 +0800621 if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then
Brian Haleya0d1b012015-11-16 17:30:48 -0500622 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False True "inet"
Adam Kacmarsky11298a02015-06-26 14:49:47 -0600623
Yalei Wang316b3482015-07-15 21:00:31 +0800624 if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then
Sean M. Collins790266f2015-11-11 13:36:35 -0500625 # ip(8) wants the prefix length when deleting
626 local v6_gateway
627 v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }')
628 sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE
Brian Haleya0d1b012015-11-16 17:30:48 -0500629 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False False "inet6"
Yalei Wang316b3482015-07-15 21:00:31 +0800630 fi
Sean M. Collins00e16a92015-02-20 11:45:21 -0500631
Yalei Wang316b3482015-07-15 21:00:31 +0800632 if is_provider_network && is_ironic_hardware; then
633 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
634 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
635 sudo ip addr add $IP dev $PUBLIC_INTERFACE
636 done
637 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
638 fi
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700639 fi
640
Mark McClainb05c8762013-07-06 23:29:39 -0400641 if is_neutron_ovs_base_plugin; then
642 neutron_ovs_base_cleanup
643 fi
644
Sean M. Collins7bc2af72015-06-08 12:36:30 -0400645 if [[ $Q_AGENT == "linuxbridge" ]]; then
646 neutron_lb_cleanup
647 fi
648
Mark McClainb05c8762013-07-06 23:29:39 -0400649 # delete all namespaces created by neutron
Doug Wiegley7e40c642016-08-20 16:32:14 +0000650 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 -0400651 sudo ip netns delete ${ns}
652 done
653}
654
Doug Wiegley93e682c2015-03-03 10:31:30 -0700655
Maru Newby952fd902015-01-30 22:27:12 +0000656function _create_neutron_conf_dir {
Mark McClainb05c8762013-07-06 23:29:39 -0400657 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
Dean Troyer8421c2b2015-03-16 13:52:19 -0500658 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
Maru Newby952fd902015-01-30 22:27:12 +0000659}
660
661# _configure_neutron_common()
662# Set common config for all neutron server and agents.
663# This MUST be called before other ``_configure_neutron_*`` functions.
664function _configure_neutron_common {
665 _create_neutron_conf_dir
Mark McClainb05c8762013-07-06 23:29:39 -0400666
Martin Hickey30d5fae2015-11-10 13:44:15 +0000667 # Uses oslo config generator to generate core sample configuration files
668 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
669
670 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
Mark McClainb05c8762013-07-06 23:29:39 -0400671
Jerry Zhao296c1e32015-08-07 20:43:54 -0400672 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
673 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
674
675 # allow neutron user to administer neutron to match neutron account
676 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
677
Mark McClainb05c8762013-07-06 23:29:39 -0400678 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
679 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
Mark McClainb05c8762013-07-06 23:29:39 -0400680 neutron_plugin_configure_common
681
sbauzae2c4ee22013-08-29 17:29:46 +0200682 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400683 die $LINENO "Neutron plugin not set.. exiting"
684 fi
685
686 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
687 mkdir -p /$Q_PLUGIN_CONF_PATH
688 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
Hirofumi Ichihara97cc85b2015-09-08 13:51:01 +0900689 # NOTE(hichihara): Some neutron vendor plugins were already decomposed and
690 # there is no config file in Neutron tree. They should prepare the file in each plugin.
Martin Hickey30d5fae2015-11-10 13:44:15 +0000691 if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then
692 cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE
693 elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then
Hirofumi Ichihara97cc85b2015-09-08 13:51:01 +0900694 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
695 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400696
Ihar Hrachyshkab816e5d2014-07-21 13:53:50 +0200697 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
Mark McClainb05c8762013-07-06 23:29:39 -0400698 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
salvatoree4e535b2014-10-29 18:22:46 +0100699 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
Brian Haley180f5eb2015-06-16 13:14:31 -0400700 iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS
Martin Hickey30d5fae2015-11-10 13:44:15 +0000701 iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock
702
Victor Ryzhenkin878d7d82016-04-27 15:15:52 +0300703 # NOTE(freerunner): Need to adjust Region Name for nova in multiregion installation
704 iniset $NEUTRON_CONF nova region_name $REGION_NAME
705
Joe Gordonbee5c502013-08-30 13:48:08 -0400706 if [ "$VIRT_DRIVER" = 'fake' ]; then
707 # Disable arbitrary limits
708 iniset $NEUTRON_CONF quotas quota_network -1
709 iniset $NEUTRON_CONF quotas quota_subnet -1
710 iniset $NEUTRON_CONF quotas quota_port -1
711 iniset $NEUTRON_CONF quotas quota_security_group -1
712 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
713 fi
714
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700715 # Format logging
Sean Dague9751be62016-04-05 12:08:57 -0400716 setup_logging $NEUTRON_CONF
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700717
Rob Crittenden18d47782014-03-19 17:47:42 -0400718 if is_service_enabled tls-proxy; then
719 # Set the service port for a proxy to take the original
720 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
Jens Harbott411c34d2017-08-29 14:40:26 +0000721 iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True
Rob Crittenden18d47782014-03-19 17:47:42 -0400722 fi
723
Mark McClainb05c8762013-07-06 23:29:39 -0400724 _neutron_setup_rootwrap
725}
726
Ian Wienandaee18c72014-02-21 15:35:08 +1100727function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400728
Martin Hickey30d5fae2015-11-10 13:44:15 +0000729 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400730
Ben Nemec03997942013-08-10 09:56:16 -0500731 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Sean Dague78801c12016-08-04 14:10:07 -0400732 # make it so we have working DNS from guests
733 iniset $Q_DHCP_CONF_FILE DEFAULT dnsmasq_local_resolv True
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700734 iniset $Q_DHCP_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400735 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700736 iniset $Q_DHCP_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400737 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400738
Tan Lin27a196e2014-10-31 15:44:34 +0800739 if ! is_service_enabled q-l3; then
740 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
741 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
742 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
743 else
744 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
745 die "$LINENO" "Enable isolated metadata is a must for metadata network"
746 fi
747 fi
748 fi
749
Mark McClainb05c8762013-07-06 23:29:39 -0400750 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
751
xurong000379977ef31d02016-07-05 11:09:40 +0800752 neutron_plugin_configure_dhcp_agent $Q_DHCP_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400753}
754
Mark McClainb05c8762013-07-06 23:29:39 -0400755
Ian Wienandaee18c72014-02-21 15:35:08 +1100756function _configure_neutron_metadata_agent {
Martin Hickey30d5fae2015-11-10 13:44:15 +0000757 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400758
Ben Nemec03997942013-08-10 09:56:16 -0500759 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400760 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
Armando Migliaccio06f2ea22017-02-02 16:47:00 -0800761 iniset $Q_META_CONF_FILE DEFAULT metadata_workers $API_WORKERS
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700762 iniset $Q_META_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400763 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700764 iniset $Q_META_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400765 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400766}
767
Dina Belova58adaa62014-07-11 18:18:12 +0400768function _configure_neutron_ceilometer_notifications {
Matt Riedemann45da7772017-03-05 13:07:39 -0500769 iniset $NEUTRON_CONF oslo_messaging_notifications driver messagingv2
Dina Belova58adaa62014-07-11 18:18:12 +0400770}
771
Ian Wienandaee18c72014-02-21 15:35:08 +1100772function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +0200773 neutron_agent_metering_configure_common
774 neutron_agent_metering_configure_agent
775}
776
Brian Haleyeea76212014-06-27 11:45:50 -0400777function _configure_dvr {
778 iniset $NEUTRON_CONF DEFAULT router_distributed True
779 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
780}
781
782
Mark McClainb05c8762013-07-06 23:29:39 -0400783# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
784# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100785function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400786 # Specify the default root helper prior to agent configuration to
787 # ensure that an agent's configuration can override the default
788 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400789 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
790 iniset /$Q_PLUGIN_CONF_FILE agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
791 fi
Ben Nemec03997942013-08-10 09:56:16 -0500792 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400793
794 # Configure agent for plugin
795 neutron_plugin_configure_plugin_agent
796}
797
798# _configure_neutron_service() - Set config files for neutron service
799# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100800function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -0400801 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
Mark McClainb05c8762013-07-06 23:29:39 -0400802 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700803
Mark McClainb05c8762013-07-06 23:29:39 -0400804 # Update either configuration file with plugin
805 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
806
Ben Nemec03997942013-08-10 09:56:16 -0500807 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Chris Dent74a85b02015-04-22 18:02:39 +0000808 iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400809 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
810
811 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
812 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
813
Atsushi SAKAIfe7b56c2015-11-13 17:06:16 +0900814 # Configuration for neutron notifications to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -0500815 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
816 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Jamie Lennoxdc757dd2015-03-09 14:48:09 +1100817
Ian Wienand1f82f432017-10-04 09:51:02 +1100818 configure_auth_token_middleware $NEUTRON_CONF nova $NEUTRON_AUTH_CACHE_DIR nova
Aaron Rosencea32b12014-03-04 16:20:14 -0800819
Mark McClainb05c8762013-07-06 23:29:39 -0400820 # Configure plugin
821 neutron_plugin_configure_service
822}
823
824# Utility Functions
825#------------------
826
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900827# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +1100828function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900829 local service_plugin_class=$1
830 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
831 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
832 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
833 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
834 fi
835}
836
Ihar Hrachyshkaf511c362017-03-07 06:31:49 +0000837# _neutron_ml2_extension_driver_add_old() - add ML2 extension driver
838function _neutron_ml2_extension_driver_add_old {
839 local extension=$1
840 if [[ $Q_ML2_PLUGIN_EXT_DRIVERS == '' ]]; then
841 Q_ML2_PLUGIN_EXT_DRIVERS=$extension
842 elif [[ ! ,${Q_ML2_PLUGIN_EXT_DRIVERS}, =~ ,${extension}, ]]; then
843 Q_ML2_PLUGIN_EXT_DRIVERS="$Q_ML2_PLUGIN_EXT_DRIVERS,$extension"
844 fi
845}
846
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900847# mutnauq_server_config_add() - add server config file
848function mutnauq_server_config_add {
849 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($1)
850}
851
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100852# _neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root).
853function _neutron_deploy_rootwrap_filters {
gong yong sheng3d6eaae2015-09-15 15:00:29 +0800854 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
855 return
856 fi
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100857 local srcdir=$1
Dean Troyer8421c2b2015-03-16 13:52:19 -0500858 sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D
859 sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100860}
861
Mark McClainb05c8762013-07-06 23:29:39 -0400862# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100863function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -0400864 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
865 return
866 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400867 # Wipe any existing ``rootwrap.d`` files first
868 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
869 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
870 sudo rm -rf $Q_CONF_ROOTWRAP_D
871 fi
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100872
873 _neutron_deploy_rootwrap_filters $NEUTRON_DIR
874
Mark McClainb05c8762013-07-06 23:29:39 -0400875 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
876 # location moved in newer versions, prefer new location
877 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Dean Troyer8421c2b2015-03-16 13:52:19 -0500878 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 -0400879 else
Dean Troyer8421c2b2015-03-16 13:52:19 -0500880 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400881 fi
882 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
Robert Li2c5d4622015-04-21 15:48:22 -0400883 sudo sed -e 's:^exec_dirs=\(.*\)$:exec_dirs=\1,/usr/local/bin:' -i $Q_RR_CONF_FILE
884
Mark McClainb05c8762013-07-06 23:29:39 -0400885 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
886 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
Yuriy Taraday26623952014-07-16 17:41:53 +0400887 ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -0400888
889 # Set up the rootwrap sudoers for neutron
890 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +0100891 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Yuriy Taraday26623952014-07-16 17:41:53 +0400892 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -0400893 chmod 0440 $TEMPFILE
894 sudo chown root:root $TEMPFILE
895 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
896
897 # Update the root_helper
898 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400899 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
900 iniset $NEUTRON_CONF agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
901 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400902}
903
Ihar Hrachyshkabb4654b2015-10-06 18:09:07 +0200904# Configures keystone integration for neutron service
Ian Wienandaee18c72014-02-21 15:35:08 +1100905function _neutron_setup_keystone {
Mark McClainb05c8762013-07-06 23:29:39 -0400906 local conf_file=$1
907 local section=$2
Jamie Lennox3561d7f2014-05-21 17:18:43 +1000908
Ian Wienand1f82f432017-10-04 09:51:02 +1100909 create_neutron_cache_dir
910 configure_auth_token_middleware $conf_file $Q_ADMIN_USERNAME $NEUTRON_AUTH_CACHE_DIR $section
Mark McClainb05c8762013-07-06 23:29:39 -0400911}
912
Ian Wienandaee18c72014-02-21 15:35:08 +1100913function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -0400914
915 # ovs_use_veth needs to be set before the plugin configuration
916 # occurs to allow plugins to override the setting.
917 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
918
919 neutron_plugin_setup_interface_driver $1
920}
Mark McClainb05c8762013-07-06 23:29:39 -0400921# Functions for Neutron Exercises
922#--------------------------------
923
Ian Wienandaee18c72014-02-21 15:35:08 +1100924function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -0400925 local from_net="$1"
926 net_id=`_get_net_id $from_net`
927 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}'`
928 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
929}
930
Ian Wienandaee18c72014-02-21 15:35:08 +1100931function _get_net_id {
Brian Haley4bc42c72017-11-07 15:22:00 -0500932 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 -0400933}
934
Ian Wienandaee18c72014-02-21 15:35:08 +1100935function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -0400936 local from_net="$1"
937 net_id=`_get_net_id $from_net`
938 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`
939 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
940}
941
Mark McClainb05c8762013-07-06 23:29:39 -0400942# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +1100943function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -0400944 local from_net=$1
945 local key_file=$2
946 local ip=$3
947 local user=$4
948 local timeout_sec=$5
949 local probe_cmd = ""
950 probe_cmd=`_get_probe_cmd_prefix $from_net`
Sean Dague442e4e92015-06-24 13:24:02 -0400951 local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success"
952 test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec
Mark McClainb05c8762013-07-06 23:29:39 -0400953}
954
Mark McClainb05c8762013-07-06 23:29:39 -0400955# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100956$_XTRACE_NEUTRON
Mark McClainb05c8762013-07-06 23:29:39 -0400957
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100958# Tell emacs to use shell-script-mode
959## Local variables:
960## mode: shell-script
961## End: