blob: a3a0dcc20dbb02a607224c4b360f476ca9d33ddd [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
23# - start_neutron_service_and_check
YAMAMOTO Takashi1a669dc2015-02-05 11:54:12 +090024# - check_neutron_third_party_integration
yunhong jiang0d6e9922014-10-10 06:12:47 -070025# - start_neutron_agents
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010026# - create_neutron_initial_network
27# - setup_neutron_debug
Mark McClainb05c8762013-07-06 23:29:39 -040028#
29# ``unstack.sh`` calls the entry points in this order:
30#
YAMAMOTO Takashi1a669dc2015-02-05 11:54:12 +090031# - teardown_neutron_debug
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010032# - stop_neutron
yunhong jiang0d6e9922014-10-10 06:12:47 -070033# - stop_neutron_third_party
34# - cleanup_neutron
Mark McClainb05c8762013-07-06 23:29:39 -040035
36# Functions in lib/neutron are classified into the following categories:
37#
38# - entry points (called from stack.sh or unstack.sh)
39# - internal functions
40# - neutron exercises
41# - 3rd party programs
42
43
44# Neutron Networking
45# ------------------
46
47# Make sure that neutron is enabled in ``ENABLED_SERVICES``. If you want
48# to run Neutron on this host, make sure that q-svc is also in
49# ``ENABLED_SERVICES``.
50#
Mark McClainb05c8762013-07-06 23:29:39 -040051# See "Neutron Network Configuration" below for additional variables
52# that must be set in localrc for connectivity across hosts with
53# Neutron.
54#
55# With Neutron networking the NETWORK_MANAGER variable is ignored.
Mark McClainb05c8762013-07-06 23:29:39 -040056
John Davidge21529a52014-06-30 09:55:11 -040057# Settings
58# --------
59
Mark McClainb05c8762013-07-06 23:29:39 -040060
61# Neutron Network Configuration
62# -----------------------------
63
Matthew Treinishabde96a2016-05-12 19:26:20 -040064deprecated "Using lib/neutron-legacy is deprecated, and it will be removed in the future"
Armando Migliaccio7dbcfae2016-02-19 14:43:42 -080065
Rob Crittenden18d47782014-03-19 17:47:42 -040066if is_ssl_enabled_service "neutron" || is_service_enabled tls-proxy; then
67 Q_PROTOCOL="https"
68fi
69
70
Mark McClainb05c8762013-07-06 23:29:39 -040071# Set up default directories
Sean Daguee08ab102014-11-13 17:09:28 -050072GITDIR["python-neutronclient"]=$DEST/python-neutronclient
Sean Dague5cb19062014-11-01 01:37:45 +010073
Doug Wiegley93e682c2015-03-03 10:31:30 -070074
Mark McClainb05c8762013-07-06 23:29:39 -040075NEUTRON_DIR=$DEST/neutron
Kyle Mestery20b839f2014-12-08 06:17:27 +000076NEUTRON_FWAAS_DIR=$DEST/neutron-fwaas
Armando Migliacciob3f26cb2016-04-13 23:28:06 +000077NEUTRON_LBAAS_DIR=$DEST/neutron-lbaas
Mark McClainb05c8762013-07-06 23:29:39 -040078NEUTRON_AUTH_CACHE_DIR=${NEUTRON_AUTH_CACHE_DIR:-/var/cache/neutron}
79
80# Support entry points installation of console scripts
81if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
82 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
Sean Dague3bdb9222013-10-22 08:36:16 -040083else
84 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
Mark McClainb05c8762013-07-06 23:29:39 -040085fi
86
87NEUTRON_CONF_DIR=/etc/neutron
88NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
89export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
90
Armando Migliacciob3f26cb2016-04-13 23:28:06 +000091# Default provider for load balancer service
92DEFAULT_LB_PROVIDER=LOADBALANCER:Haproxy:neutron_lbaas.services.loadbalancer.drivers.haproxy.plugin_driver.HaproxyOnHostPluginDriver:default
93
Adam Gandelman7614d212014-08-11 14:27:50 -070094# Agent binaries. Note, binary paths for other agents are set in per-service
95# scripts in lib/neutron_plugins/services/
96AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
97AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
98AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
99
100# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
101# loaded from per-plugin scripts in lib/neutron_plugins/
102Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
103Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
104Q_FWAAS_CONF_FILE=$NEUTRON_CONF_DIR/fwaas_driver.ini
Adam Gandelman7614d212014-08-11 14:27:50 -0700105Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
106
Henry Gessau0fc1cc22014-07-06 22:54:34 -0400107# Default name for Neutron database
108Q_DB_NAME=${Q_DB_NAME:-neutron}
Mark McClainb05c8762013-07-06 23:29:39 -0400109# Default Neutron Plugin
Kyle Mestery6d235002013-09-18 20:27:08 +0000110Q_PLUGIN=${Q_PLUGIN:-ml2}
Mark McClainb05c8762013-07-06 23:29:39 -0400111# Default Neutron Port
112Q_PORT=${Q_PORT:-9696}
Rob Crittenden18d47782014-03-19 17:47:42 -0400113# Default Neutron Internal Port when using TLS proxy
114Q_PORT_INT=${Q_PORT_INT:-19696}
Mark McClainb05c8762013-07-06 23:29:39 -0400115# Default Neutron Host
116Q_HOST=${Q_HOST:-$SERVICE_HOST}
Rob Crittenden18d47782014-03-19 17:47:42 -0400117# Default protocol
118Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
Brian Haley180f5eb2015-06-16 13:14:31 -0400119# Default listen address
120Q_LISTEN_ADDRESS=${Q_LISTEN_ADDRESS:-$SERVICE_LISTEN_ADDRESS}
Mark McClainb05c8762013-07-06 23:29:39 -0400121# Default admin username
122Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
123# Default auth strategy
124Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
Mark McClainb05c8762013-07-06 23:29:39 -0400125# RHEL's support for namespaces requires using veths with ovs
126Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
127Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
Yuriy Taraday26623952014-07-16 17:41:53 +0400128Q_USE_ROOTWRAP_DAEMON=$(trueorfalse True Q_USE_ROOTWRAP_DAEMON)
Mark McClainb05c8762013-07-06 23:29:39 -0400129# Meta data IP
130Q_META_DATA_IP=${Q_META_DATA_IP:-$SERVICE_HOST}
131# Allow Overlapping IP among subnets
132Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
133# Use neutron-debug command
134Q_USE_DEBUG_COMMAND=${Q_USE_DEBUG_COMMAND:-False}
135# The name of the default q-l3 router
136Q_ROUTER_NAME=${Q_ROUTER_NAME:-router1}
Terry Wilsonf06c4432014-05-20 10:54:51 -0500137Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
138Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
Aaron Rosencea32b12014-03-04 16:20:14 -0800139VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
140VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Aaron Rosen4540d002013-10-24 13:59:33 -0700141
Mark McClainb05c8762013-07-06 23:29:39 -0400142# List of config file names in addition to the main plugin config file
143# See _configure_neutron_common() for details about setting it up
144declare -a Q_PLUGIN_EXTRA_CONF_FILES
145
Mark McClainb05c8762013-07-06 23:29:39 -0400146
Dean Troyere2907b42014-02-26 17:35:37 -0600147Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
148if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
149 Q_RR_COMMAND="sudo"
150else
151 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
152 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
Yuriy Taraday26623952014-07-16 17:41:53 +0400153 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
154 Q_RR_DAEMON_COMMAND="sudo $NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
155 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400156fi
157
Brian Haleyeea76212014-06-27 11:45:50 -0400158
159# Distributed Virtual Router (DVR) configuration
160# Can be:
Dean Troyer3324f192014-09-18 09:26:39 -0500161# - ``legacy`` - No DVR functionality
162# - ``dvr_snat`` - Controller or single node DVR
163# - ``dvr`` - Compute node in multi-node DVR
164#
Brian Haleyeea76212014-06-27 11:45:50 -0400165Q_DVR_MODE=${Q_DVR_MODE:-legacy}
166if [[ "$Q_DVR_MODE" != "legacy" ]]; then
167 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,linuxbridge,l2population
168fi
169
Dean Troyere2907b42014-02-26 17:35:37 -0600170# Provider Network Configurations
171# --------------------------------
172
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900173# The following variables control the Neutron ML2 plugins' allocation
174# of tenant networks and availability of provider networks. If these
175# are not configured in ``localrc``, tenant networks will be local to
176# the host (with no remote connectivity), and no physical resources
177# will be available for the allocation of provider networks.
Dean Troyere2907b42014-02-26 17:35:37 -0600178
Attila Fazekas8feaf6c2014-07-27 20:47:04 +0200179# To disable tunnels (GRE or VXLAN) for tenant networks,
180# set to False in ``local.conf``.
181# GRE tunnels are only supported by the openvswitch.
182ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
Dean Troyere2907b42014-02-26 17:35:37 -0600183
184# If using GRE tunnels for tenant networks, specify the range of
185# tunnel IDs from which tenant networks are allocated. Can be
Atsushi SAKAIfe7b56c2015-11-13 17:06:16 +0900186# overridden in ``localrc`` in necessary.
Anant Patil3827dc02014-07-03 21:38:16 +0530187TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
Dean Troyere2907b42014-02-26 17:35:37 -0600188
189# To use VLANs for tenant networks, set to True in localrc. VLANs
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900190# are supported by the ML2 plugins, requiring additional configuration
191# described below.
Dean Troyere2907b42014-02-26 17:35:37 -0600192ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
193
194# If using VLANs for tenant networks, set in ``localrc`` to specify
195# the range of VLAN VIDs from which tenant networks are
196# allocated. An external network switch must be configured to
197# trunk these VLANs between hosts for multi-host connectivity.
198#
199# Example: ``TENANT_VLAN_RANGE=1000:1999``
200TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
201
202# If using VLANs for tenant networks, or if using flat or VLAN
203# provider networks, set in ``localrc`` to the name of the physical
204# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
205# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
206# agent, as described below.
207#
208# Example: ``PHYSICAL_NETWORK=default``
209PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-}
210
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900211# With the openvswitch agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600212# or if using flat or VLAN provider networks, set in ``localrc`` to
213# the name of the OVS bridge to use for the physical network. The
214# bridge will be created if it does not already exist, but a
215# physical interface must be manually added to the bridge as a
216# port for external connectivity.
217#
218# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
219OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-}
220
YAMAMOTO Takashi15130cd2014-10-28 11:49:58 +0900221# With the linuxbridge agent, if using VLANs for tenant networks,
Dean Troyere2907b42014-02-26 17:35:37 -0600222# or if using flat or VLAN provider networks, set in ``localrc`` to
223# the name of the network interface to use for the physical
224# network.
225#
226# Example: ``LB_PHYSICAL_INTERFACE=eth1``
227LB_PHYSICAL_INTERFACE=${LB_PHYSICAL_INTERFACE:-}
228
Edgar Magana6f335b92014-07-10 15:42:44 -0700229# When Neutron tunnels are enabled it is needed to specify the
230# IP address of the end point in the local server. This IP is set
231# by default to the same IP address that the HOST IP.
232# This variable can be used to specify a different end point IP address
233# Example: ``TUNNEL_ENDPOINT_IP=1.1.1.1``
234TUNNEL_ENDPOINT_IP=${TUNNEL_ENDPOINT_IP:-$HOST_IP}
235
Dean Troyere2907b42014-02-26 17:35:37 -0600236# With the openvswitch plugin, set to True in ``localrc`` to enable
237# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
238#
239# Example: ``OVS_ENABLE_TUNNELING=True``
240OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
241
Tan Lin27a196e2014-10-31 15:44:34 +0800242# Use DHCP agent for providing metadata service in the case of
243# without L3 agent (No Route Agent), set to True in localrc.
244ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
245
246# Add a static route as dhcp option, so the request to 169.254.169.254
247# will be able to reach through a route(DHCP agent)
248# This option require ENABLE_ISOLATED_METADATA = True
249ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
Mark McClainb05c8762013-07-06 23:29:39 -0400250# Neutron plugin specific functions
251# ---------------------------------
252
253# Please refer to ``lib/neutron_plugins/README.md`` for details.
Hirofumi Ichihara36daecd2015-07-23 17:50:40 +0900254if [ -f $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN ]; then
255 source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
256fi
Mark McClainb05c8762013-07-06 23:29:39 -0400257
Armando Migliacciob3f26cb2016-04-13 23:28:06 +0000258# Agent loadbalancer service plugin functions
259# -------------------------------------------
260
261# Hardcoding for 1 service plugin for now
262source $TOP_DIR/lib/neutron_plugins/services/loadbalancer
263
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
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700270# Firewall Service Plugin functions
Adam Spierscb961592013-10-05 12:11:07 +0100271# ---------------------------------
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700272source $TOP_DIR/lib/neutron_plugins/services/firewall
273
Sean M. Collins2a242512016-05-03 09:03:09 -0400274# L3 Service functions
275source $TOP_DIR/lib/neutron_plugins/services/l3
276
Mark McClainb05c8762013-07-06 23:29:39 -0400277# Use security group or not
278if has_neutron_plugin_security_group; then
279 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
280else
281 Q_USE_SECGROUP=False
282fi
283
Dean Troyere2907b42014-02-26 17:35:37 -0600284# Save trace setting
Ian Wienand523f4882015-10-13 11:03:03 +1100285_XTRACE_NEUTRON=$(set +o | grep xtrace)
Dean Troyere2907b42014-02-26 17:35:37 -0600286set +o xtrace
287
288
Mark McClainb05c8762013-07-06 23:29:39 -0400289# Functions
290# ---------
291
Adam Gandelman7614d212014-08-11 14:27:50 -0700292function _determine_config_server {
293 local cfg_file
294 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
295 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
Tom Patzig73467042016-04-19 17:02:34 +0200296 opts+=" --config-file $cfg_file"
Adam Gandelman7614d212014-08-11 14:27:50 -0700297 done
298 echo "$opts"
299}
300
Adam Gandelman7614d212014-08-11 14:27:50 -0700301function _determine_config_l3 {
302 local opts="--config-file $NEUTRON_CONF --config-file=$Q_L3_CONF_FILE"
303 if is_service_enabled q-fwaas; then
304 opts+=" --config-file $Q_FWAAS_CONF_FILE"
305 fi
306 echo "$opts"
307}
308
309# For services and agents that require it, dynamically construct a list of
310# --config-file arguments that are passed to the binary.
311function determine_config_files {
312 local opts=""
313 case "$1" in
314 "neutron-server") opts="$(_determine_config_server)" ;;
Adam Gandelman7614d212014-08-11 14:27:50 -0700315 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
316 esac
317 if [ -z "$opts" ] ; then
318 die $LINENO "Could not determine config files for $1."
319 fi
320 echo "$opts"
321}
322
Sean M. Collins2a242512016-05-03 09:03:09 -0400323# configure_mutnauq()
Mark McClainb05c8762013-07-06 23:29:39 -0400324# Set common config for all neutron server and agents.
Sean M. Collins2a242512016-05-03 09:03:09 -0400325function configure_mutnauq {
Mark McClainb05c8762013-07-06 23:29:39 -0400326 _configure_neutron_common
Brant Knudson2dd110c2015-03-14 12:39:14 -0500327 iniset_rpc_backend neutron $NEUTRON_CONF
Mark McClainb05c8762013-07-06 23:29:39 -0400328
329 # goes before q-svc to init Q_SERVICE_PLUGIN_CLASSES
Armando Migliacciob3f26cb2016-04-13 23:28:06 +0000330 if is_service_enabled q-lbaas; then
331 deprecated "Configuring q-lbaas through devstack is deprecated"
332 _configure_neutron_lbaas
333 fi
Emilien Macchi40546f72013-09-24 15:10:25 +0200334 if is_service_enabled q-metering; then
335 _configure_neutron_metering
336 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700337 if is_service_enabled q-fwaas; then
Sean Dagued6f92232016-02-09 06:34:36 -0500338 deprecated "Configuring q-fwaas through devstack is deprecated"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700339 _configure_neutron_fwaas
340 fi
Stephen Ma9b38eb22014-04-02 02:13:09 +0000341 if is_service_enabled q-agt q-svc; then
Mark McClainb05c8762013-07-06 23:29:39 -0400342 _configure_neutron_service
343 fi
344 if is_service_enabled q-agt; then
345 _configure_neutron_plugin_agent
346 fi
347 if is_service_enabled q-dhcp; then
348 _configure_neutron_dhcp_agent
349 fi
350 if is_service_enabled q-l3; then
351 _configure_neutron_l3_agent
352 fi
353 if is_service_enabled q-meta; then
354 _configure_neutron_metadata_agent
355 fi
356
Brian Haleyeea76212014-06-27 11:45:50 -0400357 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
358 _configure_dvr
359 fi
Dina Belova58adaa62014-07-11 18:18:12 +0400360 if is_service_enabled ceilometer; then
361 _configure_neutron_ceilometer_notifications
362 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400363
364 _configure_neutron_debug_command
armando-migliaccioe155b892015-06-12 08:55:02 -0700365
366 iniset $NEUTRON_CONF DEFAULT api_workers "$API_WORKERS"
Mark McClainb05c8762013-07-06 23:29:39 -0400367}
368
Ian Wienandaee18c72014-02-21 15:35:08 +1100369function create_nova_conf_neutron {
Sean Daguef21cc1f2016-03-04 11:08:32 -0500370 iniset $NOVA_CONF DEFAULT use_neutron True
Matthew Kassawara28af7962016-02-10 19:04:08 +0000371 iniset $NOVA_CONF neutron auth_type "password"
Jamie Lennox394968f2015-08-28 09:18:26 +1000372 iniset $NOVA_CONF neutron auth_url "$KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_AUTH_PORT/v3"
373 iniset $NOVA_CONF neutron username "$Q_ADMIN_USERNAME"
374 iniset $NOVA_CONF neutron password "$SERVICE_PASSWORD"
Jamie Lennoxcbcbd8f2016-01-21 16:08:14 -0600375 iniset $NOVA_CONF neutron user_domain_name "$SERVICE_DOMAIN_NAME"
Sean Dague7580a0c2016-02-17 06:23:36 -0500376 iniset $NOVA_CONF neutron project_name "$SERVICE_PROJECT_NAME"
Jamie Lennoxcbcbd8f2016-01-21 16:08:14 -0600377 iniset $NOVA_CONF neutron project_domain_name "$SERVICE_DOMAIN_NAME"
Gary Kotton13d385e2014-06-17 23:24:53 -0700378 iniset $NOVA_CONF neutron auth_strategy "$Q_AUTH_STRATEGY"
Bartosz Górski0abde392014-02-28 14:15:19 +0100379 iniset $NOVA_CONF neutron region_name "$REGION_NAME"
Rob Crittenden18d47782014-03-19 17:47:42 -0400380 iniset $NOVA_CONF neutron url "${Q_PROTOCOL}://$Q_HOST:$Q_PORT"
Mark McClainb05c8762013-07-06 23:29:39 -0400381
382 if [[ "$Q_USE_SECGROUP" == "True" ]]; then
383 LIBVIRT_FIREWALL_DRIVER=nova.virt.firewall.NoopFirewallDriver
Jeff Peeler1143f7e2013-10-31 16:21:52 -0400384 iniset $NOVA_CONF DEFAULT firewall_driver $LIBVIRT_FIREWALL_DRIVER
Mark McClainb05c8762013-07-06 23:29:39 -0400385 fi
386
Matt Riedemann925c2562015-08-25 13:40:25 -0700387 # optionally set options in nova_conf
Mark McClainb05c8762013-07-06 23:29:39 -0400388 neutron_plugin_create_nova_conf
389
Mark McClainb05c8762013-07-06 23:29:39 -0400390 if is_service_enabled q-meta; then
Gary Kottondd745502014-08-11 23:38:47 -0700391 iniset $NOVA_CONF neutron service_metadata_proxy "True"
Mark McClainb05c8762013-07-06 23:29:39 -0400392 fi
Aaron Rosencea32b12014-03-04 16:20:14 -0800393
394 iniset $NOVA_CONF DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
395 iniset $NOVA_CONF DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Mark McClainb05c8762013-07-06 23:29:39 -0400396}
397
Sean M. Collins2a242512016-05-03 09:03:09 -0400398# create_mutnauq_accounts() - Set up common required neutron accounts
Mark McClainb05c8762013-07-06 23:29:39 -0400399
400# Tenant User Roles
401# ------------------------------------------------------------------
402# service neutron admin # if enabled
403
404# Migrated from keystone_data.sh
Sean M. Collins2a242512016-05-03 09:03:09 -0400405function create_mutnauq_accounts {
Mark McClainb05c8762013-07-06 23:29:39 -0400406 if [[ "$ENABLED_SERVICES" =~ "q-svc" ]]; then
Bartosz Górski0abde392014-02-28 14:15:19 +0100407
Jamie Lennox85ff5322015-01-28 14:28:01 +1000408 create_service_user "neutron"
Bartosz Górski0abde392014-02-28 14:15:19 +0100409
Sean Dague985e9582016-02-10 07:25:24 -0500410 get_or_create_service "neutron" "network" "Neutron Service"
Matt Riedemannae4578b2016-04-23 01:45:40 +0000411 get_or_create_endpoint \
Sean Dague985e9582016-02-10 07:25:24 -0500412 "network" \
413 "$REGION_NAME" \
414 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
415 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/" \
416 "$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/"
Mark McClainb05c8762013-07-06 23:29:39 -0400417 fi
418}
419
Sean M. Collins2a242512016-05-03 09:03:09 -0400420# init_mutnauq() - Initialize databases, etc.
421function init_mutnauq {
Ihar Hrachyshka157c84b2014-10-06 13:29:39 +0200422 recreate_database $Q_DB_NAME
Salvatore Orlandodd649882013-08-05 08:56:17 -0700423 # Run Neutron db migrations
424 $NEUTRON_BIN_DIR/neutron-db-manage --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE upgrade head
Mark McClainb05c8762013-07-06 23:29:39 -0400425}
426
Sean M. Collins2a242512016-05-03 09:03:09 -0400427# install_mutnauq() - Collect source and prepare
428function install_mutnauq {
Doug Wiegley86561c32016-02-10 18:37:21 -0700429 # Install neutron-lib from git so we make sure we're testing
430 # the latest code.
431 if use_library_from_git "neutron-lib"; then
432 git_clone_by_name "neutron-lib"
433 setup_dev_lib "neutron-lib"
434 fi
435
Mark McClainb05c8762013-07-06 23:29:39 -0400436 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
437 setup_develop $NEUTRON_DIR
Kyle Mestery20b839f2014-12-08 06:17:27 +0000438 if is_service_enabled q-fwaas; then
439 git_clone $NEUTRON_FWAAS_REPO $NEUTRON_FWAAS_DIR $NEUTRON_FWAAS_BRANCH
440 setup_develop $NEUTRON_FWAAS_DIR
441 fi
Armando Migliacciob3f26cb2016-04-13 23:28:06 +0000442 if is_service_enabled q-lbaas; then
443 git_clone $NEUTRON_LBAAS_REPO $NEUTRON_LBAAS_DIR $NEUTRON_LBAAS_BRANCH
444 setup_develop $NEUTRON_LBAAS_DIR
445 fi
Mate Lakat6df64892014-10-17 13:09:49 +0200446
447 if [ "$VIRT_DRIVER" == 'xenserver' ]; then
448 local dom0_ip
449 dom0_ip=$(echo "$XENAPI_CONNECTION_URL" | cut -d "/" -f 3-)
450
451 local ssh_dom0
452 ssh_dom0="sudo -u $DOMZERO_USER ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$dom0_ip"
453
454 # Find where the plugins should go in dom0
455 local xen_functions
456 xen_functions=$(cat $TOP_DIR/tools/xen/functions)
457 local plugin_dir
458 plugin_dir=$($ssh_dom0 "$xen_functions; set -eux; xapi_plugin_location")
459
460 # install neutron plugins to dom0
Huan Xie201e3c12015-08-27 12:34:24 +0100461 tar -czf - -C $NEUTRON_DIR/neutron/plugins/ml2/drivers/openvswitch/agent/xenapi/etc/xapi.d/plugins/ ./ |
Mate Lakat6df64892014-10-17 13:09:49 +0200462 $ssh_dom0 "tar -xzf - -C $plugin_dir && chmod a+x $plugin_dir/*"
463 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400464}
465
Mark McClainb05c8762013-07-06 23:29:39 -0400466# install_neutron_agent_packages() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100467function install_neutron_agent_packages {
Robert Li72b3e442014-07-17 15:04:52 -0400468 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
469 if is_service_enabled q-l3; then
470 install_package radvd
471 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400472 # install packages that are specific to plugin agent(s)
473 if is_service_enabled q-agt q-dhcp q-l3; then
474 neutron_plugin_install_agent_packages
475 fi
Armando Migliacciob3f26cb2016-04-13 23:28:06 +0000476
477 if is_service_enabled q-lbaas; then
478 neutron_agent_lbaas_install_agent_packages
479 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400480}
481
482# Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100483function start_neutron_service_and_check {
Rob Crittenden18d47782014-03-19 17:47:42 -0400484 local service_port=$Q_PORT
485 local service_protocol=$Q_PROTOCOL
Ian Wienand7ae97292016-02-16 14:50:53 +1100486 local cfg_file_options
487
488 cfg_file_options="$(determine_config_files neutron-server)"
489
Rob Crittenden18d47782014-03-19 17:47:42 -0400490 if is_service_enabled tls-proxy; then
491 service_port=$Q_PORT_INT
492 service_protocol="http"
493 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400494 # Start the Neutron service
Davanum Srinivas59756e92015-09-23 17:42:54 -0400495 run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
Mark McClainb05c8762013-07-06 23:29:39 -0400496 echo "Waiting for Neutron to start..."
Rob Crittenden18d47782014-03-19 17:47:42 -0400497 if is_ssl_enabled_service "neutron"; then
498 ssl_ca="--ca-certificate=${SSL_BUNDLE_FILE}"
499 fi
Sean Dague442e4e92015-06-24 13:24:02 -0400500
501 local testcmd="wget ${ssl_ca} --no-proxy -q -O- $service_protocol://$Q_HOST:$service_port"
502 test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
503
Rob Crittenden18d47782014-03-19 17:47:42 -0400504 # Start proxy if enabled
505 if is_service_enabled tls-proxy; then
506 start_tls_proxy '*' $Q_PORT $Q_HOST $Q_PORT_INT &
507 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400508}
509
Russell Bryant09b94602015-06-08 15:25:43 -0400510# Control of the l2 agent is separated out to make it easier to test partial
511# upgrades (everything upgraded except the L2 agent)
Sean M. Collins2a242512016-05-03 09:03:09 -0400512function start_mutnauq_l2_agent {
Davanum Srinivas59756e92015-09-23 17:42:54 -0400513 run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
Nachi Ueno584750f2013-07-15 18:22:21 -0700514
Kahou Leid663e292015-10-24 12:18:57 -0700515 if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then
Zhongyue Luo56b7efb2014-12-16 11:36:49 +0800516 sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400517 sudo ip link set $OVS_PHYSICAL_BRIDGE up
518 sudo ip link set br-int up
519 sudo ip link set $PUBLIC_INTERFACE up
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700520 if is_ironic_hardware; then
521 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
522 sudo ip addr del $IP dev $PUBLIC_INTERFACE
523 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
524 done
gong yong sheng348c6ac2015-06-23 14:03:47 +0800525 sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700526 fi
Sean M. Collins5ec6f8f2014-05-14 17:01:03 -0400527 fi
Russell Bryant09b94602015-06-08 15:25:43 -0400528}
529
Sean M. Collins2a242512016-05-03 09:03:09 -0400530function start_mutnauq_other_agents {
Davanum Srinivas59756e92015-09-23 17:42:54 -0400531 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 -0400532
Paul Michalie4289c82015-08-14 11:49:27 -0400533 if is_service_enabled neutron-vpnaas; then
534 : # Started by plugin
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700535 else
Davanum Srinivas59756e92015-09-23 17:42:54 -0400536 run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700537 fi
538
Davanum Srinivas59756e92015-09-23 17:42:54 -0400539 run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file=$Q_META_CONF_FILE"
Armando Migliacciob3f26cb2016-04-13 23:28:06 +0000540 run_process q-lbaas "$AGENT_LBAAS_BINARY --config-file $NEUTRON_CONF --config-file=$LBAAS_AGENT_CONF_FILENAME"
Davanum Srinivas59756e92015-09-23 17:42:54 -0400541 run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
Mark McClainb05c8762013-07-06 23:29:39 -0400542
543 if [ "$VIRT_DRIVER" = 'xenserver' ]; then
544 # For XenServer, start an agent for the domU openvswitch
Davanum Srinivas59756e92015-09-23 17:42:54 -0400545 run_process q-domua "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE.domU"
Mark McClainb05c8762013-07-06 23:29:39 -0400546 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400547}
548
Russell Bryant09b94602015-06-08 15:25:43 -0400549# Start running processes, including screen
550function start_neutron_agents {
551 # Start up the neutron agents if enabled
Sean M. Collins2a242512016-05-03 09:03:09 -0400552 start_mutnauq_l2_agent
553 start_mutnauq_other_agents
Russell Bryant09b94602015-06-08 15:25:43 -0400554}
555
Sean M. Collins2a242512016-05-03 09:03:09 -0400556function stop_mutnauq_l2_agent {
Russell Bryant09b94602015-06-08 15:25:43 -0400557 stop_process q-agt
558}
559
Sean M. Collins2a242512016-05-03 09:03:09 -0400560# stop_mutnauq_other() - Stop running processes (non-screen)
561function stop_mutnauq_other {
Mark McClainb05c8762013-07-06 23:29:39 -0400562 if is_service_enabled q-dhcp; then
Chris Dent36891dc2015-02-03 16:22:44 +0000563 stop_process q-dhcp
Mark McClainb05c8762013-07-06 23:29:39 -0400564 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
565 [ ! -z "$pid" ] && sudo kill -9 $pid
566 fi
Chris Dent36891dc2015-02-03 16:22:44 +0000567
568 stop_process q-svc
Li Maa15d9de2016-01-19 19:11:51 +0800569
570 if is_service_enabled q-l3; then
571 sudo pkill -f "radvd -C $DATA_DIR/neutron/ra"
572 stop_process q-l3
573 fi
Chris Dent36891dc2015-02-03 16:22:44 +0000574
Mark McClainb05c8762013-07-06 23:29:39 -0400575 if is_service_enabled q-meta; then
Jakub Libosvar1f763282014-01-28 23:01:38 +0100576 sudo pkill -9 -f neutron-ns-metadata-proxy || :
Chris Dent36891dc2015-02-03 16:22:44 +0000577 stop_process q-meta
Mark McClainb05c8762013-07-06 23:29:39 -0400578 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900579
Armando Migliacciob3f26cb2016-04-13 23:28:06 +0000580 if is_service_enabled q-lbaas; then
581 neutron_lbaas_stop
582 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900583 if is_service_enabled q-fwaas; then
584 neutron_fwaas_stop
585 fi
Akihiro Motokiedddb1f2013-12-09 20:21:06 +0900586 if is_service_enabled q-metering; then
587 neutron_metering_stop
588 fi
Li Ma50120fa2015-12-13 10:41:34 +0800589
590 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
591 sudo pkill -9 -f $NEUTRON_ROOTWRAP-daemon || :
592 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400593}
594
Russell Bryant09b94602015-06-08 15:25:43 -0400595# stop_neutron() - Stop running processes (non-screen)
Sean M. Collins2a242512016-05-03 09:03:09 -0400596function stop_mutnauq {
597 stop_mutnauq_other
598 stop_mutnauq_l2_agent
Russell Bryant09b94602015-06-08 15:25:43 -0400599}
600
Sean M. Collins00e16a92015-02-20 11:45:21 -0500601# _move_neutron_addresses_route() - Move the primary IP to the OVS bridge
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600602# on startup, or back to the public interface on cleanup. If no IP is
603# configured on the interface, just add it as a port to the OVS bridge.
Sean M. Collins00e16a92015-02-20 11:45:21 -0500604function _move_neutron_addresses_route {
605 local from_intf=$1
606 local to_intf=$2
607 local add_ovs_port=$3
Brian Haleya0d1b012015-11-16 17:30:48 -0500608 local del_ovs_port=$4
609 local af=$5
Sean M. Collins00e16a92015-02-20 11:45:21 -0500610
611 if [[ -n "$from_intf" && -n "$to_intf" ]]; then
612 # Remove the primary IP address from $from_intf and add it to $to_intf,
613 # along with the default route, if it exists. Also, when called
614 # on configure we will also add $from_intf as a port on $to_intf,
615 # assuming it is an OVS bridge.
616
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600617 local IP_ADD=""
618 local IP_DEL=""
Shinobu KINJOf95315b2015-11-07 10:21:08 +0900619 local IP_UP=""
Ian Wienandada886d2015-10-07 14:06:26 +1100620 local DEFAULT_ROUTE_GW
Sean M. Collins59e86a32015-11-09 11:06:39 -0500621 DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf/ { print \$3; exit }")
Sean M. Collins00e16a92015-02-20 11:45:21 -0500622 local ADD_OVS_PORT=""
Brian Haleya0d1b012015-11-16 17:30:48 -0500623 local DEL_OVS_PORT=""
Sean M. Collins00e16a92015-02-20 11:45:21 -0500624
Brian Haleybb9caea2015-11-16 17:18:42 -0500625 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 -0600626
Sean M. Collins53b63cc2016-04-28 13:33:38 -0500627 if [[ "$af" == "inet" ]]; then
628 IP=$(echo $IP_BRD | awk '{ print $1; exit }' | grep -o -E '(.*)/' | cut -d "/" -f1)
629 ARP_CMD="arping -A -c 3 -w 4.5 -I $to_intf $IP "
630 else
631 ARP_CMD=""
632 fi
633
Sean M. Collins00e16a92015-02-20 11:45:21 -0500634 if [ "$DEFAULT_ROUTE_GW" != "" ]; then
Sean M. Collins59e86a32015-11-09 11:06:39 -0500635 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 -0500636 fi
637
638 if [[ "$add_ovs_port" == "True" ]]; then
Raman Budnydb02bbf2015-03-31 13:09:09 +0300639 ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf"
Sean M. Collins00e16a92015-02-20 11:45:21 -0500640 fi
641
Brian Haleya0d1b012015-11-16 17:30:48 -0500642 if [[ "$del_ovs_port" == "True" ]]; then
643 DEL_OVS_PORT="sudo ovs-vsctl --if-exists del-port $from_intf $to_intf"
644 fi
645
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600646 if [[ "$IP_BRD" != "" ]]; then
Brian Haley94510212015-09-02 15:40:04 -0400647 IP_DEL="sudo ip addr del $IP_BRD dev $from_intf"
648 IP_ADD="sudo ip addr add $IP_BRD dev $to_intf"
Shinobu KINJOf95315b2015-11-07 10:21:08 +0900649 IP_UP="sudo ip link set $to_intf up"
Adam Kacmarsky6b172c82015-08-13 15:14:05 -0600650 fi
651
Brian Haleya0d1b012015-11-16 17:30:48 -0500652 # The add/del OVS port calls have to happen either before or
653 # after the address is moved in order to not leave it orphaned.
Sean M. Collins53b63cc2016-04-28 13:33:38 -0500654 $DEL_OVS_PORT; $IP_DEL; $IP_ADD; $IP_UP; $ADD_OVS_PORT; $ADD_DEFAULT_ROUTE; $ARP_CMD
Sean M. Collins00e16a92015-02-20 11:45:21 -0500655 fi
656}
657
Sean M. Collins2a242512016-05-03 09:03:09 -0400658# cleanup_mutnauq() - Remove residual data files, anything left over from previous
Mark McClainb05c8762013-07-06 23:29:39 -0400659# runs that a clean run would need to clean up
Sean M. Collins2a242512016-05-03 09:03:09 -0400660function cleanup_mutnauq {
Sean M. Collins00e16a92015-02-20 11:45:21 -0500661
Yalei Wang316b3482015-07-15 21:00:31 +0800662 if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then
Brian Haleya0d1b012015-11-16 17:30:48 -0500663 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False True "inet"
Adam Kacmarsky11298a02015-06-26 14:49:47 -0600664
Yalei Wang316b3482015-07-15 21:00:31 +0800665 if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then
Sean M. Collins790266f2015-11-11 13:36:35 -0500666 # ip(8) wants the prefix length when deleting
667 local v6_gateway
668 v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }')
669 sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE
Brian Haleya0d1b012015-11-16 17:30:48 -0500670 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False False "inet6"
Yalei Wang316b3482015-07-15 21:00:31 +0800671 fi
Sean M. Collins00e16a92015-02-20 11:45:21 -0500672
Yalei Wang316b3482015-07-15 21:00:31 +0800673 if is_provider_network && is_ironic_hardware; then
674 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
675 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
676 sudo ip addr add $IP dev $PUBLIC_INTERFACE
677 done
678 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
679 fi
yunhong jiangae9ee6b2014-10-08 07:01:02 -0700680 fi
681
Mark McClainb05c8762013-07-06 23:29:39 -0400682 if is_neutron_ovs_base_plugin; then
683 neutron_ovs_base_cleanup
684 fi
685
Sean M. Collins7bc2af72015-06-08 12:36:30 -0400686 if [[ $Q_AGENT == "linuxbridge" ]]; then
687 neutron_lb_cleanup
688 fi
689
Mark McClainb05c8762013-07-06 23:29:39 -0400690 # delete all namespaces created by neutron
Armando Migliacciob3f26cb2016-04-13 23:28:06 +0000691 for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|qlbaas|fip|snat)-[0-9a-f-]*'); do
Mark McClainb05c8762013-07-06 23:29:39 -0400692 sudo ip netns delete ${ns}
693 done
694}
695
Doug Wiegley93e682c2015-03-03 10:31:30 -0700696
Maru Newby952fd902015-01-30 22:27:12 +0000697function _create_neutron_conf_dir {
Mark McClainb05c8762013-07-06 23:29:39 -0400698 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
Dean Troyer8421c2b2015-03-16 13:52:19 -0500699 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
Maru Newby952fd902015-01-30 22:27:12 +0000700}
701
702# _configure_neutron_common()
703# Set common config for all neutron server and agents.
704# This MUST be called before other ``_configure_neutron_*`` functions.
705function _configure_neutron_common {
706 _create_neutron_conf_dir
Mark McClainb05c8762013-07-06 23:29:39 -0400707
Martin Hickey30d5fae2015-11-10 13:44:15 +0000708 # Uses oslo config generator to generate core sample configuration files
709 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
710
711 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
Mark McClainb05c8762013-07-06 23:29:39 -0400712
Jerry Zhao296c1e32015-08-07 20:43:54 -0400713 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
714 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
715
716 # allow neutron user to administer neutron to match neutron account
717 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
718
Mark McClainb05c8762013-07-06 23:29:39 -0400719 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
720 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
Tom Patzig67223b02016-04-19 16:43:05 +0200721 # For additional plugin config files, set ``Q_PLUGIN_EXTRA_CONF_PATH`` and
Mark McClainb05c8762013-07-06 23:29:39 -0400722 # ``Q_PLUGIN_EXTRA_CONF_FILES``. For example:
Adam Spierscb961592013-10-05 12:11:07 +0100723 #
Tom Patzig67223b02016-04-19 16:43:05 +0200724 # ``Q_PLUGIN_EXTRA_CONF_PATH=/path/to/plugins``
Boden R82bca442016-04-15 10:56:09 -0600725 # ``Q_PLUGIN_EXTRA_CONF_FILES=(file1 file2)``
Mark McClainb05c8762013-07-06 23:29:39 -0400726 neutron_plugin_configure_common
727
sbauzae2c4ee22013-08-29 17:29:46 +0200728 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400729 die $LINENO "Neutron plugin not set.. exiting"
730 fi
731
732 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
733 mkdir -p /$Q_PLUGIN_CONF_PATH
734 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
Hirofumi Ichihara97cc85b2015-09-08 13:51:01 +0900735 # NOTE(hichihara): Some neutron vendor plugins were already decomposed and
736 # there is no config file in Neutron tree. They should prepare the file in each plugin.
Martin Hickey30d5fae2015-11-10 13:44:15 +0000737 if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then
738 cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE
739 elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then
Hirofumi Ichihara97cc85b2015-09-08 13:51:01 +0900740 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
741 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400742
Ihar Hrachyshkab816e5d2014-07-21 13:53:50 +0200743 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
Mark McClainb05c8762013-07-06 23:29:39 -0400744 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
salvatoree4e535b2014-10-29 18:22:46 +0100745 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
Brian Haley180f5eb2015-06-16 13:14:31 -0400746 iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS
Martin Hickey30d5fae2015-11-10 13:44:15 +0000747 iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock
748
Victor Ryzhenkin878d7d82016-04-27 15:15:52 +0300749 # NOTE(freerunner): Need to adjust Region Name for nova in multiregion installation
750 iniset $NEUTRON_CONF nova region_name $REGION_NAME
751
Mark McClainb05c8762013-07-06 23:29:39 -0400752 # If addition config files are set, make sure their path name is set as well
753 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 && $Q_PLUGIN_EXTRA_CONF_PATH == '' ]]; then
754 die $LINENO "Neutron additional plugin config not set.. exiting"
755 fi
756
757 # If additional config files exist, copy them over to neutron configuration
758 # directory
759 if [[ $Q_PLUGIN_EXTRA_CONF_PATH != '' ]]; then
Mark McClainb05c8762013-07-06 23:29:39 -0400760 local f
761 for (( f=0; $f < ${#Q_PLUGIN_EXTRA_CONF_FILES[@]}; f+=1 )); do
762 Q_PLUGIN_EXTRA_CONF_FILES[$f]=$Q_PLUGIN_EXTRA_CONF_PATH/${Q_PLUGIN_EXTRA_CONF_FILES[$f]}
Mark McClainb05c8762013-07-06 23:29:39 -0400763 done
764 fi
765
Joe Gordonbee5c502013-08-30 13:48:08 -0400766 if [ "$VIRT_DRIVER" = 'fake' ]; then
767 # Disable arbitrary limits
768 iniset $NEUTRON_CONF quotas quota_network -1
769 iniset $NEUTRON_CONF quotas quota_subnet -1
770 iniset $NEUTRON_CONF quotas quota_port -1
771 iniset $NEUTRON_CONF quotas quota_security_group -1
772 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
773 fi
774
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700775 # Format logging
776 if [ "$LOG_COLOR" == "True" ] && [ "$SYSLOG" == "False" ]; then
Salvatore Orlandobc7f6432013-11-25 10:11:14 -0800777 setup_colorized_logging $NEUTRON_CONF DEFAULT project_id
venkata anil9b1df572015-01-15 07:38:22 +0000778 else
779 # Show user_name and project_name by default like in nova
Ronald Bradforde8264902016-01-20 21:16:33 +0000780 iniset $NEUTRON_CONF DEFAULT logging_user_identity_format "%(user_name)s %(project_name)s"
Salvatore Orlando05ae8332013-08-20 14:51:08 -0700781 fi
782
Rob Crittenden18d47782014-03-19 17:47:42 -0400783 if is_service_enabled tls-proxy; then
784 # Set the service port for a proxy to take the original
785 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
786 fi
787
788 if is_ssl_enabled_service "nova"; then
Jamie Lennoxdc757dd2015-03-09 14:48:09 +1100789 iniset $NEUTRON_CONF nova cafile $SSL_BUNDLE_FILE
Rob Crittenden18d47782014-03-19 17:47:42 -0400790 fi
791
792 if is_ssl_enabled_service "neutron"; then
793 ensure_certificates NEUTRON
794
795 iniset $NEUTRON_CONF DEFAULT use_ssl True
796 iniset $NEUTRON_CONF DEFAULT ssl_cert_file "$NEUTRON_SSL_CERT"
797 iniset $NEUTRON_CONF DEFAULT ssl_key_file "$NEUTRON_SSL_KEY"
798 fi
799
Mark McClainb05c8762013-07-06 23:29:39 -0400800 _neutron_setup_rootwrap
801}
802
Ian Wienandaee18c72014-02-21 15:35:08 +1100803function _configure_neutron_debug_command {
Mark McClainb05c8762013-07-06 23:29:39 -0400804 if [[ "$Q_USE_DEBUG_COMMAND" != "True" ]]; then
805 return
806 fi
807
Martin Hickey30d5fae2015-11-10 13:44:15 +0000808 cp $NEUTRON_DIR/etc/l3_agent.ini.sample $NEUTRON_TEST_CONFIG_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400809
Mark McClainb05c8762013-07-06 23:29:39 -0400810 iniset $NEUTRON_TEST_CONFIG_FILE DEFAULT debug False
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700811 iniset $NEUTRON_TEST_CONFIG_FILE AGENT root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400812 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700813 iniset $NEUTRON_TEST_CONFIG_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400814 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400815
Mark McClainb05c8762013-07-06 23:29:39 -0400816 _neutron_setup_interface_driver $NEUTRON_TEST_CONFIG_FILE
817
818 neutron_plugin_configure_debug_command
819}
820
Ian Wienandaee18c72014-02-21 15:35:08 +1100821function _configure_neutron_dhcp_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400822
Martin Hickey30d5fae2015-11-10 13:44:15 +0000823 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400824
Ben Nemec03997942013-08-10 09:56:16 -0500825 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700826 iniset $Q_DHCP_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400827 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700828 iniset $Q_DHCP_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400829 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400830
Tan Lin27a196e2014-10-31 15:44:34 +0800831 if ! is_service_enabled q-l3; then
832 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
833 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
834 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
835 else
836 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
837 die "$LINENO" "Enable isolated metadata is a must for metadata network"
838 fi
839 fi
840 fi
841
Mark McClainb05c8762013-07-06 23:29:39 -0400842 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
843
844 neutron_plugin_configure_dhcp_agent
845}
846
Mark McClainb05c8762013-07-06 23:29:39 -0400847
Ian Wienandaee18c72014-02-21 15:35:08 +1100848function _configure_neutron_metadata_agent {
Martin Hickey30d5fae2015-11-10 13:44:15 +0000849 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400850
Ben Nemec03997942013-08-10 09:56:16 -0500851 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400852 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_ip $Q_META_DATA_IP
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700853 iniset $Q_META_CONF_FILE AGENT root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400854 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Hirofumi Ichihara2bb3a642015-08-18 12:59:08 -0700855 iniset $Q_META_CONF_FILE AGENT root_helper_daemon "$Q_RR_DAEMON_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400856 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400857}
858
Dina Belova58adaa62014-07-11 18:18:12 +0400859function _configure_neutron_ceilometer_notifications {
Wanlong Gaocf04a9a2016-01-16 17:46:35 +0800860 iniset $NEUTRON_CONF oslo_messaging_notifications driver messaging
Dina Belova58adaa62014-07-11 18:18:12 +0400861}
862
Armando Migliacciob3f26cb2016-04-13 23:28:06 +0000863function _configure_neutron_lbaas {
864 # Uses oslo config generator to generate LBaaS sample configuration files
865 (cd $NEUTRON_LBAAS_DIR && exec ./tools/generate_config_file_samples.sh)
866
867 if [ -f $NEUTRON_LBAAS_DIR/etc/neutron_lbaas.conf.sample ]; then
868 cp $NEUTRON_LBAAS_DIR/etc/neutron_lbaas.conf.sample $NEUTRON_CONF_DIR/neutron_lbaas.conf
869 iniset $NEUTRON_CONF_DIR/neutron_lbaas.conf service_providers service_provider $DEFAULT_LB_PROVIDER
870 fi
871 neutron_agent_lbaas_configure_common
872 neutron_agent_lbaas_configure_agent
873}
874
Ian Wienandaee18c72014-02-21 15:35:08 +1100875function _configure_neutron_metering {
Emilien Macchi40546f72013-09-24 15:10:25 +0200876 neutron_agent_metering_configure_common
877 neutron_agent_metering_configure_agent
878}
879
Ian Wienandaee18c72014-02-21 15:35:08 +1100880function _configure_neutron_fwaas {
Doug Wiegley37da4592015-01-30 23:30:08 -0700881 if [ -f $NEUTRON_FWAAS_DIR/etc/neutron_fwaas.conf ]; then
882 cp $NEUTRON_FWAAS_DIR/etc/neutron_fwaas.conf $NEUTRON_CONF_DIR
883 fi
Ravi Chunduru95c93e22013-07-16 04:18:47 -0700884 neutron_fwaas_configure_common
885 neutron_fwaas_configure_driver
886}
887
Brian Haleyeea76212014-06-27 11:45:50 -0400888function _configure_dvr {
889 iniset $NEUTRON_CONF DEFAULT router_distributed True
890 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
891}
892
893
Mark McClainb05c8762013-07-06 23:29:39 -0400894# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
895# It is called when q-agt is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100896function _configure_neutron_plugin_agent {
Mark McClainb05c8762013-07-06 23:29:39 -0400897 # Specify the default root helper prior to agent configuration to
898 # ensure that an agent's configuration can override the default
899 iniset /$Q_PLUGIN_CONF_FILE agent root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400900 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
901 iniset /$Q_PLUGIN_CONF_FILE agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
902 fi
Ben Nemec03997942013-08-10 09:56:16 -0500903 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Mark McClainb05c8762013-07-06 23:29:39 -0400904
905 # Configure agent for plugin
906 neutron_plugin_configure_plugin_agent
907}
908
909# _configure_neutron_service() - Set config files for neutron service
910# It is called when q-svc is enabled.
Ian Wienandaee18c72014-02-21 15:35:08 +1100911function _configure_neutron_service {
Mark McClainb05c8762013-07-06 23:29:39 -0400912 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
Mark McClainb05c8762013-07-06 23:29:39 -0400913 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
Kevin Benton08a5fcc2014-07-18 16:06:12 -0700914
Mark McClainb05c8762013-07-06 23:29:39 -0400915 # Update either configuration file with plugin
916 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
917
918 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
919 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
920 fi
921
Ben Nemec03997942013-08-10 09:56:16 -0500922 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
Chris Dent74a85b02015-04-22 18:02:39 +0000923 iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400924 iniset $NEUTRON_CONF DEFAULT allow_overlapping_ips $Q_ALLOW_OVERLAPPING_IP
925
926 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
927 _neutron_setup_keystone $NEUTRON_CONF keystone_authtoken
928
Atsushi SAKAIfe7b56c2015-11-13 17:06:16 +0900929 # Configuration for neutron notifications to nova.
Terry Wilsonf06c4432014-05-20 10:54:51 -0500930 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
931 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
Jamie Lennoxdc757dd2015-03-09 14:48:09 +1100932
Thomas Bechtoldfb948912016-03-27 08:59:42 +0200933 configure_auth_token_middleware $NEUTRON_CONF nova $NEUTRON_AUTH_CACHE_DIR nova
Aaron Rosencea32b12014-03-04 16:20:14 -0800934
Mark McClainb05c8762013-07-06 23:29:39 -0400935 # Configure plugin
936 neutron_plugin_configure_service
937}
938
939# Utility Functions
940#------------------
941
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900942# _neutron_service_plugin_class_add() - add service plugin class
Ian Wienandaee18c72014-02-21 15:35:08 +1100943function _neutron_service_plugin_class_add {
Isaku Yamahata9e136b42013-12-16 15:52:03 +0900944 local service_plugin_class=$1
945 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
946 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
947 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
948 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
949 fi
950}
951
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100952# _neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root).
953function _neutron_deploy_rootwrap_filters {
gong yong sheng3d6eaae2015-09-15 15:00:29 +0800954 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
955 return
956 fi
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100957 local srcdir=$1
Dean Troyer8421c2b2015-03-16 13:52:19 -0500958 sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D
959 sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100960}
961
Mark McClainb05c8762013-07-06 23:29:39 -0400962# _neutron_setup_rootwrap() - configure Neutron's rootwrap
Ian Wienandaee18c72014-02-21 15:35:08 +1100963function _neutron_setup_rootwrap {
Mark McClainb05c8762013-07-06 23:29:39 -0400964 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
965 return
966 fi
Mark McClainb05c8762013-07-06 23:29:39 -0400967 # Wipe any existing ``rootwrap.d`` files first
968 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
969 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
970 sudo rm -rf $Q_CONF_ROOTWRAP_D
971 fi
Ihar Hrachyshka5893cc72014-12-22 11:49:42 +0100972
973 _neutron_deploy_rootwrap_filters $NEUTRON_DIR
974
Mark McClainb05c8762013-07-06 23:29:39 -0400975 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
976 # location moved in newer versions, prefer new location
977 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
Dean Troyer8421c2b2015-03-16 13:52:19 -0500978 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 -0400979 else
Dean Troyer8421c2b2015-03-16 13:52:19 -0500980 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
Mark McClainb05c8762013-07-06 23:29:39 -0400981 fi
982 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
Robert Li2c5d4622015-04-21 15:48:22 -0400983 sudo sed -e 's:^exec_dirs=\(.*\)$:exec_dirs=\1,/usr/local/bin:' -i $Q_RR_CONF_FILE
984
Mark McClainb05c8762013-07-06 23:29:39 -0400985 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
986 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
Yuriy Taraday26623952014-07-16 17:41:53 +0400987 ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
Mark McClainb05c8762013-07-06 23:29:39 -0400988
989 # Set up the rootwrap sudoers for neutron
990 TEMPFILE=`mktemp`
Stephan Renatuse578eff2013-11-19 13:31:04 +0100991 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
Yuriy Taraday26623952014-07-16 17:41:53 +0400992 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE
Mark McClainb05c8762013-07-06 23:29:39 -0400993 chmod 0440 $TEMPFILE
994 sudo chown root:root $TEMPFILE
995 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
996
997 # Update the root_helper
998 iniset $NEUTRON_CONF agent root_helper "$Q_RR_COMMAND"
Yuriy Taraday26623952014-07-16 17:41:53 +0400999 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
1000 iniset $NEUTRON_CONF agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
1001 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001002}
1003
Ihar Hrachyshkabb4654b2015-10-06 18:09:07 +02001004# Configures keystone integration for neutron service
Ian Wienandaee18c72014-02-21 15:35:08 +11001005function _neutron_setup_keystone {
Mark McClainb05c8762013-07-06 23:29:39 -04001006 local conf_file=$1
1007 local section=$2
Jamie Lennox3561d7f2014-05-21 17:18:43 +10001008
Brant Knudson05952372014-09-19 17:22:22 -05001009 create_neutron_cache_dir
1010 configure_auth_token_middleware $conf_file $Q_ADMIN_USERNAME $NEUTRON_AUTH_CACHE_DIR $section
Mark McClainb05c8762013-07-06 23:29:39 -04001011}
1012
Ian Wienandaee18c72014-02-21 15:35:08 +11001013function _neutron_setup_interface_driver {
Mark McClainb05c8762013-07-06 23:29:39 -04001014
1015 # ovs_use_veth needs to be set before the plugin configuration
1016 # occurs to allow plugins to override the setting.
1017 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1018
1019 neutron_plugin_setup_interface_driver $1
1020}
Mark McClainb05c8762013-07-06 23:29:39 -04001021# Functions for Neutron Exercises
1022#--------------------------------
1023
Ian Wienandaee18c72014-02-21 15:35:08 +11001024function delete_probe {
Mark McClainb05c8762013-07-06 23:29:39 -04001025 local from_net="$1"
1026 net_id=`_get_net_id $from_net`
1027 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}'`
1028 neutron-debug --os-tenant-name admin --os-username admin probe-delete $probe_id
1029}
1030
Ian Wienandaee18c72014-02-21 15:35:08 +11001031function setup_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001032 if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
1033 public_net_id=`_get_net_id $PUBLIC_NETWORK_NAME`
Brad Behle629917a2016-03-22 14:27:32 -05001034 if [[ -n $public_net_id ]]; then
1035 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $public_net_id
1036 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001037 private_net_id=`_get_net_id $PRIVATE_NETWORK_NAME`
Brad Behle629917a2016-03-22 14:27:32 -05001038 if [[ -n $private_net_id ]]; then
1039 neutron-debug --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD probe-create --device-owner compute $private_net_id
1040 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001041 fi
1042}
1043
Ian Wienandaee18c72014-02-21 15:35:08 +11001044function teardown_neutron_debug {
Mark McClainb05c8762013-07-06 23:29:39 -04001045 delete_probe $PUBLIC_NETWORK_NAME
1046 delete_probe $PRIVATE_NETWORK_NAME
1047}
1048
Ian Wienandaee18c72014-02-21 15:35:08 +11001049function _get_net_id {
Victor Ryzhenkin878d7d82016-04-27 15:15:52 +03001050 neutron --os-cloud devstack-admin --os-region "$REGION_NAME" --os-tenant-name admin --os-username admin --os-password $ADMIN_PASSWORD net-list | grep $1 | awk '{print $2}'
Mark McClainb05c8762013-07-06 23:29:39 -04001051}
1052
Ian Wienandaee18c72014-02-21 15:35:08 +11001053function _get_probe_cmd_prefix {
Mark McClainb05c8762013-07-06 23:29:39 -04001054 local from_net="$1"
1055 net_id=`_get_net_id $from_net`
1056 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`
1057 echo "$Q_RR_COMMAND ip netns exec qprobe-$probe_id"
1058}
1059
Mark McClainb05c8762013-07-06 23:29:39 -04001060# ssh check
Ian Wienandaee18c72014-02-21 15:35:08 +11001061function _ssh_check_neutron {
Mark McClainb05c8762013-07-06 23:29:39 -04001062 local from_net=$1
1063 local key_file=$2
1064 local ip=$3
1065 local user=$4
1066 local timeout_sec=$5
1067 local probe_cmd = ""
1068 probe_cmd=`_get_probe_cmd_prefix $from_net`
Sean Dague442e4e92015-06-24 13:24:02 -04001069 local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success"
1070 test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec
Mark McClainb05c8762013-07-06 23:29:39 -04001071}
1072
1073# Neutron 3rd party programs
1074#---------------------------
1075
1076# please refer to ``lib/neutron_thirdparty/README.md`` for details
1077NEUTRON_THIRD_PARTIES=""
1078for f in $TOP_DIR/lib/neutron_thirdparty/*; do
Sean Dague3bdb9222013-10-22 08:36:16 -04001079 third_party=$(basename $f)
1080 if is_service_enabled $third_party; then
1081 source $TOP_DIR/lib/neutron_thirdparty/$third_party
1082 NEUTRON_THIRD_PARTIES="$NEUTRON_THIRD_PARTIES,$third_party"
1083 fi
Mark McClainb05c8762013-07-06 23:29:39 -04001084done
1085
Ian Wienandaee18c72014-02-21 15:35:08 +11001086function _neutron_third_party_do {
Mark McClainb05c8762013-07-06 23:29:39 -04001087 for third_party in ${NEUTRON_THIRD_PARTIES//,/ }; do
1088 ${1}_${third_party}
1089 done
1090}
1091
1092# configure_neutron_third_party() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +11001093function configure_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001094 _neutron_third_party_do configure
1095}
1096
1097# init_neutron_third_party() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +11001098function init_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001099 _neutron_third_party_do init
1100}
1101
1102# install_neutron_third_party() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +11001103function install_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001104 _neutron_third_party_do install
1105}
1106
1107# start_neutron_third_party() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +11001108function start_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001109 _neutron_third_party_do start
1110}
1111
1112# stop_neutron_third_party - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +11001113function stop_neutron_third_party {
Mark McClainb05c8762013-07-06 23:29:39 -04001114 _neutron_third_party_do stop
1115}
1116
armando-migliaccioef1e0802014-01-02 16:33:53 -08001117# check_neutron_third_party_integration() - Check that third party integration is sane
Ian Wienandaee18c72014-02-21 15:35:08 +11001118function check_neutron_third_party_integration {
armando-migliaccioef1e0802014-01-02 16:33:53 -08001119 _neutron_third_party_do check
1120}
1121
Mark McClainb05c8762013-07-06 23:29:39 -04001122# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +11001123$_XTRACE_NEUTRON
Mark McClainb05c8762013-07-06 23:29:39 -04001124
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01001125# Tell emacs to use shell-script-mode
1126## Local variables:
1127## mode: shell-script
1128## End: