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