blob: 474613926bac841823abf97204548ce0efab6fbb [file] [log] [blame]
Sean M. Collins2a242512016-05-03 09:03:09 -04001#!/bin/bash
2#
3# lib/neutron
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01004# functions - functions specific to neutron
Sean M. Collins2a242512016-05-03 09:03:09 -04005
6# Dependencies:
Sean M. Collins2a242512016-05-03 09:03:09 -04007# ``functions`` file
8# ``DEST`` must be defined
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01009# ``STACK_USER`` must be defined
Sean M. Collins2a242512016-05-03 09:03:09 -040010
11# ``stack.sh`` calls the entry points in this order:
12#
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010013# - install_neutron_agent_packages
14# - install_neutronclient
15# - install_neutron
16# - install_neutron_third_party
17# - configure_neutron
18# - init_neutron
19# - configure_neutron_third_party
20# - init_neutron_third_party
21# - start_neutron_third_party
22# - create_nova_conf_neutron
23# - configure_neutron_after_post_config
24# - start_neutron_service_and_check
25# - check_neutron_third_party_integration
26# - start_neutron_agents
27# - create_neutron_initial_network
28#
29# ``unstack.sh`` calls the entry points in this order:
30#
31# - stop_neutron
32# - stop_neutron_third_party
33# - cleanup_neutron
Sean M. Collins2a242512016-05-03 09:03:09 -040034
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010035# Functions in lib/neutron are classified into the following categories:
36#
37# - entry points (called from stack.sh or unstack.sh)
38# - internal functions
39# - neutron exercises
40# - 3rd party programs
Sean M. Collins2a242512016-05-03 09:03:09 -040041
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010042
43# Neutron Networking
44# ------------------
45
46# Make sure that neutron is enabled in ``ENABLED_SERVICES``. If you want
47# to run Neutron on this host, make sure that q-svc is also in
48# ``ENABLED_SERVICES``.
49#
50# See "Neutron Network Configuration" below for additional variables
51# that must be set in localrc for connectivity across hosts with
52# Neutron.
53
54# Settings
Sean M. Collins2a242512016-05-03 09:03:09 -040055# --------
56
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010057
58# Neutron Network Configuration
59# -----------------------------
60
61if is_service_enabled tls-proxy; then
62 Q_PROTOCOL="https"
63fi
64
65
Sean M. Collins2a242512016-05-03 09:03:09 -040066# Set up default directories
67GITDIR["python-neutronclient"]=$DEST/python-neutronclient
68
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010069
70NEUTRON_DIR=$DEST/neutron
71NEUTRON_FWAAS_DIR=$DEST/neutron-fwaas
72
73# Support entry points installation of console scripts
74if [[ -d $NEUTRON_DIR/bin/neutron-server ]]; then
75 NEUTRON_BIN_DIR=$NEUTRON_DIR/bin
76else
77 NEUTRON_BIN_DIR=$(get_python_exec_prefix)
78fi
79
80NEUTRON_CONF_DIR=/etc/neutron
81NEUTRON_CONF=$NEUTRON_CONF_DIR/neutron.conf
82export NEUTRON_TEST_CONFIG_FILE=${NEUTRON_TEST_CONFIG_FILE:-"$NEUTRON_CONF_DIR/debug.ini"}
83
Kevin Benton66b361b2017-06-13 00:31:01 -070084# NEUTRON_DEPLOY_MOD_WSGI defines how neutron is deployed, allowed values:
85# - False (default) : Run neutron under Eventlet
86# - True : Run neutron under uwsgi
87# TODO(annp): Switching to uwsgi in next cycle if things turn out to be stable
88# enough
Jens Harbott3492fee2018-11-30 13:57:17 +000089NEUTRON_DEPLOY_MOD_WSGI=$(trueorfalse False NEUTRON_DEPLOY_MOD_WSGI)
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010090
91NEUTRON_UWSGI_CONF=$NEUTRON_CONF_DIR/neutron-api-uwsgi.ini
Sean M. Collins2a242512016-05-03 09:03:09 -040092
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +020093# If NEUTRON_ENFORCE_SCOPE == True, it will set "enforce_scope"
94# and "enforce_new_defaults" to True in the Neutron's config to enforce usage
Ghanshyam Mannbacb8402023-10-25 12:52:28 -070095# of the new RBAC policies and scopes. Set it to False if you do not
96# want to run Neutron with new RBAC.
97NEUTRON_ENFORCE_SCOPE=$(trueorfalse True NEUTRON_ENFORCE_SCOPE)
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +020098
Slawek Kaplonskia52041c2022-11-18 11:39:56 +010099# Agent binaries. Note, binary paths for other agents are set in per-service
100# scripts in lib/neutron_plugins/services/
101AGENT_DHCP_BINARY="$NEUTRON_BIN_DIR/neutron-dhcp-agent"
102AGENT_L3_BINARY=${AGENT_L3_BINARY:-"$NEUTRON_BIN_DIR/neutron-l3-agent"}
103AGENT_META_BINARY="$NEUTRON_BIN_DIR/neutron-metadata-agent"
Brian Haley9aaa5292017-09-20 14:23:05 -0400104
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100105# Agent config files. Note, plugin-specific Q_PLUGIN_CONF_FILE is set and
106# loaded from per-plugin scripts in lib/neutron_plugins/
107Q_DHCP_CONF_FILE=$NEUTRON_CONF_DIR/dhcp_agent.ini
108# NOTE(slaweq): NEUTRON_DHCP_CONF is used e.g. in neutron repository,
109# it was previously defined in the lib/neutron module which is now deleted.
110NEUTRON_DHCP_CONF=$Q_DHCP_CONF_FILE
111Q_L3_CONF_FILE=$NEUTRON_CONF_DIR/l3_agent.ini
112# NOTE(slaweq): NEUTRON_L3_CONF is used e.g. in neutron repository,
113# it was previously defined in the lib/neutron module which is now deleted.
114NEUTRON_L3_CONF=$Q_L3_CONF_FILE
115Q_META_CONF_FILE=$NEUTRON_CONF_DIR/metadata_agent.ini
Sean M. Collins2a242512016-05-03 09:03:09 -0400116
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100117# Default name for Neutron database
118Q_DB_NAME=${Q_DB_NAME:-neutron}
119# Default Neutron Plugin
120Q_PLUGIN=${Q_PLUGIN:-ml2}
121# Default Neutron Port
122Q_PORT=${Q_PORT:-9696}
123# Default Neutron Internal Port when using TLS proxy
124Q_PORT_INT=${Q_PORT_INT:-19696}
125# Default Neutron Host
126Q_HOST=${Q_HOST:-$SERVICE_HOST}
127# Default protocol
128Q_PROTOCOL=${Q_PROTOCOL:-$SERVICE_PROTOCOL}
129# Default listen address
130Q_LISTEN_ADDRESS=${Q_LISTEN_ADDRESS:-$(ipv6_unquote $SERVICE_LISTEN_ADDRESS)}
131# Default admin username
132Q_ADMIN_USERNAME=${Q_ADMIN_USERNAME:-neutron}
133# Default auth strategy
134Q_AUTH_STRATEGY=${Q_AUTH_STRATEGY:-keystone}
135# RHEL's support for namespaces requires using veths with ovs
136Q_OVS_USE_VETH=${Q_OVS_USE_VETH:-False}
137Q_USE_ROOTWRAP=${Q_USE_ROOTWRAP:-True}
138Q_USE_ROOTWRAP_DAEMON=$(trueorfalse True Q_USE_ROOTWRAP_DAEMON)
139# Meta data IP
140Q_META_DATA_IP=${Q_META_DATA_IP:-$(ipv6_unquote $SERVICE_HOST)}
141# Allow Overlapping IP among subnets
142Q_ALLOW_OVERLAPPING_IP=${Q_ALLOW_OVERLAPPING_IP:-True}
143Q_NOTIFY_NOVA_PORT_STATUS_CHANGES=${Q_NOTIFY_NOVA_PORT_STATUS_CHANGES:-True}
144Q_NOTIFY_NOVA_PORT_DATA_CHANGES=${Q_NOTIFY_NOVA_PORT_DATA_CHANGES:-True}
Rodolfo Alonso Hernandezaaaa0372024-07-19 08:09:25 +0000145_Q_RUN_RPC_SERVER=True
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100146VIF_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
244# openvswitch agent or ``LB_PHYSICAL_INTERFACE`` for the linuxbridge
245# agent, as described below.
246#
247# Example: ``PHYSICAL_NETWORK=default``
248PHYSICAL_NETWORK=${PHYSICAL_NETWORK:-public}
249
250# With the openvswitch agent, if using VLANs for tenant networks,
251# or if using flat or VLAN provider networks, set in ``localrc`` to
252# the name of the OVS bridge to use for the physical network. The
253# bridge will be created if it does not already exist, but a
254# physical interface must be manually added to the bridge as a
255# port for external connectivity.
256#
257# Example: ``OVS_PHYSICAL_BRIDGE=br-eth1``
258OVS_PHYSICAL_BRIDGE=${OVS_PHYSICAL_BRIDGE:-br-ex}
259
260# With the linuxbridge agent, if using VLANs for tenant networks,
261# or if using flat or VLAN provider networks, set in ``localrc`` to
262# the name of the network interface to use for the physical
263# network.
264#
265# Example: ``LB_PHYSICAL_INTERFACE=eth1``
266if [[ $Q_AGENT == "linuxbridge" && -z ${LB_PHYSICAL_INTERFACE} ]]; then
267 default_route_dev=$( (ip route; ip -6 route) | grep ^default | head -n 1 | awk '{print $5}')
268 die_if_not_set $LINENO default_route_dev "Failure retrieving default route device"
269 LB_PHYSICAL_INTERFACE=$default_route_dev
270fi
271
272# With the openvswitch plugin, set to True in ``localrc`` to enable
273# provider GRE tunnels when ``ENABLE_TENANT_TUNNELS`` is False.
274#
275# Example: ``OVS_ENABLE_TUNNELING=True``
276OVS_ENABLE_TUNNELING=${OVS_ENABLE_TUNNELING:-$ENABLE_TENANT_TUNNELS}
277
278# Use DHCP agent for providing metadata service in the case of
279# without L3 agent (No Route Agent), set to True in localrc.
280ENABLE_ISOLATED_METADATA=${ENABLE_ISOLATED_METADATA:-False}
281
282# Add a static route as dhcp option, so the request to 169.254.169.254
283# will be able to reach through a route(DHCP agent)
284# This option require ENABLE_ISOLATED_METADATA = True
285ENABLE_METADATA_NETWORK=${ENABLE_METADATA_NETWORK:-False}
286# Neutron plugin specific functions
287# ---------------------------------
288
289# Please refer to ``lib/neutron_plugins/README.md`` for details.
290if [ -f $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN ]; then
291 source $TOP_DIR/lib/neutron_plugins/$Q_PLUGIN
292fi
293
294# Agent metering service plugin functions
295# -------------------------------------------
296
297# Hardcoding for 1 service plugin for now
298source $TOP_DIR/lib/neutron_plugins/services/metering
299
300# L3 Service functions
301source $TOP_DIR/lib/neutron_plugins/services/l3
302
303# Additional Neutron service plugins
304source $TOP_DIR/lib/neutron_plugins/services/placement
305source $TOP_DIR/lib/neutron_plugins/services/trunk
306source $TOP_DIR/lib/neutron_plugins/services/qos
elajkata84b2092021-11-17 11:52:56 +0100307source $TOP_DIR/lib/neutron_plugins/services/segments
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100308
309# Use security group or not
310if has_neutron_plugin_security_group; then
311 Q_USE_SECGROUP=${Q_USE_SECGROUP:-True}
312else
313 Q_USE_SECGROUP=False
314fi
315
Harald Jensås16ac21f2023-08-31 15:06:52 +0200316# OVN_BRIDGE_MAPPINGS - ovn-bridge-mappings
317# NOTE(hjensas): Initialize after sourcing neutron_plugins/services/l3
318# which initialize PUBLIC_BRIDGE.
319OVN_BRIDGE_MAPPINGS=${OVN_BRIDGE_MAPPINGS:-$PHYSICAL_NETWORK:$PUBLIC_BRIDGE}
320
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100321# Save trace setting
322_XTRACE_NEUTRON=$(set +o | grep xtrace)
323set +o xtrace
324
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900325
Sean M. Collins2a242512016-05-03 09:03:09 -0400326# Functions
327# ---------
328
329# Test if any Neutron services are enabled
330# is_neutron_enabled
331function is_neutron_enabled {
Clark Boylan902158b2017-05-30 14:11:09 -0700332 [[ ,${DISABLED_SERVICES} =~ ,"neutron" ]] && return 1
Sean M. Collins2a242512016-05-03 09:03:09 -0400333 [[ ,${ENABLED_SERVICES} =~ ,"neutron-" || ,${ENABLED_SERVICES} =~ ,"q-" ]] && return 0
334 return 1
335}
336
337# Test if any Neutron services are enabled
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100338# TODO(slaweq): this is not really needed now and we should remove it as soon
339# as it will not be called from any other Devstack plugins, like e.g. Neutron
340# plugin
Sean M. Collins2a242512016-05-03 09:03:09 -0400341function is_neutron_legacy_enabled {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100342 return 0
Sean M. Collins2a242512016-05-03 09:03:09 -0400343}
344
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100345function _determine_config_server {
346 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" != '' ]]; then
347 if [[ "$Q_PLUGIN_EXTRA_CONF_PATH" = "$_Q_PLUGIN_EXTRA_CONF_PATH" ]]; then
348 deprecated "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
349 else
350 die $LINENO "Q_PLUGIN_EXTRA_CONF_PATH is deprecated"
351 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400352 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100353 if [[ ${#Q_PLUGIN_EXTRA_CONF_FILES[@]} > 0 ]]; then
354 deprecated "Q_PLUGIN_EXTRA_CONF_FILES is deprecated. Use neutron_server_config_add instead."
Sean M. Collins2a242512016-05-03 09:03:09 -0400355 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100356 for cfg_file in ${Q_PLUGIN_EXTRA_CONF_FILES[@]}; do
357 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($_Q_PLUGIN_EXTRA_CONF_PATH/$cfg_file)
Sean M. Collins2a242512016-05-03 09:03:09 -0400358 done
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100359
360 local cfg_file
361 local opts="--config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
362 for cfg_file in ${_Q_PLUGIN_EXTRA_CONF_FILES_ABS[@]}; do
363 opts+=" --config-file $cfg_file"
364 done
365 echo "$opts"
Sean M. Collins2a242512016-05-03 09:03:09 -0400366}
367
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100368function _determine_config_l3 {
369 local opts="--config-file $NEUTRON_CONF --config-file $Q_L3_CONF_FILE"
370 echo "$opts"
Ihar Hrachyshkae65ab4a2017-02-24 17:47:55 +0000371}
372
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000373function _enable_ovn_maintenance {
374 if [[ $Q_AGENT == "ovn" ]]; then
375 enable_service neutron-ovn-maintenance-worker
376 fi
377}
378
379function _run_ovn_maintenance {
380 if [[ $Q_AGENT == "ovn" ]]; then
381 run_process neutron-ovn-maintenance-worker "$NEUTRON_BIN_DIR/neutron-ovn-maintenance-worker $cfg_file_options"
382 fi
383}
384
385function _stop_ovn_maintenance {
386 if [[ $Q_AGENT == "ovn" ]]; then
387 stop_process neutron-ovn-maintenance-worker
388 fi
389}
390
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100391# For services and agents that require it, dynamically construct a list of
392# --config-file arguments that are passed to the binary.
393function determine_config_files {
394 local opts=""
395 case "$1" in
396 "neutron-server") opts="$(_determine_config_server)" ;;
397 "neutron-l3-agent") opts="$(_determine_config_l3)" ;;
398 esac
399 if [ -z "$opts" ] ; then
400 die $LINENO "Could not determine config files for $1."
YAMAMOTO Takashi1df17c92017-05-01 17:00:42 +0900401 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100402 echo "$opts"
403}
Sean M. Collins2a242512016-05-03 09:03:09 -0400404
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100405# configure_neutron()
406# Set common config for all neutron server and agents.
407function configure_neutron {
408 _configure_neutron_common
Sean M. Collins5394cc12016-05-11 15:03:38 -0400409 iniset_rpc_backend neutron $NEUTRON_CONF
410
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100411 if is_service_enabled q-metering neutron-metering; then
412 _configure_neutron_metering
413 fi
414 if is_service_enabled q-agt neutron-agent; then
415 _configure_neutron_plugin_agent
416 fi
417 if is_service_enabled q-dhcp neutron-dhcp; then
418 _configure_neutron_dhcp_agent
419 fi
420 if is_service_enabled q-l3 neutron-l3; then
421 _configure_neutron_l3_agent
422 fi
423 if is_service_enabled q-meta neutron-metadata-agent; then
424 _configure_neutron_metadata_agent
Sean M. Collins2a242512016-05-03 09:03:09 -0400425 fi
426
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100427 if [[ "$Q_DVR_MODE" != "legacy" ]]; then
428 _configure_dvr
429 fi
430 if is_service_enabled ceilometer; then
431 _configure_neutron_ceilometer_notifications
432 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400433
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100434 if [[ $Q_AGENT == "ovn" ]]; then
435 configure_ovn
436 configure_ovn_plugin
437 fi
Brian Haley9aaa5292017-09-20 14:23:05 -0400438
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100439 # Configure Neutron's advanced services
440 if is_service_enabled q-placement neutron-placement; then
441 configure_placement_extension
442 fi
443 if is_service_enabled q-trunk neutron-trunk; then
444 configure_trunk_extension
445 fi
446 if is_service_enabled q-qos neutron-qos; then
447 configure_qos
448 if is_service_enabled q-l3 neutron-l3; then
449 configure_l3_agent_extension_fip_qos
450 configure_l3_agent_extension_gateway_ip_qos
Denis Buliga0bf75a42017-02-06 16:56:46 +0200451 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400452 fi
elajkata84b2092021-11-17 11:52:56 +0100453 if is_service_enabled neutron-segments; then
454 configure_placement_neutron
455 configure_segments_extension
456 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400457
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100458 # Finally configure Neutron server and core plugin
459 if is_service_enabled q-agt neutron-agent q-svc neutron-api; then
460 _configure_neutron_service
Sean M. Collins2a242512016-05-03 09:03:09 -0400461 fi
462
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100463 iniset $NEUTRON_CONF DEFAULT api_workers "$API_WORKERS"
464 # devstack is not a tool for running uber scale OpenStack
465 # clouds, therefore running without a dedicated RPC worker
466 # for state reports is more than adequate.
467 iniset $NEUTRON_CONF DEFAULT rpc_state_report_workers 0
Rodolfo Alonso Hernandezaaaa0372024-07-19 08:09:25 +0000468 # The default value of "rpc_workers" is None (not defined). If
469 # "rpc_workers" is explicitly set to 0, the RPC workers process should not
470 # be executed. NOTE: this service is only executed when WSGI is enabled
471 # (NEUTRON_DEPLOY_MOD_WSGI=True) for the Neutron server.
472 local rpc_workers
473 rpc_workers=$(iniget_multiline /etc/neutron/neutron.conf DEFAULT rpc_workers)
474 if ! is_service_enabled neutron-rpc-server || [ "$rpc_workers" -eq "0" ]; then
475 _Q_RUN_RPC_SERVER=False
476 fi
Ihar Hrachyshkae3915932017-02-24 06:24:47 +0000477
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100478 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
479 write_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_BIN_DIR/neutron-api" "/networking"
Sean M. Collins8063fee2016-05-24 11:27:36 -0700480 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400481}
482
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100483function configure_neutron_nova {
484 create_nova_conf_neutron $NOVA_CONF
485 if [[ "${CELLSV2_SETUP}" == "superconductor" ]]; then
486 for i in $(seq 1 $NOVA_NUM_CELLS); do
487 local conf
488 conf=$(conductor_conf $i)
489 create_nova_conf_neutron $conf
490 done
Sean M. Collins2a242512016-05-03 09:03:09 -0400491 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400492}
493
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100494function create_nova_conf_neutron {
Lucas Alvares Gomese6385932018-06-28 11:00:28 +0100495 local conf=${1:-$NOVA_CONF}
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400496 iniset $conf neutron auth_type "password"
497 iniset $conf neutron auth_url "$KEYSTONE_SERVICE_URI"
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100498 iniset $conf neutron username "$Q_ADMIN_USERNAME"
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400499 iniset $conf neutron password "$SERVICE_PASSWORD"
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100500 iniset $conf neutron user_domain_name "$SERVICE_DOMAIN_NAME"
501 iniset $conf neutron project_name "$SERVICE_PROJECT_NAME"
502 iniset $conf neutron project_domain_name "$SERVICE_DOMAIN_NAME"
503 iniset $conf neutron auth_strategy "$Q_AUTH_STRATEGY"
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400504 iniset $conf neutron region_name "$REGION_NAME"
Sean M. Collins2a242512016-05-03 09:03:09 -0400505
Gary Kotton88f85582016-08-14 06:55:42 -0700506 # optionally set options in nova_conf
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400507 neutron_plugin_create_nova_conf $conf
Gary Kotton88f85582016-08-14 06:55:42 -0700508
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100509 if is_service_enabled q-meta neutron-metadata-agent; then
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400510 iniset $conf neutron service_metadata_proxy "True"
Sean M. Collins2a242512016-05-03 09:03:09 -0400511 fi
512
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100513 iniset $conf DEFAULT vif_plugging_is_fatal "$VIF_PLUGGING_IS_FATAL"
514 iniset $conf DEFAULT vif_plugging_timeout "$VIF_PLUGGING_TIMEOUT"
Sean M. Collins2a242512016-05-03 09:03:09 -0400515}
516
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100517# create_neutron_accounts() - Set up common required neutron accounts
518
Sean M. Collins2a242512016-05-03 09:03:09 -0400519# Tenant User Roles
520# ------------------------------------------------------------------
521# service neutron admin # if enabled
522
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100523# Migrated from keystone_data.sh
524function create_neutron_accounts {
Kevin Benton66b361b2017-06-13 00:31:01 -0700525 local neutron_url
Kevin Benton66b361b2017-06-13 00:31:01 -0700526 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100527 neutron_url=$Q_PROTOCOL://$SERVICE_HOST/
Kevin Benton66b361b2017-06-13 00:31:01 -0700528 else
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100529 neutron_url=$Q_PROTOCOL://$SERVICE_HOST:$Q_PORT/
Kevin Benton66b361b2017-06-13 00:31:01 -0700530 fi
Slawek Kaplonski1a21ccb2022-07-08 21:57:45 +0200531 if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then
532 neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME
533 fi
Kevin Benton66b361b2017-06-13 00:31:01 -0700534
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100535 if is_service_enabled q-svc neutron-api; then
Sean M. Collins2a242512016-05-03 09:03:09 -0400536
537 create_service_user "neutron"
538
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100539 get_or_create_service "neutron" "network" "Neutron Service"
540 get_or_create_endpoint \
541 "network" \
Kevin Benton66b361b2017-06-13 00:31:01 -0700542 "$REGION_NAME" "$neutron_url"
Sean M. Collins2a242512016-05-03 09:03:09 -0400543 fi
544}
545
Sean M. Collins2a242512016-05-03 09:03:09 -0400546# init_neutron() - Initialize databases, etc.
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100547function init_neutron {
548 recreate_database $Q_DB_NAME
Clark Boylan633dbc32017-06-14 12:09:21 -0700549 time_start "dbsync"
Sean M. Collins2a242512016-05-03 09:03:09 -0400550 # Run Neutron db migrations
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100551 $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 -0700552 time_stop "dbsync"
Sean M. Collins2a242512016-05-03 09:03:09 -0400553}
554
555# install_neutron() - Collect source and prepare
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100556function install_neutron {
Sean M. Collins2a242512016-05-03 09:03:09 -0400557 # Install neutron-lib from git so we make sure we're testing
558 # the latest code.
559 if use_library_from_git "neutron-lib"; then
560 git_clone_by_name "neutron-lib"
561 setup_dev_lib "neutron-lib"
562 fi
563
elajkatbb0c2732023-11-16 11:30:04 +0100564 # Install SQLAlchemy and alembic from git when these are required
565 # see https://bugs.launchpad.net/neutron/+bug/2042941
566 if use_library_from_git "sqlalchemy"; then
567 git_clone $SQLALCHEMY_REPO $SQLALCHEMY_DIR $SQLALCHEMY_BRANCH
568 setup_develop $SQLALCHEMY_DIR
569 fi
570 if use_library_from_git "alembic"; then
571 git_clone $ALEMBIC_REPO $ALEMBIC_DIR $ALEMBIC_BRANCH
572 setup_develop $ALEMBIC_DIR
573 fi
574
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100575 git_clone $NEUTRON_REPO $NEUTRON_DIR $NEUTRON_BRANCH
576 setup_develop $NEUTRON_DIR
Sean M. Collins2a242512016-05-03 09:03:09 -0400577
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100578 if [[ $Q_AGENT == "ovn" ]]; then
579 install_ovn
Sean M. Collins2a242512016-05-03 09:03:09 -0400580 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400581}
582
583# install_neutronclient() - Collect source and prepare
584function install_neutronclient {
585 if use_library_from_git "python-neutronclient"; then
586 git_clone_by_name "python-neutronclient"
587 setup_dev_lib "python-neutronclient"
Sean M. Collins2a242512016-05-03 09:03:09 -0400588 fi
589}
590
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100591# install_neutron_agent_packages() - Collect source and prepare
592function install_neutron_agent_packages {
593 # radvd doesn't come with the OS. Install it if the l3 service is enabled.
594 if is_service_enabled q-l3 neutron-l3; then
595 install_package radvd
Sean M. Collins2a242512016-05-03 09:03:09 -0400596 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100597 # install packages that are specific to plugin agent(s)
598 if is_service_enabled q-agt neutron-agent q-dhcp neutron-dhcp q-l3 neutron-l3; then
599 neutron_plugin_install_agent_packages
Sean M. Collins2a242512016-05-03 09:03:09 -0400600 fi
601}
602
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100603# Finish neutron configuration
604function configure_neutron_after_post_config {
605 if [[ $Q_SERVICE_PLUGIN_CLASSES != '' ]]; then
606 iniset $NEUTRON_CONF DEFAULT service_plugins $Q_SERVICE_PLUGIN_CLASSES
Sean M. Collins2a242512016-05-03 09:03:09 -0400607 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100608 configure_rbac_policies
Sean M. Collins2a242512016-05-03 09:03:09 -0400609}
610
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +0200611# configure_rbac_policies() - Configure Neutron to enforce new RBAC
612# policies and scopes if NEUTRON_ENFORCE_SCOPE == True
613function configure_rbac_policies {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100614 if [[ "$NEUTRON_ENFORCE_SCOPE" == "True" || "$ENFORCE_SCOPE" == True ]]; then
Slawek Kaplonski24b65ad2021-06-22 15:31:46 +0200615 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults True
616 iniset $NEUTRON_CONF oslo_policy enforce_scope True
617 else
618 iniset $NEUTRON_CONF oslo_policy enforce_new_defaults False
619 iniset $NEUTRON_CONF oslo_policy enforce_scope False
620 fi
621}
622
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100623# Start running OVN processes
624function start_ovn_services {
625 if [[ $Q_AGENT == "ovn" ]]; then
Lucas Alvares Gomesa3891282023-07-18 16:31:28 +0100626 if [ "$VIRT_DRIVER" != 'ironic' ]; then
627 # NOTE(TheJulia): Ironic's devstack plugin needs to perform
628 # additional networking configuration to setup a working test
629 # environment with test virtual machines to emulate baremetal,
630 # which requires OVN to be up and running earlier to complete
631 # that base configuration.
632 init_ovn
633 start_ovn
634 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100635 if [[ "$OVN_L3_CREATE_PUBLIC_NETWORK" == "True" ]]; then
636 if [[ "$NEUTRON_CREATE_INITIAL_NETWORKS" != "True" ]]; then
637 echo "OVN_L3_CREATE_PUBLIC_NETWORK=True is being ignored "
638 echo "because NEUTRON_CREATE_INITIAL_NETWORKS is set to False"
639 else
640 create_public_bridge
641 fi
Matt Riedemanne95f2a32018-06-18 16:17:29 -0400642 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400643 fi
644}
645
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100646# Start running processes
647function start_neutron_service_and_check {
648 local service_port=$Q_PORT
649 local service_protocol=$Q_PROTOCOL
650 local cfg_file_options
651 local neutron_url
Sean M. Collins2a242512016-05-03 09:03:09 -0400652
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100653 cfg_file_options="$(determine_config_files neutron-server)"
Sean M. Collins2a242512016-05-03 09:03:09 -0400654
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100655 if is_service_enabled tls-proxy; then
656 service_port=$Q_PORT_INT
657 service_protocol="http"
Sean M. Collins2a242512016-05-03 09:03:09 -0400658 fi
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100659 # Start the Neutron service
660 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
661 enable_service neutron-api
662 run_process neutron-api "$(which uwsgi) --procname-prefix neutron-api --ini $NEUTRON_UWSGI_CONF"
663 neutron_url=$Q_PROTOCOL://$Q_HOST/
Rodolfo Alonso Hernandezaaaa0372024-07-19 08:09:25 +0000664 if [[ "$_Q_RUN_RPC_SERVER" = True ]]; then
665 enable_service neutron-rpc-server
666 fi
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000667 enable_service neutron-periodic-workers
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000668 _enable_ovn_maintenance
Rodolfo Alonso Hernandezaaaa0372024-07-19 08:09:25 +0000669 if [[ "$_Q_RUN_RPC_SERVER" = True ]]; then
670 run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $cfg_file_options"
671 fi
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000672 run_process neutron-periodic-workers "$NEUTRON_BIN_DIR/neutron-periodic-workers $cfg_file_options"
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000673 _run_ovn_maintenance
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100674 else
675 run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
676 neutron_url=$service_protocol://$Q_HOST:$service_port/
677 # Start proxy if enabled
678 if is_service_enabled tls-proxy; then
679 start_tls_proxy neutron '*' $Q_PORT $Q_HOST $Q_PORT_INT
680 fi
681 fi
682 if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then
683 neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME
684 fi
685 echo "Waiting for Neutron to start..."
Sean M. Collins2a242512016-05-03 09:03:09 -0400686
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100687 local testcmd="wget ${ssl_ca} --no-proxy -q -O- $neutron_url"
688 test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900689}
690
Sean M. Collins2a242512016-05-03 09:03:09 -0400691function start_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100692 start_l2_agent "$@"
693 start_other_agents "$@"
694}
695
696# Control of the l2 agent is separated out to make it easier to test partial
697# upgrades (everything upgraded except the L2 agent)
698function start_l2_agent {
699 run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
700
701 if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then
702 sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
703 sudo ip link set $OVS_PHYSICAL_BRIDGE up
704 sudo ip link set br-int up
705 sudo ip link set $PUBLIC_INTERFACE up
706 if is_ironic_hardware; then
707 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
708 sudo ip addr del $IP dev $PUBLIC_INTERFACE
709 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
710 done
711 sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
712 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400713 fi
714}
715
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100716function start_other_agents {
717 run_process q-dhcp "$AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file $Q_DHCP_CONF_FILE"
718
719 run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
720
721 run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file $Q_META_CONF_FILE"
722 run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
723}
724
725# Start running processes, including screen
726function start_neutron_agents {
727 # NOTE(slaweq): it's now just a wrapper for start_neutron function
728 start_neutron "$@"
729}
730
731function stop_l2_agent {
732 stop_process q-agt
733}
734
735# stop_other() - Stop running processes
736function stop_other {
737 if is_service_enabled q-dhcp neutron-dhcp; then
738 stop_process q-dhcp
739 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
740 [ ! -z "$pid" ] && sudo kill -9 $pid
741 fi
742
743 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
744 stop_process neutron-rpc-server
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000745 stop_process neutron-periodic-workers
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100746 stop_process neutron-api
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000747 _stop_ovn_maintenance
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100748 else
749 stop_process q-svc
750 fi
751
752 if is_service_enabled q-l3 neutron-l3; then
753 sudo pkill -f "radvd -C $DATA_DIR/neutron/ra"
754 stop_process q-l3
755 fi
756
757 if is_service_enabled q-meta neutron-metadata-agent; then
758 stop_process q-meta
759 fi
760
761 if is_service_enabled q-metering neutron-metering; then
762 neutron_metering_stop
763 fi
764
765 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Bence Romsics71c3c402022-12-21 13:50:54 +0100766 # pkill takes care not to kill itself, but it may kill its parent
767 # sudo unless we use the "ps | grep [f]oo" trick
768 sudo pkill -9 -f "$NEUTRON_ROOTWRAP-[d]aemon" || :
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100769 fi
770}
771
772# stop_neutron() - Stop running processes (non-screen)
Sean M. Collins2a242512016-05-03 09:03:09 -0400773function stop_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100774 stop_other
775 stop_l2_agent
776
777 if [[ $Q_AGENT == "ovn" && $SKIP_STOP_OVN != "True" ]]; then
778 stop_ovn
Sean M. Collins2a242512016-05-03 09:03:09 -0400779 fi
780}
781
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100782# _move_neutron_addresses_route() - Move the primary IP to the OVS bridge
783# on startup, or back to the public interface on cleanup. If no IP is
784# configured on the interface, just add it as a port to the OVS bridge.
785function _move_neutron_addresses_route {
786 local from_intf=$1
787 local to_intf=$2
788 local add_ovs_port=$3
789 local del_ovs_port=$4
790 local af=$5
791
792 if [[ -n "$from_intf" && -n "$to_intf" ]]; then
793 # Remove the primary IP address from $from_intf and add it to $to_intf,
794 # along with the default route, if it exists. Also, when called
795 # on configure we will also add $from_intf as a port on $to_intf,
796 # assuming it is an OVS bridge.
797
798 local IP_REPLACE=""
799 local IP_DEL=""
800 local IP_UP=""
801 local DEFAULT_ROUTE_GW
802 DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf\s/ { print \$3; exit }")
803 local ADD_OVS_PORT=""
804 local DEL_OVS_PORT=""
805 local ARP_CMD=""
806
807 IP_BRD=$(ip -f $af a s dev $from_intf scope global primary | grep inet | awk '{ print $2, $3, $4; exit }')
808
809 if [ "$DEFAULT_ROUTE_GW" != "" ]; then
810 ADD_DEFAULT_ROUTE="sudo ip -f $af r replace default via $DEFAULT_ROUTE_GW dev $to_intf"
811 fi
812
813 if [[ "$add_ovs_port" == "True" ]]; then
814 ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf"
815 fi
816
817 if [[ "$del_ovs_port" == "True" ]]; then
818 DEL_OVS_PORT="sudo ovs-vsctl --if-exists del-port $from_intf $to_intf"
819 fi
820
821 if [[ "$IP_BRD" != "" ]]; then
822 IP_DEL="sudo ip addr del $IP_BRD dev $from_intf"
823 IP_REPLACE="sudo ip addr replace $IP_BRD dev $to_intf"
824 IP_UP="sudo ip link set $to_intf up"
825 if [[ "$af" == "inet" ]]; then
826 IP=$(echo $IP_BRD | awk '{ print $1; exit }' | grep -o -E '(.*)/' | cut -d "/" -f1)
827 ARP_CMD="sudo arping -A -c 3 -w 5 -I $to_intf $IP "
828 fi
829 fi
830
831 # The add/del OVS port calls have to happen either before or
832 # after the address is moved in order to not leave it orphaned.
833 $DEL_OVS_PORT; $IP_DEL; $IP_REPLACE; $IP_UP; $ADD_OVS_PORT; $ADD_DEFAULT_ROUTE; $ARP_CMD
834 fi
835}
836
837# _configure_public_network_connectivity() - Configures connectivity to the
838# external network using $PUBLIC_INTERFACE or NAT on the single interface
839# machines
840function _configure_public_network_connectivity {
841 # If we've given a PUBLIC_INTERFACE to take over, then we assume
842 # that we can own the whole thing, and privot it into the OVS
843 # bridge. If we are not, we're probably on a single interface
844 # machine, and we just setup NAT so that fixed guests can get out.
845 if [[ -n "$PUBLIC_INTERFACE" ]]; then
846 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" True False "inet"
847
848 if [[ $(ip -f inet6 a s dev "$PUBLIC_INTERFACE" | grep -c 'global') != 0 ]]; then
849 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" False False "inet6"
850 fi
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -0500851 else
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100852 for d in $default_v4_route_devs; do
853 sudo iptables -t nat -A POSTROUTING -o $d -s $FLOATING_RANGE -j MASQUERADE
854 done
855 fi
856}
857
858# cleanup_neutron() - Remove residual data files, anything left over from previous
859# runs that a clean run would need to clean up
860function cleanup_neutron {
861 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
862 stop_process neutron-api
863 stop_process neutron-rpc-server
Rodolfo Alonso Hernandez56368c22024-06-17 15:10:40 +0000864 stop_process neutron-periodic-workers
Rodolfo Alonso Hernandez3a0c0b92024-06-24 11:09:34 +0000865 _stop_ovn_maintenance
Stephen Finucaned5182ce2024-04-19 12:27:14 +0100866 remove_uwsgi_config "$NEUTRON_UWSGI_CONF" "neutron-api"
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100867 sudo rm -f $(apache_site_config_for neutron-api)
868 fi
869
870 if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then
871 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False True "inet"
872
873 if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then
874 # ip(8) wants the prefix length when deleting
875 local v6_gateway
876 v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }')
877 sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE
878 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False False "inet6"
879 fi
880
881 if is_provider_network && is_ironic_hardware; then
882 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
883 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
884 sudo ip addr add $IP dev $PUBLIC_INTERFACE
885 done
886 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
887 fi
888 fi
889
890 if is_neutron_ovs_base_plugin; then
891 neutron_ovs_base_cleanup
892 fi
893
894 if [[ $Q_AGENT == "linuxbridge" ]]; then
895 neutron_lb_cleanup
896 fi
897
898 # delete all namespaces created by neutron
899 for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|fip|snat)-[0-9a-f-]*'); do
900 sudo ip netns delete ${ns}
901 done
902
903 if [[ $Q_AGENT == "ovn" ]]; then
904 cleanup_ovn
905 fi
906}
907
908
909function _create_neutron_conf_dir {
910 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
911 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
912}
913
914# _configure_neutron_common()
915# Set common config for all neutron server and agents.
916# This MUST be called before other ``_configure_neutron_*`` functions.
917function _configure_neutron_common {
918 _create_neutron_conf_dir
919
920 # Uses oslo config generator to generate core sample configuration files
921 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
922
923 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
924
925 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
926
927 # allow neutron user to administer neutron to match neutron account
928 # NOTE(amotoki): This is required for nova works correctly with neutron.
929 if [ -f $NEUTRON_DIR/etc/policy.json ]; then
930 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
931 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
932 else
933 echo '{"context_is_admin": "role:admin or user_name:neutron"}' > $Q_POLICY_FILE
934 fi
935
936 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
937 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
938 neutron_plugin_configure_common
939
940 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
941 die $LINENO "Neutron plugin not set.. exiting"
942 fi
943
944 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
945 mkdir -p /$Q_PLUGIN_CONF_PATH
946 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
947 # NOTE(slaweq): NEUTRON_CORE_PLUGIN_CONF is used e.g. in neutron repository,
948 # it was previously defined in the lib/neutron module which is now deleted.
949 NEUTRON_CORE_PLUGIN_CONF=$Q_PLUGIN_CONF_FILE
950 # NOTE(hichihara): Some neutron vendor plugins were already decomposed and
951 # there is no config file in Neutron tree. They should prepare the file in each plugin.
952 if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then
953 cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE
954 elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then
955 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
956 fi
957
958 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
959 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
960 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
961 iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS
962 iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock
963
964 # NOTE(freerunner): Need to adjust Region Name for nova in multiregion installation
965 iniset $NEUTRON_CONF nova region_name $REGION_NAME
966
967 if [ "$VIRT_DRIVER" = 'fake' ]; then
968 # Disable arbitrary limits
969 iniset $NEUTRON_CONF quotas quota_network -1
970 iniset $NEUTRON_CONF quotas quota_subnet -1
971 iniset $NEUTRON_CONF quotas quota_port -1
972 iniset $NEUTRON_CONF quotas quota_security_group -1
973 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
974 fi
975
976 # Format logging
977 setup_logging $NEUTRON_CONF
978
979 if is_service_enabled tls-proxy && [ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" ]; then
980 # Set the service port for a proxy to take the original
981 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
982 iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True
983 fi
984
985 _neutron_setup_rootwrap
986}
987
988function _configure_neutron_dhcp_agent {
989
990 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE
991
992 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
993 # make it so we have working DNS from guests
994 iniset $Q_DHCP_CONF_FILE DEFAULT dnsmasq_local_resolv True
995 configure_root_helper_options $Q_DHCP_CONF_FILE
996
997 if ! is_service_enabled q-l3 neutron-l3; then
998 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
999 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
1000 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
1001 else
1002 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
1003 die "$LINENO" "Enable isolated metadata is a must for metadata network"
1004 fi
1005 fi
1006 fi
1007
1008 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
1009
1010 neutron_plugin_configure_dhcp_agent $Q_DHCP_CONF_FILE
1011}
1012
1013
1014function _configure_neutron_metadata_agent {
1015 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE
1016
1017 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1018 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_host $Q_META_DATA_IP
1019 iniset $Q_META_CONF_FILE DEFAULT metadata_workers $API_WORKERS
1020 configure_root_helper_options $Q_META_CONF_FILE
1021}
1022
1023function _configure_neutron_ceilometer_notifications {
1024 iniset $NEUTRON_CONF oslo_messaging_notifications driver messagingv2
1025}
1026
1027function _configure_neutron_metering {
1028 neutron_agent_metering_configure_common
1029 neutron_agent_metering_configure_agent
1030}
1031
1032function _configure_dvr {
1033 iniset $NEUTRON_CONF DEFAULT router_distributed True
1034 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
1035}
1036
1037
1038# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
1039# It is called when q-agt is enabled.
1040function _configure_neutron_plugin_agent {
1041 # Specify the default root helper prior to agent configuration to
1042 # ensure that an agent's configuration can override the default
1043 configure_root_helper_options /$Q_PLUGIN_CONF_FILE
1044 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1045
1046 # Configure agent for plugin
1047 neutron_plugin_configure_plugin_agent
1048}
1049
1050function _replace_api_paste_composite {
1051 local sep
1052 sep=$(echo -ne "\x01")
1053 # Replace it
1054 $sudo sed -i -e "s/\/\: neutronversions_composite/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/\: neutronversions_composite/" "$Q_API_PASTE_FILE"
1055 $sudo sed -i -e "s/\/healthcheck\: healthcheck/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/healthcheck\: healthcheck/" "$Q_API_PASTE_FILE"
1056 $sudo sed -i -e "s/\/v2.0\: neutronapi_v2_0/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/v2.0\: neutronapi_v2_0/" "$Q_API_PASTE_FILE"
1057}
1058
1059# _configure_neutron_service() - Set config files for neutron service
1060# It is called when q-svc is enabled.
1061function _configure_neutron_service {
1062 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
1063 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
1064
Slawek Kaplonskib500d802024-06-14 12:58:58 +02001065 if [[ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" && -n "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001066 _replace_api_paste_composite
1067 fi
1068
1069 # Update either configuration file with plugin
1070 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
1071
1072 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1073 iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE
1074
1075 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
1076 configure_keystone_authtoken_middleware $NEUTRON_CONF $Q_ADMIN_USERNAME
1077
1078 # Configuration for neutron notifications to nova.
1079 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
1080 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
1081
1082 configure_keystone_authtoken_middleware $NEUTRON_CONF nova nova
1083
1084 # Configuration for placement client
1085 configure_keystone_authtoken_middleware $NEUTRON_CONF placement placement
1086
1087 # Configure plugin
1088 neutron_plugin_configure_service
1089}
1090
1091# Utility Functions
1092#------------------
1093
1094# neutron_service_plugin_class_add() - add service plugin class
1095function neutron_service_plugin_class_add {
1096 local service_plugin_class=$1
1097 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
1098 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
1099 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
1100 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
1101 fi
1102}
1103
1104# neutron_ml2_extension_driver_add() - add ML2 extension driver
1105function neutron_ml2_extension_driver_add {
1106 local extension=$1
1107 if [[ $Q_ML2_PLUGIN_EXT_DRIVERS == '' ]]; then
1108 Q_ML2_PLUGIN_EXT_DRIVERS=$extension
1109 elif [[ ! ,${Q_ML2_PLUGIN_EXT_DRIVERS}, =~ ,${extension}, ]]; then
1110 Q_ML2_PLUGIN_EXT_DRIVERS="$Q_ML2_PLUGIN_EXT_DRIVERS,$extension"
1111 fi
1112}
1113
1114# neutron_server_config_add() - add server config file
1115function neutron_server_config_add {
1116 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($1)
1117}
1118
1119# neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root).
1120function neutron_deploy_rootwrap_filters {
1121 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1122 return
1123 fi
1124 local srcdir=$1
1125 sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D
1126 sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
1127}
1128
1129# _neutron_setup_rootwrap() - configure Neutron's rootwrap
1130function _neutron_setup_rootwrap {
1131 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1132 return
1133 fi
1134 # Wipe any existing ``rootwrap.d`` files first
1135 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
1136 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
1137 sudo rm -rf $Q_CONF_ROOTWRAP_D
1138 fi
1139
1140 neutron_deploy_rootwrap_filters $NEUTRON_DIR
1141
1142 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
1143 # location moved in newer versions, prefer new location
1144 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
1145 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
1146 else
1147 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
1148 fi
1149 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
yatinkarelffc1b762023-08-28 10:52:26 +05301150 # Rely on $PATH set by devstack to determine what is safe to execute
1151 # by rootwrap rather than use explicit whitelist of paths in
1152 # rootwrap.conf
1153 sudo sed -e 's/^exec_dirs=.*/#&/' -i $Q_RR_CONF_FILE
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001154
1155 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
1156 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
1157 ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
1158
1159 # Set up the rootwrap sudoers for neutron
1160 TEMPFILE=`mktemp`
1161 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
1162 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE
1163 chmod 0440 $TEMPFILE
1164 sudo chown root:root $TEMPFILE
1165 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
1166
1167 # Update the root_helper
1168 configure_root_helper_options $NEUTRON_CONF
1169}
1170
1171function configure_root_helper_options {
1172 local conffile=$1
1173 iniset $conffile agent root_helper "$Q_RR_COMMAND"
1174 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
1175 iniset $conffile agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
1176 fi
1177}
1178
1179function _neutron_setup_interface_driver {
1180
1181 # ovs_use_veth needs to be set before the plugin configuration
1182 # occurs to allow plugins to override the setting.
1183 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1184
1185 neutron_plugin_setup_interface_driver $1
1186}
1187# Functions for Neutron Exercises
1188#--------------------------------
1189
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001190# ssh check
1191function _ssh_check_neutron {
1192 local from_net=$1
1193 local key_file=$2
1194 local ip=$3
1195 local user=$4
1196 local timeout_sec=$5
1197 local probe_cmd = ""
1198 probe_cmd=`_get_probe_cmd_prefix $from_net`
1199 local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success"
1200 test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec
1201}
1202
1203function plugin_agent_add_l2_agent_extension {
1204 local l2_agent_extension=$1
1205 if [[ -z "$L2_AGENT_EXTENSIONS" ]]; then
1206 L2_AGENT_EXTENSIONS=$l2_agent_extension
1207 elif [[ ! ,${L2_AGENT_EXTENSIONS}, =~ ,${l2_agent_extension}, ]]; then
1208 L2_AGENT_EXTENSIONS+=",$l2_agent_extension"
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -05001209 fi
1210}
1211
Sean M. Collins2a242512016-05-03 09:03:09 -04001212# Restore xtrace
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001213$_XTRACE_NEUTRON
1214
1215# Tell emacs to use shell-script-mode
1216## Local variables:
1217## mode: shell-script
1218## End: