blob: da21d460792d6f3d7e8a3b59b75ef5fb24940c7d [file] [log] [blame]
Sean M. Collins2a242512016-05-03 09:03:09 -04001#!/bin/bash
2#
3# lib/neutron
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01004# functions - functions specific to neutron
Sean M. Collins2a242512016-05-03 09:03:09 -04005
6# Dependencies:
Sean M. Collins2a242512016-05-03 09:03:09 -04007# ``functions`` file
8# ``DEST`` must be defined
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01009# ``STACK_USER`` must be defined
Sean M. Collins2a242512016-05-03 09:03:09 -040010
11# ``stack.sh`` calls the entry points in this order:
12#
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010013# - install_neutron_agent_packages
14# - install_neutronclient
15# - install_neutron
16# - install_neutron_third_party
17# - configure_neutron
18# - init_neutron
19# - configure_neutron_third_party
20# - init_neutron_third_party
21# - start_neutron_third_party
22# - create_nova_conf_neutron
23# - configure_neutron_after_post_config
24# - start_neutron_service_and_check
25# - check_neutron_third_party_integration
26# - start_neutron_agents
27# - create_neutron_initial_network
28#
29# ``unstack.sh`` calls the entry points in this order:
30#
31# - stop_neutron
32# - stop_neutron_third_party
33# - cleanup_neutron
Sean M. Collins2a242512016-05-03 09:03:09 -040034
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010035# Functions in lib/neutron are classified into the following categories:
36#
37# - entry points (called from stack.sh or unstack.sh)
38# - internal functions
39# - neutron exercises
40# - 3rd party programs
Sean M. Collins2a242512016-05-03 09:03:09 -040041
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010042
43# Neutron Networking
44# ------------------
45
46# Make sure that neutron is enabled in ``ENABLED_SERVICES``. If you want
47# to run Neutron on this host, make sure that q-svc is also in
48# ``ENABLED_SERVICES``.
49#
50# See "Neutron Network Configuration" below for additional variables
51# that must be set in localrc for connectivity across hosts with
52# Neutron.
53
54# Settings
Sean M. Collins2a242512016-05-03 09:03:09 -040055# --------
56
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010057
58# Neutron Network Configuration
59# -----------------------------
60
61if is_service_enabled tls-proxy; then
62 Q_PROTOCOL="https"
63fi
64
65
Sean M. Collins2a242512016-05-03 09:03:09 -040066# Set up default directories
67GITDIR["python-neutronclient"]=$DEST/python-neutronclient
68
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010069
70NEUTRON_DIR=$DEST/neutron
71NEUTRON_FWAAS_DIR=$DEST/neutron-fwaas
72
73# Support entry points installation of console scripts
74if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
75 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
76else
77 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
78fi
79
80NEUTRON_CONF_DIR=/etc/neutron
81NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
82export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
83
Kevin Benton66b361b2017-06-13 00:31:01 -070084# NEUTRON_DEPLOY_MOD_WSGI defines how neutron is deployed, allowed values:
85# - False (default) : Run neutron under Eventlet
86# - True : Run neutron under uwsgi
87# TODO(annp): Switching to uwsgi in next cycle if things turn out to be stable
88# enough
Jens Harbott3492fee2018-11-30 13:57:17 +000089NEUTRON_DEPLOY_MOD_WSGI=$(trueorfalse False NEUTRON_DEPLOY_MOD_WSGI)
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010090
91NEUTRON_UWSGI_CONF=$NEUTRON_CONF_DIR/neutron-api-uwsgi.ini
Sean M. Collins2a242512016-05-03 09:03:09 -040092
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +020093# If NEUTRON_ENFORCE_SCOPE == True, it will set "enforce_scope"
94# and "enforce_new_defaults" to True in the Neutron's config to enforce usage
Ghanshyam Mannbacb8402023-10-25 12:52:28 -070095# of the new RBAC policies and scopes. Set it to False if you do not
96# want to run Neutron with new RBAC.
97NEUTRON_ENFORCE_SCOPE=$(trueorfalse True NEUTRON_ENFORCE_SCOPE)
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +020098
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010099# Agent binaries. Note, binary paths for other agents are set in per-service
100# scripts in lib/neutron_plugins/services/
101AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
102AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
103AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
Brian Haley9aaa5292017-09-20 14:23:05 -0400104
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100105# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
106# loaded from per-plugin scripts in lib/neutron_plugins/
107Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
108# NOTE(slaweq): NEUTRON_DHCP_CONF is used e.g. in neutron repository,
109# it was previously defined in the lib/neutron module which is now deleted.
110NEUTRON_DHCP_CONF=$Q_DHCP_CONF_FILE
111Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
112# NOTE(slaweq): NEUTRON_L3_CONF is used e.g. in neutron repository,
113# it was previously defined in the lib/neutron module which is now deleted.
114NEUTRON_L3_CONF=$Q_L3_CONF_FILE
115Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
Sean M. Collins2a242512016-05-03 09:03:09 -0400116
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100117# Default name for Neutron database
118Q_DB_NAME=${Q_DB_NAME:-neutron}
119# Default Neutron Plugin
120Q_PLUGIN=${Q_PLUGIN:-ml2}
121# Default Neutron Port
122Q_PORT=${Q_PORT:-9696}
123# Default Neutron Internal Port when using TLS proxy
124Q_PORT_INT=${Q_PORT_INT:-19696}
125# Default Neutron Host
126Q_HOST=${Q_HOST:-$SERVICE_HOST}
127# Default protocol
128Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
129# Default listen address
130Q_LISTEN_ADDRESS=${Q_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)}
131# Default admin username
132Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
133# Default auth strategy
134Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
135# RHEL's support for namespaces requires using veths with ovs
136Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
137Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
138Q_USE_ROOTWRAP_DAEMON=$(trueorfalse True Q_USE_ROOTWRAP_DAEMON)
139# Meta data IP
140Q_META_DATA_IP=${Q_META_DATA_IP:-$(ipv6_unquote $SERVICE_HOST)}
141# Allow Overlapping IP among subnets
142Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
143Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
144Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
145VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
146VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Sean M. Collins2a242512016-05-03 09:03:09 -0400147
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100148# Allow to skip stopping of OVN services
149SKIP_STOP_OVN=${SKIP_STOP_OVN:-False}
Sean M. Collins2a242512016-05-03 09:03:09 -0400150
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100151# The directory which contains files for Q_PLUGIN_EXTRA_CONF_FILES.
152# /etc/neutron is assumed by many of devstack plugins. Do not change.
153_Q_PLUGIN_EXTRA_CONF_PATH=/etc/neutron
Julia Kreger6e5b1382019-01-09 17:00:45 -0800154
Slawek Kaplonski1a21ccb2022-07-08 21:57:45 +0200155# The name of the service in the endpoint URL
156NEUTRON_ENDPOINT_SERVICE_NAME=${NEUTRON_ENDPOINT_SERVICE_NAME-"networking"}
157if [[ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" && -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then
158 NEUTRON_ENDPOINT_SERVICE_NAME="networking"
159fi
160
elajkatbb0c2732023-11-16 11:30:04 +0100161# Source install libraries
162ALEMBIC_REPO=${ALEMBIC_REPO:-https://github.com/sqlalchemy/alembic.git}
163ALEMBIC_DIR=${ALEMBIC_DIR:-$DEST/alembic}
164ALEMBIC_BRANCH=${ALEMBIC_BRANCH:-main}
165SQLALCHEMY_REPO=${SQLALCHEMY_REPO:-https://github.com/sqlalchemy/sqlalchemy.git}
166SQLALCHEMY_DIR=${SQLALCHEMY_DIR:-$DEST/sqlalchemy}
167SQLALCHEMY_BRANCH=${SQLALCHEMY_BRANCH:-main}
168
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100169# List of config file names in addition to the main plugin config file
170# To add additional plugin config files, use ``neutron_server_config_add``
171# utility function. For example:
172#
173# ``neutron_server_config_add file1``
174#
175# These config files are relative to ``/etc/neutron``. The above
176# example would specify ``--config-file /etc/neutron/file1`` for
177# neutron server.
178declare -a -g Q_PLUGIN_EXTRA_CONF_FILES
Julia Kreger6e5b1382019-01-09 17:00:45 -0800179
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100180# same as Q_PLUGIN_EXTRA_CONF_FILES, but with absolute path.
181declare -a -g _Q_PLUGIN_EXTRA_CONF_FILES_ABS
182
183
184Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
185if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
186 Q_RR_COMMAND="sudo"
187else
188 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
189 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
190 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
191 Q_RR_DAEMON_COMMAND="sudo $NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
192 fi
193fi
194
195
196# Distributed Virtual Router (DVR) configuration
197# Can be:
198# - ``legacy`` - No DVR functionality
199# - ``dvr_snat`` - Controller or single node DVR
200# - ``dvr`` - Compute node in multi-node DVR
201# - ``dvr_no_external`` - Compute node in multi-node DVR, no external network
202#
203Q_DVR_MODE=${Q_DVR_MODE:-legacy}
204if [[ "$Q_DVR_MODE" != "legacy" ]]; then
205 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,l2population
206fi
207
208# Provider Network Configurations
209# --------------------------------
210
211# The following variables control the Neutron ML2 plugins' allocation
212# of tenant networks and availability of provider networks. If these
213# are not configured in ``localrc``, tenant networks will be local to
214# the host (with no remote connectivity), and no physical resources
215# will be available for the allocation of provider networks.
216
217# To disable tunnels (GRE or VXLAN) for tenant networks,
218# set to False in ``local.conf``.
219# GRE tunnels are only supported by the openvswitch.
220ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
221
222# If using GRE, VXLAN or GENEVE tunnels for tenant networks,
223# specify the range of IDs from which tenant networks are
224# allocated. Can be overridden in ``localrc`` if necessary.
225TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
226
227# To use VLANs for tenant networks, set to True in localrc. VLANs
228# are supported by the ML2 plugins, requiring additional configuration
229# described below.
230ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
231
232# If using VLANs for tenant networks, set in ``localrc`` to specify
233# the range of VLAN VIDs from which tenant networks are
234# allocated. An external network switch must be configured to
235# trunk these VLANs between hosts for multi-host connectivity.
236#
237# Example: ``TENANT_VLAN_RANGE=1000:1999``
238TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
239
240# If using VLANs for tenant networks, or if using flat or VLAN
241# provider networks, set in ``localrc`` to the name of the physical
242# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
243# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
244# agent, as described below.
245#
246# Example: ``PHYSICAL_NETWORK=default``
247PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-public}
248
249# With the openvswitch agent, if using VLANs for tenant networks,
250# or if using flat or VLAN provider networks, set in ``localrc`` to
251# the name of the OVS bridge to use for the physical network. The
252# bridge will be created if it does not already exist, but a
253# physical interface must be manually added to the bridge as a
254# port for external connectivity.
255#
256# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
257OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-br-ex}
258
259# With the linuxbridge agent, if using VLANs for tenant networks,
260# or if using flat or VLAN provider networks, set in ``localrc`` to
261# the name of the network interface to use for the physical
262# network.
263#
264# Example: ``LB_PHYSICAL_INTERFACE=eth1``
265if [[ $Q_AGENT == "linuxbridge" && -z ${LB_PHYSICAL_INTERFACE} ]]; then
266 default_route_dev=$( (ip route; ip -6 route) | grep ^default | head -n 1 | awk '{print $5}')
267 die_if_not_set $LINENO default_route_dev "Failure retrieving default route device"
268 LB_PHYSICAL_INTERFACE=$default_route_dev
269fi
270
271# With the openvswitch plugin, set to True in ``localrc`` to enable
272# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
273#
274# Example: ``OVS_ENABLE_TUNNELING=True``
275OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
276
277# Use DHCP agent for providing metadata service in the case of
278# without L3 agent (No Route Agent), set to True in localrc.
279ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
280
281# Add a static route as dhcp option, so the request to 169.254.169.254
282# will be able to reach through a route(DHCP agent)
283# This option require ENABLE_ISOLATED_METADATA = True
284ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
285# Neutron plugin specific functions
286# ---------------------------------
287
288# Please refer to ``lib/neutron_plugins/README.md`` for details.
289if [ -f $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN ]; then
290 source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
291fi
292
293# Agent metering service plugin functions
294# -------------------------------------------
295
296# Hardcoding for 1 service plugin for now
297source $TOP_DIR/lib/neutron_plugins/services/metering
298
299# L3 Service functions
300source $TOP_DIR/lib/neutron_plugins/services/l3
301
302# Additional Neutron service plugins
303source $TOP_DIR/lib/neutron_plugins/services/placement
304source $TOP_DIR/lib/neutron_plugins/services/trunk
305source $TOP_DIR/lib/neutron_plugins/services/qos
elajkata84b2092021-11-17 11:52:56 +0100306source $TOP_DIR/lib/neutron_plugins/services/segments
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100307
308# Use security group or not
309if has_neutron_plugin_security_group; then
310 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
311else
312 Q_USE_SECGROUP=False
313fi
314
Harald Jensås16ac21f2023-08-31 15:06:52 +0200315# OVN_BRIDGE_MAPPINGS - ovn-bridge-mappings
316# NOTE(hjensas): Initialize after sourcing neutron_plugins/services/l3
317# which initialize PUBLIC_BRIDGE.
318OVN_BRIDGE_MAPPINGS=${OVN_BRIDGE_MAPPINGS:-$PHYSICAL_NETWORK:$PUBLIC_BRIDGE}
319
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100320# Save trace setting
321_XTRACE_NEUTRON=$(set +o | grep xtrace)
322set +o xtrace
323
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900324
Sean M. Collins2a242512016-05-03 09:03:09 -0400325# Functions
326# ---------
327
328# Test if any Neutron services are enabled
329# is_neutron_enabled
330function is_neutron_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -0700331 [[ ,${DISABLED_SERVICES} =~ ,"neutron" ]] && return 1
Sean M. Collins2a242512016-05-03 09:03:09 -0400332 [[ ,${ENABLED_SERVICES} =~ ,"neutron-" || ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
333 return 1
334}
335
336# Test if any Neutron services are enabled
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100337# TODO(slaweq): this is not really needed now and we should remove it as soon
338# as it will not be called from any other Devstack plugins, like e.g. Neutron
339# plugin
Sean M. Collins2a242512016-05-03 09:03:09 -0400340function is_neutron_legacy_enabled {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100341 return 0
Sean M. Collins2a242512016-05-03 09:03:09 -0400342}
343
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100344function _determine_config_server {
345 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" != '' ]]; then
346 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" = "$_Q_PLUGIN_EXTRA_CONF_PATH" ]]; then
347 deprecated "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
348 else
349 die $LINENO "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
350 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400351 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100352 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 ]]; then
353 deprecated "Q_PLUGIN_EXTRA_CONF_FILES is deprecated. Use neutron_server_config_add instead."
Sean M. Collins2a242512016-05-03 09:03:09 -0400354 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100355 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
356 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($_Q_PLUGIN_EXTRA_CONF_PATH/$cfg_file)
Sean M. Collins2a242512016-05-03 09:03:09 -0400357 done
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100358
359 local cfg_file
360 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
361 for cfg_file in ${_Q_PLUGIN_EXTRA_CONF_FILES_ABS[@]}; do
362 opts+=" --config-file $cfg_file"
363 done
364 echo "$opts"
Sean M. Collins2a242512016-05-03 09:03:09 -0400365}
366
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100367function _determine_config_l3 {
368 local opts="--config-file $NEUTRON_CONF --config-file $Q_L3_CONF_FILE"
369 echo "$opts"
Ihar Hrachyshkae65ab4a2017-02-24 17:47:55 +0000370}
371
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000372function _enable_ovn_maintenance {
373 if [[ $Q_AGENT == "ovn" ]]; then
374 enable_service neutron-ovn-maintenance-worker
375 fi
376}
377
378function _run_ovn_maintenance {
379 if [[ $Q_AGENT == "ovn" ]]; then
380 run_process neutron-ovn-maintenance-worker "$NEUTRON_BIN_DIR/neutron-ovn-maintenance-worker $cfg_file_options"
381 fi
382}
383
384function _stop_ovn_maintenance {
385 if [[ $Q_AGENT == "ovn" ]]; then
386 stop_process neutron-ovn-maintenance-worker
387 fi
388}
389
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100390# For services and agents that require it, dynamically construct a list of
391# --config-file arguments that are passed to the binary.
392function determine_config_files {
393 local opts=""
394 case "$1" in
395 "neutron-server") opts="$(_determine_config_server)" ;;
396 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
397 esac
398 if [ -z "$opts" ] ; then
399 die $LINENO "Could not determine config files for $1."
YAMAMOTO Takashi1df17c92017-05-01 17:00:42 +0900400 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100401 echo "$opts"
402}
Sean M. Collins2a242512016-05-03 09:03:09 -0400403
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100404# configure_neutron()
405# Set common config for all neutron server and agents.
406function configure_neutron {
407 _configure_neutron_common
Sean M. Collins5394cc12016-05-11 15:03:38 -0400408 iniset_rpc_backend neutron $NEUTRON_CONF
409
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100410 if is_service_enabled q-metering neutron-metering; then
411 _configure_neutron_metering
412 fi
413 if is_service_enabled q-agt neutron-agent; then
414 _configure_neutron_plugin_agent
415 fi
416 if is_service_enabled q-dhcp neutron-dhcp; then
417 _configure_neutron_dhcp_agent
418 fi
419 if is_service_enabled q-l3 neutron-l3; then
420 _configure_neutron_l3_agent
421 fi
422 if is_service_enabled q-meta neutron-metadata-agent; then
423 _configure_neutron_metadata_agent
Sean M. Collins2a242512016-05-03 09:03:09 -0400424 fi
425
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100426 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
427 _configure_dvr
428 fi
429 if is_service_enabled ceilometer; then
430 _configure_neutron_ceilometer_notifications
431 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400432
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100433 if [[ $Q_AGENT == "ovn" ]]; then
434 configure_ovn
435 configure_ovn_plugin
436 fi
Brian Haley9aaa5292017-09-20 14:23:05 -0400437
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100438 # Configure Neutron's advanced services
439 if is_service_enabled q-placement neutron-placement; then
440 configure_placement_extension
441 fi
442 if is_service_enabled q-trunk neutron-trunk; then
443 configure_trunk_extension
444 fi
445 if is_service_enabled q-qos neutron-qos; then
446 configure_qos
447 if is_service_enabled q-l3 neutron-l3; then
448 configure_l3_agent_extension_fip_qos
449 configure_l3_agent_extension_gateway_ip_qos
Denis Buliga0bf75a42017-02-06 16:56:46 +0200450 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400451 fi
elajkata84b2092021-11-17 11:52:56 +0100452 if is_service_enabled neutron-segments; then
453 configure_placement_neutron
454 configure_segments_extension
455 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400456
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100457 # Finally configure Neutron server and core plugin
458 if is_service_enabled q-agt neutron-agent q-svc neutron-api; then
459 _configure_neutron_service
Sean M. Collins2a242512016-05-03 09:03:09 -0400460 fi
461
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100462 iniset $NEUTRON_CONF DEFAULT api_workers "$API_WORKERS"
463 # devstack is not a tool for running uber scale OpenStack
464 # clouds, therefore running without a dedicated RPC worker
465 # for state reports is more than adequate.
466 iniset $NEUTRON_CONF DEFAULT rpc_state_report_workers 0
Ihar Hrachyshkae3915932017-02-24 06:24:47 +0000467
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100468 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
469 write_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_BIN_DIR/neutron-api" "/networking"
Sean M. Collins8063fee2016-05-24 11:27:36 -0700470 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400471}
472
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100473function configure_neutron_nova {
474 create_nova_conf_neutron $NOVA_CONF
475 if [[ "${CELLSV2_SETUP}" == "superconductor" ]]; then
476 for i in $(seq 1 $NOVA_NUM_CELLS); do
477 local conf
478 conf=$(conductor_conf $i)
479 create_nova_conf_neutron $conf
480 done
Sean M. Collins2a242512016-05-03 09:03:09 -0400481 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400482}
483
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100484function create_nova_conf_neutron {
Lucas Alvares Gomese6385932018-06-28 11:00:28 +0100485 local conf=${1:-$NOVA_CONF}
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400486 iniset $conf neutron auth_type "password"
487 iniset $conf neutron auth_url "$KEYSTONE_SERVICE_URI"
Dr. Jens Harbott696dbdf2024-07-09 16:36:37 +0200488 iniset $conf neutron username nova
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400489 iniset $conf neutron password "$SERVICE_PASSWORD"
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100490 iniset $conf neutron user_domain_name "$SERVICE_DOMAIN_NAME"
491 iniset $conf neutron project_name "$SERVICE_PROJECT_NAME"
492 iniset $conf neutron project_domain_name "$SERVICE_DOMAIN_NAME"
493 iniset $conf neutron auth_strategy "$Q_AUTH_STRATEGY"
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400494 iniset $conf neutron region_name "$REGION_NAME"
Sean M. Collins2a242512016-05-03 09:03:09 -0400495
Gary Kotton88f85582016-08-14 06:55:42 -0700496 # optionally set options in nova_conf
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400497 neutron_plugin_create_nova_conf $conf
Gary Kotton88f85582016-08-14 06:55:42 -0700498
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100499 if is_service_enabled q-meta neutron-metadata-agent; then
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400500 iniset $conf neutron service_metadata_proxy "True"
Sean M. Collins2a242512016-05-03 09:03:09 -0400501 fi
502
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100503 iniset $conf DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
504 iniset $conf DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Sean M. Collins2a242512016-05-03 09:03:09 -0400505}
506
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100507# create_neutron_accounts() - Set up common required neutron accounts
508
Sean M. Collins2a242512016-05-03 09:03:09 -0400509# Tenant User Roles
510# ------------------------------------------------------------------
511# service neutron admin # if enabled
512
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100513# Migrated from keystone_data.sh
514function create_neutron_accounts {
Kevin Benton66b361b2017-06-13 00:31:01 -0700515 local neutron_url
Kevin Benton66b361b2017-06-13 00:31:01 -0700516 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100517 neutron_url=$Q_PROTOCOL://$SERVICE_HOST/
Kevin Benton66b361b2017-06-13 00:31:01 -0700518 else
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100519 neutron_url=$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/
Kevin Benton66b361b2017-06-13 00:31:01 -0700520 fi
Slawek Kaplonski1a21ccb2022-07-08 21:57:45 +0200521 if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then
522 neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME
523 fi
Kevin Benton66b361b2017-06-13 00:31:01 -0700524
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100525 if is_service_enabled q-svc neutron-api; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400526
527 create_service_user "neutron"
528
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100529 get_or_create_service "neutron" "network" "Neutron Service"
530 get_or_create_endpoint \
531 "network" \
Kevin Benton66b361b2017-06-13 00:31:01 -0700532 "$REGION_NAME" "$neutron_url"
Sean M. Collins2a242512016-05-03 09:03:09 -0400533 fi
534}
535
Sean M. Collins2a242512016-05-03 09:03:09 -0400536# init_neutron() - Initialize databases, etc.
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100537function init_neutron {
538 recreate_database $Q_DB_NAME
Clark Boylan633dbc32017-06-14 12:09:21 -0700539 time_start "dbsync"
Sean M. Collins2a242512016-05-03 09:03:09 -0400540 # Run Neutron db migrations
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100541 $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 -0700542 time_stop "dbsync"
Sean M. Collins2a242512016-05-03 09:03:09 -0400543}
544
545# install_neutron() - Collect source and prepare
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100546function install_neutron {
Sean M. Collins2a242512016-05-03 09:03:09 -0400547 # Install neutron-lib from git so we make sure we're testing
548 # the latest code.
549 if use_library_from_git "neutron-lib"; then
550 git_clone_by_name "neutron-lib"
551 setup_dev_lib "neutron-lib"
552 fi
553
elajkatbb0c2732023-11-16 11:30:04 +0100554 # Install SQLAlchemy and alembic from git when these are required
555 # see https://bugs.launchpad.net/neutron/+bug/2042941
556 if use_library_from_git "sqlalchemy"; then
557 git_clone $SQLALCHEMY_REPO $SQLALCHEMY_DIR $SQLALCHEMY_BRANCH
558 setup_develop $SQLALCHEMY_DIR
559 fi
560 if use_library_from_git "alembic"; then
561 git_clone $ALEMBIC_REPO $ALEMBIC_DIR $ALEMBIC_BRANCH
562 setup_develop $ALEMBIC_DIR
563 fi
564
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100565 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
566 setup_develop $NEUTRON_DIR
Sean M. Collins2a242512016-05-03 09:03:09 -0400567
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100568 if [[ $Q_AGENT == "ovn" ]]; then
569 install_ovn
Sean M. Collins2a242512016-05-03 09:03:09 -0400570 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400571}
572
573# install_neutronclient() - Collect source and prepare
574function install_neutronclient {
575 if use_library_from_git "python-neutronclient"; then
576 git_clone_by_name "python-neutronclient"
577 setup_dev_lib "python-neutronclient"
Sean M. Collins2a242512016-05-03 09:03:09 -0400578 fi
579}
580
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100581# install_neutron_agent_packages() - Collect source and prepare
582function install_neutron_agent_packages {
583 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
584 if is_service_enabled q-l3 neutron-l3; then
585 install_package radvd
Sean M. Collins2a242512016-05-03 09:03:09 -0400586 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100587 # install packages that are specific to plugin agent(s)
588 if is_service_enabled q-agt neutron-agent q-dhcp neutron-dhcp q-l3 neutron-l3; then
589 neutron_plugin_install_agent_packages
Sean M. Collins2a242512016-05-03 09:03:09 -0400590 fi
591}
592
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100593# Finish neutron configuration
594function configure_neutron_after_post_config {
595 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
596 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
Sean M. Collins2a242512016-05-03 09:03:09 -0400597 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100598 configure_rbac_policies
Sean M. Collins2a242512016-05-03 09:03:09 -0400599}
600
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +0200601# configure_rbac_policies() - Configure Neutron to enforce new RBAC
602# policies and scopes if NEUTRON_ENFORCE_SCOPE == True
603function configure_rbac_policies {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100604 if [[ "$NEUTRON_ENFORCE_SCOPE" == "True" || "$ENFORCE_SCOPE" == True ]]; then
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +0200605 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults True
606 iniset $NEUTRON_CONF oslo_policy enforce_scope True
607 else
608 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults False
609 iniset $NEUTRON_CONF oslo_policy enforce_scope False
610 fi
611}
612
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100613# Start running OVN processes
614function start_ovn_services {
615 if [[ $Q_AGENT == "ovn" ]]; then
Lucas Alvares Gomesa3891282023-07-18 16:31:28 +0100616 if [ "$VIRT_DRIVER" != 'ironic' ]; then
617 # NOTE(TheJulia): Ironic's devstack plugin needs to perform
618 # additional networking configuration to setup a working test
619 # environment with test virtual machines to emulate baremetal,
620 # which requires OVN to be up and running earlier to complete
621 # that base configuration.
622 init_ovn
623 start_ovn
624 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100625 if [[ "$OVN_L3_CREATE_PUBLIC_NETWORK" == "True" ]]; then
626 if [[ "$NEUTRON_CREATE_INITIAL_NETWORKS" != "True" ]]; then
627 echo "OVN_L3_CREATE_PUBLIC_NETWORK=True is being ignored "
628 echo "because NEUTRON_CREATE_INITIAL_NETWORKS is set to False"
629 else
630 create_public_bridge
631 fi
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400632 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400633 fi
634}
635
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100636# Start running processes
637function start_neutron_service_and_check {
638 local service_port=$Q_PORT
639 local service_protocol=$Q_PROTOCOL
640 local cfg_file_options
641 local neutron_url
Sean M. Collins2a242512016-05-03 09:03:09 -0400642
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100643 cfg_file_options="$(determine_config_files neutron-server)"
Sean M. Collins2a242512016-05-03 09:03:09 -0400644
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100645 if is_service_enabled tls-proxy; then
646 service_port=$Q_PORT_INT
647 service_protocol="http"
Sean M. Collins2a242512016-05-03 09:03:09 -0400648 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100649 # Start the Neutron service
650 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
651 enable_service neutron-api
652 run_process neutron-api "$(which uwsgi) --procname-prefix neutron-api --ini $NEUTRON_UWSGI_CONF"
653 neutron_url=$Q_PROTOCOL://$Q_HOST/
654 enable_service neutron-rpc-server
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000655 enable_service neutron-periodic-workers
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000656 _enable_ovn_maintenance
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100657 run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $cfg_file_options"
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000658 run_process neutron-periodic-workers "$NEUTRON_BIN_DIR/neutron-periodic-workers $cfg_file_options"
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000659 _run_ovn_maintenance
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100660 else
661 run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
662 neutron_url=$service_protocol://$Q_HOST:$service_port/
663 # Start proxy if enabled
664 if is_service_enabled tls-proxy; then
665 start_tls_proxy neutron '*' $Q_PORT $Q_HOST $Q_PORT_INT
666 fi
667 fi
668 if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then
669 neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME
670 fi
671 echo "Waiting for Neutron to start..."
Sean M. Collins2a242512016-05-03 09:03:09 -0400672
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100673 local testcmd="wget ${ssl_ca} --no-proxy -q -O- $neutron_url"
674 test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900675}
676
Sean M. Collins2a242512016-05-03 09:03:09 -0400677function start_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100678 start_l2_agent "$@"
679 start_other_agents "$@"
680}
681
682# Control of the l2 agent is separated out to make it easier to test partial
683# upgrades (everything upgraded except the L2 agent)
684function start_l2_agent {
685 run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
686
687 if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then
688 sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
689 sudo ip link set $OVS_PHYSICAL_BRIDGE up
690 sudo ip link set br-int up
691 sudo ip link set $PUBLIC_INTERFACE up
692 if is_ironic_hardware; then
693 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
694 sudo ip addr del $IP dev $PUBLIC_INTERFACE
695 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
696 done
697 sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
698 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400699 fi
700}
701
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100702function start_other_agents {
703 run_process q-dhcp "$AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file $Q_DHCP_CONF_FILE"
704
705 run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
706
707 run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file $Q_META_CONF_FILE"
708 run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
709}
710
711# Start running processes, including screen
712function start_neutron_agents {
713 # NOTE(slaweq): it's now just a wrapper for start_neutron function
714 start_neutron "$@"
715}
716
717function stop_l2_agent {
718 stop_process q-agt
719}
720
721# stop_other() - Stop running processes
722function stop_other {
723 if is_service_enabled q-dhcp neutron-dhcp; then
724 stop_process q-dhcp
725 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
726 [ ! -z "$pid" ] && sudo kill -9 $pid
727 fi
728
729 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
730 stop_process neutron-rpc-server
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000731 stop_process neutron-periodic-workers
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100732 stop_process neutron-api
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000733 _stop_ovn_maintenance
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100734 else
735 stop_process q-svc
736 fi
737
738 if is_service_enabled q-l3 neutron-l3; then
739 sudo pkill -f "radvd -C $DATA_DIR/neutron/ra"
740 stop_process q-l3
741 fi
742
743 if is_service_enabled q-meta neutron-metadata-agent; then
744 stop_process q-meta
745 fi
746
747 if is_service_enabled q-metering neutron-metering; then
748 neutron_metering_stop
749 fi
750
751 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Bence Romsics71c3c402022-12-21 13:50:54 +0100752 # pkill takes care not to kill itself, but it may kill its parent
753 # sudo unless we use the "ps | grep [f]oo" trick
754 sudo pkill -9 -f "$NEUTRON_ROOTWRAP-[d]aemon" || :
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100755 fi
756}
757
758# stop_neutron() - Stop running processes (non-screen)
Sean M. Collins2a242512016-05-03 09:03:09 -0400759function stop_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100760 stop_other
761 stop_l2_agent
762
763 if [[ $Q_AGENT == "ovn" && $SKIP_STOP_OVN != "True" ]]; then
764 stop_ovn
Sean M. Collins2a242512016-05-03 09:03:09 -0400765 fi
766}
767
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100768# _move_neutron_addresses_route() - Move the primary IP to the OVS bridge
769# on startup, or back to the public interface on cleanup. If no IP is
770# configured on the interface, just add it as a port to the OVS bridge.
771function _move_neutron_addresses_route {
772 local from_intf=$1
773 local to_intf=$2
774 local add_ovs_port=$3
775 local del_ovs_port=$4
776 local af=$5
777
778 if [[ -n "$from_intf" && -n "$to_intf" ]]; then
779 # Remove the primary IP address from $from_intf and add it to $to_intf,
780 # along with the default route, if it exists. Also, when called
781 # on configure we will also add $from_intf as a port on $to_intf,
782 # assuming it is an OVS bridge.
783
784 local IP_REPLACE=""
785 local IP_DEL=""
786 local IP_UP=""
787 local DEFAULT_ROUTE_GW
788 DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf\s/ { print \$3; exit }")
789 local ADD_OVS_PORT=""
790 local DEL_OVS_PORT=""
791 local ARP_CMD=""
792
793 IP_BRD=$(ip -f $af a s dev $from_intf scope global primary | grep inet | awk '{ print $2, $3, $4; exit }')
794
795 if [ "$DEFAULT_ROUTE_GW" != "" ]; then
796 ADD_DEFAULT_ROUTE="sudo ip -f $af r replace default via $DEFAULT_ROUTE_GW dev $to_intf"
797 fi
798
799 if [[ "$add_ovs_port" == "True" ]]; then
800 ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf"
801 fi
802
803 if [[ "$del_ovs_port" == "True" ]]; then
804 DEL_OVS_PORT="sudo ovs-vsctl --if-exists del-port $from_intf $to_intf"
805 fi
806
807 if [[ "$IP_BRD" != "" ]]; then
808 IP_DEL="sudo ip addr del $IP_BRD dev $from_intf"
809 IP_REPLACE="sudo ip addr replace $IP_BRD dev $to_intf"
810 IP_UP="sudo ip link set $to_intf up"
811 if [[ "$af" == "inet" ]]; then
812 IP=$(echo $IP_BRD | awk '{ print $1; exit }' | grep -o -E '(.*)/' | cut -d "/" -f1)
813 ARP_CMD="sudo arping -A -c 3 -w 5 -I $to_intf $IP "
814 fi
815 fi
816
817 # The add/del OVS port calls have to happen either before or
818 # after the address is moved in order to not leave it orphaned.
819 $DEL_OVS_PORT; $IP_DEL; $IP_REPLACE; $IP_UP; $ADD_OVS_PORT; $ADD_DEFAULT_ROUTE; $ARP_CMD
820 fi
821}
822
823# _configure_public_network_connectivity() - Configures connectivity to the
824# external network using $PUBLIC_INTERFACE or NAT on the single interface
825# machines
826function _configure_public_network_connectivity {
827 # If we've given a PUBLIC_INTERFACE to take over, then we assume
828 # that we can own the whole thing, and privot it into the OVS
829 # bridge. If we are not, we're probably on a single interface
830 # machine, and we just setup NAT so that fixed guests can get out.
831 if [[ -n "$PUBLIC_INTERFACE" ]]; then
832 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" True False "inet"
833
834 if [[ $(ip -f inet6 a s dev "$PUBLIC_INTERFACE" | grep -c 'global') != 0 ]]; then
835 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" False False "inet6"
836 fi
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -0500837 else
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100838 for d in $default_v4_route_devs; do
839 sudo iptables -t nat -A POSTROUTING -o $d -s $FLOATING_RANGE -j MASQUERADE
840 done
841 fi
842}
843
844# cleanup_neutron() - Remove residual data files, anything left over from previous
845# runs that a clean run would need to clean up
846function cleanup_neutron {
847 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
848 stop_process neutron-api
849 stop_process neutron-rpc-server
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000850 stop_process neutron-periodic-workers
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000851 _stop_ovn_maintenance
Stephen Finucaned5182ce2024-04-19 12:27:14 +0100852 remove_uwsgi_config "$NEUTRON_UWSGI_CONF" "neutron-api"
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100853 sudo rm -f $(apache_site_config_for neutron-api)
854 fi
855
856 if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then
857 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False True "inet"
858
859 if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then
860 # ip(8) wants the prefix length when deleting
861 local v6_gateway
862 v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }')
863 sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE
864 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False False "inet6"
865 fi
866
867 if is_provider_network && is_ironic_hardware; then
868 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
869 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
870 sudo ip addr add $IP dev $PUBLIC_INTERFACE
871 done
872 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
873 fi
874 fi
875
876 if is_neutron_ovs_base_plugin; then
877 neutron_ovs_base_cleanup
878 fi
879
880 if [[ $Q_AGENT == "linuxbridge" ]]; then
881 neutron_lb_cleanup
882 fi
883
884 # delete all namespaces created by neutron
885 for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|fip|snat)-[0-9a-f-]*'); do
886 sudo ip netns delete ${ns}
887 done
888
889 if [[ $Q_AGENT == "ovn" ]]; then
890 cleanup_ovn
891 fi
892}
893
894
895function _create_neutron_conf_dir {
896 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
897 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
898}
899
900# _configure_neutron_common()
901# Set common config for all neutron server and agents.
902# This MUST be called before other ``_configure_neutron_*`` functions.
903function _configure_neutron_common {
904 _create_neutron_conf_dir
905
906 # Uses oslo config generator to generate core sample configuration files
907 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
908
909 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
910
911 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
912
913 # allow neutron user to administer neutron to match neutron account
914 # NOTE(amotoki): This is required for nova works correctly with neutron.
915 if [ -f $NEUTRON_DIR/etc/policy.json ]; then
916 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
917 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
918 else
919 echo '{"context_is_admin": "role:admin or user_name:neutron"}' > $Q_POLICY_FILE
920 fi
921
922 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
923 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
924 neutron_plugin_configure_common
925
926 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
927 die $LINENO "Neutron plugin not set.. exiting"
928 fi
929
930 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
931 mkdir -p /$Q_PLUGIN_CONF_PATH
932 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
933 # NOTE(slaweq): NEUTRON_CORE_PLUGIN_CONF is used e.g. in neutron repository,
934 # it was previously defined in the lib/neutron module which is now deleted.
935 NEUTRON_CORE_PLUGIN_CONF=$Q_PLUGIN_CONF_FILE
936 # NOTE(hichihara): Some neutron vendor plugins were already decomposed and
937 # there is no config file in Neutron tree. They should prepare the file in each plugin.
938 if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then
939 cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE
940 elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then
941 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
942 fi
943
944 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
945 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
946 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
947 iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS
948 iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock
949
950 # NOTE(freerunner): Need to adjust Region Name for nova in multiregion installation
951 iniset $NEUTRON_CONF nova region_name $REGION_NAME
952
953 if [ "$VIRT_DRIVER" = 'fake' ]; then
954 # Disable arbitrary limits
955 iniset $NEUTRON_CONF quotas quota_network -1
956 iniset $NEUTRON_CONF quotas quota_subnet -1
957 iniset $NEUTRON_CONF quotas quota_port -1
958 iniset $NEUTRON_CONF quotas quota_security_group -1
959 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
960 fi
961
962 # Format logging
963 setup_logging $NEUTRON_CONF
964
965 if is_service_enabled tls-proxy && [ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" ]; then
966 # Set the service port for a proxy to take the original
967 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
968 iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True
969 fi
970
971 _neutron_setup_rootwrap
972}
973
974function _configure_neutron_dhcp_agent {
975
976 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE
977
978 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
979 # make it so we have working DNS from guests
980 iniset $Q_DHCP_CONF_FILE DEFAULT dnsmasq_local_resolv True
981 configure_root_helper_options $Q_DHCP_CONF_FILE
982
983 if ! is_service_enabled q-l3 neutron-l3; then
984 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
985 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
986 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
987 else
988 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
989 die "$LINENO" "Enable isolated metadata is a must for metadata network"
990 fi
991 fi
992 fi
993
994 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
995
996 neutron_plugin_configure_dhcp_agent $Q_DHCP_CONF_FILE
997}
998
999
1000function _configure_neutron_metadata_agent {
1001 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE
1002
1003 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1004 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_host $Q_META_DATA_IP
1005 iniset $Q_META_CONF_FILE DEFAULT metadata_workers $API_WORKERS
1006 configure_root_helper_options $Q_META_CONF_FILE
1007}
1008
1009function _configure_neutron_ceilometer_notifications {
1010 iniset $NEUTRON_CONF oslo_messaging_notifications driver messagingv2
1011}
1012
1013function _configure_neutron_metering {
1014 neutron_agent_metering_configure_common
1015 neutron_agent_metering_configure_agent
1016}
1017
1018function _configure_dvr {
1019 iniset $NEUTRON_CONF DEFAULT router_distributed True
1020 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
1021}
1022
1023
1024# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
1025# It is called when q-agt is enabled.
1026function _configure_neutron_plugin_agent {
1027 # Specify the default root helper prior to agent configuration to
1028 # ensure that an agent's configuration can override the default
1029 configure_root_helper_options /$Q_PLUGIN_CONF_FILE
1030 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1031
1032 # Configure agent for plugin
1033 neutron_plugin_configure_plugin_agent
1034}
1035
1036function _replace_api_paste_composite {
1037 local sep
1038 sep=$(echo -ne "\x01")
1039 # Replace it
1040 $sudo sed -i -e "s/\/\: neutronversions_composite/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/\: neutronversions_composite/" "$Q_API_PASTE_FILE"
1041 $sudo sed -i -e "s/\/healthcheck\: healthcheck/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/healthcheck\: healthcheck/" "$Q_API_PASTE_FILE"
1042 $sudo sed -i -e "s/\/v2.0\: neutronapi_v2_0/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/v2.0\: neutronapi_v2_0/" "$Q_API_PASTE_FILE"
1043}
1044
1045# _configure_neutron_service() - Set config files for neutron service
1046# It is called when q-svc is enabled.
1047function _configure_neutron_service {
1048 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
1049 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
1050
Slawek Kaplonskib500d802024-06-14 12:58:58 +02001051 if [[ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" && -n "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001052 _replace_api_paste_composite
1053 fi
1054
1055 # Update either configuration file with plugin
1056 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
1057
1058 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1059 iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE
1060
1061 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
1062 configure_keystone_authtoken_middleware $NEUTRON_CONF $Q_ADMIN_USERNAME
1063
1064 # Configuration for neutron notifications to nova.
1065 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
1066 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
1067
1068 configure_keystone_authtoken_middleware $NEUTRON_CONF nova nova
1069
1070 # Configuration for placement client
1071 configure_keystone_authtoken_middleware $NEUTRON_CONF placement placement
1072
1073 # Configure plugin
1074 neutron_plugin_configure_service
1075}
1076
1077# Utility Functions
1078#------------------
1079
1080# neutron_service_plugin_class_add() - add service plugin class
1081function neutron_service_plugin_class_add {
1082 local service_plugin_class=$1
1083 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
1084 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
1085 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
1086 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
1087 fi
1088}
1089
1090# neutron_ml2_extension_driver_add() - add ML2 extension driver
1091function neutron_ml2_extension_driver_add {
1092 local extension=$1
1093 if [[ $Q_ML2_PLUGIN_EXT_DRIVERS == '' ]]; then
1094 Q_ML2_PLUGIN_EXT_DRIVERS=$extension
1095 elif [[ ! ,${Q_ML2_PLUGIN_EXT_DRIVERS}, =~ ,${extension}, ]]; then
1096 Q_ML2_PLUGIN_EXT_DRIVERS="$Q_ML2_PLUGIN_EXT_DRIVERS,$extension"
1097 fi
1098}
1099
1100# neutron_server_config_add() - add server config file
1101function neutron_server_config_add {
1102 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($1)
1103}
1104
1105# neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root).
1106function neutron_deploy_rootwrap_filters {
1107 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1108 return
1109 fi
1110 local srcdir=$1
1111 sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D
1112 sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
1113}
1114
1115# _neutron_setup_rootwrap() - configure Neutron's rootwrap
1116function _neutron_setup_rootwrap {
1117 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1118 return
1119 fi
1120 # Wipe any existing ``rootwrap.d`` files first
1121 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
1122 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
1123 sudo rm -rf $Q_CONF_ROOTWRAP_D
1124 fi
1125
1126 neutron_deploy_rootwrap_filters $NEUTRON_DIR
1127
1128 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
1129 # location moved in newer versions, prefer new location
1130 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
1131 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
1132 else
1133 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
1134 fi
1135 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
yatinkarelffc1b762023-08-28 10:52:26 +05301136 # Rely on $PATH set by devstack to determine what is safe to execute
1137 # by rootwrap rather than use explicit whitelist of paths in
1138 # rootwrap.conf
1139 sudo sed -e 's/^exec_dirs=.*/#&/' -i $Q_RR_CONF_FILE
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001140
1141 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
1142 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
1143 ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
1144
1145 # Set up the rootwrap sudoers for neutron
1146 TEMPFILE=`mktemp`
1147 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
1148 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE
1149 chmod 0440 $TEMPFILE
1150 sudo chown root:root $TEMPFILE
1151 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
1152
1153 # Update the root_helper
1154 configure_root_helper_options $NEUTRON_CONF
1155}
1156
1157function configure_root_helper_options {
1158 local conffile=$1
1159 iniset $conffile agent root_helper "$Q_RR_COMMAND"
1160 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
1161 iniset $conffile agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
1162 fi
1163}
1164
1165function _neutron_setup_interface_driver {
1166
1167 # ovs_use_veth needs to be set before the plugin configuration
1168 # occurs to allow plugins to override the setting.
1169 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1170
1171 neutron_plugin_setup_interface_driver $1
1172}
1173# Functions for Neutron Exercises
1174#--------------------------------
1175
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001176# ssh check
1177function _ssh_check_neutron {
1178 local from_net=$1
1179 local key_file=$2
1180 local ip=$3
1181 local user=$4
1182 local timeout_sec=$5
1183 local probe_cmd = ""
1184 probe_cmd=`_get_probe_cmd_prefix $from_net`
1185 local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success"
1186 test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec
1187}
1188
1189function plugin_agent_add_l2_agent_extension {
1190 local l2_agent_extension=$1
1191 if [[ -z "$L2_AGENT_EXTENSIONS" ]]; then
1192 L2_AGENT_EXTENSIONS=$l2_agent_extension
1193 elif [[ ! ,${L2_AGENT_EXTENSIONS}, =~ ,${l2_agent_extension}, ]]; then
1194 L2_AGENT_EXTENSIONS+=",$l2_agent_extension"
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -05001195 fi
1196}
1197
Sean M. Collins2a242512016-05-03 09:03:09 -04001198# Restore xtrace
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001199$_XTRACE_NEUTRON
1200
1201# Tell emacs to use shell-script-mode
1202## Local variables:
1203## mode: shell-script
1204## End: