blob: 78ff6cfb240cda67276b1ed8c3e9db8cc9867d3b [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:
Stephen Finucane74837e02024-10-11 16:15:47 +010085# - False : Run neutron under Eventlet
86# - True (default) : Run neutron under uwsgi
87NEUTRON_DEPLOY_MOD_WSGI=$(trueorfalse True NEUTRON_DEPLOY_MOD_WSGI)
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010088
Stephen Finucane0cd87632024-04-19 12:12:16 +010089NEUTRON_UWSGI=neutron.wsgi.api:application
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010090NEUTRON_UWSGI_CONF=$NEUTRON_CONF_DIR/neutron-api-uwsgi.ini
Sean M. Collins2a242512016-05-03 09:03:09 -040091
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +020092# If NEUTRON_ENFORCE_SCOPE == True, it will set "enforce_scope"
93# and "enforce_new_defaults" to True in the Neutron's config to enforce usage
Ghanshyam Mannbacb8402023-10-25 12:52:28 -070094# of the new RBAC policies and scopes. Set it to False if you do not
95# want to run Neutron with new RBAC.
96NEUTRON_ENFORCE_SCOPE=$(trueorfalse True NEUTRON_ENFORCE_SCOPE)
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +020097
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
elajkatbb0c2732023-11-16 11:30:04 +0100160# Source install libraries
161ALEMBIC_REPO=${ALEMBIC_REPO:-https://github.com/sqlalchemy/alembic.git}
162ALEMBIC_DIR=${ALEMBIC_DIR:-$DEST/alembic}
163ALEMBIC_BRANCH=${ALEMBIC_BRANCH:-main}
164SQLALCHEMY_REPO=${SQLALCHEMY_REPO:-https://github.com/sqlalchemy/sqlalchemy.git}
165SQLALCHEMY_DIR=${SQLALCHEMY_DIR:-$DEST/sqlalchemy}
166SQLALCHEMY_BRANCH=${SQLALCHEMY_BRANCH:-main}
167
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100168# List of config file names in addition to the main plugin config file
169# To add additional plugin config files, use ``neutron_server_config_add``
170# utility function. For example:
171#
172# ``neutron_server_config_add file1``
173#
174# These config files are relative to ``/etc/neutron``. The above
175# example would specify ``--config-file /etc/neutron/file1`` for
176# neutron server.
177declare -a -g Q_PLUGIN_EXTRA_CONF_FILES
Julia Kreger6e5b1382019-01-09 17:00:45 -0800178
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100179# same as Q_PLUGIN_EXTRA_CONF_FILES, but with absolute path.
180declare -a -g _Q_PLUGIN_EXTRA_CONF_FILES_ABS
181
182
183Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
184if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
185 Q_RR_COMMAND="sudo"
186else
187 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
188 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
189 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
190 Q_RR_DAEMON_COMMAND="sudo $NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
191 fi
192fi
193
194
195# Distributed Virtual Router (DVR) configuration
196# Can be:
197# - ``legacy`` - No DVR functionality
198# - ``dvr_snat`` - Controller or single node DVR
199# - ``dvr`` - Compute node in multi-node DVR
200# - ``dvr_no_external`` - Compute node in multi-node DVR, no external network
201#
202Q_DVR_MODE=${Q_DVR_MODE:-legacy}
203if [[ "$Q_DVR_MODE" != "legacy" ]]; then
204 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,l2population
205fi
206
207# Provider Network Configurations
208# --------------------------------
209
210# The following variables control the Neutron ML2 plugins' allocation
211# of tenant networks and availability of provider networks. If these
212# are not configured in ``localrc``, tenant networks will be local to
213# the host (with no remote connectivity), and no physical resources
214# will be available for the allocation of provider networks.
215
216# To disable tunnels (GRE or VXLAN) for tenant networks,
217# set to False in ``local.conf``.
218# GRE tunnels are only supported by the openvswitch.
219ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
220
221# If using GRE, VXLAN or GENEVE tunnels for tenant networks,
222# specify the range of IDs from which tenant networks are
223# allocated. Can be overridden in ``localrc`` if necessary.
224TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
225
226# To use VLANs for tenant networks, set to True in localrc. VLANs
227# are supported by the ML2 plugins, requiring additional configuration
228# described below.
229ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
230
231# If using VLANs for tenant networks, set in ``localrc`` to specify
232# the range of VLAN VIDs from which tenant networks are
233# allocated. An external network switch must be configured to
234# trunk these VLANs between hosts for multi-host connectivity.
235#
236# Example: ``TENANT_VLAN_RANGE=1000:1999``
237TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
238
239# If using VLANs for tenant networks, or if using flat or VLAN
240# provider networks, set in ``localrc`` to the name of the physical
241# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
Brian Haley12abc722025-02-10 13:48:37 -0500242# openvswitch agent, as described below.
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100243#
244# Example: ``PHYSICAL_NETWORK=default``
245PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-public}
246
247# With the openvswitch agent, if using VLANs for tenant networks,
248# or if using flat or VLAN provider networks, set in ``localrc`` to
249# the name of the OVS bridge to use for the physical network. The
250# bridge will be created if it does not already exist, but a
251# physical interface must be manually added to the bridge as a
252# port for external connectivity.
253#
254# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
255OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-br-ex}
256
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100257# With the openvswitch plugin, set to True in ``localrc`` to enable
258# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
259#
260# Example: ``OVS_ENABLE_TUNNELING=True``
261OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
262
263# Use DHCP agent for providing metadata service in the case of
264# without L3 agent (No Route Agent), set to True in localrc.
265ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
266
267# Add a static route as dhcp option, so the request to 169.254.169.254
268# will be able to reach through a route(DHCP agent)
269# This option require ENABLE_ISOLATED_METADATA = True
270ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
271# Neutron plugin specific functions
272# ---------------------------------
273
274# Please refer to ``lib/neutron_plugins/README.md`` for details.
275if [ -f $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN ]; then
276 source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
277fi
278
279# Agent metering service plugin functions
280# -------------------------------------------
281
282# Hardcoding for 1 service plugin for now
283source $TOP_DIR/lib/neutron_plugins/services/metering
284
285# L3 Service functions
286source $TOP_DIR/lib/neutron_plugins/services/l3
287
288# Additional Neutron service plugins
289source $TOP_DIR/lib/neutron_plugins/services/placement
290source $TOP_DIR/lib/neutron_plugins/services/trunk
291source $TOP_DIR/lib/neutron_plugins/services/qos
elajkata84b2092021-11-17 11:52:56 +0100292source $TOP_DIR/lib/neutron_plugins/services/segments
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100293
294# Use security group or not
295if has_neutron_plugin_security_group; then
296 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
297else
298 Q_USE_SECGROUP=False
299fi
300
Harald Jensås16ac21f2023-08-31 15:06:52 +0200301# OVN_BRIDGE_MAPPINGS - ovn-bridge-mappings
302# NOTE(hjensas): Initialize after sourcing neutron_plugins/services/l3
303# which initialize PUBLIC_BRIDGE.
304OVN_BRIDGE_MAPPINGS=${OVN_BRIDGE_MAPPINGS:-$PHYSICAL_NETWORK:$PUBLIC_BRIDGE}
305
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100306# 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
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000358function _enable_ovn_maintenance {
359 if [[ $Q_AGENT == "ovn" ]]; then
360 enable_service neutron-ovn-maintenance-worker
361 fi
362}
363
364function _run_ovn_maintenance {
365 if [[ $Q_AGENT == "ovn" ]]; then
366 run_process neutron-ovn-maintenance-worker "$NEUTRON_BIN_DIR/neutron-ovn-maintenance-worker $cfg_file_options"
367 fi
368}
369
370function _stop_ovn_maintenance {
371 if [[ $Q_AGENT == "ovn" ]]; then
372 stop_process neutron-ovn-maintenance-worker
373 fi
374}
375
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100376# For services and agents that require it, dynamically construct a list of
377# --config-file arguments that are passed to the binary.
378function determine_config_files {
379 local opts=""
380 case "$1" in
381 "neutron-server") opts="$(_determine_config_server)" ;;
382 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
383 esac
384 if [ -z "$opts" ] ; then
385 die $LINENO "Could not determine config files for $1."
YAMAMOTO Takashi1df17c92017-05-01 17:00:42 +0900386 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100387 echo "$opts"
388}
Sean M. Collins2a242512016-05-03 09:03:09 -0400389
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100390# configure_neutron()
391# Set common config for all neutron server and agents.
392function configure_neutron {
393 _configure_neutron_common
Sean M. Collins5394cc12016-05-11 15:03:38 -0400394 iniset_rpc_backend neutron $NEUTRON_CONF
395
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100396 if is_service_enabled q-metering neutron-metering; then
397 _configure_neutron_metering
398 fi
399 if is_service_enabled q-agt neutron-agent; then
400 _configure_neutron_plugin_agent
401 fi
402 if is_service_enabled q-dhcp neutron-dhcp; then
403 _configure_neutron_dhcp_agent
404 fi
405 if is_service_enabled q-l3 neutron-l3; then
406 _configure_neutron_l3_agent
407 fi
408 if is_service_enabled q-meta neutron-metadata-agent; then
409 _configure_neutron_metadata_agent
Sean M. Collins2a242512016-05-03 09:03:09 -0400410 fi
411
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100412 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
413 _configure_dvr
414 fi
415 if is_service_enabled ceilometer; then
416 _configure_neutron_ceilometer_notifications
417 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400418
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100419 if [[ $Q_AGENT == "ovn" ]]; then
420 configure_ovn
421 configure_ovn_plugin
422 fi
Brian Haley9aaa5292017-09-20 14:23:05 -0400423
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100424 # Configure Neutron's advanced services
425 if is_service_enabled q-placement neutron-placement; then
426 configure_placement_extension
427 fi
428 if is_service_enabled q-trunk neutron-trunk; then
429 configure_trunk_extension
430 fi
431 if is_service_enabled q-qos neutron-qos; then
432 configure_qos
433 if is_service_enabled q-l3 neutron-l3; then
434 configure_l3_agent_extension_fip_qos
435 configure_l3_agent_extension_gateway_ip_qos
Denis Buliga0bf75a42017-02-06 16:56:46 +0200436 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400437 fi
elajkata84b2092021-11-17 11:52:56 +0100438 if is_service_enabled neutron-segments; then
439 configure_placement_neutron
440 configure_segments_extension
441 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400442
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100443 # Finally configure Neutron server and core plugin
444 if is_service_enabled q-agt neutron-agent q-svc neutron-api; then
445 _configure_neutron_service
Sean M. Collins2a242512016-05-03 09:03:09 -0400446 fi
447
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100448 iniset $NEUTRON_CONF DEFAULT api_workers "$API_WORKERS"
449 # devstack is not a tool for running uber scale OpenStack
450 # clouds, therefore running without a dedicated RPC worker
451 # for state reports is more than adequate.
452 iniset $NEUTRON_CONF DEFAULT rpc_state_report_workers 0
Ihar Hrachyshkae3915932017-02-24 06:24:47 +0000453
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100454 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
Stephen Finucane0cd87632024-04-19 12:12:16 +0100455 write_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_UWSGI" "/networking" "" "neutron-api"
Sean M. Collins8063fee2016-05-24 11:27:36 -0700456 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400457}
458
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100459function configure_neutron_nova {
460 create_nova_conf_neutron $NOVA_CONF
461 if [[ "${CELLSV2_SETUP}" == "superconductor" ]]; then
462 for i in $(seq 1 $NOVA_NUM_CELLS); do
463 local conf
464 conf=$(conductor_conf $i)
465 create_nova_conf_neutron $conf
466 done
Sean M. Collins2a242512016-05-03 09:03:09 -0400467 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400468}
469
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100470function create_nova_conf_neutron {
Lucas Alvares Gomese6385932018-06-28 11:00:28 +0100471 local conf=${1:-$NOVA_CONF}
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400472 iniset $conf neutron auth_type "password"
473 iniset $conf neutron auth_url "$KEYSTONE_SERVICE_URI"
Dr. Jens Harbott696dbdf2024-07-09 16:36:37 +0200474 iniset $conf neutron username nova
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400475 iniset $conf neutron password "$SERVICE_PASSWORD"
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100476 iniset $conf neutron user_domain_name "$SERVICE_DOMAIN_NAME"
477 iniset $conf neutron project_name "$SERVICE_PROJECT_NAME"
478 iniset $conf neutron project_domain_name "$SERVICE_DOMAIN_NAME"
479 iniset $conf neutron auth_strategy "$Q_AUTH_STRATEGY"
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400480 iniset $conf neutron region_name "$REGION_NAME"
Sean M. Collins2a242512016-05-03 09:03:09 -0400481
Gary Kotton88f85582016-08-14 06:55:42 -0700482 # optionally set options in nova_conf
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400483 neutron_plugin_create_nova_conf $conf
Gary Kotton88f85582016-08-14 06:55:42 -0700484
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100485 if is_service_enabled q-meta neutron-metadata-agent; then
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400486 iniset $conf neutron service_metadata_proxy "True"
Sean M. Collins2a242512016-05-03 09:03:09 -0400487 fi
488
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100489 iniset $conf DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
490 iniset $conf DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Sean M. Collins2a242512016-05-03 09:03:09 -0400491}
492
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100493# create_neutron_accounts() - Set up common required neutron accounts
494
Sean M. Collins2a242512016-05-03 09:03:09 -0400495# Tenant User Roles
496# ------------------------------------------------------------------
497# service neutron admin # if enabled
498
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100499# Migrated from keystone_data.sh
500function create_neutron_accounts {
Kevin Benton66b361b2017-06-13 00:31:01 -0700501 local neutron_url
Kevin Benton66b361b2017-06-13 00:31:01 -0700502 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100503 neutron_url=$Q_PROTOCOL://$SERVICE_HOST/
Kevin Benton66b361b2017-06-13 00:31:01 -0700504 else
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100505 neutron_url=$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/
Kevin Benton66b361b2017-06-13 00:31:01 -0700506 fi
Slawek Kaplonski1a21ccb2022-07-08 21:57:45 +0200507 if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then
508 neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME
509 fi
Kevin Benton66b361b2017-06-13 00:31:01 -0700510
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100511 if is_service_enabled q-svc neutron-api; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400512
513 create_service_user "neutron"
514
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100515 get_or_create_service "neutron" "network" "Neutron Service"
516 get_or_create_endpoint \
517 "network" \
Kevin Benton66b361b2017-06-13 00:31:01 -0700518 "$REGION_NAME" "$neutron_url"
Sean M. Collins2a242512016-05-03 09:03:09 -0400519 fi
520}
521
Sean M. Collins2a242512016-05-03 09:03:09 -0400522# init_neutron() - Initialize databases, etc.
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100523function init_neutron {
524 recreate_database $Q_DB_NAME
Clark Boylan633dbc32017-06-14 12:09:21 -0700525 time_start "dbsync"
Sean M. Collins2a242512016-05-03 09:03:09 -0400526 # Run Neutron db migrations
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100527 $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 -0700528 time_stop "dbsync"
Sean M. Collins2a242512016-05-03 09:03:09 -0400529}
530
531# install_neutron() - Collect source and prepare
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100532function install_neutron {
Sean M. Collins2a242512016-05-03 09:03:09 -0400533 # Install neutron-lib from git so we make sure we're testing
534 # the latest code.
535 if use_library_from_git "neutron-lib"; then
536 git_clone_by_name "neutron-lib"
537 setup_dev_lib "neutron-lib"
538 fi
539
elajkatbb0c2732023-11-16 11:30:04 +0100540 # Install SQLAlchemy and alembic from git when these are required
541 # see https://bugs.launchpad.net/neutron/+bug/2042941
542 if use_library_from_git "sqlalchemy"; then
543 git_clone $SQLALCHEMY_REPO $SQLALCHEMY_DIR $SQLALCHEMY_BRANCH
544 setup_develop $SQLALCHEMY_DIR
545 fi
546 if use_library_from_git "alembic"; then
547 git_clone $ALEMBIC_REPO $ALEMBIC_DIR $ALEMBIC_BRANCH
548 setup_develop $ALEMBIC_DIR
549 fi
550
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100551 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
552 setup_develop $NEUTRON_DIR
Sean M. Collins2a242512016-05-03 09:03:09 -0400553
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100554 if [[ $Q_AGENT == "ovn" ]]; then
555 install_ovn
Sean M. Collins2a242512016-05-03 09:03:09 -0400556 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400557}
558
559# install_neutronclient() - Collect source and prepare
560function install_neutronclient {
561 if use_library_from_git "python-neutronclient"; then
562 git_clone_by_name "python-neutronclient"
563 setup_dev_lib "python-neutronclient"
Sean M. Collins2a242512016-05-03 09:03:09 -0400564 fi
565}
566
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100567# install_neutron_agent_packages() - Collect source and prepare
568function install_neutron_agent_packages {
569 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
570 if is_service_enabled q-l3 neutron-l3; then
571 install_package radvd
Sean M. Collins2a242512016-05-03 09:03:09 -0400572 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100573 # install packages that are specific to plugin agent(s)
574 if is_service_enabled q-agt neutron-agent q-dhcp neutron-dhcp q-l3 neutron-l3; then
575 neutron_plugin_install_agent_packages
Sean M. Collins2a242512016-05-03 09:03:09 -0400576 fi
577}
578
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100579# Finish neutron configuration
580function configure_neutron_after_post_config {
581 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
582 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
Sean M. Collins2a242512016-05-03 09:03:09 -0400583 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100584 configure_rbac_policies
Sean M. Collins2a242512016-05-03 09:03:09 -0400585}
586
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +0200587# configure_rbac_policies() - Configure Neutron to enforce new RBAC
588# policies and scopes if NEUTRON_ENFORCE_SCOPE == True
589function configure_rbac_policies {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100590 if [[ "$NEUTRON_ENFORCE_SCOPE" == "True" || "$ENFORCE_SCOPE" == True ]]; then
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +0200591 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults True
592 iniset $NEUTRON_CONF oslo_policy enforce_scope True
593 else
594 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults False
595 iniset $NEUTRON_CONF oslo_policy enforce_scope False
596 fi
597}
598
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100599# Start running OVN processes
600function start_ovn_services {
601 if [[ $Q_AGENT == "ovn" ]]; then
Lucas Alvares Gomesa3891282023-07-18 16:31:28 +0100602 if [ "$VIRT_DRIVER" != 'ironic' ]; then
603 # NOTE(TheJulia): Ironic's devstack plugin needs to perform
604 # additional networking configuration to setup a working test
605 # environment with test virtual machines to emulate baremetal,
606 # which requires OVN to be up and running earlier to complete
607 # that base configuration.
608 init_ovn
609 start_ovn
610 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100611 if [[ "$OVN_L3_CREATE_PUBLIC_NETWORK" == "True" ]]; then
612 if [[ "$NEUTRON_CREATE_INITIAL_NETWORKS" != "True" ]]; then
613 echo "OVN_L3_CREATE_PUBLIC_NETWORK=True is being ignored "
614 echo "because NEUTRON_CREATE_INITIAL_NETWORKS is set to False"
615 else
616 create_public_bridge
617 fi
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400618 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400619 fi
620}
621
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100622# Start running processes
623function start_neutron_service_and_check {
624 local service_port=$Q_PORT
625 local service_protocol=$Q_PROTOCOL
626 local cfg_file_options
627 local neutron_url
Sean M. Collins2a242512016-05-03 09:03:09 -0400628
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100629 cfg_file_options="$(determine_config_files neutron-server)"
Sean M. Collins2a242512016-05-03 09:03:09 -0400630
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100631 if is_service_enabled tls-proxy; then
632 service_port=$Q_PORT_INT
633 service_protocol="http"
Sean M. Collins2a242512016-05-03 09:03:09 -0400634 fi
Rodolfo Alonso Hernandez79a812a2024-07-31 14:41:33 +0000635
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100636 # Start the Neutron service
637 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
Rodolfo Alonso Hernandez79a812a2024-07-31 14:41:33 +0000638 # The default value of "rpc_workers" is None (not defined). If
639 # "rpc_workers" is explicitly set to 0, the RPC workers process
640 # should not be executed.
641 local rpc_workers
642 rpc_workers=$(iniget_multiline $NEUTRON_CONF DEFAULT rpc_workers)
643
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100644 enable_service neutron-api
645 run_process neutron-api "$(which uwsgi) --procname-prefix neutron-api --ini $NEUTRON_UWSGI_CONF"
646 neutron_url=$Q_PROTOCOL://$Q_HOST/
Rodolfo Alonso Hernandez79a812a2024-07-31 14:41:33 +0000647 if [ "$rpc_workers" != "0" ]; then
Rodolfo Alonso Hernandezaaaa0372024-07-19 08:09:25 +0000648 enable_service neutron-rpc-server
649 fi
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000650 enable_service neutron-periodic-workers
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000651 _enable_ovn_maintenance
Rodolfo Alonso Hernandez79a812a2024-07-31 14:41:33 +0000652 if [ "$rpc_workers" != "0" ]; then
Rodolfo Alonso Hernandezaaaa0372024-07-19 08:09:25 +0000653 run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $cfg_file_options"
654 fi
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000655 run_process neutron-periodic-workers "$NEUTRON_BIN_DIR/neutron-periodic-workers $cfg_file_options"
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000656 _run_ovn_maintenance
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100657 else
658 run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
659 neutron_url=$service_protocol://$Q_HOST:$service_port/
660 # Start proxy if enabled
661 if is_service_enabled tls-proxy; then
662 start_tls_proxy neutron '*' $Q_PORT $Q_HOST $Q_PORT_INT
663 fi
664 fi
665 if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then
666 neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME
667 fi
668 echo "Waiting for Neutron to start..."
Sean M. Collins2a242512016-05-03 09:03:09 -0400669
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100670 local testcmd="wget ${ssl_ca} --no-proxy -q -O- $neutron_url"
671 test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900672}
673
Sean M. Collins2a242512016-05-03 09:03:09 -0400674function start_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100675 start_l2_agent "$@"
676 start_other_agents "$@"
677}
678
679# Control of the l2 agent is separated out to make it easier to test partial
680# upgrades (everything upgraded except the L2 agent)
681function start_l2_agent {
682 run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
683
684 if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then
685 sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
686 sudo ip link set $OVS_PHYSICAL_BRIDGE up
687 sudo ip link set br-int up
688 sudo ip link set $PUBLIC_INTERFACE up
689 if is_ironic_hardware; then
690 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
691 sudo ip addr del $IP dev $PUBLIC_INTERFACE
692 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
693 done
694 sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
695 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400696 fi
697}
698
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100699function start_other_agents {
700 run_process q-dhcp "$AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file $Q_DHCP_CONF_FILE"
701
702 run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
703
704 run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file $Q_META_CONF_FILE"
705 run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
706}
707
708# Start running processes, including screen
709function start_neutron_agents {
710 # NOTE(slaweq): it's now just a wrapper for start_neutron function
711 start_neutron "$@"
712}
713
714function stop_l2_agent {
715 stop_process q-agt
716}
717
718# stop_other() - Stop running processes
719function stop_other {
720 if is_service_enabled q-dhcp neutron-dhcp; then
721 stop_process q-dhcp
722 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
723 [ ! -z "$pid" ] && sudo kill -9 $pid
724 fi
725
726 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
727 stop_process neutron-rpc-server
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000728 stop_process neutron-periodic-workers
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100729 stop_process neutron-api
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000730 _stop_ovn_maintenance
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100731 else
732 stop_process q-svc
733 fi
734
735 if is_service_enabled q-l3 neutron-l3; then
736 sudo pkill -f "radvd -C $DATA_DIR/neutron/ra"
737 stop_process q-l3
738 fi
739
740 if is_service_enabled q-meta neutron-metadata-agent; then
741 stop_process q-meta
742 fi
743
744 if is_service_enabled q-metering neutron-metering; then
745 neutron_metering_stop
746 fi
747
748 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Bence Romsics71c3c402022-12-21 13:50:54 +0100749 # pkill takes care not to kill itself, but it may kill its parent
750 # sudo unless we use the "ps | grep [f]oo" trick
751 sudo pkill -9 -f "$NEUTRON_ROOTWRAP-[d]aemon" || :
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100752 fi
753}
754
755# stop_neutron() - Stop running processes (non-screen)
Sean M. Collins2a242512016-05-03 09:03:09 -0400756function stop_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100757 stop_other
758 stop_l2_agent
759
760 if [[ $Q_AGENT == "ovn" && $SKIP_STOP_OVN != "True" ]]; then
761 stop_ovn
Sean M. Collins2a242512016-05-03 09:03:09 -0400762 fi
763}
764
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100765# _move_neutron_addresses_route() - Move the primary IP to the OVS bridge
766# on startup, or back to the public interface on cleanup. If no IP is
767# configured on the interface, just add it as a port to the OVS bridge.
768function _move_neutron_addresses_route {
769 local from_intf=$1
770 local to_intf=$2
771 local add_ovs_port=$3
772 local del_ovs_port=$4
773 local af=$5
774
775 if [[ -n "$from_intf" && -n "$to_intf" ]]; then
776 # Remove the primary IP address from $from_intf and add it to $to_intf,
777 # along with the default route, if it exists. Also, when called
778 # on configure we will also add $from_intf as a port on $to_intf,
779 # assuming it is an OVS bridge.
780
781 local IP_REPLACE=""
782 local IP_DEL=""
783 local IP_UP=""
784 local DEFAULT_ROUTE_GW
785 DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf\s/ { print \$3; exit }")
786 local ADD_OVS_PORT=""
787 local DEL_OVS_PORT=""
788 local ARP_CMD=""
789
790 IP_BRD=$(ip -f $af a s dev $from_intf scope global primary | grep inet | awk '{ print $2, $3, $4; exit }')
791
792 if [ "$DEFAULT_ROUTE_GW" != "" ]; then
793 ADD_DEFAULT_ROUTE="sudo ip -f $af r replace default via $DEFAULT_ROUTE_GW dev $to_intf"
794 fi
795
796 if [[ "$add_ovs_port" == "True" ]]; then
797 ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf"
798 fi
799
800 if [[ "$del_ovs_port" == "True" ]]; then
801 DEL_OVS_PORT="sudo ovs-vsctl --if-exists del-port $from_intf $to_intf"
802 fi
803
804 if [[ "$IP_BRD" != "" ]]; then
805 IP_DEL="sudo ip addr del $IP_BRD dev $from_intf"
806 IP_REPLACE="sudo ip addr replace $IP_BRD dev $to_intf"
807 IP_UP="sudo ip link set $to_intf up"
808 if [[ "$af" == "inet" ]]; then
809 IP=$(echo $IP_BRD | awk '{ print $1; exit }' | grep -o -E '(.*)/' | cut -d "/" -f1)
810 ARP_CMD="sudo arping -A -c 3 -w 5 -I $to_intf $IP "
811 fi
812 fi
813
814 # The add/del OVS port calls have to happen either before or
815 # after the address is moved in order to not leave it orphaned.
816 $DEL_OVS_PORT; $IP_DEL; $IP_REPLACE; $IP_UP; $ADD_OVS_PORT; $ADD_DEFAULT_ROUTE; $ARP_CMD
817 fi
818}
819
820# _configure_public_network_connectivity() - Configures connectivity to the
821# external network using $PUBLIC_INTERFACE or NAT on the single interface
822# machines
823function _configure_public_network_connectivity {
824 # If we've given a PUBLIC_INTERFACE to take over, then we assume
825 # that we can own the whole thing, and privot it into the OVS
826 # bridge. If we are not, we're probably on a single interface
827 # machine, and we just setup NAT so that fixed guests can get out.
828 if [[ -n "$PUBLIC_INTERFACE" ]]; then
829 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" True False "inet"
830
831 if [[ $(ip -f inet6 a s dev "$PUBLIC_INTERFACE" | grep -c 'global') != 0 ]]; then
832 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" False False "inet6"
833 fi
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -0500834 else
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100835 for d in $default_v4_route_devs; do
836 sudo iptables -t nat -A POSTROUTING -o $d -s $FLOATING_RANGE -j MASQUERADE
837 done
838 fi
839}
840
841# cleanup_neutron() - Remove residual data files, anything left over from previous
842# runs that a clean run would need to clean up
843function cleanup_neutron {
844 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
845 stop_process neutron-api
846 stop_process neutron-rpc-server
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000847 stop_process neutron-periodic-workers
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000848 _stop_ovn_maintenance
Stephen Finucaned5182ce2024-04-19 12:27:14 +0100849 remove_uwsgi_config "$NEUTRON_UWSGI_CONF" "neutron-api"
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100850 sudo rm -f $(apache_site_config_for neutron-api)
851 fi
852
853 if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then
854 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False True "inet"
855
856 if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then
857 # ip(8) wants the prefix length when deleting
858 local v6_gateway
859 v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }')
860 sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE
861 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False False "inet6"
862 fi
863
864 if is_provider_network && is_ironic_hardware; then
865 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
866 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
867 sudo ip addr add $IP dev $PUBLIC_INTERFACE
868 done
869 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
870 fi
871 fi
872
873 if is_neutron_ovs_base_plugin; then
874 neutron_ovs_base_cleanup
875 fi
876
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100877 # delete all namespaces created by neutron
878 for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|fip|snat)-[0-9a-f-]*'); do
879 sudo ip netns delete ${ns}
880 done
881
882 if [[ $Q_AGENT == "ovn" ]]; then
883 cleanup_ovn
884 fi
885}
886
887
888function _create_neutron_conf_dir {
889 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
890 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
891}
892
893# _configure_neutron_common()
894# Set common config for all neutron server and agents.
895# This MUST be called before other ``_configure_neutron_*`` functions.
896function _configure_neutron_common {
897 _create_neutron_conf_dir
898
899 # Uses oslo config generator to generate core sample configuration files
900 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
901
902 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
903
904 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
905
906 # allow neutron user to administer neutron to match neutron account
907 # NOTE(amotoki): This is required for nova works correctly with neutron.
908 if [ -f $NEUTRON_DIR/etc/policy.json ]; then
909 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
910 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
911 else
912 echo '{"context_is_admin": "role:admin or user_name:neutron"}' > $Q_POLICY_FILE
913 fi
914
915 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
916 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
917 neutron_plugin_configure_common
918
919 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
920 die $LINENO "Neutron plugin not set.. exiting"
921 fi
922
923 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
924 mkdir -p /$Q_PLUGIN_CONF_PATH
925 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
926 # NOTE(slaweq): NEUTRON_CORE_PLUGIN_CONF is used e.g. in neutron repository,
927 # it was previously defined in the lib/neutron module which is now deleted.
928 NEUTRON_CORE_PLUGIN_CONF=$Q_PLUGIN_CONF_FILE
929 # NOTE(hichihara): Some neutron vendor plugins were already decomposed and
930 # there is no config file in Neutron tree. They should prepare the file in each plugin.
931 if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then
932 cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE
933 elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then
934 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
935 fi
936
937 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
938 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
939 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
940 iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS
941 iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock
942
943 # NOTE(freerunner): Need to adjust Region Name for nova in multiregion installation
944 iniset $NEUTRON_CONF nova region_name $REGION_NAME
945
946 if [ "$VIRT_DRIVER" = 'fake' ]; then
947 # Disable arbitrary limits
948 iniset $NEUTRON_CONF quotas quota_network -1
949 iniset $NEUTRON_CONF quotas quota_subnet -1
950 iniset $NEUTRON_CONF quotas quota_port -1
951 iniset $NEUTRON_CONF quotas quota_security_group -1
952 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
953 fi
954
955 # Format logging
956 setup_logging $NEUTRON_CONF
957
958 if is_service_enabled tls-proxy && [ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" ]; then
959 # Set the service port for a proxy to take the original
960 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
961 iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True
962 fi
963
964 _neutron_setup_rootwrap
965}
966
967function _configure_neutron_dhcp_agent {
968
969 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE
970
971 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
972 # make it so we have working DNS from guests
973 iniset $Q_DHCP_CONF_FILE DEFAULT dnsmasq_local_resolv True
974 configure_root_helper_options $Q_DHCP_CONF_FILE
975
976 if ! is_service_enabled q-l3 neutron-l3; then
977 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
978 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
979 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
980 else
981 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
982 die "$LINENO" "Enable isolated metadata is a must for metadata network"
983 fi
984 fi
985 fi
986
987 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
988
989 neutron_plugin_configure_dhcp_agent $Q_DHCP_CONF_FILE
990}
991
992
993function _configure_neutron_metadata_agent {
994 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE
995
996 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
997 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_host $Q_META_DATA_IP
998 iniset $Q_META_CONF_FILE DEFAULT metadata_workers $API_WORKERS
999 configure_root_helper_options $Q_META_CONF_FILE
1000}
1001
1002function _configure_neutron_ceilometer_notifications {
1003 iniset $NEUTRON_CONF oslo_messaging_notifications driver messagingv2
1004}
1005
1006function _configure_neutron_metering {
1007 neutron_agent_metering_configure_common
1008 neutron_agent_metering_configure_agent
1009}
1010
1011function _configure_dvr {
1012 iniset $NEUTRON_CONF DEFAULT router_distributed True
1013 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
1014}
1015
1016
1017# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
1018# It is called when q-agt is enabled.
1019function _configure_neutron_plugin_agent {
1020 # Specify the default root helper prior to agent configuration to
1021 # ensure that an agent's configuration can override the default
1022 configure_root_helper_options /$Q_PLUGIN_CONF_FILE
1023 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1024
1025 # Configure agent for plugin
1026 neutron_plugin_configure_plugin_agent
1027}
1028
1029function _replace_api_paste_composite {
1030 local sep
1031 sep=$(echo -ne "\x01")
1032 # Replace it
1033 $sudo sed -i -e "s/\/\: neutronversions_composite/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/\: neutronversions_composite/" "$Q_API_PASTE_FILE"
1034 $sudo sed -i -e "s/\/healthcheck\: healthcheck/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/healthcheck\: healthcheck/" "$Q_API_PASTE_FILE"
1035 $sudo sed -i -e "s/\/v2.0\: neutronapi_v2_0/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/v2.0\: neutronapi_v2_0/" "$Q_API_PASTE_FILE"
1036}
1037
1038# _configure_neutron_service() - Set config files for neutron service
1039# It is called when q-svc is enabled.
1040function _configure_neutron_service {
1041 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
1042 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
1043
Slawek Kaplonskib500d802024-06-14 12:58:58 +02001044 if [[ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" && -n "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001045 _replace_api_paste_composite
1046 fi
1047
1048 # Update either configuration file with plugin
1049 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
1050
1051 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1052 iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE
1053
1054 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
1055 configure_keystone_authtoken_middleware $NEUTRON_CONF $Q_ADMIN_USERNAME
1056
1057 # Configuration for neutron notifications to nova.
1058 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
1059 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
1060
1061 configure_keystone_authtoken_middleware $NEUTRON_CONF nova nova
1062
1063 # Configuration for placement client
1064 configure_keystone_authtoken_middleware $NEUTRON_CONF placement placement
1065
1066 # Configure plugin
1067 neutron_plugin_configure_service
1068}
1069
1070# Utility Functions
1071#------------------
1072
1073# neutron_service_plugin_class_add() - add service plugin class
1074function neutron_service_plugin_class_add {
1075 local service_plugin_class=$1
1076 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
1077 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
1078 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
1079 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
1080 fi
1081}
1082
1083# neutron_ml2_extension_driver_add() - add ML2 extension driver
1084function neutron_ml2_extension_driver_add {
1085 local extension=$1
1086 if [[ $Q_ML2_PLUGIN_EXT_DRIVERS == '' ]]; then
1087 Q_ML2_PLUGIN_EXT_DRIVERS=$extension
1088 elif [[ ! ,${Q_ML2_PLUGIN_EXT_DRIVERS}, =~ ,${extension}, ]]; then
1089 Q_ML2_PLUGIN_EXT_DRIVERS="$Q_ML2_PLUGIN_EXT_DRIVERS,$extension"
1090 fi
1091}
1092
1093# neutron_server_config_add() - add server config file
1094function neutron_server_config_add {
1095 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($1)
1096}
1097
1098# neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root).
1099function neutron_deploy_rootwrap_filters {
1100 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1101 return
1102 fi
1103 local srcdir=$1
1104 sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D
1105 sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
1106}
1107
1108# _neutron_setup_rootwrap() - configure Neutron's rootwrap
1109function _neutron_setup_rootwrap {
1110 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1111 return
1112 fi
1113 # Wipe any existing ``rootwrap.d`` files first
1114 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
1115 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
1116 sudo rm -rf $Q_CONF_ROOTWRAP_D
1117 fi
1118
1119 neutron_deploy_rootwrap_filters $NEUTRON_DIR
1120
1121 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
1122 # location moved in newer versions, prefer new location
1123 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
1124 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
1125 else
1126 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
1127 fi
1128 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
yatinkarelffc1b762023-08-28 10:52:26 +05301129 # Rely on $PATH set by devstack to determine what is safe to execute
1130 # by rootwrap rather than use explicit whitelist of paths in
1131 # rootwrap.conf
1132 sudo sed -e 's/^exec_dirs=.*/#&/' -i $Q_RR_CONF_FILE
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001133
1134 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
1135 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
1136 ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
1137
1138 # Set up the rootwrap sudoers for neutron
1139 TEMPFILE=`mktemp`
1140 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
1141 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE
1142 chmod 0440 $TEMPFILE
1143 sudo chown root:root $TEMPFILE
1144 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
1145
1146 # Update the root_helper
1147 configure_root_helper_options $NEUTRON_CONF
1148}
1149
1150function configure_root_helper_options {
1151 local conffile=$1
1152 iniset $conffile agent root_helper "$Q_RR_COMMAND"
1153 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
1154 iniset $conffile agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
1155 fi
1156}
1157
1158function _neutron_setup_interface_driver {
1159
1160 # ovs_use_veth needs to be set before the plugin configuration
1161 # occurs to allow plugins to override the setting.
1162 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1163
1164 neutron_plugin_setup_interface_driver $1
1165}
1166# Functions for Neutron Exercises
1167#--------------------------------
1168
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001169# ssh check
1170function _ssh_check_neutron {
1171 local from_net=$1
1172 local key_file=$2
1173 local ip=$3
1174 local user=$4
1175 local timeout_sec=$5
1176 local probe_cmd = ""
1177 probe_cmd=`_get_probe_cmd_prefix $from_net`
1178 local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success"
1179 test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec
1180}
1181
1182function plugin_agent_add_l2_agent_extension {
1183 local l2_agent_extension=$1
1184 if [[ -z "$L2_AGENT_EXTENSIONS" ]]; then
1185 L2_AGENT_EXTENSIONS=$l2_agent_extension
1186 elif [[ ! ,${L2_AGENT_EXTENSIONS}, =~ ,${l2_agent_extension}, ]]; then
1187 L2_AGENT_EXTENSIONS+=",$l2_agent_extension"
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -05001188 fi
1189}
1190
Sean M. Collins2a242512016-05-03 09:03:09 -04001191# Restore xtrace
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001192$_XTRACE_NEUTRON
1193
1194# Tell emacs to use shell-script-mode
1195## Local variables:
1196## mode: shell-script
1197## End: