blob: 6336795f2eb63a34e82ec116e013347ec22482ed [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
Stephen Finucane0cd87632024-04-19 12:12:16 +010091NEUTRON_UWSGI=neutron.wsgi.api:application
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010092NEUTRON_UWSGI_CONF=$NEUTRON_CONF_DIR/neutron-api-uwsgi.ini
Sean M. Collins2a242512016-05-03 09:03:09 -040093
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +020094# If NEUTRON_ENFORCE_SCOPE == True, it will set "enforce_scope"
95# and "enforce_new_defaults" to True in the Neutron's config to enforce usage
Ghanshyam Mannbacb8402023-10-25 12:52:28 -070096# of the new RBAC policies and scopes. Set it to False if you do not
97# want to run Neutron with new RBAC.
98NEUTRON_ENFORCE_SCOPE=$(trueorfalse True NEUTRON_ENFORCE_SCOPE)
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +020099
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100100# Agent binaries. Note, binary paths for other agents are set in per-service
101# scripts in lib/neutron_plugins/services/
102AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
103AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
104AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
Brian Haley9aaa5292017-09-20 14:23:05 -0400105
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100106# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
107# loaded from per-plugin scripts in lib/neutron_plugins/
108Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
109# NOTE(slaweq): NEUTRON_DHCP_CONF is used e.g. in neutron repository,
110# it was previously defined in the lib/neutron module which is now deleted.
111NEUTRON_DHCP_CONF=$Q_DHCP_CONF_FILE
112Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
113# NOTE(slaweq): NEUTRON_L3_CONF is used e.g. in neutron repository,
114# it was previously defined in the lib/neutron module which is now deleted.
115NEUTRON_L3_CONF=$Q_L3_CONF_FILE
116Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
Sean M. Collins2a242512016-05-03 09:03:09 -0400117
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100118# Default name for Neutron database
119Q_DB_NAME=${Q_DB_NAME:-neutron}
120# Default Neutron Plugin
121Q_PLUGIN=${Q_PLUGIN:-ml2}
122# Default Neutron Port
123Q_PORT=${Q_PORT:-9696}
124# Default Neutron Internal Port when using TLS proxy
125Q_PORT_INT=${Q_PORT_INT:-19696}
126# Default Neutron Host
127Q_HOST=${Q_HOST:-$SERVICE_HOST}
128# Default protocol
129Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
130# Default listen address
131Q_LISTEN_ADDRESS=${Q_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)}
132# Default admin username
133Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
134# Default auth strategy
135Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
136# RHEL's support for namespaces requires using veths with ovs
137Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
138Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
139Q_USE_ROOTWRAP_DAEMON=$(trueorfalse True Q_USE_ROOTWRAP_DAEMON)
140# Meta data IP
141Q_META_DATA_IP=${Q_META_DATA_IP:-$(ipv6_unquote $SERVICE_HOST)}
142# Allow Overlapping IP among subnets
143Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
144Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
145Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
146VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
147VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Sean M. Collins2a242512016-05-03 09:03:09 -0400148
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100149# Allow to skip stopping of OVN services
150SKIP_STOP_OVN=${SKIP_STOP_OVN:-False}
Sean M. Collins2a242512016-05-03 09:03:09 -0400151
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100152# The directory which contains files for Q_PLUGIN_EXTRA_CONF_FILES.
153# /etc/neutron is assumed by many of devstack plugins. Do not change.
154_Q_PLUGIN_EXTRA_CONF_PATH=/etc/neutron
Julia Kreger6e5b1382019-01-09 17:00:45 -0800155
Slawek Kaplonski1a21ccb2022-07-08 21:57:45 +0200156# The name of the service in the endpoint URL
157NEUTRON_ENDPOINT_SERVICE_NAME=${NEUTRON_ENDPOINT_SERVICE_NAME-"networking"}
158if [[ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" && -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then
159 NEUTRON_ENDPOINT_SERVICE_NAME="networking"
160fi
161
elajkatbb0c2732023-11-16 11:30:04 +0100162# Source install libraries
163ALEMBIC_REPO=${ALEMBIC_REPO:-https://github.com/sqlalchemy/alembic.git}
164ALEMBIC_DIR=${ALEMBIC_DIR:-$DEST/alembic}
165ALEMBIC_BRANCH=${ALEMBIC_BRANCH:-main}
166SQLALCHEMY_REPO=${SQLALCHEMY_REPO:-https://github.com/sqlalchemy/sqlalchemy.git}
167SQLALCHEMY_DIR=${SQLALCHEMY_DIR:-$DEST/sqlalchemy}
168SQLALCHEMY_BRANCH=${SQLALCHEMY_BRANCH:-main}
169
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100170# List of config file names in addition to the main plugin config file
171# To add additional plugin config files, use ``neutron_server_config_add``
172# utility function. For example:
173#
174# ``neutron_server_config_add file1``
175#
176# These config files are relative to ``/etc/neutron``. The above
177# example would specify ``--config-file /etc/neutron/file1`` for
178# neutron server.
179declare -a -g Q_PLUGIN_EXTRA_CONF_FILES
Julia Kreger6e5b1382019-01-09 17:00:45 -0800180
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100181# same as Q_PLUGIN_EXTRA_CONF_FILES, but with absolute path.
182declare -a -g _Q_PLUGIN_EXTRA_CONF_FILES_ABS
183
184
185Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
186if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
187 Q_RR_COMMAND="sudo"
188else
189 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
190 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
191 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
192 Q_RR_DAEMON_COMMAND="sudo $NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
193 fi
194fi
195
196
197# Distributed Virtual Router (DVR) configuration
198# Can be:
199# - ``legacy`` - No DVR functionality
200# - ``dvr_snat`` - Controller or single node DVR
201# - ``dvr`` - Compute node in multi-node DVR
202# - ``dvr_no_external`` - Compute node in multi-node DVR, no external network
203#
204Q_DVR_MODE=${Q_DVR_MODE:-legacy}
205if [[ "$Q_DVR_MODE" != "legacy" ]]; then
206 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,l2population
207fi
208
209# Provider Network Configurations
210# --------------------------------
211
212# The following variables control the Neutron ML2 plugins' allocation
213# of tenant networks and availability of provider networks. If these
214# are not configured in ``localrc``, tenant networks will be local to
215# the host (with no remote connectivity), and no physical resources
216# will be available for the allocation of provider networks.
217
218# To disable tunnels (GRE or VXLAN) for tenant networks,
219# set to False in ``local.conf``.
220# GRE tunnels are only supported by the openvswitch.
221ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
222
223# If using GRE, VXLAN or GENEVE tunnels for tenant networks,
224# specify the range of IDs from which tenant networks are
225# allocated. Can be overridden in ``localrc`` if necessary.
226TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
227
228# To use VLANs for tenant networks, set to True in localrc. VLANs
229# are supported by the ML2 plugins, requiring additional configuration
230# described below.
231ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
232
233# If using VLANs for tenant networks, set in ``localrc`` to specify
234# the range of VLAN VIDs from which tenant networks are
235# allocated. An external network switch must be configured to
236# trunk these VLANs between hosts for multi-host connectivity.
237#
238# Example: ``TENANT_VLAN_RANGE=1000:1999``
239TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
240
241# If using VLANs for tenant networks, or if using flat or VLAN
242# provider networks, set in ``localrc`` to the name of the physical
243# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
244# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
245# agent, as described below.
246#
247# Example: ``PHYSICAL_NETWORK=default``
248PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-public}
249
250# With the openvswitch 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 OVS bridge to use for the physical network. The
253# bridge will be created if it does not already exist, but a
254# physical interface must be manually added to the bridge as a
255# port for external connectivity.
256#
257# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
258OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-br-ex}
259
260# With the linuxbridge agent, if using VLANs for tenant networks,
261# or if using flat or VLAN provider networks, set in ``localrc`` to
262# the name of the network interface to use for the physical
263# network.
264#
265# Example: ``LB_PHYSICAL_INTERFACE=eth1``
266if [[ $Q_AGENT == "linuxbridge" && -z ${LB_PHYSICAL_INTERFACE} ]]; then
267 default_route_dev=$( (ip route; ip -6 route) | grep ^default | head -n 1 | awk '{print $5}')
268 die_if_not_set $LINENO default_route_dev "Failure retrieving default route device"
269 LB_PHYSICAL_INTERFACE=$default_route_dev
270fi
271
272# With the openvswitch plugin, set to True in ``localrc`` to enable
273# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
274#
275# Example: ``OVS_ENABLE_TUNNELING=True``
276OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
277
278# Use DHCP agent for providing metadata service in the case of
279# without L3 agent (No Route Agent), set to True in localrc.
280ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
281
282# Add a static route as dhcp option, so the request to 169.254.169.254
283# will be able to reach through a route(DHCP agent)
284# This option require ENABLE_ISOLATED_METADATA = True
285ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
286# Neutron plugin specific functions
287# ---------------------------------
288
289# Please refer to ``lib/neutron_plugins/README.md`` for details.
290if [ -f $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN ]; then
291 source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
292fi
293
294# Agent metering service plugin functions
295# -------------------------------------------
296
297# Hardcoding for 1 service plugin for now
298source $TOP_DIR/lib/neutron_plugins/services/metering
299
300# L3 Service functions
301source $TOP_DIR/lib/neutron_plugins/services/l3
302
303# Additional Neutron service plugins
304source $TOP_DIR/lib/neutron_plugins/services/placement
305source $TOP_DIR/lib/neutron_plugins/services/trunk
306source $TOP_DIR/lib/neutron_plugins/services/qos
elajkata84b2092021-11-17 11:52:56 +0100307source $TOP_DIR/lib/neutron_plugins/services/segments
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100308
309# Use security group or not
310if has_neutron_plugin_security_group; then
311 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
312else
313 Q_USE_SECGROUP=False
314fi
315
Harald Jensås16ac21f2023-08-31 15:06:52 +0200316# OVN_BRIDGE_MAPPINGS - ovn-bridge-mappings
317# NOTE(hjensas): Initialize after sourcing neutron_plugins/services/l3
318# which initialize PUBLIC_BRIDGE.
319OVN_BRIDGE_MAPPINGS=${OVN_BRIDGE_MAPPINGS:-$PHYSICAL_NETWORK:$PUBLIC_BRIDGE}
320
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100321# Save trace setting
322_XTRACE_NEUTRON=$(set +o | grep xtrace)
323set +o xtrace
324
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900325
Sean M. Collins2a242512016-05-03 09:03:09 -0400326# Functions
327# ---------
328
329# Test if any Neutron services are enabled
330# is_neutron_enabled
331function is_neutron_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -0700332 [[ ,${DISABLED_SERVICES} =~ ,"neutron" ]] && return 1
Sean M. Collins2a242512016-05-03 09:03:09 -0400333 [[ ,${ENABLED_SERVICES} =~ ,"neutron-" || ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
334 return 1
335}
336
337# Test if any Neutron services are enabled
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100338# TODO(slaweq): this is not really needed now and we should remove it as soon
339# as it will not be called from any other Devstack plugins, like e.g. Neutron
340# plugin
Sean M. Collins2a242512016-05-03 09:03:09 -0400341function is_neutron_legacy_enabled {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100342 return 0
Sean M. Collins2a242512016-05-03 09:03:09 -0400343}
344
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100345function _determine_config_server {
346 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" != '' ]]; then
347 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" = "$_Q_PLUGIN_EXTRA_CONF_PATH" ]]; then
348 deprecated "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
349 else
350 die $LINENO "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
351 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400352 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100353 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 ]]; then
354 deprecated "Q_PLUGIN_EXTRA_CONF_FILES is deprecated. Use neutron_server_config_add instead."
Sean M. Collins2a242512016-05-03 09:03:09 -0400355 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100356 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
357 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($_Q_PLUGIN_EXTRA_CONF_PATH/$cfg_file)
Sean M. Collins2a242512016-05-03 09:03:09 -0400358 done
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100359
360 local cfg_file
361 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
362 for cfg_file in ${_Q_PLUGIN_EXTRA_CONF_FILES_ABS[@]}; do
363 opts+=" --config-file $cfg_file"
364 done
365 echo "$opts"
Sean M. Collins2a242512016-05-03 09:03:09 -0400366}
367
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100368function _determine_config_l3 {
369 local opts="--config-file $NEUTRON_CONF --config-file $Q_L3_CONF_FILE"
370 echo "$opts"
Ihar Hrachyshkae65ab4a2017-02-24 17:47:55 +0000371}
372
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000373function _enable_ovn_maintenance {
374 if [[ $Q_AGENT == "ovn" ]]; then
375 enable_service neutron-ovn-maintenance-worker
376 fi
377}
378
379function _run_ovn_maintenance {
380 if [[ $Q_AGENT == "ovn" ]]; then
381 run_process neutron-ovn-maintenance-worker "$NEUTRON_BIN_DIR/neutron-ovn-maintenance-worker $cfg_file_options"
382 fi
383}
384
385function _stop_ovn_maintenance {
386 if [[ $Q_AGENT == "ovn" ]]; then
387 stop_process neutron-ovn-maintenance-worker
388 fi
389}
390
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100391# For services and agents that require it, dynamically construct a list of
392# --config-file arguments that are passed to the binary.
393function determine_config_files {
394 local opts=""
395 case "$1" in
396 "neutron-server") opts="$(_determine_config_server)" ;;
397 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
398 esac
399 if [ -z "$opts" ] ; then
400 die $LINENO "Could not determine config files for $1."
YAMAMOTO Takashi1df17c92017-05-01 17:00:42 +0900401 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100402 echo "$opts"
403}
Sean M. Collins2a242512016-05-03 09:03:09 -0400404
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100405# configure_neutron()
406# Set common config for all neutron server and agents.
407function configure_neutron {
408 _configure_neutron_common
Sean M. Collins5394cc12016-05-11 15:03:38 -0400409 iniset_rpc_backend neutron $NEUTRON_CONF
410
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100411 if is_service_enabled q-metering neutron-metering; then
412 _configure_neutron_metering
413 fi
414 if is_service_enabled q-agt neutron-agent; then
415 _configure_neutron_plugin_agent
416 fi
417 if is_service_enabled q-dhcp neutron-dhcp; then
418 _configure_neutron_dhcp_agent
419 fi
420 if is_service_enabled q-l3 neutron-l3; then
421 _configure_neutron_l3_agent
422 fi
423 if is_service_enabled q-meta neutron-metadata-agent; then
424 _configure_neutron_metadata_agent
Sean M. Collins2a242512016-05-03 09:03:09 -0400425 fi
426
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100427 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
428 _configure_dvr
429 fi
430 if is_service_enabled ceilometer; then
431 _configure_neutron_ceilometer_notifications
432 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400433
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100434 if [[ $Q_AGENT == "ovn" ]]; then
435 configure_ovn
436 configure_ovn_plugin
437 fi
Brian Haley9aaa5292017-09-20 14:23:05 -0400438
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100439 # Configure Neutron's advanced services
440 if is_service_enabled q-placement neutron-placement; then
441 configure_placement_extension
442 fi
443 if is_service_enabled q-trunk neutron-trunk; then
444 configure_trunk_extension
445 fi
446 if is_service_enabled q-qos neutron-qos; then
447 configure_qos
448 if is_service_enabled q-l3 neutron-l3; then
449 configure_l3_agent_extension_fip_qos
450 configure_l3_agent_extension_gateway_ip_qos
Denis Buliga0bf75a42017-02-06 16:56:46 +0200451 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400452 fi
elajkata84b2092021-11-17 11:52:56 +0100453 if is_service_enabled neutron-segments; then
454 configure_placement_neutron
455 configure_segments_extension
456 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400457
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100458 # Finally configure Neutron server and core plugin
459 if is_service_enabled q-agt neutron-agent q-svc neutron-api; then
460 _configure_neutron_service
Sean M. Collins2a242512016-05-03 09:03:09 -0400461 fi
462
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100463 iniset $NEUTRON_CONF DEFAULT api_workers "$API_WORKERS"
464 # devstack is not a tool for running uber scale OpenStack
465 # clouds, therefore running without a dedicated RPC worker
466 # for state reports is more than adequate.
467 iniset $NEUTRON_CONF DEFAULT rpc_state_report_workers 0
Ihar Hrachyshkae3915932017-02-24 06:24:47 +0000468
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100469 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
Stephen Finucane0cd87632024-04-19 12:12:16 +0100470 write_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_UWSGI" "/networking" "" "neutron-api"
Sean M. Collins8063fee2016-05-24 11:27:36 -0700471 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400472}
473
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100474function configure_neutron_nova {
475 create_nova_conf_neutron $NOVA_CONF
476 if [[ "${CELLSV2_SETUP}" == "superconductor" ]]; then
477 for i in $(seq 1 $NOVA_NUM_CELLS); do
478 local conf
479 conf=$(conductor_conf $i)
480 create_nova_conf_neutron $conf
481 done
Sean M. Collins2a242512016-05-03 09:03:09 -0400482 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400483}
484
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100485function create_nova_conf_neutron {
Lucas Alvares Gomese6385932018-06-28 11:00:28 +0100486 local conf=${1:-$NOVA_CONF}
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400487 iniset $conf neutron auth_type "password"
488 iniset $conf neutron auth_url "$KEYSTONE_SERVICE_URI"
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100489 iniset $conf neutron username "$Q_ADMIN_USERNAME"
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400490 iniset $conf neutron password "$SERVICE_PASSWORD"
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100491 iniset $conf neutron user_domain_name "$SERVICE_DOMAIN_NAME"
492 iniset $conf neutron project_name "$SERVICE_PROJECT_NAME"
493 iniset $conf neutron project_domain_name "$SERVICE_DOMAIN_NAME"
494 iniset $conf neutron auth_strategy "$Q_AUTH_STRATEGY"
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400495 iniset $conf neutron region_name "$REGION_NAME"
Sean M. Collins2a242512016-05-03 09:03:09 -0400496
Gary Kotton88f85582016-08-14 06:55:42 -0700497 # optionally set options in nova_conf
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400498 neutron_plugin_create_nova_conf $conf
Gary Kotton88f85582016-08-14 06:55:42 -0700499
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100500 if is_service_enabled q-meta neutron-metadata-agent; then
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400501 iniset $conf neutron service_metadata_proxy "True"
Sean M. Collins2a242512016-05-03 09:03:09 -0400502 fi
503
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100504 iniset $conf DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
505 iniset $conf DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Sean M. Collins2a242512016-05-03 09:03:09 -0400506}
507
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100508# create_neutron_accounts() - Set up common required neutron accounts
509
Sean M. Collins2a242512016-05-03 09:03:09 -0400510# Tenant User Roles
511# ------------------------------------------------------------------
512# service neutron admin # if enabled
513
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100514# Migrated from keystone_data.sh
515function create_neutron_accounts {
Kevin Benton66b361b2017-06-13 00:31:01 -0700516 local neutron_url
Kevin Benton66b361b2017-06-13 00:31:01 -0700517 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100518 neutron_url=$Q_PROTOCOL://$SERVICE_HOST/
Kevin Benton66b361b2017-06-13 00:31:01 -0700519 else
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100520 neutron_url=$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/
Kevin Benton66b361b2017-06-13 00:31:01 -0700521 fi
Slawek Kaplonski1a21ccb2022-07-08 21:57:45 +0200522 if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then
523 neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME
524 fi
Kevin Benton66b361b2017-06-13 00:31:01 -0700525
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100526 if is_service_enabled q-svc neutron-api; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400527
528 create_service_user "neutron"
529
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100530 get_or_create_service "neutron" "network" "Neutron Service"
531 get_or_create_endpoint \
532 "network" \
Kevin Benton66b361b2017-06-13 00:31:01 -0700533 "$REGION_NAME" "$neutron_url"
Sean M. Collins2a242512016-05-03 09:03:09 -0400534 fi
535}
536
Sean M. Collins2a242512016-05-03 09:03:09 -0400537# init_neutron() - Initialize databases, etc.
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100538function init_neutron {
539 recreate_database $Q_DB_NAME
Clark Boylan633dbc32017-06-14 12:09:21 -0700540 time_start "dbsync"
Sean M. Collins2a242512016-05-03 09:03:09 -0400541 # Run Neutron db migrations
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100542 $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 -0700543 time_stop "dbsync"
Sean M. Collins2a242512016-05-03 09:03:09 -0400544}
545
546# install_neutron() - Collect source and prepare
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100547function install_neutron {
Sean M. Collins2a242512016-05-03 09:03:09 -0400548 # Install neutron-lib from git so we make sure we're testing
549 # the latest code.
550 if use_library_from_git "neutron-lib"; then
551 git_clone_by_name "neutron-lib"
552 setup_dev_lib "neutron-lib"
553 fi
554
elajkatbb0c2732023-11-16 11:30:04 +0100555 # Install SQLAlchemy and alembic from git when these are required
556 # see https://bugs.launchpad.net/neutron/+bug/2042941
557 if use_library_from_git "sqlalchemy"; then
558 git_clone $SQLALCHEMY_REPO $SQLALCHEMY_DIR $SQLALCHEMY_BRANCH
559 setup_develop $SQLALCHEMY_DIR
560 fi
561 if use_library_from_git "alembic"; then
562 git_clone $ALEMBIC_REPO $ALEMBIC_DIR $ALEMBIC_BRANCH
563 setup_develop $ALEMBIC_DIR
564 fi
565
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100566 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
567 setup_develop $NEUTRON_DIR
Sean M. Collins2a242512016-05-03 09:03:09 -0400568
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100569 if [[ $Q_AGENT == "ovn" ]]; then
570 install_ovn
Sean M. Collins2a242512016-05-03 09:03:09 -0400571 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400572}
573
574# install_neutronclient() - Collect source and prepare
575function install_neutronclient {
576 if use_library_from_git "python-neutronclient"; then
577 git_clone_by_name "python-neutronclient"
578 setup_dev_lib "python-neutronclient"
Sean M. Collins2a242512016-05-03 09:03:09 -0400579 fi
580}
581
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100582# install_neutron_agent_packages() - Collect source and prepare
583function install_neutron_agent_packages {
584 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
585 if is_service_enabled q-l3 neutron-l3; then
586 install_package radvd
Sean M. Collins2a242512016-05-03 09:03:09 -0400587 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100588 # install packages that are specific to plugin agent(s)
589 if is_service_enabled q-agt neutron-agent q-dhcp neutron-dhcp q-l3 neutron-l3; then
590 neutron_plugin_install_agent_packages
Sean M. Collins2a242512016-05-03 09:03:09 -0400591 fi
592}
593
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100594# Finish neutron configuration
595function configure_neutron_after_post_config {
596 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
597 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
Sean M. Collins2a242512016-05-03 09:03:09 -0400598 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100599 configure_rbac_policies
Sean M. Collins2a242512016-05-03 09:03:09 -0400600}
601
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +0200602# configure_rbac_policies() - Configure Neutron to enforce new RBAC
603# policies and scopes if NEUTRON_ENFORCE_SCOPE == True
604function configure_rbac_policies {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100605 if [[ "$NEUTRON_ENFORCE_SCOPE" == "True" || "$ENFORCE_SCOPE" == True ]]; then
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +0200606 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults True
607 iniset $NEUTRON_CONF oslo_policy enforce_scope True
608 else
609 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults False
610 iniset $NEUTRON_CONF oslo_policy enforce_scope False
611 fi
612}
613
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100614# Start running OVN processes
615function start_ovn_services {
616 if [[ $Q_AGENT == "ovn" ]]; then
Lucas Alvares Gomesa3891282023-07-18 16:31:28 +0100617 if [ "$VIRT_DRIVER" != 'ironic' ]; then
618 # NOTE(TheJulia): Ironic's devstack plugin needs to perform
619 # additional networking configuration to setup a working test
620 # environment with test virtual machines to emulate baremetal,
621 # which requires OVN to be up and running earlier to complete
622 # that base configuration.
623 init_ovn
624 start_ovn
625 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100626 if [[ "$OVN_L3_CREATE_PUBLIC_NETWORK" == "True" ]]; then
627 if [[ "$NEUTRON_CREATE_INITIAL_NETWORKS" != "True" ]]; then
628 echo "OVN_L3_CREATE_PUBLIC_NETWORK=True is being ignored "
629 echo "because NEUTRON_CREATE_INITIAL_NETWORKS is set to False"
630 else
631 create_public_bridge
632 fi
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400633 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400634 fi
635}
636
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100637# Start running processes
638function start_neutron_service_and_check {
639 local service_port=$Q_PORT
640 local service_protocol=$Q_PROTOCOL
641 local cfg_file_options
642 local neutron_url
Sean M. Collins2a242512016-05-03 09:03:09 -0400643
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100644 cfg_file_options="$(determine_config_files neutron-server)"
Sean M. Collins2a242512016-05-03 09:03:09 -0400645
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100646 if is_service_enabled tls-proxy; then
647 service_port=$Q_PORT_INT
648 service_protocol="http"
Sean M. Collins2a242512016-05-03 09:03:09 -0400649 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100650 # Start the Neutron service
651 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
652 enable_service neutron-api
653 run_process neutron-api "$(which uwsgi) --procname-prefix neutron-api --ini $NEUTRON_UWSGI_CONF"
654 neutron_url=$Q_PROTOCOL://$Q_HOST/
655 enable_service neutron-rpc-server
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000656 enable_service neutron-periodic-workers
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000657 _enable_ovn_maintenance
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100658 run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $cfg_file_options"
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000659 run_process neutron-periodic-workers "$NEUTRON_BIN_DIR/neutron-periodic-workers $cfg_file_options"
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000660 _run_ovn_maintenance
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100661 else
662 run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
663 neutron_url=$service_protocol://$Q_HOST:$service_port/
664 # Start proxy if enabled
665 if is_service_enabled tls-proxy; then
666 start_tls_proxy neutron '*' $Q_PORT $Q_HOST $Q_PORT_INT
667 fi
668 fi
669 if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then
670 neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME
671 fi
672 echo "Waiting for Neutron to start..."
Sean M. Collins2a242512016-05-03 09:03:09 -0400673
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100674 local testcmd="wget ${ssl_ca} --no-proxy -q -O- $neutron_url"
675 test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900676}
677
Sean M. Collins2a242512016-05-03 09:03:09 -0400678function start_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100679 start_l2_agent "$@"
680 start_other_agents "$@"
681}
682
683# Control of the l2 agent is separated out to make it easier to test partial
684# upgrades (everything upgraded except the L2 agent)
685function start_l2_agent {
686 run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
687
688 if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then
689 sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
690 sudo ip link set $OVS_PHYSICAL_BRIDGE up
691 sudo ip link set br-int up
692 sudo ip link set $PUBLIC_INTERFACE up
693 if is_ironic_hardware; then
694 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
695 sudo ip addr del $IP dev $PUBLIC_INTERFACE
696 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
697 done
698 sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
699 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400700 fi
701}
702
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100703function start_other_agents {
704 run_process q-dhcp "$AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file $Q_DHCP_CONF_FILE"
705
706 run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
707
708 run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file $Q_META_CONF_FILE"
709 run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
710}
711
712# Start running processes, including screen
713function start_neutron_agents {
714 # NOTE(slaweq): it's now just a wrapper for start_neutron function
715 start_neutron "$@"
716}
717
718function stop_l2_agent {
719 stop_process q-agt
720}
721
722# stop_other() - Stop running processes
723function stop_other {
724 if is_service_enabled q-dhcp neutron-dhcp; then
725 stop_process q-dhcp
726 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
727 [ ! -z "$pid" ] && sudo kill -9 $pid
728 fi
729
730 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
731 stop_process neutron-rpc-server
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000732 stop_process neutron-periodic-workers
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100733 stop_process neutron-api
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000734 _stop_ovn_maintenance
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100735 else
736 stop_process q-svc
737 fi
738
739 if is_service_enabled q-l3 neutron-l3; then
740 sudo pkill -f "radvd -C $DATA_DIR/neutron/ra"
741 stop_process q-l3
742 fi
743
744 if is_service_enabled q-meta neutron-metadata-agent; then
745 stop_process q-meta
746 fi
747
748 if is_service_enabled q-metering neutron-metering; then
749 neutron_metering_stop
750 fi
751
752 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Bence Romsics71c3c402022-12-21 13:50:54 +0100753 # pkill takes care not to kill itself, but it may kill its parent
754 # sudo unless we use the "ps | grep [f]oo" trick
755 sudo pkill -9 -f "$NEUTRON_ROOTWRAP-[d]aemon" || :
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100756 fi
757}
758
759# stop_neutron() - Stop running processes (non-screen)
Sean M. Collins2a242512016-05-03 09:03:09 -0400760function stop_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100761 stop_other
762 stop_l2_agent
763
764 if [[ $Q_AGENT == "ovn" && $SKIP_STOP_OVN != "True" ]]; then
765 stop_ovn
Sean M. Collins2a242512016-05-03 09:03:09 -0400766 fi
767}
768
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100769# _move_neutron_addresses_route() - Move the primary IP to the OVS bridge
770# on startup, or back to the public interface on cleanup. If no IP is
771# configured on the interface, just add it as a port to the OVS bridge.
772function _move_neutron_addresses_route {
773 local from_intf=$1
774 local to_intf=$2
775 local add_ovs_port=$3
776 local del_ovs_port=$4
777 local af=$5
778
779 if [[ -n "$from_intf" && -n "$to_intf" ]]; then
780 # Remove the primary IP address from $from_intf and add it to $to_intf,
781 # along with the default route, if it exists. Also, when called
782 # on configure we will also add $from_intf as a port on $to_intf,
783 # assuming it is an OVS bridge.
784
785 local IP_REPLACE=""
786 local IP_DEL=""
787 local IP_UP=""
788 local DEFAULT_ROUTE_GW
789 DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf\s/ { print \$3; exit }")
790 local ADD_OVS_PORT=""
791 local DEL_OVS_PORT=""
792 local ARP_CMD=""
793
794 IP_BRD=$(ip -f $af a s dev $from_intf scope global primary | grep inet | awk '{ print $2, $3, $4; exit }')
795
796 if [ "$DEFAULT_ROUTE_GW" != "" ]; then
797 ADD_DEFAULT_ROUTE="sudo ip -f $af r replace default via $DEFAULT_ROUTE_GW dev $to_intf"
798 fi
799
800 if [[ "$add_ovs_port" == "True" ]]; then
801 ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf"
802 fi
803
804 if [[ "$del_ovs_port" == "True" ]]; then
805 DEL_OVS_PORT="sudo ovs-vsctl --if-exists del-port $from_intf $to_intf"
806 fi
807
808 if [[ "$IP_BRD" != "" ]]; then
809 IP_DEL="sudo ip addr del $IP_BRD dev $from_intf"
810 IP_REPLACE="sudo ip addr replace $IP_BRD dev $to_intf"
811 IP_UP="sudo ip link set $to_intf up"
812 if [[ "$af" == "inet" ]]; then
813 IP=$(echo $IP_BRD | awk '{ print $1; exit }' | grep -o -E '(.*)/' | cut -d "/" -f1)
814 ARP_CMD="sudo arping -A -c 3 -w 5 -I $to_intf $IP "
815 fi
816 fi
817
818 # The add/del OVS port calls have to happen either before or
819 # after the address is moved in order to not leave it orphaned.
820 $DEL_OVS_PORT; $IP_DEL; $IP_REPLACE; $IP_UP; $ADD_OVS_PORT; $ADD_DEFAULT_ROUTE; $ARP_CMD
821 fi
822}
823
824# _configure_public_network_connectivity() - Configures connectivity to the
825# external network using $PUBLIC_INTERFACE or NAT on the single interface
826# machines
827function _configure_public_network_connectivity {
828 # If we've given a PUBLIC_INTERFACE to take over, then we assume
829 # that we can own the whole thing, and privot it into the OVS
830 # bridge. If we are not, we're probably on a single interface
831 # machine, and we just setup NAT so that fixed guests can get out.
832 if [[ -n "$PUBLIC_INTERFACE" ]]; then
833 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" True False "inet"
834
835 if [[ $(ip -f inet6 a s dev "$PUBLIC_INTERFACE" | grep -c 'global') != 0 ]]; then
836 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" False False "inet6"
837 fi
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -0500838 else
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100839 for d in $default_v4_route_devs; do
840 sudo iptables -t nat -A POSTROUTING -o $d -s $FLOATING_RANGE -j MASQUERADE
841 done
842 fi
843}
844
845# cleanup_neutron() - Remove residual data files, anything left over from previous
846# runs that a clean run would need to clean up
847function cleanup_neutron {
848 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
849 stop_process neutron-api
850 stop_process neutron-rpc-server
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000851 stop_process neutron-periodic-workers
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000852 _stop_ovn_maintenance
Stephen Finucaned5182ce2024-04-19 12:27:14 +0100853 remove_uwsgi_config "$NEUTRON_UWSGI_CONF" "neutron-api"
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100854 sudo rm -f $(apache_site_config_for neutron-api)
855 fi
856
857 if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then
858 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False True "inet"
859
860 if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then
861 # ip(8) wants the prefix length when deleting
862 local v6_gateway
863 v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }')
864 sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE
865 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False False "inet6"
866 fi
867
868 if is_provider_network && is_ironic_hardware; then
869 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
870 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
871 sudo ip addr add $IP dev $PUBLIC_INTERFACE
872 done
873 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
874 fi
875 fi
876
877 if is_neutron_ovs_base_plugin; then
878 neutron_ovs_base_cleanup
879 fi
880
881 if [[ $Q_AGENT == "linuxbridge" ]]; then
882 neutron_lb_cleanup
883 fi
884
885 # delete all namespaces created by neutron
886 for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|fip|snat)-[0-9a-f-]*'); do
887 sudo ip netns delete ${ns}
888 done
889
890 if [[ $Q_AGENT == "ovn" ]]; then
891 cleanup_ovn
892 fi
893}
894
895
896function _create_neutron_conf_dir {
897 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
898 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
899}
900
901# _configure_neutron_common()
902# Set common config for all neutron server and agents.
903# This MUST be called before other ``_configure_neutron_*`` functions.
904function _configure_neutron_common {
905 _create_neutron_conf_dir
906
907 # Uses oslo config generator to generate core sample configuration files
908 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
909
910 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
911
912 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
913
914 # allow neutron user to administer neutron to match neutron account
915 # NOTE(amotoki): This is required for nova works correctly with neutron.
916 if [ -f $NEUTRON_DIR/etc/policy.json ]; then
917 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
918 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
919 else
920 echo '{"context_is_admin": "role:admin or user_name:neutron"}' > $Q_POLICY_FILE
921 fi
922
923 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
924 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
925 neutron_plugin_configure_common
926
927 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
928 die $LINENO "Neutron plugin not set.. exiting"
929 fi
930
931 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
932 mkdir -p /$Q_PLUGIN_CONF_PATH
933 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
934 # NOTE(slaweq): NEUTRON_CORE_PLUGIN_CONF is used e.g. in neutron repository,
935 # it was previously defined in the lib/neutron module which is now deleted.
936 NEUTRON_CORE_PLUGIN_CONF=$Q_PLUGIN_CONF_FILE
937 # NOTE(hichihara): Some neutron vendor plugins were already decomposed and
938 # there is no config file in Neutron tree. They should prepare the file in each plugin.
939 if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then
940 cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE
941 elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then
942 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
943 fi
944
945 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
946 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
947 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
948 iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS
949 iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock
950
951 # NOTE(freerunner): Need to adjust Region Name for nova in multiregion installation
952 iniset $NEUTRON_CONF nova region_name $REGION_NAME
953
954 if [ "$VIRT_DRIVER" = 'fake' ]; then
955 # Disable arbitrary limits
956 iniset $NEUTRON_CONF quotas quota_network -1
957 iniset $NEUTRON_CONF quotas quota_subnet -1
958 iniset $NEUTRON_CONF quotas quota_port -1
959 iniset $NEUTRON_CONF quotas quota_security_group -1
960 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
961 fi
962
963 # Format logging
964 setup_logging $NEUTRON_CONF
965
966 if is_service_enabled tls-proxy && [ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" ]; then
967 # Set the service port for a proxy to take the original
968 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
969 iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True
970 fi
971
972 _neutron_setup_rootwrap
973}
974
975function _configure_neutron_dhcp_agent {
976
977 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE
978
979 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
980 # make it so we have working DNS from guests
981 iniset $Q_DHCP_CONF_FILE DEFAULT dnsmasq_local_resolv True
982 configure_root_helper_options $Q_DHCP_CONF_FILE
983
984 if ! is_service_enabled q-l3 neutron-l3; then
985 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
986 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
987 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
988 else
989 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
990 die "$LINENO" "Enable isolated metadata is a must for metadata network"
991 fi
992 fi
993 fi
994
995 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
996
997 neutron_plugin_configure_dhcp_agent $Q_DHCP_CONF_FILE
998}
999
1000
1001function _configure_neutron_metadata_agent {
1002 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE
1003
1004 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1005 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_host $Q_META_DATA_IP
1006 iniset $Q_META_CONF_FILE DEFAULT metadata_workers $API_WORKERS
1007 configure_root_helper_options $Q_META_CONF_FILE
1008}
1009
1010function _configure_neutron_ceilometer_notifications {
1011 iniset $NEUTRON_CONF oslo_messaging_notifications driver messagingv2
1012}
1013
1014function _configure_neutron_metering {
1015 neutron_agent_metering_configure_common
1016 neutron_agent_metering_configure_agent
1017}
1018
1019function _configure_dvr {
1020 iniset $NEUTRON_CONF DEFAULT router_distributed True
1021 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
1022}
1023
1024
1025# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
1026# It is called when q-agt is enabled.
1027function _configure_neutron_plugin_agent {
1028 # Specify the default root helper prior to agent configuration to
1029 # ensure that an agent's configuration can override the default
1030 configure_root_helper_options /$Q_PLUGIN_CONF_FILE
1031 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1032
1033 # Configure agent for plugin
1034 neutron_plugin_configure_plugin_agent
1035}
1036
1037function _replace_api_paste_composite {
1038 local sep
1039 sep=$(echo -ne "\x01")
1040 # Replace it
1041 $sudo sed -i -e "s/\/\: neutronversions_composite/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/\: neutronversions_composite/" "$Q_API_PASTE_FILE"
1042 $sudo sed -i -e "s/\/healthcheck\: healthcheck/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/healthcheck\: healthcheck/" "$Q_API_PASTE_FILE"
1043 $sudo sed -i -e "s/\/v2.0\: neutronapi_v2_0/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/v2.0\: neutronapi_v2_0/" "$Q_API_PASTE_FILE"
1044}
1045
1046# _configure_neutron_service() - Set config files for neutron service
1047# It is called when q-svc is enabled.
1048function _configure_neutron_service {
1049 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
1050 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
1051
Slawek Kaplonskib500d802024-06-14 12:58:58 +02001052 if [[ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" && -n "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001053 _replace_api_paste_composite
1054 fi
1055
1056 # Update either configuration file with plugin
1057 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
1058
1059 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1060 iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE
1061
1062 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
1063 configure_keystone_authtoken_middleware $NEUTRON_CONF $Q_ADMIN_USERNAME
1064
1065 # Configuration for neutron notifications to nova.
1066 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
1067 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
1068
1069 configure_keystone_authtoken_middleware $NEUTRON_CONF nova nova
1070
1071 # Configuration for placement client
1072 configure_keystone_authtoken_middleware $NEUTRON_CONF placement placement
1073
1074 # Configure plugin
1075 neutron_plugin_configure_service
1076}
1077
1078# Utility Functions
1079#------------------
1080
1081# neutron_service_plugin_class_add() - add service plugin class
1082function neutron_service_plugin_class_add {
1083 local service_plugin_class=$1
1084 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
1085 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
1086 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
1087 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
1088 fi
1089}
1090
1091# neutron_ml2_extension_driver_add() - add ML2 extension driver
1092function neutron_ml2_extension_driver_add {
1093 local extension=$1
1094 if [[ $Q_ML2_PLUGIN_EXT_DRIVERS == '' ]]; then
1095 Q_ML2_PLUGIN_EXT_DRIVERS=$extension
1096 elif [[ ! ,${Q_ML2_PLUGIN_EXT_DRIVERS}, =~ ,${extension}, ]]; then
1097 Q_ML2_PLUGIN_EXT_DRIVERS="$Q_ML2_PLUGIN_EXT_DRIVERS,$extension"
1098 fi
1099}
1100
1101# neutron_server_config_add() - add server config file
1102function neutron_server_config_add {
1103 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($1)
1104}
1105
1106# neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root).
1107function neutron_deploy_rootwrap_filters {
1108 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1109 return
1110 fi
1111 local srcdir=$1
1112 sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D
1113 sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
1114}
1115
1116# _neutron_setup_rootwrap() - configure Neutron's rootwrap
1117function _neutron_setup_rootwrap {
1118 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1119 return
1120 fi
1121 # Wipe any existing ``rootwrap.d`` files first
1122 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
1123 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
1124 sudo rm -rf $Q_CONF_ROOTWRAP_D
1125 fi
1126
1127 neutron_deploy_rootwrap_filters $NEUTRON_DIR
1128
1129 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
1130 # location moved in newer versions, prefer new location
1131 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
1132 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
1133 else
1134 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
1135 fi
1136 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
yatinkarelffc1b762023-08-28 10:52:26 +05301137 # Rely on $PATH set by devstack to determine what is safe to execute
1138 # by rootwrap rather than use explicit whitelist of paths in
1139 # rootwrap.conf
1140 sudo sed -e 's/^exec_dirs=.*/#&/' -i $Q_RR_CONF_FILE
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001141
1142 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
1143 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
1144 ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
1145
1146 # Set up the rootwrap sudoers for neutron
1147 TEMPFILE=`mktemp`
1148 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
1149 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE
1150 chmod 0440 $TEMPFILE
1151 sudo chown root:root $TEMPFILE
1152 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
1153
1154 # Update the root_helper
1155 configure_root_helper_options $NEUTRON_CONF
1156}
1157
1158function configure_root_helper_options {
1159 local conffile=$1
1160 iniset $conffile agent root_helper "$Q_RR_COMMAND"
1161 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
1162 iniset $conffile agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
1163 fi
1164}
1165
1166function _neutron_setup_interface_driver {
1167
1168 # ovs_use_veth needs to be set before the plugin configuration
1169 # occurs to allow plugins to override the setting.
1170 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1171
1172 neutron_plugin_setup_interface_driver $1
1173}
1174# Functions for Neutron Exercises
1175#--------------------------------
1176
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001177# ssh check
1178function _ssh_check_neutron {
1179 local from_net=$1
1180 local key_file=$2
1181 local ip=$3
1182 local user=$4
1183 local timeout_sec=$5
1184 local probe_cmd = ""
1185 probe_cmd=`_get_probe_cmd_prefix $from_net`
1186 local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success"
1187 test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec
1188}
1189
1190function plugin_agent_add_l2_agent_extension {
1191 local l2_agent_extension=$1
1192 if [[ -z "$L2_AGENT_EXTENSIONS" ]]; then
1193 L2_AGENT_EXTENSIONS=$l2_agent_extension
1194 elif [[ ! ,${L2_AGENT_EXTENSIONS}, =~ ,${l2_agent_extension}, ]]; then
1195 L2_AGENT_EXTENSIONS+=",$l2_agent_extension"
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -05001196 fi
1197}
1198
Sean M. Collins2a242512016-05-03 09:03:09 -04001199# Restore xtrace
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001200$_XTRACE_NEUTRON
1201
1202# Tell emacs to use shell-script-mode
1203## Local variables:
1204## mode: shell-script
1205## End: