blob: 2325188f9467f2577914502c01f69e7ce3242fe8 [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}
Rodolfo Alonso Hernandezaaaa0372024-07-19 08:09:25 +0000146_Q_RUN_RPC_SERVER=True
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100147VIF_PLUGGING_IS_FATAL=${VIF_PLUGGING_IS_FATAL:-True}
148VIF_PLUGGING_TIMEOUT=${VIF_PLUGGING_TIMEOUT:-300}
Sean M. Collins2a242512016-05-03 09:03:09 -0400149
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100150# Allow to skip stopping of OVN services
151SKIP_STOP_OVN=${SKIP_STOP_OVN:-False}
Sean M. Collins2a242512016-05-03 09:03:09 -0400152
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100153# The directory which contains files for Q_PLUGIN_EXTRA_CONF_FILES.
154# /etc/neutron is assumed by many of devstack plugins. Do not change.
155_Q_PLUGIN_EXTRA_CONF_PATH=/etc/neutron
Julia Kreger6e5b1382019-01-09 17:00:45 -0800156
Slawek Kaplonski1a21ccb2022-07-08 21:57:45 +0200157# The name of the service in the endpoint URL
158NEUTRON_ENDPOINT_SERVICE_NAME=${NEUTRON_ENDPOINT_SERVICE_NAME-"networking"}
159if [[ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" && -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then
160 NEUTRON_ENDPOINT_SERVICE_NAME="networking"
161fi
162
elajkatbb0c2732023-11-16 11:30:04 +0100163# Source install libraries
164ALEMBIC_REPO=${ALEMBIC_REPO:-https://github.com/sqlalchemy/alembic.git}
165ALEMBIC_DIR=${ALEMBIC_DIR:-$DEST/alembic}
166ALEMBIC_BRANCH=${ALEMBIC_BRANCH:-main}
167SQLALCHEMY_REPO=${SQLALCHEMY_REPO:-https://github.com/sqlalchemy/sqlalchemy.git}
168SQLALCHEMY_DIR=${SQLALCHEMY_DIR:-$DEST/sqlalchemy}
169SQLALCHEMY_BRANCH=${SQLALCHEMY_BRANCH:-main}
170
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100171# List of config file names in addition to the main plugin config file
172# To add additional plugin config files, use ``neutron_server_config_add``
173# utility function. For example:
174#
175# ``neutron_server_config_add file1``
176#
177# These config files are relative to ``/etc/neutron``. The above
178# example would specify ``--config-file /etc/neutron/file1`` for
179# neutron server.
180declare -a -g Q_PLUGIN_EXTRA_CONF_FILES
Julia Kreger6e5b1382019-01-09 17:00:45 -0800181
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100182# same as Q_PLUGIN_EXTRA_CONF_FILES, but with absolute path.
183declare -a -g _Q_PLUGIN_EXTRA_CONF_FILES_ABS
184
185
186Q_RR_CONF_FILE=$NEUTRON_CONF_DIR/rootwrap.conf
187if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
188 Q_RR_COMMAND="sudo"
189else
190 NEUTRON_ROOTWRAP=$(get_rootwrap_location neutron)
191 Q_RR_COMMAND="sudo $NEUTRON_ROOTWRAP $Q_RR_CONF_FILE"
192 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
193 Q_RR_DAEMON_COMMAND="sudo $NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
194 fi
195fi
196
197
198# Distributed Virtual Router (DVR) configuration
199# Can be:
200# - ``legacy`` - No DVR functionality
201# - ``dvr_snat`` - Controller or single node DVR
202# - ``dvr`` - Compute node in multi-node DVR
203# - ``dvr_no_external`` - Compute node in multi-node DVR, no external network
204#
205Q_DVR_MODE=${Q_DVR_MODE:-legacy}
206if [[ "$Q_DVR_MODE" != "legacy" ]]; then
207 Q_ML2_PLUGIN_MECHANISM_DRIVERS=openvswitch,l2population
208fi
209
210# Provider Network Configurations
211# --------------------------------
212
213# The following variables control the Neutron ML2 plugins' allocation
214# of tenant networks and availability of provider networks. If these
215# are not configured in ``localrc``, tenant networks will be local to
216# the host (with no remote connectivity), and no physical resources
217# will be available for the allocation of provider networks.
218
219# To disable tunnels (GRE or VXLAN) for tenant networks,
220# set to False in ``local.conf``.
221# GRE tunnels are only supported by the openvswitch.
222ENABLE_TENANT_TUNNELS=${ENABLE_TENANT_TUNNELS:-True}
223
224# If using GRE, VXLAN or GENEVE tunnels for tenant networks,
225# specify the range of IDs from which tenant networks are
226# allocated. Can be overridden in ``localrc`` if necessary.
227TENANT_TUNNEL_RANGES=${TENANT_TUNNEL_RANGES:-1:1000}
228
229# To use VLANs for tenant networks, set to True in localrc. VLANs
230# are supported by the ML2 plugins, requiring additional configuration
231# described below.
232ENABLE_TENANT_VLANS=${ENABLE_TENANT_VLANS:-False}
233
234# If using VLANs for tenant networks, set in ``localrc`` to specify
235# the range of VLAN VIDs from which tenant networks are
236# allocated. An external network switch must be configured to
237# trunk these VLANs between hosts for multi-host connectivity.
238#
239# Example: ``TENANT_VLAN_RANGE=1000:1999``
240TENANT_VLAN_RANGE=${TENANT_VLAN_RANGE:-}
241
242# If using VLANs for tenant networks, or if using flat or VLAN
243# provider networks, set in ``localrc`` to the name of the physical
244# network, and also configure ``OVS_PHYSICAL_BRIDGE`` for the
245# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
246# agent, as described below.
247#
248# Example: ``PHYSICAL_NETWORK=default``
249PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-public}
250
251# With the openvswitch agent, if using VLANs for tenant networks,
252# or if using flat or VLAN provider networks, set in ``localrc`` to
253# the name of the OVS bridge to use for the physical network. The
254# bridge will be created if it does not already exist, but a
255# physical interface must be manually added to the bridge as a
256# port for external connectivity.
257#
258# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
259OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-br-ex}
260
261# With the linuxbridge agent, if using VLANs for tenant networks,
262# or if using flat or VLAN provider networks, set in ``localrc`` to
263# the name of the network interface to use for the physical
264# network.
265#
266# Example: ``LB_PHYSICAL_INTERFACE=eth1``
267if [[ $Q_AGENT == "linuxbridge" && -z ${LB_PHYSICAL_INTERFACE} ]]; then
268 default_route_dev=$( (ip route; ip -6 route) | grep ^default | head -n 1 | awk '{print $5}')
269 die_if_not_set $LINENO default_route_dev "Failure retrieving default route device"
270 LB_PHYSICAL_INTERFACE=$default_route_dev
271fi
272
273# With the openvswitch plugin, set to True in ``localrc`` to enable
274# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
275#
276# Example: ``OVS_ENABLE_TUNNELING=True``
277OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
278
279# Use DHCP agent for providing metadata service in the case of
280# without L3 agent (No Route Agent), set to True in localrc.
281ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
282
283# Add a static route as dhcp option, so the request to 169.254.169.254
284# will be able to reach through a route(DHCP agent)
285# This option require ENABLE_ISOLATED_METADATA = True
286ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
287# Neutron plugin specific functions
288# ---------------------------------
289
290# Please refer to ``lib/neutron_plugins/README.md`` for details.
291if [ -f $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN ]; then
292 source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
293fi
294
295# Agent metering service plugin functions
296# -------------------------------------------
297
298# Hardcoding for 1 service plugin for now
299source $TOP_DIR/lib/neutron_plugins/services/metering
300
301# L3 Service functions
302source $TOP_DIR/lib/neutron_plugins/services/l3
303
304# Additional Neutron service plugins
305source $TOP_DIR/lib/neutron_plugins/services/placement
306source $TOP_DIR/lib/neutron_plugins/services/trunk
307source $TOP_DIR/lib/neutron_plugins/services/qos
elajkata84b2092021-11-17 11:52:56 +0100308source $TOP_DIR/lib/neutron_plugins/services/segments
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100309
310# Use security group or not
311if has_neutron_plugin_security_group; then
312 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
313else
314 Q_USE_SECGROUP=False
315fi
316
Harald Jensås16ac21f2023-08-31 15:06:52 +0200317# OVN_BRIDGE_MAPPINGS - ovn-bridge-mappings
318# NOTE(hjensas): Initialize after sourcing neutron_plugins/services/l3
319# which initialize PUBLIC_BRIDGE.
320OVN_BRIDGE_MAPPINGS=${OVN_BRIDGE_MAPPINGS:-$PHYSICAL_NETWORK:$PUBLIC_BRIDGE}
321
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100322# Save trace setting
323_XTRACE_NEUTRON=$(set +o | grep xtrace)
324set +o xtrace
325
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900326
Sean M. Collins2a242512016-05-03 09:03:09 -0400327# Functions
328# ---------
329
330# Test if any Neutron services are enabled
331# is_neutron_enabled
332function is_neutron_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -0700333 [[ ,${DISABLED_SERVICES} =~ ,"neutron" ]] && return 1
Sean M. Collins2a242512016-05-03 09:03:09 -0400334 [[ ,${ENABLED_SERVICES} =~ ,"neutron-" || ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
335 return 1
336}
337
338# Test if any Neutron services are enabled
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100339# TODO(slaweq): this is not really needed now and we should remove it as soon
340# as it will not be called from any other Devstack plugins, like e.g. Neutron
341# plugin
Sean M. Collins2a242512016-05-03 09:03:09 -0400342function is_neutron_legacy_enabled {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100343 return 0
Sean M. Collins2a242512016-05-03 09:03:09 -0400344}
345
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100346function _determine_config_server {
347 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" != '' ]]; then
348 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" = "$_Q_PLUGIN_EXTRA_CONF_PATH" ]]; then
349 deprecated "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
350 else
351 die $LINENO "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
352 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400353 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100354 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 ]]; then
355 deprecated "Q_PLUGIN_EXTRA_CONF_FILES is deprecated. Use neutron_server_config_add instead."
Sean M. Collins2a242512016-05-03 09:03:09 -0400356 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100357 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
358 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($_Q_PLUGIN_EXTRA_CONF_PATH/$cfg_file)
Sean M. Collins2a242512016-05-03 09:03:09 -0400359 done
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100360
361 local cfg_file
362 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
363 for cfg_file in ${_Q_PLUGIN_EXTRA_CONF_FILES_ABS[@]}; do
364 opts+=" --config-file $cfg_file"
365 done
366 echo "$opts"
Sean M. Collins2a242512016-05-03 09:03:09 -0400367}
368
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100369function _determine_config_l3 {
370 local opts="--config-file $NEUTRON_CONF --config-file $Q_L3_CONF_FILE"
371 echo "$opts"
Ihar Hrachyshkae65ab4a2017-02-24 17:47:55 +0000372}
373
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000374function _enable_ovn_maintenance {
375 if [[ $Q_AGENT == "ovn" ]]; then
376 enable_service neutron-ovn-maintenance-worker
377 fi
378}
379
380function _run_ovn_maintenance {
381 if [[ $Q_AGENT == "ovn" ]]; then
382 run_process neutron-ovn-maintenance-worker "$NEUTRON_BIN_DIR/neutron-ovn-maintenance-worker $cfg_file_options"
383 fi
384}
385
386function _stop_ovn_maintenance {
387 if [[ $Q_AGENT == "ovn" ]]; then
388 stop_process neutron-ovn-maintenance-worker
389 fi
390}
391
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100392# For services and agents that require it, dynamically construct a list of
393# --config-file arguments that are passed to the binary.
394function determine_config_files {
395 local opts=""
396 case "$1" in
397 "neutron-server") opts="$(_determine_config_server)" ;;
398 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
399 esac
400 if [ -z "$opts" ] ; then
401 die $LINENO "Could not determine config files for $1."
YAMAMOTO Takashi1df17c92017-05-01 17:00:42 +0900402 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100403 echo "$opts"
404}
Sean M. Collins2a242512016-05-03 09:03:09 -0400405
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100406# configure_neutron()
407# Set common config for all neutron server and agents.
408function configure_neutron {
409 _configure_neutron_common
Sean M. Collins5394cc12016-05-11 15:03:38 -0400410 iniset_rpc_backend neutron $NEUTRON_CONF
411
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100412 if is_service_enabled q-metering neutron-metering; then
413 _configure_neutron_metering
414 fi
415 if is_service_enabled q-agt neutron-agent; then
416 _configure_neutron_plugin_agent
417 fi
418 if is_service_enabled q-dhcp neutron-dhcp; then
419 _configure_neutron_dhcp_agent
420 fi
421 if is_service_enabled q-l3 neutron-l3; then
422 _configure_neutron_l3_agent
423 fi
424 if is_service_enabled q-meta neutron-metadata-agent; then
425 _configure_neutron_metadata_agent
Sean M. Collins2a242512016-05-03 09:03:09 -0400426 fi
427
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100428 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
429 _configure_dvr
430 fi
431 if is_service_enabled ceilometer; then
432 _configure_neutron_ceilometer_notifications
433 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400434
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100435 if [[ $Q_AGENT == "ovn" ]]; then
436 configure_ovn
437 configure_ovn_plugin
438 fi
Brian Haley9aaa5292017-09-20 14:23:05 -0400439
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100440 # Configure Neutron's advanced services
441 if is_service_enabled q-placement neutron-placement; then
442 configure_placement_extension
443 fi
444 if is_service_enabled q-trunk neutron-trunk; then
445 configure_trunk_extension
446 fi
447 if is_service_enabled q-qos neutron-qos; then
448 configure_qos
449 if is_service_enabled q-l3 neutron-l3; then
450 configure_l3_agent_extension_fip_qos
451 configure_l3_agent_extension_gateway_ip_qos
Denis Buliga0bf75a42017-02-06 16:56:46 +0200452 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400453 fi
elajkata84b2092021-11-17 11:52:56 +0100454 if is_service_enabled neutron-segments; then
455 configure_placement_neutron
456 configure_segments_extension
457 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400458
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100459 # Finally configure Neutron server and core plugin
460 if is_service_enabled q-agt neutron-agent q-svc neutron-api; then
461 _configure_neutron_service
Sean M. Collins2a242512016-05-03 09:03:09 -0400462 fi
463
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100464 iniset $NEUTRON_CONF DEFAULT api_workers "$API_WORKERS"
465 # devstack is not a tool for running uber scale OpenStack
466 # clouds, therefore running without a dedicated RPC worker
467 # for state reports is more than adequate.
468 iniset $NEUTRON_CONF DEFAULT rpc_state_report_workers 0
Rodolfo Alonso Hernandezaaaa0372024-07-19 08:09:25 +0000469 # The default value of "rpc_workers" is None (not defined). If
470 # "rpc_workers" is explicitly set to 0, the RPC workers process should not
471 # be executed. NOTE: this service is only executed when WSGI is enabled
472 # (NEUTRON_DEPLOY_MOD_WSGI=True) for the Neutron server.
473 local rpc_workers
474 rpc_workers=$(iniget_multiline /etc/neutron/neutron.conf DEFAULT rpc_workers)
Rodolfo Alonso Hernandez13888a32024-07-20 15:50:30 +0000475 if [ "$rpc_workers" == "0" ]; then
Rodolfo Alonso Hernandezaaaa0372024-07-19 08:09:25 +0000476 _Q_RUN_RPC_SERVER=False
477 fi
Ihar Hrachyshkae3915932017-02-24 06:24:47 +0000478
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100479 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
Stephen Finucane0cd87632024-04-19 12:12:16 +0100480 write_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_UWSGI" "/networking" "" "neutron-api"
Sean M. Collins8063fee2016-05-24 11:27:36 -0700481 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400482}
483
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100484function configure_neutron_nova {
485 create_nova_conf_neutron $NOVA_CONF
486 if [[ "${CELLSV2_SETUP}" == "superconductor" ]]; then
487 for i in $(seq 1 $NOVA_NUM_CELLS); do
488 local conf
489 conf=$(conductor_conf $i)
490 create_nova_conf_neutron $conf
491 done
Sean M. Collins2a242512016-05-03 09:03:09 -0400492 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400493}
494
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100495function create_nova_conf_neutron {
Lucas Alvares Gomese6385932018-06-28 11:00:28 +0100496 local conf=${1:-$NOVA_CONF}
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400497 iniset $conf neutron auth_type "password"
498 iniset $conf neutron auth_url "$KEYSTONE_SERVICE_URI"
Dr. Jens Harbott696dbdf2024-07-09 16:36:37 +0200499 iniset $conf neutron username nova
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400500 iniset $conf neutron password "$SERVICE_PASSWORD"
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100501 iniset $conf neutron user_domain_name "$SERVICE_DOMAIN_NAME"
502 iniset $conf neutron project_name "$SERVICE_PROJECT_NAME"
503 iniset $conf neutron project_domain_name "$SERVICE_DOMAIN_NAME"
504 iniset $conf neutron auth_strategy "$Q_AUTH_STRATEGY"
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400505 iniset $conf neutron region_name "$REGION_NAME"
Sean M. Collins2a242512016-05-03 09:03:09 -0400506
Gary Kotton88f85582016-08-14 06:55:42 -0700507 # optionally set options in nova_conf
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400508 neutron_plugin_create_nova_conf $conf
Gary Kotton88f85582016-08-14 06:55:42 -0700509
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100510 if is_service_enabled q-meta neutron-metadata-agent; then
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400511 iniset $conf neutron service_metadata_proxy "True"
Sean M. Collins2a242512016-05-03 09:03:09 -0400512 fi
513
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100514 iniset $conf DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
515 iniset $conf DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Sean M. Collins2a242512016-05-03 09:03:09 -0400516}
517
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100518# create_neutron_accounts() - Set up common required neutron accounts
519
Sean M. Collins2a242512016-05-03 09:03:09 -0400520# Tenant User Roles
521# ------------------------------------------------------------------
522# service neutron admin # if enabled
523
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100524# Migrated from keystone_data.sh
525function create_neutron_accounts {
Kevin Benton66b361b2017-06-13 00:31:01 -0700526 local neutron_url
Kevin Benton66b361b2017-06-13 00:31:01 -0700527 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100528 neutron_url=$Q_PROTOCOL://$SERVICE_HOST/
Kevin Benton66b361b2017-06-13 00:31:01 -0700529 else
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100530 neutron_url=$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/
Kevin Benton66b361b2017-06-13 00:31:01 -0700531 fi
Slawek Kaplonski1a21ccb2022-07-08 21:57:45 +0200532 if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then
533 neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME
534 fi
Kevin Benton66b361b2017-06-13 00:31:01 -0700535
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100536 if is_service_enabled q-svc neutron-api; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400537
538 create_service_user "neutron"
539
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100540 get_or_create_service "neutron" "network" "Neutron Service"
541 get_or_create_endpoint \
542 "network" \
Kevin Benton66b361b2017-06-13 00:31:01 -0700543 "$REGION_NAME" "$neutron_url"
Sean M. Collins2a242512016-05-03 09:03:09 -0400544 fi
545}
546
Sean M. Collins2a242512016-05-03 09:03:09 -0400547# init_neutron() - Initialize databases, etc.
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100548function init_neutron {
549 recreate_database $Q_DB_NAME
Clark Boylan633dbc32017-06-14 12:09:21 -0700550 time_start "dbsync"
Sean M. Collins2a242512016-05-03 09:03:09 -0400551 # Run Neutron db migrations
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100552 $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 -0700553 time_stop "dbsync"
Sean M. Collins2a242512016-05-03 09:03:09 -0400554}
555
556# install_neutron() - Collect source and prepare
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100557function install_neutron {
Sean M. Collins2a242512016-05-03 09:03:09 -0400558 # Install neutron-lib from git so we make sure we're testing
559 # the latest code.
560 if use_library_from_git "neutron-lib"; then
561 git_clone_by_name "neutron-lib"
562 setup_dev_lib "neutron-lib"
563 fi
564
elajkatbb0c2732023-11-16 11:30:04 +0100565 # Install SQLAlchemy and alembic from git when these are required
566 # see https://bugs.launchpad.net/neutron/+bug/2042941
567 if use_library_from_git "sqlalchemy"; then
568 git_clone $SQLALCHEMY_REPO $SQLALCHEMY_DIR $SQLALCHEMY_BRANCH
569 setup_develop $SQLALCHEMY_DIR
570 fi
571 if use_library_from_git "alembic"; then
572 git_clone $ALEMBIC_REPO $ALEMBIC_DIR $ALEMBIC_BRANCH
573 setup_develop $ALEMBIC_DIR
574 fi
575
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100576 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
577 setup_develop $NEUTRON_DIR
Sean M. Collins2a242512016-05-03 09:03:09 -0400578
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100579 if [[ $Q_AGENT == "ovn" ]]; then
580 install_ovn
Sean M. Collins2a242512016-05-03 09:03:09 -0400581 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400582}
583
584# install_neutronclient() - Collect source and prepare
585function install_neutronclient {
586 if use_library_from_git "python-neutronclient"; then
587 git_clone_by_name "python-neutronclient"
588 setup_dev_lib "python-neutronclient"
Sean M. Collins2a242512016-05-03 09:03:09 -0400589 fi
590}
591
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100592# install_neutron_agent_packages() - Collect source and prepare
593function install_neutron_agent_packages {
594 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
595 if is_service_enabled q-l3 neutron-l3; then
596 install_package radvd
Sean M. Collins2a242512016-05-03 09:03:09 -0400597 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100598 # install packages that are specific to plugin agent(s)
599 if is_service_enabled q-agt neutron-agent q-dhcp neutron-dhcp q-l3 neutron-l3; then
600 neutron_plugin_install_agent_packages
Sean M. Collins2a242512016-05-03 09:03:09 -0400601 fi
602}
603
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100604# Finish neutron configuration
605function configure_neutron_after_post_config {
606 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
607 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
Sean M. Collins2a242512016-05-03 09:03:09 -0400608 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100609 configure_rbac_policies
Sean M. Collins2a242512016-05-03 09:03:09 -0400610}
611
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +0200612# configure_rbac_policies() - Configure Neutron to enforce new RBAC
613# policies and scopes if NEUTRON_ENFORCE_SCOPE == True
614function configure_rbac_policies {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100615 if [[ "$NEUTRON_ENFORCE_SCOPE" == "True" || "$ENFORCE_SCOPE" == True ]]; then
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +0200616 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults True
617 iniset $NEUTRON_CONF oslo_policy enforce_scope True
618 else
619 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults False
620 iniset $NEUTRON_CONF oslo_policy enforce_scope False
621 fi
622}
623
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100624# Start running OVN processes
625function start_ovn_services {
626 if [[ $Q_AGENT == "ovn" ]]; then
Lucas Alvares Gomesa3891282023-07-18 16:31:28 +0100627 if [ "$VIRT_DRIVER" != 'ironic' ]; then
628 # NOTE(TheJulia): Ironic's devstack plugin needs to perform
629 # additional networking configuration to setup a working test
630 # environment with test virtual machines to emulate baremetal,
631 # which requires OVN to be up and running earlier to complete
632 # that base configuration.
633 init_ovn
634 start_ovn
635 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100636 if [[ "$OVN_L3_CREATE_PUBLIC_NETWORK" == "True" ]]; then
637 if [[ "$NEUTRON_CREATE_INITIAL_NETWORKS" != "True" ]]; then
638 echo "OVN_L3_CREATE_PUBLIC_NETWORK=True is being ignored "
639 echo "because NEUTRON_CREATE_INITIAL_NETWORKS is set to False"
640 else
641 create_public_bridge
642 fi
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400643 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400644 fi
645}
646
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100647# Start running processes
648function start_neutron_service_and_check {
649 local service_port=$Q_PORT
650 local service_protocol=$Q_PROTOCOL
651 local cfg_file_options
652 local neutron_url
Sean M. Collins2a242512016-05-03 09:03:09 -0400653
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100654 cfg_file_options="$(determine_config_files neutron-server)"
Sean M. Collins2a242512016-05-03 09:03:09 -0400655
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100656 if is_service_enabled tls-proxy; then
657 service_port=$Q_PORT_INT
658 service_protocol="http"
Sean M. Collins2a242512016-05-03 09:03:09 -0400659 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100660 # Start the Neutron service
661 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
662 enable_service neutron-api
663 run_process neutron-api "$(which uwsgi) --procname-prefix neutron-api --ini $NEUTRON_UWSGI_CONF"
664 neutron_url=$Q_PROTOCOL://$Q_HOST/
Rodolfo Alonso Hernandezaaaa0372024-07-19 08:09:25 +0000665 if [[ "$_Q_RUN_RPC_SERVER" = True ]]; then
666 enable_service neutron-rpc-server
667 fi
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000668 enable_service neutron-periodic-workers
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000669 _enable_ovn_maintenance
Rodolfo Alonso Hernandezaaaa0372024-07-19 08:09:25 +0000670 if [[ "$_Q_RUN_RPC_SERVER" = True ]]; then
671 run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $cfg_file_options"
672 fi
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000673 run_process neutron-periodic-workers "$NEUTRON_BIN_DIR/neutron-periodic-workers $cfg_file_options"
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000674 _run_ovn_maintenance
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100675 else
676 run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
677 neutron_url=$service_protocol://$Q_HOST:$service_port/
678 # Start proxy if enabled
679 if is_service_enabled tls-proxy; then
680 start_tls_proxy neutron '*' $Q_PORT $Q_HOST $Q_PORT_INT
681 fi
682 fi
683 if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then
684 neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME
685 fi
686 echo "Waiting for Neutron to start..."
Sean M. Collins2a242512016-05-03 09:03:09 -0400687
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100688 local testcmd="wget ${ssl_ca} --no-proxy -q -O- $neutron_url"
689 test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900690}
691
Sean M. Collins2a242512016-05-03 09:03:09 -0400692function start_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100693 start_l2_agent "$@"
694 start_other_agents "$@"
695}
696
697# Control of the l2 agent is separated out to make it easier to test partial
698# upgrades (everything upgraded except the L2 agent)
699function start_l2_agent {
700 run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
701
702 if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then
703 sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
704 sudo ip link set $OVS_PHYSICAL_BRIDGE up
705 sudo ip link set br-int up
706 sudo ip link set $PUBLIC_INTERFACE up
707 if is_ironic_hardware; then
708 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
709 sudo ip addr del $IP dev $PUBLIC_INTERFACE
710 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
711 done
712 sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
713 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400714 fi
715}
716
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100717function start_other_agents {
718 run_process q-dhcp "$AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file $Q_DHCP_CONF_FILE"
719
720 run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
721
722 run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file $Q_META_CONF_FILE"
723 run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
724}
725
726# Start running processes, including screen
727function start_neutron_agents {
728 # NOTE(slaweq): it's now just a wrapper for start_neutron function
729 start_neutron "$@"
730}
731
732function stop_l2_agent {
733 stop_process q-agt
734}
735
736# stop_other() - Stop running processes
737function stop_other {
738 if is_service_enabled q-dhcp neutron-dhcp; then
739 stop_process q-dhcp
740 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
741 [ ! -z "$pid" ] && sudo kill -9 $pid
742 fi
743
744 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
745 stop_process neutron-rpc-server
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000746 stop_process neutron-periodic-workers
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100747 stop_process neutron-api
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000748 _stop_ovn_maintenance
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100749 else
750 stop_process q-svc
751 fi
752
753 if is_service_enabled q-l3 neutron-l3; then
754 sudo pkill -f "radvd -C $DATA_DIR/neutron/ra"
755 stop_process q-l3
756 fi
757
758 if is_service_enabled q-meta neutron-metadata-agent; then
759 stop_process q-meta
760 fi
761
762 if is_service_enabled q-metering neutron-metering; then
763 neutron_metering_stop
764 fi
765
766 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Bence Romsics71c3c402022-12-21 13:50:54 +0100767 # pkill takes care not to kill itself, but it may kill its parent
768 # sudo unless we use the "ps | grep [f]oo" trick
769 sudo pkill -9 -f "$NEUTRON_ROOTWRAP-[d]aemon" || :
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100770 fi
771}
772
773# stop_neutron() - Stop running processes (non-screen)
Sean M. Collins2a242512016-05-03 09:03:09 -0400774function stop_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100775 stop_other
776 stop_l2_agent
777
778 if [[ $Q_AGENT == "ovn" && $SKIP_STOP_OVN != "True" ]]; then
779 stop_ovn
Sean M. Collins2a242512016-05-03 09:03:09 -0400780 fi
781}
782
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100783# _move_neutron_addresses_route() - Move the primary IP to the OVS bridge
784# on startup, or back to the public interface on cleanup. If no IP is
785# configured on the interface, just add it as a port to the OVS bridge.
786function _move_neutron_addresses_route {
787 local from_intf=$1
788 local to_intf=$2
789 local add_ovs_port=$3
790 local del_ovs_port=$4
791 local af=$5
792
793 if [[ -n "$from_intf" && -n "$to_intf" ]]; then
794 # Remove the primary IP address from $from_intf and add it to $to_intf,
795 # along with the default route, if it exists. Also, when called
796 # on configure we will also add $from_intf as a port on $to_intf,
797 # assuming it is an OVS bridge.
798
799 local IP_REPLACE=""
800 local IP_DEL=""
801 local IP_UP=""
802 local DEFAULT_ROUTE_GW
803 DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf\s/ { print \$3; exit }")
804 local ADD_OVS_PORT=""
805 local DEL_OVS_PORT=""
806 local ARP_CMD=""
807
808 IP_BRD=$(ip -f $af a s dev $from_intf scope global primary | grep inet | awk '{ print $2, $3, $4; exit }')
809
810 if [ "$DEFAULT_ROUTE_GW" != "" ]; then
811 ADD_DEFAULT_ROUTE="sudo ip -f $af r replace default via $DEFAULT_ROUTE_GW dev $to_intf"
812 fi
813
814 if [[ "$add_ovs_port" == "True" ]]; then
815 ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf"
816 fi
817
818 if [[ "$del_ovs_port" == "True" ]]; then
819 DEL_OVS_PORT="sudo ovs-vsctl --if-exists del-port $from_intf $to_intf"
820 fi
821
822 if [[ "$IP_BRD" != "" ]]; then
823 IP_DEL="sudo ip addr del $IP_BRD dev $from_intf"
824 IP_REPLACE="sudo ip addr replace $IP_BRD dev $to_intf"
825 IP_UP="sudo ip link set $to_intf up"
826 if [[ "$af" == "inet" ]]; then
827 IP=$(echo $IP_BRD | awk '{ print $1; exit }' | grep -o -E '(.*)/' | cut -d "/" -f1)
828 ARP_CMD="sudo arping -A -c 3 -w 5 -I $to_intf $IP "
829 fi
830 fi
831
832 # The add/del OVS port calls have to happen either before or
833 # after the address is moved in order to not leave it orphaned.
834 $DEL_OVS_PORT; $IP_DEL; $IP_REPLACE; $IP_UP; $ADD_OVS_PORT; $ADD_DEFAULT_ROUTE; $ARP_CMD
835 fi
836}
837
838# _configure_public_network_connectivity() - Configures connectivity to the
839# external network using $PUBLIC_INTERFACE or NAT on the single interface
840# machines
841function _configure_public_network_connectivity {
842 # If we've given a PUBLIC_INTERFACE to take over, then we assume
843 # that we can own the whole thing, and privot it into the OVS
844 # bridge. If we are not, we're probably on a single interface
845 # machine, and we just setup NAT so that fixed guests can get out.
846 if [[ -n "$PUBLIC_INTERFACE" ]]; then
847 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" True False "inet"
848
849 if [[ $(ip -f inet6 a s dev "$PUBLIC_INTERFACE" | grep -c 'global') != 0 ]]; then
850 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" False False "inet6"
851 fi
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -0500852 else
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100853 for d in $default_v4_route_devs; do
854 sudo iptables -t nat -A POSTROUTING -o $d -s $FLOATING_RANGE -j MASQUERADE
855 done
856 fi
857}
858
859# cleanup_neutron() - Remove residual data files, anything left over from previous
860# runs that a clean run would need to clean up
861function cleanup_neutron {
862 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
863 stop_process neutron-api
864 stop_process neutron-rpc-server
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000865 stop_process neutron-periodic-workers
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000866 _stop_ovn_maintenance
Stephen Finucaned5182ce2024-04-19 12:27:14 +0100867 remove_uwsgi_config "$NEUTRON_UWSGI_CONF" "neutron-api"
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100868 sudo rm -f $(apache_site_config_for neutron-api)
869 fi
870
871 if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then
872 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False True "inet"
873
874 if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then
875 # ip(8) wants the prefix length when deleting
876 local v6_gateway
877 v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }')
878 sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE
879 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False False "inet6"
880 fi
881
882 if is_provider_network && is_ironic_hardware; then
883 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
884 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
885 sudo ip addr add $IP dev $PUBLIC_INTERFACE
886 done
887 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
888 fi
889 fi
890
891 if is_neutron_ovs_base_plugin; then
892 neutron_ovs_base_cleanup
893 fi
894
895 if [[ $Q_AGENT == "linuxbridge" ]]; then
896 neutron_lb_cleanup
897 fi
898
899 # delete all namespaces created by neutron
900 for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|fip|snat)-[0-9a-f-]*'); do
901 sudo ip netns delete ${ns}
902 done
903
904 if [[ $Q_AGENT == "ovn" ]]; then
905 cleanup_ovn
906 fi
907}
908
909
910function _create_neutron_conf_dir {
911 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
912 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
913}
914
915# _configure_neutron_common()
916# Set common config for all neutron server and agents.
917# This MUST be called before other ``_configure_neutron_*`` functions.
918function _configure_neutron_common {
919 _create_neutron_conf_dir
920
921 # Uses oslo config generator to generate core sample configuration files
922 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
923
924 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
925
926 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
927
928 # allow neutron user to administer neutron to match neutron account
929 # NOTE(amotoki): This is required for nova works correctly with neutron.
930 if [ -f $NEUTRON_DIR/etc/policy.json ]; then
931 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
932 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
933 else
934 echo '{"context_is_admin": "role:admin or user_name:neutron"}' > $Q_POLICY_FILE
935 fi
936
937 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
938 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
939 neutron_plugin_configure_common
940
941 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
942 die $LINENO "Neutron plugin not set.. exiting"
943 fi
944
945 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
946 mkdir -p /$Q_PLUGIN_CONF_PATH
947 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
948 # NOTE(slaweq): NEUTRON_CORE_PLUGIN_CONF is used e.g. in neutron repository,
949 # it was previously defined in the lib/neutron module which is now deleted.
950 NEUTRON_CORE_PLUGIN_CONF=$Q_PLUGIN_CONF_FILE
951 # NOTE(hichihara): Some neutron vendor plugins were already decomposed and
952 # there is no config file in Neutron tree. They should prepare the file in each plugin.
953 if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then
954 cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE
955 elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then
956 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
957 fi
958
959 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
960 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
961 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
962 iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS
963 iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock
964
965 # NOTE(freerunner): Need to adjust Region Name for nova in multiregion installation
966 iniset $NEUTRON_CONF nova region_name $REGION_NAME
967
968 if [ "$VIRT_DRIVER" = 'fake' ]; then
969 # Disable arbitrary limits
970 iniset $NEUTRON_CONF quotas quota_network -1
971 iniset $NEUTRON_CONF quotas quota_subnet -1
972 iniset $NEUTRON_CONF quotas quota_port -1
973 iniset $NEUTRON_CONF quotas quota_security_group -1
974 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
975 fi
976
977 # Format logging
978 setup_logging $NEUTRON_CONF
979
980 if is_service_enabled tls-proxy && [ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" ]; then
981 # Set the service port for a proxy to take the original
982 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
983 iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True
984 fi
985
986 _neutron_setup_rootwrap
987}
988
989function _configure_neutron_dhcp_agent {
990
991 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE
992
993 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
994 # make it so we have working DNS from guests
995 iniset $Q_DHCP_CONF_FILE DEFAULT dnsmasq_local_resolv True
996 configure_root_helper_options $Q_DHCP_CONF_FILE
997
998 if ! is_service_enabled q-l3 neutron-l3; then
999 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
1000 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
1001 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
1002 else
1003 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
1004 die "$LINENO" "Enable isolated metadata is a must for metadata network"
1005 fi
1006 fi
1007 fi
1008
1009 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
1010
1011 neutron_plugin_configure_dhcp_agent $Q_DHCP_CONF_FILE
1012}
1013
1014
1015function _configure_neutron_metadata_agent {
1016 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE
1017
1018 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1019 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_host $Q_META_DATA_IP
1020 iniset $Q_META_CONF_FILE DEFAULT metadata_workers $API_WORKERS
1021 configure_root_helper_options $Q_META_CONF_FILE
1022}
1023
1024function _configure_neutron_ceilometer_notifications {
1025 iniset $NEUTRON_CONF oslo_messaging_notifications driver messagingv2
1026}
1027
1028function _configure_neutron_metering {
1029 neutron_agent_metering_configure_common
1030 neutron_agent_metering_configure_agent
1031}
1032
1033function _configure_dvr {
1034 iniset $NEUTRON_CONF DEFAULT router_distributed True
1035 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
1036}
1037
1038
1039# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
1040# It is called when q-agt is enabled.
1041function _configure_neutron_plugin_agent {
1042 # Specify the default root helper prior to agent configuration to
1043 # ensure that an agent's configuration can override the default
1044 configure_root_helper_options /$Q_PLUGIN_CONF_FILE
1045 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1046
1047 # Configure agent for plugin
1048 neutron_plugin_configure_plugin_agent
1049}
1050
1051function _replace_api_paste_composite {
1052 local sep
1053 sep=$(echo -ne "\x01")
1054 # Replace it
1055 $sudo sed -i -e "s/\/\: neutronversions_composite/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/\: neutronversions_composite/" "$Q_API_PASTE_FILE"
1056 $sudo sed -i -e "s/\/healthcheck\: healthcheck/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/healthcheck\: healthcheck/" "$Q_API_PASTE_FILE"
1057 $sudo sed -i -e "s/\/v2.0\: neutronapi_v2_0/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/v2.0\: neutronapi_v2_0/" "$Q_API_PASTE_FILE"
1058}
1059
1060# _configure_neutron_service() - Set config files for neutron service
1061# It is called when q-svc is enabled.
1062function _configure_neutron_service {
1063 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
1064 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
1065
Slawek Kaplonskib500d802024-06-14 12:58:58 +02001066 if [[ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" && -n "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001067 _replace_api_paste_composite
1068 fi
1069
1070 # Update either configuration file with plugin
1071 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
1072
1073 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1074 iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE
1075
1076 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
1077 configure_keystone_authtoken_middleware $NEUTRON_CONF $Q_ADMIN_USERNAME
1078
1079 # Configuration for neutron notifications to nova.
1080 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
1081 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
1082
1083 configure_keystone_authtoken_middleware $NEUTRON_CONF nova nova
1084
1085 # Configuration for placement client
1086 configure_keystone_authtoken_middleware $NEUTRON_CONF placement placement
1087
1088 # Configure plugin
1089 neutron_plugin_configure_service
1090}
1091
1092# Utility Functions
1093#------------------
1094
1095# neutron_service_plugin_class_add() - add service plugin class
1096function neutron_service_plugin_class_add {
1097 local service_plugin_class=$1
1098 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
1099 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
1100 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
1101 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
1102 fi
1103}
1104
1105# neutron_ml2_extension_driver_add() - add ML2 extension driver
1106function neutron_ml2_extension_driver_add {
1107 local extension=$1
1108 if [[ $Q_ML2_PLUGIN_EXT_DRIVERS == '' ]]; then
1109 Q_ML2_PLUGIN_EXT_DRIVERS=$extension
1110 elif [[ ! ,${Q_ML2_PLUGIN_EXT_DRIVERS}, =~ ,${extension}, ]]; then
1111 Q_ML2_PLUGIN_EXT_DRIVERS="$Q_ML2_PLUGIN_EXT_DRIVERS,$extension"
1112 fi
1113}
1114
1115# neutron_server_config_add() - add server config file
1116function neutron_server_config_add {
1117 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($1)
1118}
1119
1120# neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root).
1121function neutron_deploy_rootwrap_filters {
1122 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1123 return
1124 fi
1125 local srcdir=$1
1126 sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D
1127 sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
1128}
1129
1130# _neutron_setup_rootwrap() - configure Neutron's rootwrap
1131function _neutron_setup_rootwrap {
1132 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1133 return
1134 fi
1135 # Wipe any existing ``rootwrap.d`` files first
1136 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
1137 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
1138 sudo rm -rf $Q_CONF_ROOTWRAP_D
1139 fi
1140
1141 neutron_deploy_rootwrap_filters $NEUTRON_DIR
1142
1143 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
1144 # location moved in newer versions, prefer new location
1145 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
1146 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
1147 else
1148 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
1149 fi
1150 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
yatinkarelffc1b762023-08-28 10:52:26 +05301151 # Rely on $PATH set by devstack to determine what is safe to execute
1152 # by rootwrap rather than use explicit whitelist of paths in
1153 # rootwrap.conf
1154 sudo sed -e 's/^exec_dirs=.*/#&/' -i $Q_RR_CONF_FILE
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001155
1156 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
1157 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
1158 ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
1159
1160 # Set up the rootwrap sudoers for neutron
1161 TEMPFILE=`mktemp`
1162 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
1163 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE
1164 chmod 0440 $TEMPFILE
1165 sudo chown root:root $TEMPFILE
1166 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
1167
1168 # Update the root_helper
1169 configure_root_helper_options $NEUTRON_CONF
1170}
1171
1172function configure_root_helper_options {
1173 local conffile=$1
1174 iniset $conffile agent root_helper "$Q_RR_COMMAND"
1175 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
1176 iniset $conffile agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
1177 fi
1178}
1179
1180function _neutron_setup_interface_driver {
1181
1182 # ovs_use_veth needs to be set before the plugin configuration
1183 # occurs to allow plugins to override the setting.
1184 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1185
1186 neutron_plugin_setup_interface_driver $1
1187}
1188# Functions for Neutron Exercises
1189#--------------------------------
1190
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001191# ssh check
1192function _ssh_check_neutron {
1193 local from_net=$1
1194 local key_file=$2
1195 local ip=$3
1196 local user=$4
1197 local timeout_sec=$5
1198 local probe_cmd = ""
1199 probe_cmd=`_get_probe_cmd_prefix $from_net`
1200 local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success"
1201 test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec
1202}
1203
1204function plugin_agent_add_l2_agent_extension {
1205 local l2_agent_extension=$1
1206 if [[ -z "$L2_AGENT_EXTENSIONS" ]]; then
1207 L2_AGENT_EXTENSIONS=$l2_agent_extension
1208 elif [[ ! ,${L2_AGENT_EXTENSIONS}, =~ ,${l2_agent_extension}, ]]; then
1209 L2_AGENT_EXTENSIONS+=",$l2_agent_extension"
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -05001210 fi
1211}
1212
Sean M. Collins2a242512016-05-03 09:03:09 -04001213# Restore xtrace
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001214$_XTRACE_NEUTRON
1215
1216# Tell emacs to use shell-script-mode
1217## Local variables:
1218## mode: shell-script
1219## End: