blob: 5407f8a7b80341ef5d6da60122f1205c4a2fbc34 [file] [log] [blame]
Sean M. Collins2a242512016-05-03 09:03:09 -04001#!/bin/bash
2#
3# lib/neutron
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01004# functions - functions specific to neutron
Sean M. Collins2a242512016-05-03 09:03:09 -04005
6# Dependencies:
Sean M. Collins2a242512016-05-03 09:03:09 -04007# ``functions`` file
8# ``DEST`` must be defined
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01009# ``STACK_USER`` must be defined
Sean M. Collins2a242512016-05-03 09:03:09 -040010
11# ``stack.sh`` calls the entry points in this order:
12#
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010013# - install_neutron_agent_packages
14# - install_neutronclient
15# - install_neutron
16# - 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# - configure_neutron_after_post_config
24# - start_neutron_service_and_check
25# - check_neutron_third_party_integration
26# - start_neutron_agents
27# - create_neutron_initial_network
28#
29# ``unstack.sh`` calls the entry points in this order:
30#
31# - stop_neutron
32# - stop_neutron_third_party
33# - cleanup_neutron
Sean M. Collins2a242512016-05-03 09:03:09 -040034
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010035# 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
Sean M. Collins2a242512016-05-03 09:03:09 -040041
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010042
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#
50# See "Neutron Network Configuration" below for additional variables
51# that must be set in localrc for connectivity across hosts with
52# Neutron.
53
54# Settings
Sean M. Collins2a242512016-05-03 09:03:09 -040055# --------
56
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010057
58# Neutron Network Configuration
59# -----------------------------
60
61if is_service_enabled tls-proxy; then
62 Q_PROTOCOL="https"
63fi
64
65
Sean M. Collins2a242512016-05-03 09:03:09 -040066# Set up default directories
67GITDIR["python-neutronclient"]=$DEST/python-neutronclient
68
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010069
70NEUTRON_DIR=$DEST/neutron
71NEUTRON_FWAAS_DIR=$DEST/neutron-fwaas
72
73# Support entry points installation of console scripts
74if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
75 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
76else
77 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
78fi
79
80NEUTRON_CONF_DIR=/etc/neutron
81NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
82export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
83
Kevin Benton66b361b2017-06-13 00:31:01 -070084# NEUTRON_DEPLOY_MOD_WSGI defines how neutron is deployed, allowed values:
85# - False (default) : Run neutron under Eventlet
86# - True : Run neutron under uwsgi
87# TODO(annp): Switching to uwsgi in next cycle if things turn out to be stable
88# enough
Jens Harbott3492fee2018-11-30 13:57:17 +000089NEUTRON_DEPLOY_MOD_WSGI=$(trueorfalse False NEUTRON_DEPLOY_MOD_WSGI)
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010090
91NEUTRON_UWSGI_CONF=$NEUTRON_CONF_DIR/neutron-api-uwsgi.ini
Sean M. Collins2a242512016-05-03 09:03:09 -040092
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +020093# If NEUTRON_ENFORCE_SCOPE == True, it will set "enforce_scope"
94# and "enforce_new_defaults" to True in the Neutron's config to enforce usage
95# of the new RBAC policies and scopes.
96NEUTRON_ENFORCE_SCOPE=$(trueorfalse False NEUTRON_ENFORCE_SCOPE)
97
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010098# Agent binaries. Note, binary paths for other agents are set in per-service
99# scripts in lib/neutron_plugins/services/
100AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
101AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
102AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
Brian Haley9aaa5292017-09-20 14:23:05 -0400103
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100104# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
105# loaded from per-plugin scripts in lib/neutron_plugins/
106Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
107# NOTE(slaweq): NEUTRON_DHCP_CONF is used e.g. in neutron repository,
108# it was previously defined in the lib/neutron module which is now deleted.
109NEUTRON_DHCP_CONF=$Q_DHCP_CONF_FILE
110Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
111# NOTE(slaweq): NEUTRON_L3_CONF is used e.g. in neutron repository,
112# it was previously defined in the lib/neutron module which is now deleted.
113NEUTRON_L3_CONF=$Q_L3_CONF_FILE
114Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
Sean M. Collins2a242512016-05-03 09:03:09 -0400115
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100116# Default name for Neutron database
117Q_DB_NAME=${Q_DB_NAME:-neutron}
118# Default Neutron Plugin
119Q_PLUGIN=${Q_PLUGIN:-ml2}
120# Default Neutron Port
121Q_PORT=${Q_PORT:-9696}
122# Default Neutron Internal Port when using TLS proxy
123Q_PORT_INT=${Q_PORT_INT:-19696}
124# Default Neutron Host
125Q_HOST=${Q_HOST:-$SERVICE_HOST}
126# Default protocol
127Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
128# Default listen address
129Q_LISTEN_ADDRESS=${Q_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)}
130# Default admin username
131Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
132# Default auth strategy
133Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
134# RHEL's support for namespaces requires using veths with ovs
135Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
136Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
137Q_USE_ROOTWRAP_DAEMON=$(trueorfalse True Q_USE_ROOTWRAP_DAEMON)
138# Meta data IP
139Q_META_DATA_IP=${Q_META_DATA_IP:-$(ipv6_unquote $SERVICE_HOST)}
140# Allow Overlapping IP among subnets
141Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
142Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
143Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
144VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
145VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Sean M. Collins2a242512016-05-03 09:03:09 -0400146
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100147# Allow to skip stopping of OVN services
148SKIP_STOP_OVN=${SKIP_STOP_OVN:-False}
Sean M. Collins2a242512016-05-03 09:03:09 -0400149
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100150# The directory which contains files for Q_PLUGIN_EXTRA_CONF_FILES.
151# /etc/neutron is assumed by many of devstack plugins. Do not change.
152_Q_PLUGIN_EXTRA_CONF_PATH=/etc/neutron
Julia Kreger6e5b1382019-01-09 17:00:45 -0800153
Slawek Kaplonski1a21ccb2022-07-08 21:57:45 +0200154# The name of the service in the endpoint URL
155NEUTRON_ENDPOINT_SERVICE_NAME=${NEUTRON_ENDPOINT_SERVICE_NAME-"networking"}
156if [[ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" && -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then
157 NEUTRON_ENDPOINT_SERVICE_NAME="networking"
158fi
159
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100160# List of config file names in addition to the main plugin config file
161# To add additional plugin config files, use ``neutron_server_config_add``
162# utility function. For example:
163#
164# ``neutron_server_config_add file1``
165#
166# These config files are relative to ``/etc/neutron``. The above
167# example would specify ``--config-file /etc/neutron/file1`` for
168# neutron server.
169declare -a -g Q_PLUGIN_EXTRA_CONF_FILES
Julia Kreger6e5b1382019-01-09 17:00:45 -0800170
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100171# same as Q_PLUGIN_EXTRA_CONF_FILES, but with absolute path.
172declare -a -g _Q_PLUGIN_EXTRA_CONF_FILES_ABS
173
174
175Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
176if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
177 Q_RR_COMMAND="sudo"
178else
179 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
180 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
181 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
182 Q_RR_DAEMON_COMMAND="sudo $NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
183 fi
184fi
185
186
187# Distributed Virtual Router (DVR) configuration
188# Can be:
189# - ``legacy`` - No DVR functionality
190# - ``dvr_snat`` - Controller or single node DVR
191# - ``dvr`` - Compute node in multi-node DVR
192# - ``dvr_no_external`` - Compute node in multi-node DVR, no external network
193#
194Q_DVR_MODE=${Q_DVR_MODE:-legacy}
195if [[ "$Q_DVR_MODE" != "legacy" ]]; then
196 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,l2population
197fi
198
199# Provider Network Configurations
200# --------------------------------
201
202# The following variables control the Neutron ML2 plugins' allocation
203# of tenant networks and availability of provider networks. If these
204# are not configured in ``localrc``, tenant networks will be local to
205# the host (with no remote connectivity), and no physical resources
206# will be available for the allocation of provider networks.
207
208# To disable tunnels (GRE or VXLAN) for tenant networks,
209# set to False in ``local.conf``.
210# GRE tunnels are only supported by the openvswitch.
211ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
212
213# If using GRE, VXLAN or GENEVE tunnels for tenant networks,
214# specify the range of IDs from which tenant networks are
215# allocated. Can be overridden in ``localrc`` if necessary.
216TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
217
218# To use VLANs for tenant networks, set to True in localrc. VLANs
219# are supported by the ML2 plugins, requiring additional configuration
220# described below.
221ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
222
223# If using VLANs for tenant networks, set in ``localrc`` to specify
224# the range of VLAN VIDs from which tenant networks are
225# allocated. An external network switch must be configured to
226# trunk these VLANs between hosts for multi-host connectivity.
227#
228# Example: ``TENANT_VLAN_RANGE=1000:1999``
229TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
230
231# If using VLANs for tenant networks, or if using flat or VLAN
232# provider networks, set in ``localrc`` to the name of the physical
233# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
234# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
235# agent, as described below.
236#
237# Example: ``PHYSICAL_NETWORK=default``
238PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-public}
239
240# With the openvswitch agent, if using VLANs for tenant networks,
241# or if using flat or VLAN provider networks, set in ``localrc`` to
242# the name of the OVS bridge to use for the physical network. The
243# bridge will be created if it does not already exist, but a
244# physical interface must be manually added to the bridge as a
245# port for external connectivity.
246#
247# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
248OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-br-ex}
249
250# With the linuxbridge agent, if using VLANs for tenant networks,
251# or if using flat or VLAN provider networks, set in ``localrc`` to
252# the name of the network interface to use for the physical
253# network.
254#
255# Example: ``LB_PHYSICAL_INTERFACE=eth1``
256if [[ $Q_AGENT == "linuxbridge" && -z ${LB_PHYSICAL_INTERFACE} ]]; then
257 default_route_dev=$( (ip route; ip -6 route) | grep ^default | head -n 1 | awk '{print $5}')
258 die_if_not_set $LINENO default_route_dev "Failure retrieving default route device"
259 LB_PHYSICAL_INTERFACE=$default_route_dev
260fi
261
262# With the openvswitch plugin, set to True in ``localrc`` to enable
263# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
264#
265# Example: ``OVS_ENABLE_TUNNELING=True``
266OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
267
268# Use DHCP agent for providing metadata service in the case of
269# without L3 agent (No Route Agent), set to True in localrc.
270ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
271
272# Add a static route as dhcp option, so the request to 169.254.169.254
273# will be able to reach through a route(DHCP agent)
274# This option require ENABLE_ISOLATED_METADATA = True
275ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
276# Neutron plugin specific functions
277# ---------------------------------
278
279# Please refer to ``lib/neutron_plugins/README.md`` for details.
280if [ -f $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN ]; then
281 source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
282fi
283
284# Agent metering service plugin functions
285# -------------------------------------------
286
287# Hardcoding for 1 service plugin for now
288source $TOP_DIR/lib/neutron_plugins/services/metering
289
290# L3 Service functions
291source $TOP_DIR/lib/neutron_plugins/services/l3
292
293# Additional Neutron service plugins
294source $TOP_DIR/lib/neutron_plugins/services/placement
295source $TOP_DIR/lib/neutron_plugins/services/trunk
296source $TOP_DIR/lib/neutron_plugins/services/qos
elajkata84b2092021-11-17 11:52:56 +0100297source $TOP_DIR/lib/neutron_plugins/services/segments
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100298
299# Use security group or not
300if has_neutron_plugin_security_group; then
301 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
302else
303 Q_USE_SECGROUP=False
304fi
305
306# Save trace setting
307_XTRACE_NEUTRON=$(set +o | grep xtrace)
308set +o xtrace
309
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900310
Sean M. Collins2a242512016-05-03 09:03:09 -0400311# Functions
312# ---------
313
314# Test if any Neutron services are enabled
315# is_neutron_enabled
316function is_neutron_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -0700317 [[ ,${DISABLED_SERVICES} =~ ,"neutron" ]] && return 1
Sean M. Collins2a242512016-05-03 09:03:09 -0400318 [[ ,${ENABLED_SERVICES} =~ ,"neutron-" || ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
319 return 1
320}
321
322# Test if any Neutron services are enabled
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100323# TODO(slaweq): this is not really needed now and we should remove it as soon
324# as it will not be called from any other Devstack plugins, like e.g. Neutron
325# plugin
Sean M. Collins2a242512016-05-03 09:03:09 -0400326function is_neutron_legacy_enabled {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100327 return 0
Sean M. Collins2a242512016-05-03 09:03:09 -0400328}
329
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100330function _determine_config_server {
331 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" != '' ]]; then
332 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" = "$_Q_PLUGIN_EXTRA_CONF_PATH" ]]; then
333 deprecated "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
334 else
335 die $LINENO "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
336 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400337 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100338 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 ]]; then
339 deprecated "Q_PLUGIN_EXTRA_CONF_FILES is deprecated. Use neutron_server_config_add instead."
Sean M. Collins2a242512016-05-03 09:03:09 -0400340 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100341 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
342 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($_Q_PLUGIN_EXTRA_CONF_PATH/$cfg_file)
Sean M. Collins2a242512016-05-03 09:03:09 -0400343 done
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100344
345 local cfg_file
346 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
347 for cfg_file in ${_Q_PLUGIN_EXTRA_CONF_FILES_ABS[@]}; do
348 opts+=" --config-file $cfg_file"
349 done
350 echo "$opts"
Sean M. Collins2a242512016-05-03 09:03:09 -0400351}
352
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100353function _determine_config_l3 {
354 local opts="--config-file $NEUTRON_CONF --config-file $Q_L3_CONF_FILE"
355 echo "$opts"
Ihar Hrachyshkae65ab4a2017-02-24 17:47:55 +0000356}
357
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100358# For services and agents that require it, dynamically construct a list of
359# --config-file arguments that are passed to the binary.
360function determine_config_files {
361 local opts=""
362 case "$1" in
363 "neutron-server") opts="$(_determine_config_server)" ;;
364 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
365 esac
366 if [ -z "$opts" ] ; then
367 die $LINENO "Could not determine config files for $1."
YAMAMOTO Takashi1df17c92017-05-01 17:00:42 +0900368 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100369 echo "$opts"
370}
Sean M. Collins2a242512016-05-03 09:03:09 -0400371
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100372# configure_neutron()
373# Set common config for all neutron server and agents.
374function configure_neutron {
375 _configure_neutron_common
Sean M. Collins5394cc12016-05-11 15:03:38 -0400376 iniset_rpc_backend neutron $NEUTRON_CONF
377
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100378 if is_service_enabled q-metering neutron-metering; then
379 _configure_neutron_metering
380 fi
381 if is_service_enabled q-agt neutron-agent; then
382 _configure_neutron_plugin_agent
383 fi
384 if is_service_enabled q-dhcp neutron-dhcp; then
385 _configure_neutron_dhcp_agent
386 fi
387 if is_service_enabled q-l3 neutron-l3; then
388 _configure_neutron_l3_agent
389 fi
390 if is_service_enabled q-meta neutron-metadata-agent; then
391 _configure_neutron_metadata_agent
Sean M. Collins2a242512016-05-03 09:03:09 -0400392 fi
393
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100394 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
395 _configure_dvr
396 fi
397 if is_service_enabled ceilometer; then
398 _configure_neutron_ceilometer_notifications
399 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400400
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100401 if [[ $Q_AGENT == "ovn" ]]; then
402 configure_ovn
403 configure_ovn_plugin
404 fi
Brian Haley9aaa5292017-09-20 14:23:05 -0400405
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100406 # Configure Neutron's advanced services
407 if is_service_enabled q-placement neutron-placement; then
408 configure_placement_extension
409 fi
410 if is_service_enabled q-trunk neutron-trunk; then
411 configure_trunk_extension
412 fi
413 if is_service_enabled q-qos neutron-qos; then
414 configure_qos
415 if is_service_enabled q-l3 neutron-l3; then
416 configure_l3_agent_extension_fip_qos
417 configure_l3_agent_extension_gateway_ip_qos
Denis Buliga0bf75a42017-02-06 16:56:46 +0200418 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400419 fi
elajkata84b2092021-11-17 11:52:56 +0100420 if is_service_enabled neutron-segments; then
421 configure_placement_neutron
422 configure_segments_extension
423 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400424
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100425 # Finally configure Neutron server and core plugin
426 if is_service_enabled q-agt neutron-agent q-svc neutron-api; then
427 _configure_neutron_service
Sean M. Collins2a242512016-05-03 09:03:09 -0400428 fi
429
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100430 iniset $NEUTRON_CONF DEFAULT api_workers "$API_WORKERS"
431 # devstack is not a tool for running uber scale OpenStack
432 # clouds, therefore running without a dedicated RPC worker
433 # for state reports is more than adequate.
434 iniset $NEUTRON_CONF DEFAULT rpc_state_report_workers 0
Ihar Hrachyshkae3915932017-02-24 06:24:47 +0000435
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100436 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
437 write_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_BIN_DIR/neutron-api" "/networking"
Sean M. Collins8063fee2016-05-24 11:27:36 -0700438 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400439}
440
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100441function configure_neutron_nova {
442 create_nova_conf_neutron $NOVA_CONF
443 if [[ "${CELLSV2_SETUP}" == "superconductor" ]]; then
444 for i in $(seq 1 $NOVA_NUM_CELLS); do
445 local conf
446 conf=$(conductor_conf $i)
447 create_nova_conf_neutron $conf
448 done
Sean M. Collins2a242512016-05-03 09:03:09 -0400449 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400450}
451
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100452function create_nova_conf_neutron {
Lucas Alvares Gomese6385932018-06-28 11:00:28 +0100453 local conf=${1:-$NOVA_CONF}
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400454 iniset $conf neutron auth_type "password"
455 iniset $conf neutron auth_url "$KEYSTONE_SERVICE_URI"
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100456 iniset $conf neutron username "$Q_ADMIN_USERNAME"
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400457 iniset $conf neutron password "$SERVICE_PASSWORD"
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100458 iniset $conf neutron user_domain_name "$SERVICE_DOMAIN_NAME"
459 iniset $conf neutron project_name "$SERVICE_PROJECT_NAME"
460 iniset $conf neutron project_domain_name "$SERVICE_DOMAIN_NAME"
461 iniset $conf neutron auth_strategy "$Q_AUTH_STRATEGY"
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400462 iniset $conf neutron region_name "$REGION_NAME"
Sean M. Collins2a242512016-05-03 09:03:09 -0400463
Gary Kotton88f85582016-08-14 06:55:42 -0700464 # optionally set options in nova_conf
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400465 neutron_plugin_create_nova_conf $conf
Gary Kotton88f85582016-08-14 06:55:42 -0700466
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100467 if is_service_enabled q-meta neutron-metadata-agent; then
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400468 iniset $conf neutron service_metadata_proxy "True"
Sean M. Collins2a242512016-05-03 09:03:09 -0400469 fi
470
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100471 iniset $conf DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
472 iniset $conf DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Sean M. Collins2a242512016-05-03 09:03:09 -0400473}
474
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100475# create_neutron_accounts() - Set up common required neutron accounts
476
Sean M. Collins2a242512016-05-03 09:03:09 -0400477# Tenant User Roles
478# ------------------------------------------------------------------
479# service neutron admin # if enabled
480
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100481# Migrated from keystone_data.sh
482function create_neutron_accounts {
Kevin Benton66b361b2017-06-13 00:31:01 -0700483 local neutron_url
Kevin Benton66b361b2017-06-13 00:31:01 -0700484 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100485 neutron_url=$Q_PROTOCOL://$SERVICE_HOST/
Kevin Benton66b361b2017-06-13 00:31:01 -0700486 else
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100487 neutron_url=$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/
Kevin Benton66b361b2017-06-13 00:31:01 -0700488 fi
Slawek Kaplonski1a21ccb2022-07-08 21:57:45 +0200489 if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then
490 neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME
491 fi
Kevin Benton66b361b2017-06-13 00:31:01 -0700492
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100493 if is_service_enabled q-svc neutron-api; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400494
495 create_service_user "neutron"
496
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100497 get_or_create_service "neutron" "network" "Neutron Service"
498 get_or_create_endpoint \
499 "network" \
Kevin Benton66b361b2017-06-13 00:31:01 -0700500 "$REGION_NAME" "$neutron_url"
Sean M. Collins2a242512016-05-03 09:03:09 -0400501 fi
502}
503
Sean M. Collins2a242512016-05-03 09:03:09 -0400504# init_neutron() - Initialize databases, etc.
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100505function init_neutron {
506 recreate_database $Q_DB_NAME
Clark Boylan633dbc32017-06-14 12:09:21 -0700507 time_start "dbsync"
Sean M. Collins2a242512016-05-03 09:03:09 -0400508 # Run Neutron db migrations
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100509 $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 -0700510 time_stop "dbsync"
Sean M. Collins2a242512016-05-03 09:03:09 -0400511}
512
513# install_neutron() - Collect source and prepare
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100514function install_neutron {
Sean M. Collins2a242512016-05-03 09:03:09 -0400515 # Install neutron-lib from git so we make sure we're testing
516 # the latest code.
517 if use_library_from_git "neutron-lib"; then
518 git_clone_by_name "neutron-lib"
519 setup_dev_lib "neutron-lib"
520 fi
521
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100522 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
523 setup_develop $NEUTRON_DIR
Sean M. Collins2a242512016-05-03 09:03:09 -0400524
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100525 if [[ $Q_AGENT == "ovn" ]]; then
526 install_ovn
Sean M. Collins2a242512016-05-03 09:03:09 -0400527 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400528}
529
530# install_neutronclient() - Collect source and prepare
531function install_neutronclient {
532 if use_library_from_git "python-neutronclient"; then
533 git_clone_by_name "python-neutronclient"
534 setup_dev_lib "python-neutronclient"
Sean M. Collins2a242512016-05-03 09:03:09 -0400535 fi
536}
537
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100538# install_neutron_agent_packages() - Collect source and prepare
539function install_neutron_agent_packages {
540 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
541 if is_service_enabled q-l3 neutron-l3; then
542 install_package radvd
Sean M. Collins2a242512016-05-03 09:03:09 -0400543 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100544 # install packages that are specific to plugin agent(s)
545 if is_service_enabled q-agt neutron-agent q-dhcp neutron-dhcp q-l3 neutron-l3; then
546 neutron_plugin_install_agent_packages
Sean M. Collins2a242512016-05-03 09:03:09 -0400547 fi
548}
549
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100550# Finish neutron configuration
551function configure_neutron_after_post_config {
552 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
553 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
Sean M. Collins2a242512016-05-03 09:03:09 -0400554 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100555 configure_rbac_policies
Sean M. Collins2a242512016-05-03 09:03:09 -0400556}
557
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +0200558# configure_rbac_policies() - Configure Neutron to enforce new RBAC
559# policies and scopes if NEUTRON_ENFORCE_SCOPE == True
560function configure_rbac_policies {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100561 if [[ "$NEUTRON_ENFORCE_SCOPE" == "True" || "$ENFORCE_SCOPE" == True ]]; then
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +0200562 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults True
563 iniset $NEUTRON_CONF oslo_policy enforce_scope True
564 else
565 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults False
566 iniset $NEUTRON_CONF oslo_policy enforce_scope False
567 fi
568}
569
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100570# Start running OVN processes
571function start_ovn_services {
572 if [[ $Q_AGENT == "ovn" ]]; then
Lucas Alvares Gomesa3891282023-07-18 16:31:28 +0100573 if [ "$VIRT_DRIVER" != 'ironic' ]; then
574 # NOTE(TheJulia): Ironic's devstack plugin needs to perform
575 # additional networking configuration to setup a working test
576 # environment with test virtual machines to emulate baremetal,
577 # which requires OVN to be up and running earlier to complete
578 # that base configuration.
579 init_ovn
580 start_ovn
581 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100582 if [[ "$OVN_L3_CREATE_PUBLIC_NETWORK" == "True" ]]; then
583 if [[ "$NEUTRON_CREATE_INITIAL_NETWORKS" != "True" ]]; then
584 echo "OVN_L3_CREATE_PUBLIC_NETWORK=True is being ignored "
585 echo "because NEUTRON_CREATE_INITIAL_NETWORKS is set to False"
586 else
587 create_public_bridge
588 fi
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400589 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400590 fi
591}
592
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100593# Start running processes
594function start_neutron_service_and_check {
595 local service_port=$Q_PORT
596 local service_protocol=$Q_PROTOCOL
597 local cfg_file_options
598 local neutron_url
Sean M. Collins2a242512016-05-03 09:03:09 -0400599
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100600 cfg_file_options="$(determine_config_files neutron-server)"
Sean M. Collins2a242512016-05-03 09:03:09 -0400601
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100602 if is_service_enabled tls-proxy; then
603 service_port=$Q_PORT_INT
604 service_protocol="http"
Sean M. Collins2a242512016-05-03 09:03:09 -0400605 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100606 # Start the Neutron service
607 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
608 enable_service neutron-api
609 run_process neutron-api "$(which uwsgi) --procname-prefix neutron-api --ini $NEUTRON_UWSGI_CONF"
610 neutron_url=$Q_PROTOCOL://$Q_HOST/
611 enable_service neutron-rpc-server
612 run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $cfg_file_options"
613 else
614 run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
615 neutron_url=$service_protocol://$Q_HOST:$service_port/
616 # Start proxy if enabled
617 if is_service_enabled tls-proxy; then
618 start_tls_proxy neutron '*' $Q_PORT $Q_HOST $Q_PORT_INT
619 fi
620 fi
621 if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then
622 neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME
623 fi
624 echo "Waiting for Neutron to start..."
Sean M. Collins2a242512016-05-03 09:03:09 -0400625
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100626 local testcmd="wget ${ssl_ca} --no-proxy -q -O- $neutron_url"
627 test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900628}
629
Sean M. Collins2a242512016-05-03 09:03:09 -0400630function start_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100631 start_l2_agent "$@"
632 start_other_agents "$@"
633}
634
635# Control of the l2 agent is separated out to make it easier to test partial
636# upgrades (everything upgraded except the L2 agent)
637function start_l2_agent {
638 run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
639
640 if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then
641 sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
642 sudo ip link set $OVS_PHYSICAL_BRIDGE up
643 sudo ip link set br-int up
644 sudo ip link set $PUBLIC_INTERFACE up
645 if is_ironic_hardware; then
646 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
647 sudo ip addr del $IP dev $PUBLIC_INTERFACE
648 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
649 done
650 sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
651 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400652 fi
653}
654
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100655function start_other_agents {
656 run_process q-dhcp "$AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file $Q_DHCP_CONF_FILE"
657
658 run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
659
660 run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file $Q_META_CONF_FILE"
661 run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
662}
663
664# Start running processes, including screen
665function start_neutron_agents {
666 # NOTE(slaweq): it's now just a wrapper for start_neutron function
667 start_neutron "$@"
668}
669
670function stop_l2_agent {
671 stop_process q-agt
672}
673
674# stop_other() - Stop running processes
675function stop_other {
676 if is_service_enabled q-dhcp neutron-dhcp; then
677 stop_process q-dhcp
678 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
679 [ ! -z "$pid" ] && sudo kill -9 $pid
680 fi
681
682 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
683 stop_process neutron-rpc-server
684 stop_process neutron-api
685 else
686 stop_process q-svc
687 fi
688
689 if is_service_enabled q-l3 neutron-l3; then
690 sudo pkill -f "radvd -C $DATA_DIR/neutron/ra"
691 stop_process q-l3
692 fi
693
694 if is_service_enabled q-meta neutron-metadata-agent; then
695 stop_process q-meta
696 fi
697
698 if is_service_enabled q-metering neutron-metering; then
699 neutron_metering_stop
700 fi
701
702 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Bence Romsics71c3c402022-12-21 13:50:54 +0100703 # pkill takes care not to kill itself, but it may kill its parent
704 # sudo unless we use the "ps | grep [f]oo" trick
705 sudo pkill -9 -f "$NEUTRON_ROOTWRAP-[d]aemon" || :
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100706 fi
707}
708
709# stop_neutron() - Stop running processes (non-screen)
Sean M. Collins2a242512016-05-03 09:03:09 -0400710function stop_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100711 stop_other
712 stop_l2_agent
713
714 if [[ $Q_AGENT == "ovn" && $SKIP_STOP_OVN != "True" ]]; then
715 stop_ovn
Sean M. Collins2a242512016-05-03 09:03:09 -0400716 fi
717}
718
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100719# _move_neutron_addresses_route() - Move the primary IP to the OVS bridge
720# on startup, or back to the public interface on cleanup. If no IP is
721# configured on the interface, just add it as a port to the OVS bridge.
722function _move_neutron_addresses_route {
723 local from_intf=$1
724 local to_intf=$2
725 local add_ovs_port=$3
726 local del_ovs_port=$4
727 local af=$5
728
729 if [[ -n "$from_intf" && -n "$to_intf" ]]; then
730 # Remove the primary IP address from $from_intf and add it to $to_intf,
731 # along with the default route, if it exists. Also, when called
732 # on configure we will also add $from_intf as a port on $to_intf,
733 # assuming it is an OVS bridge.
734
735 local IP_REPLACE=""
736 local IP_DEL=""
737 local IP_UP=""
738 local DEFAULT_ROUTE_GW
739 DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf\s/ { print \$3; exit }")
740 local ADD_OVS_PORT=""
741 local DEL_OVS_PORT=""
742 local ARP_CMD=""
743
744 IP_BRD=$(ip -f $af a s dev $from_intf scope global primary | grep inet | awk '{ print $2, $3, $4; exit }')
745
746 if [ "$DEFAULT_ROUTE_GW" != "" ]; then
747 ADD_DEFAULT_ROUTE="sudo ip -f $af r replace default via $DEFAULT_ROUTE_GW dev $to_intf"
748 fi
749
750 if [[ "$add_ovs_port" == "True" ]]; then
751 ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf"
752 fi
753
754 if [[ "$del_ovs_port" == "True" ]]; then
755 DEL_OVS_PORT="sudo ovs-vsctl --if-exists del-port $from_intf $to_intf"
756 fi
757
758 if [[ "$IP_BRD" != "" ]]; then
759 IP_DEL="sudo ip addr del $IP_BRD dev $from_intf"
760 IP_REPLACE="sudo ip addr replace $IP_BRD dev $to_intf"
761 IP_UP="sudo ip link set $to_intf up"
762 if [[ "$af" == "inet" ]]; then
763 IP=$(echo $IP_BRD | awk '{ print $1; exit }' | grep -o -E '(.*)/' | cut -d "/" -f1)
764 ARP_CMD="sudo arping -A -c 3 -w 5 -I $to_intf $IP "
765 fi
766 fi
767
768 # The add/del OVS port calls have to happen either before or
769 # after the address is moved in order to not leave it orphaned.
770 $DEL_OVS_PORT; $IP_DEL; $IP_REPLACE; $IP_UP; $ADD_OVS_PORT; $ADD_DEFAULT_ROUTE; $ARP_CMD
771 fi
772}
773
774# _configure_public_network_connectivity() - Configures connectivity to the
775# external network using $PUBLIC_INTERFACE or NAT on the single interface
776# machines
777function _configure_public_network_connectivity {
778 # If we've given a PUBLIC_INTERFACE to take over, then we assume
779 # that we can own the whole thing, and privot it into the OVS
780 # bridge. If we are not, we're probably on a single interface
781 # machine, and we just setup NAT so that fixed guests can get out.
782 if [[ -n "$PUBLIC_INTERFACE" ]]; then
783 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" True False "inet"
784
785 if [[ $(ip -f inet6 a s dev "$PUBLIC_INTERFACE" | grep -c 'global') != 0 ]]; then
786 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" False False "inet6"
787 fi
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -0500788 else
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100789 for d in $default_v4_route_devs; do
790 sudo iptables -t nat -A POSTROUTING -o $d -s $FLOATING_RANGE -j MASQUERADE
791 done
792 fi
793}
794
795# cleanup_neutron() - Remove residual data files, anything left over from previous
796# runs that a clean run would need to clean up
797function cleanup_neutron {
798 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
799 stop_process neutron-api
800 stop_process neutron-rpc-server
801 remove_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_BIN_DIR/neutron-api"
802 sudo rm -f $(apache_site_config_for neutron-api)
803 fi
804
805 if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then
806 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False True "inet"
807
808 if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then
809 # ip(8) wants the prefix length when deleting
810 local v6_gateway
811 v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }')
812 sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE
813 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False False "inet6"
814 fi
815
816 if is_provider_network && is_ironic_hardware; then
817 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
818 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
819 sudo ip addr add $IP dev $PUBLIC_INTERFACE
820 done
821 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
822 fi
823 fi
824
825 if is_neutron_ovs_base_plugin; then
826 neutron_ovs_base_cleanup
827 fi
828
829 if [[ $Q_AGENT == "linuxbridge" ]]; then
830 neutron_lb_cleanup
831 fi
832
833 # delete all namespaces created by neutron
834 for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|fip|snat)-[0-9a-f-]*'); do
835 sudo ip netns delete ${ns}
836 done
837
838 if [[ $Q_AGENT == "ovn" ]]; then
839 cleanup_ovn
840 fi
841}
842
843
844function _create_neutron_conf_dir {
845 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
846 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
847}
848
849# _configure_neutron_common()
850# Set common config for all neutron server and agents.
851# This MUST be called before other ``_configure_neutron_*`` functions.
852function _configure_neutron_common {
853 _create_neutron_conf_dir
854
855 # Uses oslo config generator to generate core sample configuration files
856 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
857
858 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
859
860 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
861
862 # allow neutron user to administer neutron to match neutron account
863 # NOTE(amotoki): This is required for nova works correctly with neutron.
864 if [ -f $NEUTRON_DIR/etc/policy.json ]; then
865 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
866 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
867 else
868 echo '{"context_is_admin": "role:admin or user_name:neutron"}' > $Q_POLICY_FILE
869 fi
870
871 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
872 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
873 neutron_plugin_configure_common
874
875 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
876 die $LINENO "Neutron plugin not set.. exiting"
877 fi
878
879 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
880 mkdir -p /$Q_PLUGIN_CONF_PATH
881 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
882 # NOTE(slaweq): NEUTRON_CORE_PLUGIN_CONF is used e.g. in neutron repository,
883 # it was previously defined in the lib/neutron module which is now deleted.
884 NEUTRON_CORE_PLUGIN_CONF=$Q_PLUGIN_CONF_FILE
885 # NOTE(hichihara): Some neutron vendor plugins were already decomposed and
886 # there is no config file in Neutron tree. They should prepare the file in each plugin.
887 if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then
888 cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE
889 elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then
890 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
891 fi
892
893 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
894 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
895 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
896 iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS
897 iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock
898
899 # NOTE(freerunner): Need to adjust Region Name for nova in multiregion installation
900 iniset $NEUTRON_CONF nova region_name $REGION_NAME
901
902 if [ "$VIRT_DRIVER" = 'fake' ]; then
903 # Disable arbitrary limits
904 iniset $NEUTRON_CONF quotas quota_network -1
905 iniset $NEUTRON_CONF quotas quota_subnet -1
906 iniset $NEUTRON_CONF quotas quota_port -1
907 iniset $NEUTRON_CONF quotas quota_security_group -1
908 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
909 fi
910
911 # Format logging
912 setup_logging $NEUTRON_CONF
913
914 if is_service_enabled tls-proxy && [ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" ]; then
915 # Set the service port for a proxy to take the original
916 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
917 iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True
918 fi
919
920 _neutron_setup_rootwrap
921}
922
923function _configure_neutron_dhcp_agent {
924
925 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE
926
927 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
928 # make it so we have working DNS from guests
929 iniset $Q_DHCP_CONF_FILE DEFAULT dnsmasq_local_resolv True
930 configure_root_helper_options $Q_DHCP_CONF_FILE
931
932 if ! is_service_enabled q-l3 neutron-l3; then
933 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
934 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
935 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
936 else
937 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
938 die "$LINENO" "Enable isolated metadata is a must for metadata network"
939 fi
940 fi
941 fi
942
943 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
944
945 neutron_plugin_configure_dhcp_agent $Q_DHCP_CONF_FILE
946}
947
948
949function _configure_neutron_metadata_agent {
950 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE
951
952 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
953 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_host $Q_META_DATA_IP
954 iniset $Q_META_CONF_FILE DEFAULT metadata_workers $API_WORKERS
955 configure_root_helper_options $Q_META_CONF_FILE
956}
957
958function _configure_neutron_ceilometer_notifications {
959 iniset $NEUTRON_CONF oslo_messaging_notifications driver messagingv2
960}
961
962function _configure_neutron_metering {
963 neutron_agent_metering_configure_common
964 neutron_agent_metering_configure_agent
965}
966
967function _configure_dvr {
968 iniset $NEUTRON_CONF DEFAULT router_distributed True
969 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
970}
971
972
973# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
974# It is called when q-agt is enabled.
975function _configure_neutron_plugin_agent {
976 # Specify the default root helper prior to agent configuration to
977 # ensure that an agent's configuration can override the default
978 configure_root_helper_options /$Q_PLUGIN_CONF_FILE
979 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
980
981 # Configure agent for plugin
982 neutron_plugin_configure_plugin_agent
983}
984
985function _replace_api_paste_composite {
986 local sep
987 sep=$(echo -ne "\x01")
988 # Replace it
989 $sudo sed -i -e "s/\/\: neutronversions_composite/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/\: neutronversions_composite/" "$Q_API_PASTE_FILE"
990 $sudo sed -i -e "s/\/healthcheck\: healthcheck/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/healthcheck\: healthcheck/" "$Q_API_PASTE_FILE"
991 $sudo sed -i -e "s/\/v2.0\: neutronapi_v2_0/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/v2.0\: neutronapi_v2_0/" "$Q_API_PASTE_FILE"
992}
993
994# _configure_neutron_service() - Set config files for neutron service
995# It is called when q-svc is enabled.
996function _configure_neutron_service {
997 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
998 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
999
1000 if [[ -n "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then
1001 _replace_api_paste_composite
1002 fi
1003
1004 # Update either configuration file with plugin
1005 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
1006
1007 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1008 iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE
1009
1010 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
1011 configure_keystone_authtoken_middleware $NEUTRON_CONF $Q_ADMIN_USERNAME
1012
1013 # Configuration for neutron notifications to nova.
1014 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
1015 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
1016
1017 configure_keystone_authtoken_middleware $NEUTRON_CONF nova nova
1018
1019 # Configuration for placement client
1020 configure_keystone_authtoken_middleware $NEUTRON_CONF placement placement
1021
1022 # Configure plugin
1023 neutron_plugin_configure_service
1024}
1025
1026# Utility Functions
1027#------------------
1028
1029# neutron_service_plugin_class_add() - add service plugin class
1030function neutron_service_plugin_class_add {
1031 local service_plugin_class=$1
1032 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
1033 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
1034 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
1035 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
1036 fi
1037}
1038
1039# neutron_ml2_extension_driver_add() - add ML2 extension driver
1040function neutron_ml2_extension_driver_add {
1041 local extension=$1
1042 if [[ $Q_ML2_PLUGIN_EXT_DRIVERS == '' ]]; then
1043 Q_ML2_PLUGIN_EXT_DRIVERS=$extension
1044 elif [[ ! ,${Q_ML2_PLUGIN_EXT_DRIVERS}, =~ ,${extension}, ]]; then
1045 Q_ML2_PLUGIN_EXT_DRIVERS="$Q_ML2_PLUGIN_EXT_DRIVERS,$extension"
1046 fi
1047}
1048
1049# neutron_server_config_add() - add server config file
1050function neutron_server_config_add {
1051 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($1)
1052}
1053
1054# neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root).
1055function neutron_deploy_rootwrap_filters {
1056 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1057 return
1058 fi
1059 local srcdir=$1
1060 sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D
1061 sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
1062}
1063
1064# _neutron_setup_rootwrap() - configure Neutron's rootwrap
1065function _neutron_setup_rootwrap {
1066 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1067 return
1068 fi
1069 # Wipe any existing ``rootwrap.d`` files first
1070 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
1071 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
1072 sudo rm -rf $Q_CONF_ROOTWRAP_D
1073 fi
1074
1075 neutron_deploy_rootwrap_filters $NEUTRON_DIR
1076
1077 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
1078 # location moved in newer versions, prefer new location
1079 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
1080 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
1081 else
1082 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
1083 fi
1084 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
yatinkarelffc1b762023-08-28 10:52:26 +05301085 # Rely on $PATH set by devstack to determine what is safe to execute
1086 # by rootwrap rather than use explicit whitelist of paths in
1087 # rootwrap.conf
1088 sudo sed -e 's/^exec_dirs=.*/#&/' -i $Q_RR_CONF_FILE
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001089
1090 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
1091 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
1092 ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
1093
1094 # Set up the rootwrap sudoers for neutron
1095 TEMPFILE=`mktemp`
1096 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
1097 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE
1098 chmod 0440 $TEMPFILE
1099 sudo chown root:root $TEMPFILE
1100 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
1101
1102 # Update the root_helper
1103 configure_root_helper_options $NEUTRON_CONF
1104}
1105
1106function configure_root_helper_options {
1107 local conffile=$1
1108 iniset $conffile agent root_helper "$Q_RR_COMMAND"
1109 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
1110 iniset $conffile agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
1111 fi
1112}
1113
1114function _neutron_setup_interface_driver {
1115
1116 # ovs_use_veth needs to be set before the plugin configuration
1117 # occurs to allow plugins to override the setting.
1118 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1119
1120 neutron_plugin_setup_interface_driver $1
1121}
1122# Functions for Neutron Exercises
1123#--------------------------------
1124
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001125# ssh check
1126function _ssh_check_neutron {
1127 local from_net=$1
1128 local key_file=$2
1129 local ip=$3
1130 local user=$4
1131 local timeout_sec=$5
1132 local probe_cmd = ""
1133 probe_cmd=`_get_probe_cmd_prefix $from_net`
1134 local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success"
1135 test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec
1136}
1137
1138function plugin_agent_add_l2_agent_extension {
1139 local l2_agent_extension=$1
1140 if [[ -z "$L2_AGENT_EXTENSIONS" ]]; then
1141 L2_AGENT_EXTENSIONS=$l2_agent_extension
1142 elif [[ ! ,${L2_AGENT_EXTENSIONS}, =~ ,${l2_agent_extension}, ]]; then
1143 L2_AGENT_EXTENSIONS+=",$l2_agent_extension"
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -05001144 fi
1145}
1146
Sean M. Collins2a242512016-05-03 09:03:09 -04001147# Restore xtrace
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001148$_XTRACE_NEUTRON
1149
1150# Tell emacs to use shell-script-mode
1151## Local variables:
1152## mode: shell-script
1153## End: