blob: ea2d8e728ac422fb0ece8e332eeb8e74bbc172d9 [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
Sean M. Collins2a242512016-05-03 09:03:09 -040065# Set up default directories
66GITDIR["python-neutronclient"]=$DEST/python-neutronclient
67
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010068NEUTRON_DIR=$DEST/neutron
69NEUTRON_FWAAS_DIR=$DEST/neutron-fwaas
70
71# Support entry points installation of console scripts
72if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
73 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
74else
75 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
76fi
77
78NEUTRON_CONF_DIR=/etc/neutron
79NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
80export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
81
Stephen Finucane0cd87632024-04-19 12:12:16 +010082NEUTRON_UWSGI=neutron.wsgi.api:application
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010083NEUTRON_UWSGI_CONF=$NEUTRON_CONF_DIR/neutron-api-uwsgi.ini
Sean M. Collins2a242512016-05-03 09:03:09 -040084
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +020085# If NEUTRON_ENFORCE_SCOPE == True, it will set "enforce_scope"
86# and "enforce_new_defaults" to True in the Neutron's config to enforce usage
Ghanshyam Mannbacb8402023-10-25 12:52:28 -070087# of the new RBAC policies and scopes. Set it to False if you do not
88# want to run Neutron with new RBAC.
89NEUTRON_ENFORCE_SCOPE=$(trueorfalse True NEUTRON_ENFORCE_SCOPE)
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +020090
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010091# Agent binaries. Note, binary paths for other agents are set in per-service
92# scripts in lib/neutron_plugins/services/
93AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
94AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
95AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
Brian Haley9aaa5292017-09-20 14:23:05 -040096
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010097# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
98# loaded from per-plugin scripts in lib/neutron_plugins/
99Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
100# NOTE(slaweq): NEUTRON_DHCP_CONF is used e.g. in neutron repository,
101# it was previously defined in the lib/neutron module which is now deleted.
102NEUTRON_DHCP_CONF=$Q_DHCP_CONF_FILE
103Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
104# NOTE(slaweq): NEUTRON_L3_CONF is used e.g. in neutron repository,
105# it was previously defined in the lib/neutron module which is now deleted.
106NEUTRON_L3_CONF=$Q_L3_CONF_FILE
107Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
Sean M. Collins2a242512016-05-03 09:03:09 -0400108
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100109# Default name for Neutron database
110Q_DB_NAME=${Q_DB_NAME:-neutron}
111# Default Neutron Plugin
112Q_PLUGIN=${Q_PLUGIN:-ml2}
113# Default Neutron Port
114Q_PORT=${Q_PORT:-9696}
115# Default Neutron Internal Port when using TLS proxy
116Q_PORT_INT=${Q_PORT_INT:-19696}
117# Default Neutron Host
118Q_HOST=${Q_HOST:-$SERVICE_HOST}
119# Default protocol
120Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
121# Default listen address
122Q_LISTEN_ADDRESS=${Q_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)}
123# Default admin username
124Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
125# Default auth strategy
126Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
127# RHEL's support for namespaces requires using veths with ovs
128Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
129Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
130Q_USE_ROOTWRAP_DAEMON=$(trueorfalse True Q_USE_ROOTWRAP_DAEMON)
131# Meta data IP
132Q_META_DATA_IP=${Q_META_DATA_IP:-$(ipv6_unquote $SERVICE_HOST)}
133# Allow Overlapping IP among subnets
134Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
135Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
136Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
137VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
138VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Sean M. Collins2a242512016-05-03 09:03:09 -0400139
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100140# Allow to skip stopping of OVN services
141SKIP_STOP_OVN=${SKIP_STOP_OVN:-False}
Sean M. Collins2a242512016-05-03 09:03:09 -0400142
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100143# The directory which contains files for Q_PLUGIN_EXTRA_CONF_FILES.
144# /etc/neutron is assumed by many of devstack plugins. Do not change.
145_Q_PLUGIN_EXTRA_CONF_PATH=/etc/neutron
Julia Kreger6e5b1382019-01-09 17:00:45 -0800146
Slawek Kaplonski1a21ccb2022-07-08 21:57:45 +0200147# The name of the service in the endpoint URL
148NEUTRON_ENDPOINT_SERVICE_NAME=${NEUTRON_ENDPOINT_SERVICE_NAME-"networking"}
Stephen Finucaned040e152024-10-11 16:18:19 +0100149if [[ -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then
Slawek Kaplonski1a21ccb2022-07-08 21:57:45 +0200150 NEUTRON_ENDPOINT_SERVICE_NAME="networking"
151fi
152
elajkatbb0c2732023-11-16 11:30:04 +0100153# Source install libraries
154ALEMBIC_REPO=${ALEMBIC_REPO:-https://github.com/sqlalchemy/alembic.git}
155ALEMBIC_DIR=${ALEMBIC_DIR:-$DEST/alembic}
156ALEMBIC_BRANCH=${ALEMBIC_BRANCH:-main}
157SQLALCHEMY_REPO=${SQLALCHEMY_REPO:-https://github.com/sqlalchemy/sqlalchemy.git}
158SQLALCHEMY_DIR=${SQLALCHEMY_DIR:-$DEST/sqlalchemy}
159SQLALCHEMY_BRANCH=${SQLALCHEMY_BRANCH:-main}
160
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100161# List of config file names in addition to the main plugin config file
162# To add additional plugin config files, use ``neutron_server_config_add``
163# utility function. For example:
164#
165# ``neutron_server_config_add file1``
166#
167# These config files are relative to ``/etc/neutron``. The above
168# example would specify ``--config-file /etc/neutron/file1`` for
169# neutron server.
170declare -a -g Q_PLUGIN_EXTRA_CONF_FILES
Julia Kreger6e5b1382019-01-09 17:00:45 -0800171
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100172# same as Q_PLUGIN_EXTRA_CONF_FILES, but with absolute path.
173declare -a -g _Q_PLUGIN_EXTRA_CONF_FILES_ABS
174
175
176Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
177if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
178 Q_RR_COMMAND="sudo"
179else
180 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
181 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
182 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
183 Q_RR_DAEMON_COMMAND="sudo $NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
184 fi
185fi
186
187
188# Distributed Virtual Router (DVR) configuration
189# Can be:
190# - ``legacy`` - No DVR functionality
191# - ``dvr_snat`` - Controller or single node DVR
192# - ``dvr`` - Compute node in multi-node DVR
193# - ``dvr_no_external`` - Compute node in multi-node DVR, no external network
194#
195Q_DVR_MODE=${Q_DVR_MODE:-legacy}
196if [[ "$Q_DVR_MODE" != "legacy" ]]; then
197 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,l2population
198fi
199
200# Provider Network Configurations
201# --------------------------------
202
203# The following variables control the Neutron ML2 plugins' allocation
204# of tenant networks and availability of provider networks. If these
205# are not configured in ``localrc``, tenant networks will be local to
206# the host (with no remote connectivity), and no physical resources
207# will be available for the allocation of provider networks.
208
209# To disable tunnels (GRE or VXLAN) for tenant networks,
210# set to False in ``local.conf``.
211# GRE tunnels are only supported by the openvswitch.
212ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
213
214# If using GRE, VXLAN or GENEVE tunnels for tenant networks,
215# specify the range of IDs from which tenant networks are
216# allocated. Can be overridden in ``localrc`` if necessary.
217TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
218
219# To use VLANs for tenant networks, set to True in localrc. VLANs
220# are supported by the ML2 plugins, requiring additional configuration
221# described below.
222ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
223
224# If using VLANs for tenant networks, set in ``localrc`` to specify
225# the range of VLAN VIDs from which tenant networks are
226# allocated. An external network switch must be configured to
227# trunk these VLANs between hosts for multi-host connectivity.
228#
229# Example: ``TENANT_VLAN_RANGE=1000:1999``
230TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
231
232# If using VLANs for tenant networks, or if using flat or VLAN
233# provider networks, set in ``localrc`` to the name of the physical
234# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
Brian Haley12abc722025-02-10 13:48:37 -0500235# openvswitch agent, as described below.
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100236#
237# Example: ``PHYSICAL_NETWORK=default``
238PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-public}
239
240# With the openvswitch agent, if using VLANs for tenant networks,
241# or if using flat or VLAN provider networks, set in ``localrc`` to
242# the name of the OVS bridge to use for the physical network. The
243# bridge will be created if it does not already exist, but a
244# physical interface must be manually added to the bridge as a
245# port for external connectivity.
246#
247# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
248OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-br-ex}
249
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100250# With the openvswitch plugin, set to True in ``localrc`` to enable
251# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
252#
253# Example: ``OVS_ENABLE_TUNNELING=True``
254OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
255
256# Use DHCP agent for providing metadata service in the case of
257# without L3 agent (No Route Agent), set to True in localrc.
258ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
259
260# Add a static route as dhcp option, so the request to 169.254.169.254
261# will be able to reach through a route(DHCP agent)
262# This option require ENABLE_ISOLATED_METADATA = True
263ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
264# Neutron plugin specific functions
265# ---------------------------------
266
267# Please refer to ``lib/neutron_plugins/README.md`` for details.
268if [ -f $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN ]; then
269 source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
270fi
271
272# Agent metering service plugin functions
273# -------------------------------------------
274
275# Hardcoding for 1 service plugin for now
276source $TOP_DIR/lib/neutron_plugins/services/metering
277
278# L3 Service functions
279source $TOP_DIR/lib/neutron_plugins/services/l3
280
281# Additional Neutron service plugins
282source $TOP_DIR/lib/neutron_plugins/services/placement
283source $TOP_DIR/lib/neutron_plugins/services/trunk
284source $TOP_DIR/lib/neutron_plugins/services/qos
elajkata84b2092021-11-17 11:52:56 +0100285source $TOP_DIR/lib/neutron_plugins/services/segments
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100286
287# Use security group or not
288if has_neutron_plugin_security_group; then
289 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
290else
291 Q_USE_SECGROUP=False
292fi
293
Harald Jensås16ac21f2023-08-31 15:06:52 +0200294# OVN_BRIDGE_MAPPINGS - ovn-bridge-mappings
295# NOTE(hjensas): Initialize after sourcing neutron_plugins/services/l3
296# which initialize PUBLIC_BRIDGE.
297OVN_BRIDGE_MAPPINGS=${OVN_BRIDGE_MAPPINGS:-$PHYSICAL_NETWORK:$PUBLIC_BRIDGE}
298
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100299# Save trace setting
300_XTRACE_NEUTRON=$(set +o | grep xtrace)
301set +o xtrace
302
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900303
Sean M. Collins2a242512016-05-03 09:03:09 -0400304# Functions
305# ---------
306
307# Test if any Neutron services are enabled
308# is_neutron_enabled
309function is_neutron_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -0700310 [[ ,${DISABLED_SERVICES} =~ ,"neutron" ]] && return 1
Sean M. Collins2a242512016-05-03 09:03:09 -0400311 [[ ,${ENABLED_SERVICES} =~ ,"neutron-" || ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
312 return 1
313}
314
315# Test if any Neutron services are enabled
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100316# TODO(slaweq): this is not really needed now and we should remove it as soon
317# as it will not be called from any other Devstack plugins, like e.g. Neutron
318# plugin
Sean M. Collins2a242512016-05-03 09:03:09 -0400319function is_neutron_legacy_enabled {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100320 return 0
Sean M. Collins2a242512016-05-03 09:03:09 -0400321}
322
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100323function _determine_config_server {
324 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" != '' ]]; then
325 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" = "$_Q_PLUGIN_EXTRA_CONF_PATH" ]]; then
326 deprecated "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
327 else
328 die $LINENO "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
329 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400330 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100331 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 ]]; then
332 deprecated "Q_PLUGIN_EXTRA_CONF_FILES is deprecated. Use neutron_server_config_add instead."
Sean M. Collins2a242512016-05-03 09:03:09 -0400333 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100334 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
335 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($_Q_PLUGIN_EXTRA_CONF_PATH/$cfg_file)
Sean M. Collins2a242512016-05-03 09:03:09 -0400336 done
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100337
338 local cfg_file
339 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
340 for cfg_file in ${_Q_PLUGIN_EXTRA_CONF_FILES_ABS[@]}; do
341 opts+=" --config-file $cfg_file"
342 done
343 echo "$opts"
Sean M. Collins2a242512016-05-03 09:03:09 -0400344}
345
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100346function _determine_config_l3 {
347 local opts="--config-file $NEUTRON_CONF --config-file $Q_L3_CONF_FILE"
348 echo "$opts"
Ihar Hrachyshkae65ab4a2017-02-24 17:47:55 +0000349}
350
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000351function _enable_ovn_maintenance {
352 if [[ $Q_AGENT == "ovn" ]]; then
353 enable_service neutron-ovn-maintenance-worker
354 fi
355}
356
357function _run_ovn_maintenance {
358 if [[ $Q_AGENT == "ovn" ]]; then
359 run_process neutron-ovn-maintenance-worker "$NEUTRON_BIN_DIR/neutron-ovn-maintenance-worker $cfg_file_options"
360 fi
361}
362
363function _stop_ovn_maintenance {
364 if [[ $Q_AGENT == "ovn" ]]; then
365 stop_process neutron-ovn-maintenance-worker
366 fi
367}
368
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100369# For services and agents that require it, dynamically construct a list of
370# --config-file arguments that are passed to the binary.
371function determine_config_files {
372 local opts=""
373 case "$1" in
374 "neutron-server") opts="$(_determine_config_server)" ;;
375 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
376 esac
377 if [ -z "$opts" ] ; then
378 die $LINENO "Could not determine config files for $1."
YAMAMOTO Takashi1df17c92017-05-01 17:00:42 +0900379 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100380 echo "$opts"
381}
Sean M. Collins2a242512016-05-03 09:03:09 -0400382
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100383# configure_neutron()
384# Set common config for all neutron server and agents.
385function configure_neutron {
386 _configure_neutron_common
Sean M. Collins5394cc12016-05-11 15:03:38 -0400387 iniset_rpc_backend neutron $NEUTRON_CONF
388
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100389 if is_service_enabled q-metering neutron-metering; then
390 _configure_neutron_metering
391 fi
392 if is_service_enabled q-agt neutron-agent; then
393 _configure_neutron_plugin_agent
394 fi
395 if is_service_enabled q-dhcp neutron-dhcp; then
396 _configure_neutron_dhcp_agent
397 fi
398 if is_service_enabled q-l3 neutron-l3; then
399 _configure_neutron_l3_agent
400 fi
401 if is_service_enabled q-meta neutron-metadata-agent; then
402 _configure_neutron_metadata_agent
Sean M. Collins2a242512016-05-03 09:03:09 -0400403 fi
404
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100405 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
406 _configure_dvr
407 fi
408 if is_service_enabled ceilometer; then
409 _configure_neutron_ceilometer_notifications
410 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400411
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100412 if [[ $Q_AGENT == "ovn" ]]; then
413 configure_ovn
414 configure_ovn_plugin
415 fi
Brian Haley9aaa5292017-09-20 14:23:05 -0400416
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100417 # Configure Neutron's advanced services
418 if is_service_enabled q-placement neutron-placement; then
419 configure_placement_extension
420 fi
421 if is_service_enabled q-trunk neutron-trunk; then
422 configure_trunk_extension
423 fi
424 if is_service_enabled q-qos neutron-qos; then
425 configure_qos
426 if is_service_enabled q-l3 neutron-l3; then
427 configure_l3_agent_extension_fip_qos
428 configure_l3_agent_extension_gateway_ip_qos
Denis Buliga0bf75a42017-02-06 16:56:46 +0200429 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400430 fi
elajkata84b2092021-11-17 11:52:56 +0100431 if is_service_enabled neutron-segments; then
432 configure_placement_neutron
433 configure_segments_extension
434 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400435
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100436 # Finally configure Neutron server and core plugin
437 if is_service_enabled q-agt neutron-agent q-svc neutron-api; then
438 _configure_neutron_service
Sean M. Collins2a242512016-05-03 09:03:09 -0400439 fi
440
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100441 iniset $NEUTRON_CONF DEFAULT api_workers "$API_WORKERS"
442 # devstack is not a tool for running uber scale OpenStack
443 # clouds, therefore running without a dedicated RPC worker
444 # for state reports is more than adequate.
445 iniset $NEUTRON_CONF DEFAULT rpc_state_report_workers 0
Ihar Hrachyshkae3915932017-02-24 06:24:47 +0000446
Stephen Finucaned040e152024-10-11 16:18:19 +0100447 write_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_UWSGI" "/networking" "" "neutron-api"
Sean M. Collins2a242512016-05-03 09:03:09 -0400448}
449
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100450function configure_neutron_nova {
451 create_nova_conf_neutron $NOVA_CONF
452 if [[ "${CELLSV2_SETUP}" == "superconductor" ]]; then
453 for i in $(seq 1 $NOVA_NUM_CELLS); do
454 local conf
455 conf=$(conductor_conf $i)
456 create_nova_conf_neutron $conf
457 done
Sean M. Collins2a242512016-05-03 09:03:09 -0400458 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400459}
460
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100461function create_nova_conf_neutron {
Lucas Alvares Gomese6385932018-06-28 11:00:28 +0100462 local conf=${1:-$NOVA_CONF}
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400463 iniset $conf neutron auth_type "password"
464 iniset $conf neutron auth_url "$KEYSTONE_SERVICE_URI"
Dr. Jens Harbott696dbdf2024-07-09 16:36:37 +0200465 iniset $conf neutron username nova
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400466 iniset $conf neutron password "$SERVICE_PASSWORD"
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100467 iniset $conf neutron user_domain_name "$SERVICE_DOMAIN_NAME"
468 iniset $conf neutron project_name "$SERVICE_PROJECT_NAME"
469 iniset $conf neutron project_domain_name "$SERVICE_DOMAIN_NAME"
470 iniset $conf neutron auth_strategy "$Q_AUTH_STRATEGY"
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400471 iniset $conf neutron region_name "$REGION_NAME"
Sean M. Collins2a242512016-05-03 09:03:09 -0400472
Gary Kotton88f85582016-08-14 06:55:42 -0700473 # optionally set options in nova_conf
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400474 neutron_plugin_create_nova_conf $conf
Gary Kotton88f85582016-08-14 06:55:42 -0700475
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100476 if is_service_enabled q-meta neutron-metadata-agent; then
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400477 iniset $conf neutron service_metadata_proxy "True"
Sean M. Collins2a242512016-05-03 09:03:09 -0400478 fi
479
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100480 iniset $conf DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
481 iniset $conf DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Sean M. Collins2a242512016-05-03 09:03:09 -0400482}
483
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100484# create_neutron_accounts() - Set up common required neutron accounts
485
Sean M. Collins2a242512016-05-03 09:03:09 -0400486# Tenant User Roles
487# ------------------------------------------------------------------
488# service neutron admin # if enabled
489
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100490# Migrated from keystone_data.sh
491function create_neutron_accounts {
Kevin Benton66b361b2017-06-13 00:31:01 -0700492 local neutron_url
Stephen Finucaned040e152024-10-11 16:18:19 +0100493 neutron_url=$Q_PROTOCOL://$SERVICE_HOST/
Slawek Kaplonski1a21ccb2022-07-08 21:57:45 +0200494 if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then
495 neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME
496 fi
Kevin Benton66b361b2017-06-13 00:31:01 -0700497
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100498 if is_service_enabled q-svc neutron-api; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400499
500 create_service_user "neutron"
501
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100502 get_or_create_service "neutron" "network" "Neutron Service"
503 get_or_create_endpoint \
504 "network" \
Kevin Benton66b361b2017-06-13 00:31:01 -0700505 "$REGION_NAME" "$neutron_url"
Sean M. Collins2a242512016-05-03 09:03:09 -0400506 fi
507}
508
Sean M. Collins2a242512016-05-03 09:03:09 -0400509# init_neutron() - Initialize databases, etc.
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100510function init_neutron {
511 recreate_database $Q_DB_NAME
Clark Boylan633dbc32017-06-14 12:09:21 -0700512 time_start "dbsync"
Sean M. Collins2a242512016-05-03 09:03:09 -0400513 # Run Neutron db migrations
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100514 $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 -0700515 time_stop "dbsync"
Sean M. Collins2a242512016-05-03 09:03:09 -0400516}
517
518# install_neutron() - Collect source and prepare
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100519function install_neutron {
Sean M. Collins2a242512016-05-03 09:03:09 -0400520 # Install neutron-lib from git so we make sure we're testing
521 # the latest code.
522 if use_library_from_git "neutron-lib"; then
523 git_clone_by_name "neutron-lib"
524 setup_dev_lib "neutron-lib"
525 fi
526
elajkatbb0c2732023-11-16 11:30:04 +0100527 # Install SQLAlchemy and alembic from git when these are required
528 # see https://bugs.launchpad.net/neutron/+bug/2042941
529 if use_library_from_git "sqlalchemy"; then
530 git_clone $SQLALCHEMY_REPO $SQLALCHEMY_DIR $SQLALCHEMY_BRANCH
531 setup_develop $SQLALCHEMY_DIR
532 fi
533 if use_library_from_git "alembic"; then
534 git_clone $ALEMBIC_REPO $ALEMBIC_DIR $ALEMBIC_BRANCH
535 setup_develop $ALEMBIC_DIR
536 fi
537
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100538 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
539 setup_develop $NEUTRON_DIR
Sean M. Collins2a242512016-05-03 09:03:09 -0400540
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100541 if [[ $Q_AGENT == "ovn" ]]; then
542 install_ovn
Sean M. Collins2a242512016-05-03 09:03:09 -0400543 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400544}
545
546# install_neutronclient() - Collect source and prepare
547function install_neutronclient {
548 if use_library_from_git "python-neutronclient"; then
549 git_clone_by_name "python-neutronclient"
550 setup_dev_lib "python-neutronclient"
Sean M. Collins2a242512016-05-03 09:03:09 -0400551 fi
552}
553
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100554# install_neutron_agent_packages() - Collect source and prepare
555function install_neutron_agent_packages {
556 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
557 if is_service_enabled q-l3 neutron-l3; then
558 install_package radvd
Sean M. Collins2a242512016-05-03 09:03:09 -0400559 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100560 # install packages that are specific to plugin agent(s)
561 if is_service_enabled q-agt neutron-agent q-dhcp neutron-dhcp q-l3 neutron-l3; then
562 neutron_plugin_install_agent_packages
Sean M. Collins2a242512016-05-03 09:03:09 -0400563 fi
564}
565
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100566# Finish neutron configuration
567function configure_neutron_after_post_config {
568 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
569 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
Sean M. Collins2a242512016-05-03 09:03:09 -0400570 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100571 configure_rbac_policies
Sean M. Collins2a242512016-05-03 09:03:09 -0400572}
573
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +0200574# configure_rbac_policies() - Configure Neutron to enforce new RBAC
575# policies and scopes if NEUTRON_ENFORCE_SCOPE == True
576function configure_rbac_policies {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100577 if [[ "$NEUTRON_ENFORCE_SCOPE" == "True" || "$ENFORCE_SCOPE" == True ]]; then
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +0200578 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults True
579 iniset $NEUTRON_CONF oslo_policy enforce_scope True
580 else
581 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults False
582 iniset $NEUTRON_CONF oslo_policy enforce_scope False
583 fi
584}
585
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100586# Start running OVN processes
587function start_ovn_services {
588 if [[ $Q_AGENT == "ovn" ]]; then
Lucas Alvares Gomesa3891282023-07-18 16:31:28 +0100589 if [ "$VIRT_DRIVER" != 'ironic' ]; then
590 # NOTE(TheJulia): Ironic's devstack plugin needs to perform
591 # additional networking configuration to setup a working test
592 # environment with test virtual machines to emulate baremetal,
593 # which requires OVN to be up and running earlier to complete
594 # that base configuration.
595 init_ovn
596 start_ovn
597 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100598 if [[ "$OVN_L3_CREATE_PUBLIC_NETWORK" == "True" ]]; then
599 if [[ "$NEUTRON_CREATE_INITIAL_NETWORKS" != "True" ]]; then
600 echo "OVN_L3_CREATE_PUBLIC_NETWORK=True is being ignored "
601 echo "because NEUTRON_CREATE_INITIAL_NETWORKS is set to False"
602 else
603 create_public_bridge
604 fi
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400605 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400606 fi
607}
608
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100609# Start running processes
610function start_neutron_service_and_check {
611 local service_port=$Q_PORT
612 local service_protocol=$Q_PROTOCOL
613 local cfg_file_options
614 local neutron_url
Sean M. Collins2a242512016-05-03 09:03:09 -0400615
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100616 cfg_file_options="$(determine_config_files neutron-server)"
Sean M. Collins2a242512016-05-03 09:03:09 -0400617
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100618 if is_service_enabled tls-proxy; then
619 service_port=$Q_PORT_INT
620 service_protocol="http"
Sean M. Collins2a242512016-05-03 09:03:09 -0400621 fi
Rodolfo Alonso Hernandez79a812a2024-07-31 14:41:33 +0000622
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100623 # Start the Neutron service
Stephen Finucaned040e152024-10-11 16:18:19 +0100624 # The default value of "rpc_workers" is None (not defined). If
625 # "rpc_workers" is explicitly set to 0, the RPC workers process
626 # should not be executed.
627 local rpc_workers
628 rpc_workers=$(iniget_multiline $NEUTRON_CONF DEFAULT rpc_workers)
Rodolfo Alonso Hernandez79a812a2024-07-31 14:41:33 +0000629
Stephen Finucaned040e152024-10-11 16:18:19 +0100630 enable_service neutron-api
631 run_process neutron-api "$(which uwsgi) --procname-prefix neutron-api --ini $NEUTRON_UWSGI_CONF"
632 neutron_url=$Q_PROTOCOL://$Q_HOST/
633 if [ "$rpc_workers" != "0" ]; then
634 enable_service neutron-rpc-server
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100635 fi
Stephen Finucaned040e152024-10-11 16:18:19 +0100636 enable_service neutron-periodic-workers
637 _enable_ovn_maintenance
638 if [ "$rpc_workers" != "0" ]; then
639 run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $cfg_file_options"
640 fi
641 run_process neutron-periodic-workers "$NEUTRON_BIN_DIR/neutron-periodic-workers $cfg_file_options"
642 _run_ovn_maintenance
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100643 if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then
644 neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME
645 fi
646 echo "Waiting for Neutron to start..."
Sean M. Collins2a242512016-05-03 09:03:09 -0400647
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100648 local testcmd="wget ${ssl_ca} --no-proxy -q -O- $neutron_url"
649 test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900650}
651
Sean M. Collins2a242512016-05-03 09:03:09 -0400652function start_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100653 start_l2_agent "$@"
654 start_other_agents "$@"
655}
656
657# Control of the l2 agent is separated out to make it easier to test partial
658# upgrades (everything upgraded except the L2 agent)
659function start_l2_agent {
660 run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
661
662 if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then
663 sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
664 sudo ip link set $OVS_PHYSICAL_BRIDGE up
665 sudo ip link set br-int up
666 sudo ip link set $PUBLIC_INTERFACE up
667 if is_ironic_hardware; then
668 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
669 sudo ip addr del $IP dev $PUBLIC_INTERFACE
670 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
671 done
672 sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
673 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400674 fi
675}
676
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100677function start_other_agents {
678 run_process q-dhcp "$AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file $Q_DHCP_CONF_FILE"
679
680 run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
681
682 run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file $Q_META_CONF_FILE"
683 run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
684}
685
686# Start running processes, including screen
687function start_neutron_agents {
688 # NOTE(slaweq): it's now just a wrapper for start_neutron function
689 start_neutron "$@"
690}
691
692function stop_l2_agent {
693 stop_process q-agt
694}
695
696# stop_other() - Stop running processes
697function stop_other {
698 if is_service_enabled q-dhcp neutron-dhcp; then
699 stop_process q-dhcp
700 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
701 [ ! -z "$pid" ] && sudo kill -9 $pid
702 fi
703
Stephen Finucaned040e152024-10-11 16:18:19 +0100704 stop_process neutron-rpc-server
705 stop_process neutron-periodic-workers
706 stop_process neutron-api
707 _stop_ovn_maintenance
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100708
709 if is_service_enabled q-l3 neutron-l3; then
710 sudo pkill -f "radvd -C $DATA_DIR/neutron/ra"
711 stop_process q-l3
712 fi
713
714 if is_service_enabled q-meta neutron-metadata-agent; then
715 stop_process q-meta
716 fi
717
718 if is_service_enabled q-metering neutron-metering; then
719 neutron_metering_stop
720 fi
721
722 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Bence Romsics71c3c402022-12-21 13:50:54 +0100723 # pkill takes care not to kill itself, but it may kill its parent
724 # sudo unless we use the "ps | grep [f]oo" trick
725 sudo pkill -9 -f "$NEUTRON_ROOTWRAP-[d]aemon" || :
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100726 fi
727}
728
729# stop_neutron() - Stop running processes (non-screen)
Sean M. Collins2a242512016-05-03 09:03:09 -0400730function stop_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100731 stop_other
732 stop_l2_agent
733
734 if [[ $Q_AGENT == "ovn" && $SKIP_STOP_OVN != "True" ]]; then
735 stop_ovn
Sean M. Collins2a242512016-05-03 09:03:09 -0400736 fi
737}
738
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100739# _move_neutron_addresses_route() - Move the primary IP to the OVS bridge
740# on startup, or back to the public interface on cleanup. If no IP is
741# configured on the interface, just add it as a port to the OVS bridge.
742function _move_neutron_addresses_route {
743 local from_intf=$1
744 local to_intf=$2
745 local add_ovs_port=$3
746 local del_ovs_port=$4
747 local af=$5
748
749 if [[ -n "$from_intf" && -n "$to_intf" ]]; then
750 # Remove the primary IP address from $from_intf and add it to $to_intf,
751 # along with the default route, if it exists. Also, when called
752 # on configure we will also add $from_intf as a port on $to_intf,
753 # assuming it is an OVS bridge.
754
755 local IP_REPLACE=""
756 local IP_DEL=""
757 local IP_UP=""
758 local DEFAULT_ROUTE_GW
759 DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf\s/ { print \$3; exit }")
760 local ADD_OVS_PORT=""
761 local DEL_OVS_PORT=""
762 local ARP_CMD=""
763
764 IP_BRD=$(ip -f $af a s dev $from_intf scope global primary | grep inet | awk '{ print $2, $3, $4; exit }')
765
766 if [ "$DEFAULT_ROUTE_GW" != "" ]; then
767 ADD_DEFAULT_ROUTE="sudo ip -f $af r replace default via $DEFAULT_ROUTE_GW dev $to_intf"
768 fi
769
770 if [[ "$add_ovs_port" == "True" ]]; then
771 ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf"
772 fi
773
774 if [[ "$del_ovs_port" == "True" ]]; then
775 DEL_OVS_PORT="sudo ovs-vsctl --if-exists del-port $from_intf $to_intf"
776 fi
777
778 if [[ "$IP_BRD" != "" ]]; then
779 IP_DEL="sudo ip addr del $IP_BRD dev $from_intf"
780 IP_REPLACE="sudo ip addr replace $IP_BRD dev $to_intf"
781 IP_UP="sudo ip link set $to_intf up"
782 if [[ "$af" == "inet" ]]; then
783 IP=$(echo $IP_BRD | awk '{ print $1; exit }' | grep -o -E '(.*)/' | cut -d "/" -f1)
784 ARP_CMD="sudo arping -A -c 3 -w 5 -I $to_intf $IP "
785 fi
786 fi
787
788 # The add/del OVS port calls have to happen either before or
789 # after the address is moved in order to not leave it orphaned.
790 $DEL_OVS_PORT; $IP_DEL; $IP_REPLACE; $IP_UP; $ADD_OVS_PORT; $ADD_DEFAULT_ROUTE; $ARP_CMD
791 fi
792}
793
794# _configure_public_network_connectivity() - Configures connectivity to the
795# external network using $PUBLIC_INTERFACE or NAT on the single interface
796# machines
797function _configure_public_network_connectivity {
798 # If we've given a PUBLIC_INTERFACE to take over, then we assume
799 # that we can own the whole thing, and privot it into the OVS
800 # bridge. If we are not, we're probably on a single interface
801 # machine, and we just setup NAT so that fixed guests can get out.
802 if [[ -n "$PUBLIC_INTERFACE" ]]; then
803 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" True False "inet"
804
805 if [[ $(ip -f inet6 a s dev "$PUBLIC_INTERFACE" | grep -c 'global') != 0 ]]; then
806 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" False False "inet6"
807 fi
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -0500808 else
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100809 for d in $default_v4_route_devs; do
810 sudo iptables -t nat -A POSTROUTING -o $d -s $FLOATING_RANGE -j MASQUERADE
811 done
812 fi
813}
814
815# cleanup_neutron() - Remove residual data files, anything left over from previous
816# runs that a clean run would need to clean up
817function cleanup_neutron {
Stephen Finucaned040e152024-10-11 16:18:19 +0100818 stop_process neutron-api
819 stop_process neutron-rpc-server
820 stop_process neutron-periodic-workers
821 _stop_ovn_maintenance
822 remove_uwsgi_config "$NEUTRON_UWSGI_CONF" "neutron-api"
823 sudo rm -f $(apache_site_config_for neutron-api)
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100824
825 if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then
826 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False True "inet"
827
828 if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then
829 # ip(8) wants the prefix length when deleting
830 local v6_gateway
831 v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }')
832 sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE
833 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False False "inet6"
834 fi
835
836 if is_provider_network && is_ironic_hardware; then
837 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
838 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
839 sudo ip addr add $IP dev $PUBLIC_INTERFACE
840 done
841 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
842 fi
843 fi
844
845 if is_neutron_ovs_base_plugin; then
846 neutron_ovs_base_cleanup
847 fi
848
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100849 # delete all namespaces created by neutron
850 for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|fip|snat)-[0-9a-f-]*'); do
851 sudo ip netns delete ${ns}
852 done
853
854 if [[ $Q_AGENT == "ovn" ]]; then
855 cleanup_ovn
856 fi
857}
858
859
860function _create_neutron_conf_dir {
861 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
862 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
863}
864
865# _configure_neutron_common()
866# Set common config for all neutron server and agents.
867# This MUST be called before other ``_configure_neutron_*`` functions.
868function _configure_neutron_common {
869 _create_neutron_conf_dir
870
871 # Uses oslo config generator to generate core sample configuration files
872 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
873
874 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
875
876 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
877
878 # allow neutron user to administer neutron to match neutron account
879 # NOTE(amotoki): This is required for nova works correctly with neutron.
880 if [ -f $NEUTRON_DIR/etc/policy.json ]; then
881 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
882 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
883 else
884 echo '{"context_is_admin": "role:admin or user_name:neutron"}' > $Q_POLICY_FILE
885 fi
886
887 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
888 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
889 neutron_plugin_configure_common
890
891 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
892 die $LINENO "Neutron plugin not set.. exiting"
893 fi
894
895 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
896 mkdir -p /$Q_PLUGIN_CONF_PATH
897 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
898 # NOTE(slaweq): NEUTRON_CORE_PLUGIN_CONF is used e.g. in neutron repository,
899 # it was previously defined in the lib/neutron module which is now deleted.
900 NEUTRON_CORE_PLUGIN_CONF=$Q_PLUGIN_CONF_FILE
901 # NOTE(hichihara): Some neutron vendor plugins were already decomposed and
902 # there is no config file in Neutron tree. They should prepare the file in each plugin.
903 if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then
904 cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE
905 elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then
906 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
907 fi
908
909 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
910 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
911 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
912 iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS
913 iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock
914
915 # NOTE(freerunner): Need to adjust Region Name for nova in multiregion installation
916 iniset $NEUTRON_CONF nova region_name $REGION_NAME
917
918 if [ "$VIRT_DRIVER" = 'fake' ]; then
919 # Disable arbitrary limits
920 iniset $NEUTRON_CONF quotas quota_network -1
921 iniset $NEUTRON_CONF quotas quota_subnet -1
922 iniset $NEUTRON_CONF quotas quota_port -1
923 iniset $NEUTRON_CONF quotas quota_security_group -1
924 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
925 fi
926
927 # Format logging
928 setup_logging $NEUTRON_CONF
929
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100930 _neutron_setup_rootwrap
931}
932
933function _configure_neutron_dhcp_agent {
934
935 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE
936
937 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
938 # make it so we have working DNS from guests
939 iniset $Q_DHCP_CONF_FILE DEFAULT dnsmasq_local_resolv True
940 configure_root_helper_options $Q_DHCP_CONF_FILE
941
942 if ! is_service_enabled q-l3 neutron-l3; then
943 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
944 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
945 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
946 else
947 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
948 die "$LINENO" "Enable isolated metadata is a must for metadata network"
949 fi
950 fi
951 fi
952
953 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
954
955 neutron_plugin_configure_dhcp_agent $Q_DHCP_CONF_FILE
956}
957
958
959function _configure_neutron_metadata_agent {
960 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE
961
962 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
963 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_host $Q_META_DATA_IP
964 iniset $Q_META_CONF_FILE DEFAULT metadata_workers $API_WORKERS
965 configure_root_helper_options $Q_META_CONF_FILE
966}
967
968function _configure_neutron_ceilometer_notifications {
969 iniset $NEUTRON_CONF oslo_messaging_notifications driver messagingv2
970}
971
972function _configure_neutron_metering {
973 neutron_agent_metering_configure_common
974 neutron_agent_metering_configure_agent
975}
976
977function _configure_dvr {
978 iniset $NEUTRON_CONF DEFAULT router_distributed True
979 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
980}
981
982
983# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
984# It is called when q-agt is enabled.
985function _configure_neutron_plugin_agent {
986 # Specify the default root helper prior to agent configuration to
987 # ensure that an agent's configuration can override the default
988 configure_root_helper_options /$Q_PLUGIN_CONF_FILE
989 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
990
991 # Configure agent for plugin
992 neutron_plugin_configure_plugin_agent
993}
994
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100995# _configure_neutron_service() - Set config files for neutron service
996# It is called when q-svc is enabled.
997function _configure_neutron_service {
998 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
999 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
1000
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001001 # Update either configuration file with plugin
1002 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
1003
1004 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1005 iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE
1006
1007 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
1008 configure_keystone_authtoken_middleware $NEUTRON_CONF $Q_ADMIN_USERNAME
1009
1010 # Configuration for neutron notifications to nova.
1011 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
1012 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
1013
1014 configure_keystone_authtoken_middleware $NEUTRON_CONF nova nova
1015
1016 # Configuration for placement client
1017 configure_keystone_authtoken_middleware $NEUTRON_CONF placement placement
1018
1019 # Configure plugin
1020 neutron_plugin_configure_service
1021}
1022
1023# Utility Functions
1024#------------------
1025
1026# neutron_service_plugin_class_add() - add service plugin class
1027function neutron_service_plugin_class_add {
1028 local service_plugin_class=$1
1029 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
1030 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
1031 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
1032 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
1033 fi
1034}
1035
1036# neutron_ml2_extension_driver_add() - add ML2 extension driver
1037function neutron_ml2_extension_driver_add {
1038 local extension=$1
1039 if [[ $Q_ML2_PLUGIN_EXT_DRIVERS == '' ]]; then
1040 Q_ML2_PLUGIN_EXT_DRIVERS=$extension
1041 elif [[ ! ,${Q_ML2_PLUGIN_EXT_DRIVERS}, =~ ,${extension}, ]]; then
1042 Q_ML2_PLUGIN_EXT_DRIVERS="$Q_ML2_PLUGIN_EXT_DRIVERS,$extension"
1043 fi
1044}
1045
1046# neutron_server_config_add() - add server config file
1047function neutron_server_config_add {
1048 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($1)
1049}
1050
1051# neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root).
1052function neutron_deploy_rootwrap_filters {
1053 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1054 return
1055 fi
1056 local srcdir=$1
1057 sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D
1058 sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
1059}
1060
1061# _neutron_setup_rootwrap() - configure Neutron's rootwrap
1062function _neutron_setup_rootwrap {
1063 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1064 return
1065 fi
1066 # Wipe any existing ``rootwrap.d`` files first
1067 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
1068 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
1069 sudo rm -rf $Q_CONF_ROOTWRAP_D
1070 fi
1071
1072 neutron_deploy_rootwrap_filters $NEUTRON_DIR
1073
1074 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
1075 # location moved in newer versions, prefer new location
1076 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
1077 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
1078 else
1079 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
1080 fi
1081 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
yatinkarelffc1b762023-08-28 10:52:26 +05301082 # Rely on $PATH set by devstack to determine what is safe to execute
1083 # by rootwrap rather than use explicit whitelist of paths in
1084 # rootwrap.conf
1085 sudo sed -e 's/^exec_dirs=.*/#&/' -i $Q_RR_CONF_FILE
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001086
1087 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
1088 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
1089 ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
1090
1091 # Set up the rootwrap sudoers for neutron
1092 TEMPFILE=`mktemp`
1093 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
1094 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE
1095 chmod 0440 $TEMPFILE
1096 sudo chown root:root $TEMPFILE
1097 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
1098
1099 # Update the root_helper
1100 configure_root_helper_options $NEUTRON_CONF
1101}
1102
1103function configure_root_helper_options {
1104 local conffile=$1
1105 iniset $conffile agent root_helper "$Q_RR_COMMAND"
1106 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
1107 iniset $conffile agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
1108 fi
1109}
1110
1111function _neutron_setup_interface_driver {
1112
1113 # ovs_use_veth needs to be set before the plugin configuration
1114 # occurs to allow plugins to override the setting.
1115 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1116
1117 neutron_plugin_setup_interface_driver $1
1118}
1119# Functions for Neutron Exercises
1120#--------------------------------
1121
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001122# ssh check
1123function _ssh_check_neutron {
1124 local from_net=$1
1125 local key_file=$2
1126 local ip=$3
1127 local user=$4
1128 local timeout_sec=$5
1129 local probe_cmd = ""
1130 probe_cmd=`_get_probe_cmd_prefix $from_net`
1131 local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success"
1132 test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec
1133}
1134
1135function plugin_agent_add_l2_agent_extension {
1136 local l2_agent_extension=$1
1137 if [[ -z "$L2_AGENT_EXTENSIONS" ]]; then
1138 L2_AGENT_EXTENSIONS=$l2_agent_extension
1139 elif [[ ! ,${L2_AGENT_EXTENSIONS}, =~ ,${l2_agent_extension}, ]]; then
1140 L2_AGENT_EXTENSIONS+=",$l2_agent_extension"
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -05001141 fi
1142}
1143
Sean M. Collins2a242512016-05-03 09:03:09 -04001144# Restore xtrace
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001145$_XTRACE_NEUTRON
1146
1147# Tell emacs to use shell-script-mode
1148## Local variables:
1149## mode: shell-script
1150## End: