blob: 69ff212991aeb03876a190a1027888671a982ab0 [file] [log] [blame]
Sean M. Collins2a242512016-05-03 09:03:09 -04001#!/bin/bash
2#
3# lib/neutron
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01004# functions - functions specific to neutron
Sean M. Collins2a242512016-05-03 09:03:09 -04005
6# Dependencies:
Sean M. Collins2a242512016-05-03 09:03:09 -04007# ``functions`` file
8# ``DEST`` must be defined
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01009# ``STACK_USER`` must be defined
Sean M. Collins2a242512016-05-03 09:03:09 -040010
11# ``stack.sh`` calls the entry points in this order:
12#
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010013# - install_neutron_agent_packages
14# - install_neutronclient
15# - install_neutron
16# - install_neutron_third_party
17# - configure_neutron
18# - init_neutron
19# - configure_neutron_third_party
20# - init_neutron_third_party
21# - start_neutron_third_party
22# - create_nova_conf_neutron
23# - configure_neutron_after_post_config
24# - start_neutron_service_and_check
25# - check_neutron_third_party_integration
26# - start_neutron_agents
27# - create_neutron_initial_network
28#
29# ``unstack.sh`` calls the entry points in this order:
30#
31# - stop_neutron
32# - stop_neutron_third_party
33# - cleanup_neutron
Sean M. Collins2a242512016-05-03 09:03:09 -040034
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010035# Functions in lib/neutron are classified into the following categories:
36#
37# - entry points (called from stack.sh or unstack.sh)
38# - internal functions
39# - neutron exercises
40# - 3rd party programs
Sean M. Collins2a242512016-05-03 09:03:09 -040041
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010042
43# Neutron Networking
44# ------------------
45
46# Make sure that neutron is enabled in ``ENABLED_SERVICES``. If you want
47# to run Neutron on this host, make sure that q-svc is also in
48# ``ENABLED_SERVICES``.
49#
50# See "Neutron Network Configuration" below for additional variables
51# that must be set in localrc for connectivity across hosts with
52# Neutron.
53
54# Settings
Sean M. Collins2a242512016-05-03 09:03:09 -040055# --------
56
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010057
58# Neutron Network Configuration
59# -----------------------------
60
61if is_service_enabled tls-proxy; then
62 Q_PROTOCOL="https"
63fi
64
65
Sean M. Collins2a242512016-05-03 09:03:09 -040066# Set up default directories
67GITDIR["python-neutronclient"]=$DEST/python-neutronclient
68
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010069
70NEUTRON_DIR=$DEST/neutron
71NEUTRON_FWAAS_DIR=$DEST/neutron-fwaas
72
73# Support entry points installation of console scripts
74if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
75 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
76else
77 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
78fi
79
80NEUTRON_CONF_DIR=/etc/neutron
81NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
82export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
83
Kevin Benton66b361b2017-06-13 00:31:01 -070084# NEUTRON_DEPLOY_MOD_WSGI defines how neutron is deployed, allowed values:
85# - False (default) : Run neutron under Eventlet
86# - True : Run neutron under uwsgi
87# TODO(annp): Switching to uwsgi in next cycle if things turn out to be stable
88# enough
Jens Harbott3492fee2018-11-30 13:57:17 +000089NEUTRON_DEPLOY_MOD_WSGI=$(trueorfalse False NEUTRON_DEPLOY_MOD_WSGI)
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010090
Stephen Finucane0cd87632024-04-19 12:12:16 +010091NEUTRON_UWSGI=neutron.wsgi.api:application
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010092NEUTRON_UWSGI_CONF=$NEUTRON_CONF_DIR/neutron-api-uwsgi.ini
Sean M. Collins2a242512016-05-03 09:03:09 -040093
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +020094# If NEUTRON_ENFORCE_SCOPE == True, it will set "enforce_scope"
95# and "enforce_new_defaults" to True in the Neutron's config to enforce usage
Ghanshyam Mannbacb8402023-10-25 12:52:28 -070096# of the new RBAC policies and scopes. Set it to False if you do not
97# want to run Neutron with new RBAC.
98NEUTRON_ENFORCE_SCOPE=$(trueorfalse True NEUTRON_ENFORCE_SCOPE)
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +020099
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100100# Agent binaries. Note, binary paths for other agents are set in per-service
101# scripts in lib/neutron_plugins/services/
102AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
103AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
104AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
Brian Haley9aaa5292017-09-20 14:23:05 -0400105
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100106# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
107# loaded from per-plugin scripts in lib/neutron_plugins/
108Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
109# NOTE(slaweq): NEUTRON_DHCP_CONF is used e.g. in neutron repository,
110# it was previously defined in the lib/neutron module which is now deleted.
111NEUTRON_DHCP_CONF=$Q_DHCP_CONF_FILE
112Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
113# NOTE(slaweq): NEUTRON_L3_CONF is used e.g. in neutron repository,
114# it was previously defined in the lib/neutron module which is now deleted.
115NEUTRON_L3_CONF=$Q_L3_CONF_FILE
116Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
Sean M. Collins2a242512016-05-03 09:03:09 -0400117
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100118# Default name for Neutron database
119Q_DB_NAME=${Q_DB_NAME:-neutron}
120# Default Neutron Plugin
121Q_PLUGIN=${Q_PLUGIN:-ml2}
122# Default Neutron Port
123Q_PORT=${Q_PORT:-9696}
124# Default Neutron Internal Port when using TLS proxy
125Q_PORT_INT=${Q_PORT_INT:-19696}
126# Default Neutron Host
127Q_HOST=${Q_HOST:-$SERVICE_HOST}
128# Default protocol
129Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
130# Default listen address
131Q_LISTEN_ADDRESS=${Q_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)}
132# Default admin username
133Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
134# Default auth strategy
135Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
136# RHEL's support for namespaces requires using veths with ovs
137Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
138Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
139Q_USE_ROOTWRAP_DAEMON=$(trueorfalse True Q_USE_ROOTWRAP_DAEMON)
140# Meta data IP
141Q_META_DATA_IP=${Q_META_DATA_IP:-$(ipv6_unquote $SERVICE_HOST)}
142# Allow Overlapping IP among subnets
143Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
144Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
145Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
146VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
147VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Sean M. Collins2a242512016-05-03 09:03:09 -0400148
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100149# Allow to skip stopping of OVN services
150SKIP_STOP_OVN=${SKIP_STOP_OVN:-False}
Sean M. Collins2a242512016-05-03 09:03:09 -0400151
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100152# The directory which contains files for Q_PLUGIN_EXTRA_CONF_FILES.
153# /etc/neutron is assumed by many of devstack plugins. Do not change.
154_Q_PLUGIN_EXTRA_CONF_PATH=/etc/neutron
Julia Kreger6e5b1382019-01-09 17:00:45 -0800155
Slawek Kaplonski1a21ccb2022-07-08 21:57:45 +0200156# The name of the service in the endpoint URL
157NEUTRON_ENDPOINT_SERVICE_NAME=${NEUTRON_ENDPOINT_SERVICE_NAME-"networking"}
158if [[ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" && -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then
159 NEUTRON_ENDPOINT_SERVICE_NAME="networking"
160fi
161
elajkatbb0c2732023-11-16 11:30:04 +0100162# Source install libraries
163ALEMBIC_REPO=${ALEMBIC_REPO:-https://github.com/sqlalchemy/alembic.git}
164ALEMBIC_DIR=${ALEMBIC_DIR:-$DEST/alembic}
165ALEMBIC_BRANCH=${ALEMBIC_BRANCH:-main}
166SQLALCHEMY_REPO=${SQLALCHEMY_REPO:-https://github.com/sqlalchemy/sqlalchemy.git}
167SQLALCHEMY_DIR=${SQLALCHEMY_DIR:-$DEST/sqlalchemy}
168SQLALCHEMY_BRANCH=${SQLALCHEMY_BRANCH:-main}
169
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100170# List of config file names in addition to the main plugin config file
171# To add additional plugin config files, use ``neutron_server_config_add``
172# utility function. For example:
173#
174# ``neutron_server_config_add file1``
175#
176# These config files are relative to ``/etc/neutron``. The above
177# example would specify ``--config-file /etc/neutron/file1`` for
178# neutron server.
179declare -a -g Q_PLUGIN_EXTRA_CONF_FILES
Julia Kreger6e5b1382019-01-09 17:00:45 -0800180
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100181# same as Q_PLUGIN_EXTRA_CONF_FILES, but with absolute path.
182declare -a -g _Q_PLUGIN_EXTRA_CONF_FILES_ABS
183
184
185Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
186if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
187 Q_RR_COMMAND="sudo"
188else
189 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
190 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
191 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
192 Q_RR_DAEMON_COMMAND="sudo $NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
193 fi
194fi
195
196
197# Distributed Virtual Router (DVR) configuration
198# Can be:
199# - ``legacy`` - No DVR functionality
200# - ``dvr_snat`` - Controller or single node DVR
201# - ``dvr`` - Compute node in multi-node DVR
202# - ``dvr_no_external`` - Compute node in multi-node DVR, no external network
203#
204Q_DVR_MODE=${Q_DVR_MODE:-legacy}
205if [[ "$Q_DVR_MODE" != "legacy" ]]; then
206 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,l2population
207fi
208
209# Provider Network Configurations
210# --------------------------------
211
212# The following variables control the Neutron ML2 plugins' allocation
213# of tenant networks and availability of provider networks. If these
214# are not configured in ``localrc``, tenant networks will be local to
215# the host (with no remote connectivity), and no physical resources
216# will be available for the allocation of provider networks.
217
218# To disable tunnels (GRE or VXLAN) for tenant networks,
219# set to False in ``local.conf``.
220# GRE tunnels are only supported by the openvswitch.
221ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
222
223# If using GRE, VXLAN or GENEVE tunnels for tenant networks,
224# specify the range of IDs from which tenant networks are
225# allocated. Can be overridden in ``localrc`` if necessary.
226TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
227
228# To use VLANs for tenant networks, set to True in localrc. VLANs
229# are supported by the ML2 plugins, requiring additional configuration
230# described below.
231ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
232
233# If using VLANs for tenant networks, set in ``localrc`` to specify
234# the range of VLAN VIDs from which tenant networks are
235# allocated. An external network switch must be configured to
236# trunk these VLANs between hosts for multi-host connectivity.
237#
238# Example: ``TENANT_VLAN_RANGE=1000:1999``
239TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
240
241# If using VLANs for tenant networks, or if using flat or VLAN
242# provider networks, set in ``localrc`` to the name of the physical
243# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
Brian Haley12abc722025-02-10 13:48:37 -0500244# openvswitch agent, as described below.
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100245#
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
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100259# With the openvswitch plugin, set to True in ``localrc`` to enable
260# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
261#
262# Example: ``OVS_ENABLE_TUNNELING=True``
263OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
264
265# Use DHCP agent for providing metadata service in the case of
266# without L3 agent (No Route Agent), set to True in localrc.
267ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
268
269# Add a static route as dhcp option, so the request to 169.254.169.254
270# will be able to reach through a route(DHCP agent)
271# This option require ENABLE_ISOLATED_METADATA = True
272ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
273# Neutron plugin specific functions
274# ---------------------------------
275
276# Please refer to ``lib/neutron_plugins/README.md`` for details.
277if [ -f $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN ]; then
278 source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
279fi
280
281# Agent metering service plugin functions
282# -------------------------------------------
283
284# Hardcoding for 1 service plugin for now
285source $TOP_DIR/lib/neutron_plugins/services/metering
286
287# L3 Service functions
288source $TOP_DIR/lib/neutron_plugins/services/l3
289
290# Additional Neutron service plugins
291source $TOP_DIR/lib/neutron_plugins/services/placement
292source $TOP_DIR/lib/neutron_plugins/services/trunk
293source $TOP_DIR/lib/neutron_plugins/services/qos
elajkata84b2092021-11-17 11:52:56 +0100294source $TOP_DIR/lib/neutron_plugins/services/segments
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100295
296# Use security group or not
297if has_neutron_plugin_security_group; then
298 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
299else
300 Q_USE_SECGROUP=False
301fi
302
Harald Jensås16ac21f2023-08-31 15:06:52 +0200303# OVN_BRIDGE_MAPPINGS - ovn-bridge-mappings
304# NOTE(hjensas): Initialize after sourcing neutron_plugins/services/l3
305# which initialize PUBLIC_BRIDGE.
306OVN_BRIDGE_MAPPINGS=${OVN_BRIDGE_MAPPINGS:-$PHYSICAL_NETWORK:$PUBLIC_BRIDGE}
307
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100308# Save trace setting
309_XTRACE_NEUTRON=$(set +o | grep xtrace)
310set +o xtrace
311
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900312
Sean M. Collins2a242512016-05-03 09:03:09 -0400313# Functions
314# ---------
315
316# Test if any Neutron services are enabled
317# is_neutron_enabled
318function is_neutron_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -0700319 [[ ,${DISABLED_SERVICES} =~ ,"neutron" ]] && return 1
Sean M. Collins2a242512016-05-03 09:03:09 -0400320 [[ ,${ENABLED_SERVICES} =~ ,"neutron-" || ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
321 return 1
322}
323
324# Test if any Neutron services are enabled
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100325# TODO(slaweq): this is not really needed now and we should remove it as soon
326# as it will not be called from any other Devstack plugins, like e.g. Neutron
327# plugin
Sean M. Collins2a242512016-05-03 09:03:09 -0400328function is_neutron_legacy_enabled {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100329 return 0
Sean M. Collins2a242512016-05-03 09:03:09 -0400330}
331
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100332function _determine_config_server {
333 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" != '' ]]; then
334 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" = "$_Q_PLUGIN_EXTRA_CONF_PATH" ]]; then
335 deprecated "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
336 else
337 die $LINENO "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
338 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400339 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100340 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 ]]; then
341 deprecated "Q_PLUGIN_EXTRA_CONF_FILES is deprecated. Use neutron_server_config_add instead."
Sean M. Collins2a242512016-05-03 09:03:09 -0400342 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100343 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
344 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($_Q_PLUGIN_EXTRA_CONF_PATH/$cfg_file)
Sean M. Collins2a242512016-05-03 09:03:09 -0400345 done
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100346
347 local cfg_file
348 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
349 for cfg_file in ${_Q_PLUGIN_EXTRA_CONF_FILES_ABS[@]}; do
350 opts+=" --config-file $cfg_file"
351 done
352 echo "$opts"
Sean M. Collins2a242512016-05-03 09:03:09 -0400353}
354
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100355function _determine_config_l3 {
356 local opts="--config-file $NEUTRON_CONF --config-file $Q_L3_CONF_FILE"
357 echo "$opts"
Ihar Hrachyshkae65ab4a2017-02-24 17:47:55 +0000358}
359
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000360function _enable_ovn_maintenance {
361 if [[ $Q_AGENT == "ovn" ]]; then
362 enable_service neutron-ovn-maintenance-worker
363 fi
364}
365
366function _run_ovn_maintenance {
367 if [[ $Q_AGENT == "ovn" ]]; then
368 run_process neutron-ovn-maintenance-worker "$NEUTRON_BIN_DIR/neutron-ovn-maintenance-worker $cfg_file_options"
369 fi
370}
371
372function _stop_ovn_maintenance {
373 if [[ $Q_AGENT == "ovn" ]]; then
374 stop_process neutron-ovn-maintenance-worker
375 fi
376}
377
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100378# For services and agents that require it, dynamically construct a list of
379# --config-file arguments that are passed to the binary.
380function determine_config_files {
381 local opts=""
382 case "$1" in
383 "neutron-server") opts="$(_determine_config_server)" ;;
384 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
385 esac
386 if [ -z "$opts" ] ; then
387 die $LINENO "Could not determine config files for $1."
YAMAMOTO Takashi1df17c92017-05-01 17:00:42 +0900388 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100389 echo "$opts"
390}
Sean M. Collins2a242512016-05-03 09:03:09 -0400391
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100392# configure_neutron()
393# Set common config for all neutron server and agents.
394function configure_neutron {
395 _configure_neutron_common
Sean M. Collins5394cc12016-05-11 15:03:38 -0400396 iniset_rpc_backend neutron $NEUTRON_CONF
397
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100398 if is_service_enabled q-metering neutron-metering; then
399 _configure_neutron_metering
400 fi
401 if is_service_enabled q-agt neutron-agent; then
402 _configure_neutron_plugin_agent
403 fi
404 if is_service_enabled q-dhcp neutron-dhcp; then
405 _configure_neutron_dhcp_agent
406 fi
407 if is_service_enabled q-l3 neutron-l3; then
408 _configure_neutron_l3_agent
409 fi
410 if is_service_enabled q-meta neutron-metadata-agent; then
411 _configure_neutron_metadata_agent
Sean M. Collins2a242512016-05-03 09:03:09 -0400412 fi
413
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100414 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
415 _configure_dvr
416 fi
417 if is_service_enabled ceilometer; then
418 _configure_neutron_ceilometer_notifications
419 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400420
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100421 if [[ $Q_AGENT == "ovn" ]]; then
422 configure_ovn
423 configure_ovn_plugin
424 fi
Brian Haley9aaa5292017-09-20 14:23:05 -0400425
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100426 # Configure Neutron's advanced services
427 if is_service_enabled q-placement neutron-placement; then
428 configure_placement_extension
429 fi
430 if is_service_enabled q-trunk neutron-trunk; then
431 configure_trunk_extension
432 fi
433 if is_service_enabled q-qos neutron-qos; then
434 configure_qos
435 if is_service_enabled q-l3 neutron-l3; then
436 configure_l3_agent_extension_fip_qos
437 configure_l3_agent_extension_gateway_ip_qos
Denis Buliga0bf75a42017-02-06 16:56:46 +0200438 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400439 fi
elajkata84b2092021-11-17 11:52:56 +0100440 if is_service_enabled neutron-segments; then
441 configure_placement_neutron
442 configure_segments_extension
443 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400444
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100445 # Finally configure Neutron server and core plugin
446 if is_service_enabled q-agt neutron-agent q-svc neutron-api; then
447 _configure_neutron_service
Sean M. Collins2a242512016-05-03 09:03:09 -0400448 fi
449
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100450 iniset $NEUTRON_CONF DEFAULT api_workers "$API_WORKERS"
451 # devstack is not a tool for running uber scale OpenStack
452 # clouds, therefore running without a dedicated RPC worker
453 # for state reports is more than adequate.
454 iniset $NEUTRON_CONF DEFAULT rpc_state_report_workers 0
Ihar Hrachyshkae3915932017-02-24 06:24:47 +0000455
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100456 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
Stephen Finucane0cd87632024-04-19 12:12:16 +0100457 write_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_UWSGI" "/networking" "" "neutron-api"
Sean M. Collins8063fee2016-05-24 11:27:36 -0700458 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400459}
460
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100461function configure_neutron_nova {
462 create_nova_conf_neutron $NOVA_CONF
463 if [[ "${CELLSV2_SETUP}" == "superconductor" ]]; then
464 for i in $(seq 1 $NOVA_NUM_CELLS); do
465 local conf
466 conf=$(conductor_conf $i)
467 create_nova_conf_neutron $conf
468 done
Sean M. Collins2a242512016-05-03 09:03:09 -0400469 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400470}
471
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100472function create_nova_conf_neutron {
Lucas Alvares Gomese6385932018-06-28 11:00:28 +0100473 local conf=${1:-$NOVA_CONF}
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400474 iniset $conf neutron auth_type "password"
475 iniset $conf neutron auth_url "$KEYSTONE_SERVICE_URI"
Dr. Jens Harbott696dbdf2024-07-09 16:36:37 +0200476 iniset $conf neutron username nova
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400477 iniset $conf neutron password "$SERVICE_PASSWORD"
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100478 iniset $conf neutron user_domain_name "$SERVICE_DOMAIN_NAME"
479 iniset $conf neutron project_name "$SERVICE_PROJECT_NAME"
480 iniset $conf neutron project_domain_name "$SERVICE_DOMAIN_NAME"
481 iniset $conf neutron auth_strategy "$Q_AUTH_STRATEGY"
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400482 iniset $conf neutron region_name "$REGION_NAME"
Sean M. Collins2a242512016-05-03 09:03:09 -0400483
Gary Kotton88f85582016-08-14 06:55:42 -0700484 # optionally set options in nova_conf
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400485 neutron_plugin_create_nova_conf $conf
Gary Kotton88f85582016-08-14 06:55:42 -0700486
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100487 if is_service_enabled q-meta neutron-metadata-agent; then
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400488 iniset $conf neutron service_metadata_proxy "True"
Sean M. Collins2a242512016-05-03 09:03:09 -0400489 fi
490
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100491 iniset $conf DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
492 iniset $conf DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Sean M. Collins2a242512016-05-03 09:03:09 -0400493}
494
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100495# create_neutron_accounts() - Set up common required neutron accounts
496
Sean M. Collins2a242512016-05-03 09:03:09 -0400497# Tenant User Roles
498# ------------------------------------------------------------------
499# service neutron admin # if enabled
500
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100501# Migrated from keystone_data.sh
502function create_neutron_accounts {
Kevin Benton66b361b2017-06-13 00:31:01 -0700503 local neutron_url
Kevin Benton66b361b2017-06-13 00:31:01 -0700504 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100505 neutron_url=$Q_PROTOCOL://$SERVICE_HOST/
Kevin Benton66b361b2017-06-13 00:31:01 -0700506 else
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100507 neutron_url=$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/
Kevin Benton66b361b2017-06-13 00:31:01 -0700508 fi
Slawek Kaplonski1a21ccb2022-07-08 21:57:45 +0200509 if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then
510 neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME
511 fi
Kevin Benton66b361b2017-06-13 00:31:01 -0700512
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100513 if is_service_enabled q-svc neutron-api; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400514
515 create_service_user "neutron"
516
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100517 get_or_create_service "neutron" "network" "Neutron Service"
518 get_or_create_endpoint \
519 "network" \
Kevin Benton66b361b2017-06-13 00:31:01 -0700520 "$REGION_NAME" "$neutron_url"
Sean M. Collins2a242512016-05-03 09:03:09 -0400521 fi
522}
523
Sean M. Collins2a242512016-05-03 09:03:09 -0400524# init_neutron() - Initialize databases, etc.
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100525function init_neutron {
526 recreate_database $Q_DB_NAME
Clark Boylan633dbc32017-06-14 12:09:21 -0700527 time_start "dbsync"
Sean M. Collins2a242512016-05-03 09:03:09 -0400528 # Run Neutron db migrations
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100529 $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 -0700530 time_stop "dbsync"
Sean M. Collins2a242512016-05-03 09:03:09 -0400531}
532
533# install_neutron() - Collect source and prepare
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100534function install_neutron {
Sean M. Collins2a242512016-05-03 09:03:09 -0400535 # Install neutron-lib from git so we make sure we're testing
536 # the latest code.
537 if use_library_from_git "neutron-lib"; then
538 git_clone_by_name "neutron-lib"
539 setup_dev_lib "neutron-lib"
540 fi
541
elajkatbb0c2732023-11-16 11:30:04 +0100542 # Install SQLAlchemy and alembic from git when these are required
543 # see https://bugs.launchpad.net/neutron/+bug/2042941
544 if use_library_from_git "sqlalchemy"; then
545 git_clone $SQLALCHEMY_REPO $SQLALCHEMY_DIR $SQLALCHEMY_BRANCH
546 setup_develop $SQLALCHEMY_DIR
547 fi
548 if use_library_from_git "alembic"; then
549 git_clone $ALEMBIC_REPO $ALEMBIC_DIR $ALEMBIC_BRANCH
550 setup_develop $ALEMBIC_DIR
551 fi
552
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100553 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
554 setup_develop $NEUTRON_DIR
Sean M. Collins2a242512016-05-03 09:03:09 -0400555
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100556 if [[ $Q_AGENT == "ovn" ]]; then
557 install_ovn
Sean M. Collins2a242512016-05-03 09:03:09 -0400558 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400559}
560
561# install_neutronclient() - Collect source and prepare
562function install_neutronclient {
563 if use_library_from_git "python-neutronclient"; then
564 git_clone_by_name "python-neutronclient"
565 setup_dev_lib "python-neutronclient"
Sean M. Collins2a242512016-05-03 09:03:09 -0400566 fi
567}
568
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100569# install_neutron_agent_packages() - Collect source and prepare
570function install_neutron_agent_packages {
571 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
572 if is_service_enabled q-l3 neutron-l3; then
573 install_package radvd
Sean M. Collins2a242512016-05-03 09:03:09 -0400574 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100575 # install packages that are specific to plugin agent(s)
576 if is_service_enabled q-agt neutron-agent q-dhcp neutron-dhcp q-l3 neutron-l3; then
577 neutron_plugin_install_agent_packages
Sean M. Collins2a242512016-05-03 09:03:09 -0400578 fi
579}
580
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100581# Finish neutron configuration
582function configure_neutron_after_post_config {
583 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
584 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
Sean M. Collins2a242512016-05-03 09:03:09 -0400585 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100586 configure_rbac_policies
Sean M. Collins2a242512016-05-03 09:03:09 -0400587}
588
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +0200589# configure_rbac_policies() - Configure Neutron to enforce new RBAC
590# policies and scopes if NEUTRON_ENFORCE_SCOPE == True
591function configure_rbac_policies {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100592 if [[ "$NEUTRON_ENFORCE_SCOPE" == "True" || "$ENFORCE_SCOPE" == True ]]; then
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +0200593 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults True
594 iniset $NEUTRON_CONF oslo_policy enforce_scope True
595 else
596 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults False
597 iniset $NEUTRON_CONF oslo_policy enforce_scope False
598 fi
599}
600
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100601# Start running OVN processes
602function start_ovn_services {
603 if [[ $Q_AGENT == "ovn" ]]; then
Lucas Alvares Gomesa3891282023-07-18 16:31:28 +0100604 if [ "$VIRT_DRIVER" != 'ironic' ]; then
605 # NOTE(TheJulia): Ironic's devstack plugin needs to perform
606 # additional networking configuration to setup a working test
607 # environment with test virtual machines to emulate baremetal,
608 # which requires OVN to be up and running earlier to complete
609 # that base configuration.
610 init_ovn
611 start_ovn
612 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100613 if [[ "$OVN_L3_CREATE_PUBLIC_NETWORK" == "True" ]]; then
614 if [[ "$NEUTRON_CREATE_INITIAL_NETWORKS" != "True" ]]; then
615 echo "OVN_L3_CREATE_PUBLIC_NETWORK=True is being ignored "
616 echo "because NEUTRON_CREATE_INITIAL_NETWORKS is set to False"
617 else
618 create_public_bridge
619 fi
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400620 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400621 fi
622}
623
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100624# Start running processes
625function start_neutron_service_and_check {
626 local service_port=$Q_PORT
627 local service_protocol=$Q_PROTOCOL
628 local cfg_file_options
629 local neutron_url
Sean M. Collins2a242512016-05-03 09:03:09 -0400630
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100631 cfg_file_options="$(determine_config_files neutron-server)"
Sean M. Collins2a242512016-05-03 09:03:09 -0400632
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100633 if is_service_enabled tls-proxy; then
634 service_port=$Q_PORT_INT
635 service_protocol="http"
Sean M. Collins2a242512016-05-03 09:03:09 -0400636 fi
Rodolfo Alonso Hernandez79a812a2024-07-31 14:41:33 +0000637
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100638 # Start the Neutron service
639 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
Rodolfo Alonso Hernandez79a812a2024-07-31 14:41:33 +0000640 # The default value of "rpc_workers" is None (not defined). If
641 # "rpc_workers" is explicitly set to 0, the RPC workers process
642 # should not be executed.
643 local rpc_workers
644 rpc_workers=$(iniget_multiline $NEUTRON_CONF DEFAULT rpc_workers)
645
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100646 enable_service neutron-api
647 run_process neutron-api "$(which uwsgi) --procname-prefix neutron-api --ini $NEUTRON_UWSGI_CONF"
648 neutron_url=$Q_PROTOCOL://$Q_HOST/
Rodolfo Alonso Hernandez79a812a2024-07-31 14:41:33 +0000649 if [ "$rpc_workers" != "0" ]; then
Rodolfo Alonso Hernandezaaaa0372024-07-19 08:09:25 +0000650 enable_service neutron-rpc-server
651 fi
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000652 enable_service neutron-periodic-workers
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000653 _enable_ovn_maintenance
Rodolfo Alonso Hernandez79a812a2024-07-31 14:41:33 +0000654 if [ "$rpc_workers" != "0" ]; then
Rodolfo Alonso Hernandezaaaa0372024-07-19 08:09:25 +0000655 run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $cfg_file_options"
656 fi
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000657 run_process neutron-periodic-workers "$NEUTRON_BIN_DIR/neutron-periodic-workers $cfg_file_options"
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000658 _run_ovn_maintenance
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100659 else
660 run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
661 neutron_url=$service_protocol://$Q_HOST:$service_port/
662 # Start proxy if enabled
663 if is_service_enabled tls-proxy; then
664 start_tls_proxy neutron '*' $Q_PORT $Q_HOST $Q_PORT_INT
665 fi
666 fi
667 if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then
668 neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME
669 fi
670 echo "Waiting for Neutron to start..."
Sean M. Collins2a242512016-05-03 09:03:09 -0400671
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100672 local testcmd="wget ${ssl_ca} --no-proxy -q -O- $neutron_url"
673 test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900674}
675
Sean M. Collins2a242512016-05-03 09:03:09 -0400676function start_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100677 start_l2_agent "$@"
678 start_other_agents "$@"
679}
680
681# Control of the l2 agent is separated out to make it easier to test partial
682# upgrades (everything upgraded except the L2 agent)
683function start_l2_agent {
684 run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
685
686 if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then
687 sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
688 sudo ip link set $OVS_PHYSICAL_BRIDGE up
689 sudo ip link set br-int up
690 sudo ip link set $PUBLIC_INTERFACE up
691 if is_ironic_hardware; then
692 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
693 sudo ip addr del $IP dev $PUBLIC_INTERFACE
694 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
695 done
696 sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
697 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400698 fi
699}
700
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100701function start_other_agents {
702 run_process q-dhcp "$AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file $Q_DHCP_CONF_FILE"
703
704 run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
705
706 run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file $Q_META_CONF_FILE"
707 run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
708}
709
710# Start running processes, including screen
711function start_neutron_agents {
712 # NOTE(slaweq): it's now just a wrapper for start_neutron function
713 start_neutron "$@"
714}
715
716function stop_l2_agent {
717 stop_process q-agt
718}
719
720# stop_other() - Stop running processes
721function stop_other {
722 if is_service_enabled q-dhcp neutron-dhcp; then
723 stop_process q-dhcp
724 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
725 [ ! -z "$pid" ] && sudo kill -9 $pid
726 fi
727
728 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
729 stop_process neutron-rpc-server
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000730 stop_process neutron-periodic-workers
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100731 stop_process neutron-api
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000732 _stop_ovn_maintenance
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100733 else
734 stop_process q-svc
735 fi
736
737 if is_service_enabled q-l3 neutron-l3; then
738 sudo pkill -f "radvd -C $DATA_DIR/neutron/ra"
739 stop_process q-l3
740 fi
741
742 if is_service_enabled q-meta neutron-metadata-agent; then
743 stop_process q-meta
744 fi
745
746 if is_service_enabled q-metering neutron-metering; then
747 neutron_metering_stop
748 fi
749
750 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Bence Romsics71c3c402022-12-21 13:50:54 +0100751 # pkill takes care not to kill itself, but it may kill its parent
752 # sudo unless we use the "ps | grep [f]oo" trick
753 sudo pkill -9 -f "$NEUTRON_ROOTWRAP-[d]aemon" || :
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100754 fi
755}
756
757# stop_neutron() - Stop running processes (non-screen)
Sean M. Collins2a242512016-05-03 09:03:09 -0400758function stop_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100759 stop_other
760 stop_l2_agent
761
762 if [[ $Q_AGENT == "ovn" && $SKIP_STOP_OVN != "True" ]]; then
763 stop_ovn
Sean M. Collins2a242512016-05-03 09:03:09 -0400764 fi
765}
766
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100767# _move_neutron_addresses_route() - Move the primary IP to the OVS bridge
768# on startup, or back to the public interface on cleanup. If no IP is
769# configured on the interface, just add it as a port to the OVS bridge.
770function _move_neutron_addresses_route {
771 local from_intf=$1
772 local to_intf=$2
773 local add_ovs_port=$3
774 local del_ovs_port=$4
775 local af=$5
776
777 if [[ -n "$from_intf" && -n "$to_intf" ]]; then
778 # Remove the primary IP address from $from_intf and add it to $to_intf,
779 # along with the default route, if it exists. Also, when called
780 # on configure we will also add $from_intf as a port on $to_intf,
781 # assuming it is an OVS bridge.
782
783 local IP_REPLACE=""
784 local IP_DEL=""
785 local IP_UP=""
786 local DEFAULT_ROUTE_GW
787 DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf\s/ { print \$3; exit }")
788 local ADD_OVS_PORT=""
789 local DEL_OVS_PORT=""
790 local ARP_CMD=""
791
792 IP_BRD=$(ip -f $af a s dev $from_intf scope global primary | grep inet | awk '{ print $2, $3, $4; exit }')
793
794 if [ "$DEFAULT_ROUTE_GW" != "" ]; then
795 ADD_DEFAULT_ROUTE="sudo ip -f $af r replace default via $DEFAULT_ROUTE_GW dev $to_intf"
796 fi
797
798 if [[ "$add_ovs_port" == "True" ]]; then
799 ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf"
800 fi
801
802 if [[ "$del_ovs_port" == "True" ]]; then
803 DEL_OVS_PORT="sudo ovs-vsctl --if-exists del-port $from_intf $to_intf"
804 fi
805
806 if [[ "$IP_BRD" != "" ]]; then
807 IP_DEL="sudo ip addr del $IP_BRD dev $from_intf"
808 IP_REPLACE="sudo ip addr replace $IP_BRD dev $to_intf"
809 IP_UP="sudo ip link set $to_intf up"
810 if [[ "$af" == "inet" ]]; then
811 IP=$(echo $IP_BRD | awk '{ print $1; exit }' | grep -o -E '(.*)/' | cut -d "/" -f1)
812 ARP_CMD="sudo arping -A -c 3 -w 5 -I $to_intf $IP "
813 fi
814 fi
815
816 # The add/del OVS port calls have to happen either before or
817 # after the address is moved in order to not leave it orphaned.
818 $DEL_OVS_PORT; $IP_DEL; $IP_REPLACE; $IP_UP; $ADD_OVS_PORT; $ADD_DEFAULT_ROUTE; $ARP_CMD
819 fi
820}
821
822# _configure_public_network_connectivity() - Configures connectivity to the
823# external network using $PUBLIC_INTERFACE or NAT on the single interface
824# machines
825function _configure_public_network_connectivity {
826 # If we've given a PUBLIC_INTERFACE to take over, then we assume
827 # that we can own the whole thing, and privot it into the OVS
828 # bridge. If we are not, we're probably on a single interface
829 # machine, and we just setup NAT so that fixed guests can get out.
830 if [[ -n "$PUBLIC_INTERFACE" ]]; then
831 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" True False "inet"
832
833 if [[ $(ip -f inet6 a s dev "$PUBLIC_INTERFACE" | grep -c 'global') != 0 ]]; then
834 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" False False "inet6"
835 fi
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -0500836 else
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100837 for d in $default_v4_route_devs; do
838 sudo iptables -t nat -A POSTROUTING -o $d -s $FLOATING_RANGE -j MASQUERADE
839 done
840 fi
841}
842
843# cleanup_neutron() - Remove residual data files, anything left over from previous
844# runs that a clean run would need to clean up
845function cleanup_neutron {
846 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
847 stop_process neutron-api
848 stop_process neutron-rpc-server
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000849 stop_process neutron-periodic-workers
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000850 _stop_ovn_maintenance
Stephen Finucaned5182ce2024-04-19 12:27:14 +0100851 remove_uwsgi_config "$NEUTRON_UWSGI_CONF" "neutron-api"
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100852 sudo rm -f $(apache_site_config_for neutron-api)
853 fi
854
855 if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then
856 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False True "inet"
857
858 if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then
859 # ip(8) wants the prefix length when deleting
860 local v6_gateway
861 v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }')
862 sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE
863 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False False "inet6"
864 fi
865
866 if is_provider_network && is_ironic_hardware; then
867 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
868 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
869 sudo ip addr add $IP dev $PUBLIC_INTERFACE
870 done
871 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
872 fi
873 fi
874
875 if is_neutron_ovs_base_plugin; then
876 neutron_ovs_base_cleanup
877 fi
878
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100879 # delete all namespaces created by neutron
880 for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|fip|snat)-[0-9a-f-]*'); do
881 sudo ip netns delete ${ns}
882 done
883
884 if [[ $Q_AGENT == "ovn" ]]; then
885 cleanup_ovn
886 fi
887}
888
889
890function _create_neutron_conf_dir {
891 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
892 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
893}
894
895# _configure_neutron_common()
896# Set common config for all neutron server and agents.
897# This MUST be called before other ``_configure_neutron_*`` functions.
898function _configure_neutron_common {
899 _create_neutron_conf_dir
900
901 # Uses oslo config generator to generate core sample configuration files
902 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
903
904 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
905
906 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
907
908 # allow neutron user to administer neutron to match neutron account
909 # NOTE(amotoki): This is required for nova works correctly with neutron.
910 if [ -f $NEUTRON_DIR/etc/policy.json ]; then
911 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
912 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
913 else
914 echo '{"context_is_admin": "role:admin or user_name:neutron"}' > $Q_POLICY_FILE
915 fi
916
917 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
918 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
919 neutron_plugin_configure_common
920
921 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
922 die $LINENO "Neutron plugin not set.. exiting"
923 fi
924
925 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
926 mkdir -p /$Q_PLUGIN_CONF_PATH
927 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
928 # NOTE(slaweq): NEUTRON_CORE_PLUGIN_CONF is used e.g. in neutron repository,
929 # it was previously defined in the lib/neutron module which is now deleted.
930 NEUTRON_CORE_PLUGIN_CONF=$Q_PLUGIN_CONF_FILE
931 # NOTE(hichihara): Some neutron vendor plugins were already decomposed and
932 # there is no config file in Neutron tree. They should prepare the file in each plugin.
933 if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then
934 cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE
935 elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then
936 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
937 fi
938
939 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
940 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
941 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
942 iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS
943 iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock
944
945 # NOTE(freerunner): Need to adjust Region Name for nova in multiregion installation
946 iniset $NEUTRON_CONF nova region_name $REGION_NAME
947
948 if [ "$VIRT_DRIVER" = 'fake' ]; then
949 # Disable arbitrary limits
950 iniset $NEUTRON_CONF quotas quota_network -1
951 iniset $NEUTRON_CONF quotas quota_subnet -1
952 iniset $NEUTRON_CONF quotas quota_port -1
953 iniset $NEUTRON_CONF quotas quota_security_group -1
954 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
955 fi
956
957 # Format logging
958 setup_logging $NEUTRON_CONF
959
960 if is_service_enabled tls-proxy && [ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" ]; then
961 # Set the service port for a proxy to take the original
962 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
963 iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True
964 fi
965
966 _neutron_setup_rootwrap
967}
968
969function _configure_neutron_dhcp_agent {
970
971 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE
972
973 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
974 # make it so we have working DNS from guests
975 iniset $Q_DHCP_CONF_FILE DEFAULT dnsmasq_local_resolv True
976 configure_root_helper_options $Q_DHCP_CONF_FILE
977
978 if ! is_service_enabled q-l3 neutron-l3; then
979 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
980 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
981 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
982 else
983 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
984 die "$LINENO" "Enable isolated metadata is a must for metadata network"
985 fi
986 fi
987 fi
988
989 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
990
991 neutron_plugin_configure_dhcp_agent $Q_DHCP_CONF_FILE
992}
993
994
995function _configure_neutron_metadata_agent {
996 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE
997
998 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
999 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_host $Q_META_DATA_IP
1000 iniset $Q_META_CONF_FILE DEFAULT metadata_workers $API_WORKERS
1001 configure_root_helper_options $Q_META_CONF_FILE
1002}
1003
1004function _configure_neutron_ceilometer_notifications {
1005 iniset $NEUTRON_CONF oslo_messaging_notifications driver messagingv2
1006}
1007
1008function _configure_neutron_metering {
1009 neutron_agent_metering_configure_common
1010 neutron_agent_metering_configure_agent
1011}
1012
1013function _configure_dvr {
1014 iniset $NEUTRON_CONF DEFAULT router_distributed True
1015 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
1016}
1017
1018
1019# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
1020# It is called when q-agt is enabled.
1021function _configure_neutron_plugin_agent {
1022 # Specify the default root helper prior to agent configuration to
1023 # ensure that an agent's configuration can override the default
1024 configure_root_helper_options /$Q_PLUGIN_CONF_FILE
1025 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1026
1027 # Configure agent for plugin
1028 neutron_plugin_configure_plugin_agent
1029}
1030
1031function _replace_api_paste_composite {
1032 local sep
1033 sep=$(echo -ne "\x01")
1034 # Replace it
1035 $sudo sed -i -e "s/\/\: neutronversions_composite/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/\: neutronversions_composite/" "$Q_API_PASTE_FILE"
1036 $sudo sed -i -e "s/\/healthcheck\: healthcheck/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/healthcheck\: healthcheck/" "$Q_API_PASTE_FILE"
1037 $sudo sed -i -e "s/\/v2.0\: neutronapi_v2_0/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/v2.0\: neutronapi_v2_0/" "$Q_API_PASTE_FILE"
1038}
1039
1040# _configure_neutron_service() - Set config files for neutron service
1041# It is called when q-svc is enabled.
1042function _configure_neutron_service {
1043 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
1044 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
1045
Slawek Kaplonskib500d802024-06-14 12:58:58 +02001046 if [[ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" && -n "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001047 _replace_api_paste_composite
1048 fi
1049
1050 # Update either configuration file with plugin
1051 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
1052
1053 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1054 iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE
1055
1056 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
1057 configure_keystone_authtoken_middleware $NEUTRON_CONF $Q_ADMIN_USERNAME
1058
1059 # Configuration for neutron notifications to nova.
1060 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
1061 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
1062
1063 configure_keystone_authtoken_middleware $NEUTRON_CONF nova nova
1064
1065 # Configuration for placement client
1066 configure_keystone_authtoken_middleware $NEUTRON_CONF placement placement
1067
1068 # Configure plugin
1069 neutron_plugin_configure_service
1070}
1071
1072# Utility Functions
1073#------------------
1074
1075# neutron_service_plugin_class_add() - add service plugin class
1076function neutron_service_plugin_class_add {
1077 local service_plugin_class=$1
1078 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
1079 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
1080 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
1081 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
1082 fi
1083}
1084
1085# neutron_ml2_extension_driver_add() - add ML2 extension driver
1086function neutron_ml2_extension_driver_add {
1087 local extension=$1
1088 if [[ $Q_ML2_PLUGIN_EXT_DRIVERS == '' ]]; then
1089 Q_ML2_PLUGIN_EXT_DRIVERS=$extension
1090 elif [[ ! ,${Q_ML2_PLUGIN_EXT_DRIVERS}, =~ ,${extension}, ]]; then
1091 Q_ML2_PLUGIN_EXT_DRIVERS="$Q_ML2_PLUGIN_EXT_DRIVERS,$extension"
1092 fi
1093}
1094
1095# neutron_server_config_add() - add server config file
1096function neutron_server_config_add {
1097 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($1)
1098}
1099
1100# neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root).
1101function neutron_deploy_rootwrap_filters {
1102 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1103 return
1104 fi
1105 local srcdir=$1
1106 sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D
1107 sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
1108}
1109
1110# _neutron_setup_rootwrap() - configure Neutron's rootwrap
1111function _neutron_setup_rootwrap {
1112 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1113 return
1114 fi
1115 # Wipe any existing ``rootwrap.d`` files first
1116 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
1117 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
1118 sudo rm -rf $Q_CONF_ROOTWRAP_D
1119 fi
1120
1121 neutron_deploy_rootwrap_filters $NEUTRON_DIR
1122
1123 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
1124 # location moved in newer versions, prefer new location
1125 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
1126 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
1127 else
1128 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
1129 fi
1130 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
yatinkarelffc1b762023-08-28 10:52:26 +05301131 # Rely on $PATH set by devstack to determine what is safe to execute
1132 # by rootwrap rather than use explicit whitelist of paths in
1133 # rootwrap.conf
1134 sudo sed -e 's/^exec_dirs=.*/#&/' -i $Q_RR_CONF_FILE
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001135
1136 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
1137 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
1138 ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
1139
1140 # Set up the rootwrap sudoers for neutron
1141 TEMPFILE=`mktemp`
1142 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
1143 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE
1144 chmod 0440 $TEMPFILE
1145 sudo chown root:root $TEMPFILE
1146 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
1147
1148 # Update the root_helper
1149 configure_root_helper_options $NEUTRON_CONF
1150}
1151
1152function configure_root_helper_options {
1153 local conffile=$1
1154 iniset $conffile agent root_helper "$Q_RR_COMMAND"
1155 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
1156 iniset $conffile agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
1157 fi
1158}
1159
1160function _neutron_setup_interface_driver {
1161
1162 # ovs_use_veth needs to be set before the plugin configuration
1163 # occurs to allow plugins to override the setting.
1164 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1165
1166 neutron_plugin_setup_interface_driver $1
1167}
1168# Functions for Neutron Exercises
1169#--------------------------------
1170
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001171# ssh check
1172function _ssh_check_neutron {
1173 local from_net=$1
1174 local key_file=$2
1175 local ip=$3
1176 local user=$4
1177 local timeout_sec=$5
1178 local probe_cmd = ""
1179 probe_cmd=`_get_probe_cmd_prefix $from_net`
1180 local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success"
1181 test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec
1182}
1183
1184function plugin_agent_add_l2_agent_extension {
1185 local l2_agent_extension=$1
1186 if [[ -z "$L2_AGENT_EXTENSIONS" ]]; then
1187 L2_AGENT_EXTENSIONS=$l2_agent_extension
1188 elif [[ ! ,${L2_AGENT_EXTENSIONS}, =~ ,${l2_agent_extension}, ]]; then
1189 L2_AGENT_EXTENSIONS+=",$l2_agent_extension"
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -05001190 fi
1191}
1192
Sean M. Collins2a242512016-05-03 09:03:09 -04001193# Restore xtrace
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001194$_XTRACE_NEUTRON
1195
1196# Tell emacs to use shell-script-mode
1197## Local variables:
1198## mode: shell-script
1199## End: