blob: bc77f161d7e4fc1e147b8f516a45f3ef2eec3e05 [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
637 run_process neutron-rpc-server "$NEUTRON_BIN_DIR/neutron-rpc-server $cfg_file_options"
638 else
639 run_process q-svc "$NEUTRON_BIN_DIR/neutron-server $cfg_file_options"
640 neutron_url=$service_protocol://$Q_HOST:$service_port/
641 # Start proxy if enabled
642 if is_service_enabled tls-proxy; then
643 start_tls_proxy neutron '*' $Q_PORT $Q_HOST $Q_PORT_INT
644 fi
645 fi
646 if [ ! -z "$NEUTRON_ENDPOINT_SERVICE_NAME" ]; then
647 neutron_url=$neutron_url$NEUTRON_ENDPOINT_SERVICE_NAME
648 fi
649 echo "Waiting for Neutron to start..."
Sean M. Collins2a242512016-05-03 09:03:09 -0400650
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100651 local testcmd="wget ${ssl_ca} --no-proxy -q -O- $neutron_url"
652 test_with_retry "$testcmd" "Neutron did not start" $SERVICE_TIMEOUT
YAMAMOTO Takashieede9dd2016-07-15 10:27:53 +0900653}
654
Sean M. Collins2a242512016-05-03 09:03:09 -0400655function start_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100656 start_l2_agent "$@"
657 start_other_agents "$@"
658}
659
660# Control of the l2 agent is separated out to make it easier to test partial
661# upgrades (everything upgraded except the L2 agent)
662function start_l2_agent {
663 run_process q-agt "$AGENT_BINARY --config-file $NEUTRON_CONF --config-file /$Q_PLUGIN_CONF_FILE"
664
665 if is_provider_network && [[ $Q_AGENT == "openvswitch" ]]; then
666 sudo ovs-vsctl --no-wait -- --may-exist add-port $OVS_PHYSICAL_BRIDGE $PUBLIC_INTERFACE
667 sudo ip link set $OVS_PHYSICAL_BRIDGE up
668 sudo ip link set br-int up
669 sudo ip link set $PUBLIC_INTERFACE up
670 if is_ironic_hardware; then
671 for IP in $(ip addr show dev $PUBLIC_INTERFACE | grep ' inet ' | awk '{print $2}'); do
672 sudo ip addr del $IP dev $PUBLIC_INTERFACE
673 sudo ip addr add $IP dev $OVS_PHYSICAL_BRIDGE
674 done
675 sudo ip route replace $FIXED_RANGE via $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
676 fi
Sean M. Collins2a242512016-05-03 09:03:09 -0400677 fi
678}
679
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100680function start_other_agents {
681 run_process q-dhcp "$AGENT_DHCP_BINARY --config-file $NEUTRON_CONF --config-file $Q_DHCP_CONF_FILE"
682
683 run_process q-l3 "$AGENT_L3_BINARY $(determine_config_files neutron-l3-agent)"
684
685 run_process q-meta "$AGENT_META_BINARY --config-file $NEUTRON_CONF --config-file $Q_META_CONF_FILE"
686 run_process q-metering "$AGENT_METERING_BINARY --config-file $NEUTRON_CONF --config-file $METERING_AGENT_CONF_FILENAME"
687}
688
689# Start running processes, including screen
690function start_neutron_agents {
691 # NOTE(slaweq): it's now just a wrapper for start_neutron function
692 start_neutron "$@"
693}
694
695function stop_l2_agent {
696 stop_process q-agt
697}
698
699# stop_other() - Stop running processes
700function stop_other {
701 if is_service_enabled q-dhcp neutron-dhcp; then
702 stop_process q-dhcp
703 pid=$(ps aux | awk '/[d]nsmasq.+interface=(tap|ns-)/ { print $2 }')
704 [ ! -z "$pid" ] && sudo kill -9 $pid
705 fi
706
707 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
708 stop_process neutron-rpc-server
709 stop_process neutron-api
710 else
711 stop_process q-svc
712 fi
713
714 if is_service_enabled q-l3 neutron-l3; then
715 sudo pkill -f "radvd -C $DATA_DIR/neutron/ra"
716 stop_process q-l3
717 fi
718
719 if is_service_enabled q-meta neutron-metadata-agent; then
720 stop_process q-meta
721 fi
722
723 if is_service_enabled q-metering neutron-metering; then
724 neutron_metering_stop
725 fi
726
727 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
Bence Romsics71c3c402022-12-21 13:50:54 +0100728 # pkill takes care not to kill itself, but it may kill its parent
729 # sudo unless we use the "ps | grep [f]oo" trick
730 sudo pkill -9 -f "$NEUTRON_ROOTWRAP-[d]aemon" || :
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100731 fi
732}
733
734# stop_neutron() - Stop running processes (non-screen)
Sean M. Collins2a242512016-05-03 09:03:09 -0400735function stop_neutron {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100736 stop_other
737 stop_l2_agent
738
739 if [[ $Q_AGENT == "ovn" && $SKIP_STOP_OVN != "True" ]]; then
740 stop_ovn
Sean M. Collins2a242512016-05-03 09:03:09 -0400741 fi
742}
743
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100744# _move_neutron_addresses_route() - Move the primary IP to the OVS bridge
745# on startup, or back to the public interface on cleanup. If no IP is
746# configured on the interface, just add it as a port to the OVS bridge.
747function _move_neutron_addresses_route {
748 local from_intf=$1
749 local to_intf=$2
750 local add_ovs_port=$3
751 local del_ovs_port=$4
752 local af=$5
753
754 if [[ -n "$from_intf" && -n "$to_intf" ]]; then
755 # Remove the primary IP address from $from_intf and add it to $to_intf,
756 # along with the default route, if it exists. Also, when called
757 # on configure we will also add $from_intf as a port on $to_intf,
758 # assuming it is an OVS bridge.
759
760 local IP_REPLACE=""
761 local IP_DEL=""
762 local IP_UP=""
763 local DEFAULT_ROUTE_GW
764 DEFAULT_ROUTE_GW=$(ip -f $af r | awk "/default.+$from_intf\s/ { print \$3; exit }")
765 local ADD_OVS_PORT=""
766 local DEL_OVS_PORT=""
767 local ARP_CMD=""
768
769 IP_BRD=$(ip -f $af a s dev $from_intf scope global primary | grep inet | awk '{ print $2, $3, $4; exit }')
770
771 if [ "$DEFAULT_ROUTE_GW" != "" ]; then
772 ADD_DEFAULT_ROUTE="sudo ip -f $af r replace default via $DEFAULT_ROUTE_GW dev $to_intf"
773 fi
774
775 if [[ "$add_ovs_port" == "True" ]]; then
776 ADD_OVS_PORT="sudo ovs-vsctl --may-exist add-port $to_intf $from_intf"
777 fi
778
779 if [[ "$del_ovs_port" == "True" ]]; then
780 DEL_OVS_PORT="sudo ovs-vsctl --if-exists del-port $from_intf $to_intf"
781 fi
782
783 if [[ "$IP_BRD" != "" ]]; then
784 IP_DEL="sudo ip addr del $IP_BRD dev $from_intf"
785 IP_REPLACE="sudo ip addr replace $IP_BRD dev $to_intf"
786 IP_UP="sudo ip link set $to_intf up"
787 if [[ "$af" == "inet" ]]; then
788 IP=$(echo $IP_BRD | awk '{ print $1; exit }' | grep -o -E '(.*)/' | cut -d "/" -f1)
789 ARP_CMD="sudo arping -A -c 3 -w 5 -I $to_intf $IP "
790 fi
791 fi
792
793 # The add/del OVS port calls have to happen either before or
794 # after the address is moved in order to not leave it orphaned.
795 $DEL_OVS_PORT; $IP_DEL; $IP_REPLACE; $IP_UP; $ADD_OVS_PORT; $ADD_DEFAULT_ROUTE; $ARP_CMD
796 fi
797}
798
799# _configure_public_network_connectivity() - Configures connectivity to the
800# external network using $PUBLIC_INTERFACE or NAT on the single interface
801# machines
802function _configure_public_network_connectivity {
803 # If we've given a PUBLIC_INTERFACE to take over, then we assume
804 # that we can own the whole thing, and privot it into the OVS
805 # bridge. If we are not, we're probably on a single interface
806 # machine, and we just setup NAT so that fixed guests can get out.
807 if [[ -n "$PUBLIC_INTERFACE" ]]; then
808 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" True False "inet"
809
810 if [[ $(ip -f inet6 a s dev "$PUBLIC_INTERFACE" | grep -c 'global') != 0 ]]; then
811 _move_neutron_addresses_route "$PUBLIC_INTERFACE" "$OVS_PHYSICAL_BRIDGE" False False "inet6"
812 fi
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -0500813 else
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100814 for d in $default_v4_route_devs; do
815 sudo iptables -t nat -A POSTROUTING -o $d -s $FLOATING_RANGE -j MASQUERADE
816 done
817 fi
818}
819
820# cleanup_neutron() - Remove residual data files, anything left over from previous
821# runs that a clean run would need to clean up
822function cleanup_neutron {
823 if [ "$NEUTRON_DEPLOY_MOD_WSGI" == "True" ]; then
824 stop_process neutron-api
825 stop_process neutron-rpc-server
826 remove_uwsgi_config "$NEUTRON_UWSGI_CONF" "$NEUTRON_BIN_DIR/neutron-api"
827 sudo rm -f $(apache_site_config_for neutron-api)
828 fi
829
830 if [[ -n "$OVS_PHYSICAL_BRIDGE" ]]; then
831 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False True "inet"
832
833 if [[ $(ip -f inet6 a s dev "$OVS_PHYSICAL_BRIDGE" | grep -c 'global') != 0 ]]; then
834 # ip(8) wants the prefix length when deleting
835 local v6_gateway
836 v6_gateway=$(ip -6 a s dev $OVS_PHYSICAL_BRIDGE | grep $IPV6_PUBLIC_NETWORK_GATEWAY | awk '{ print $2 }')
837 sudo ip -6 addr del $v6_gateway dev $OVS_PHYSICAL_BRIDGE
838 _move_neutron_addresses_route "$OVS_PHYSICAL_BRIDGE" "$PUBLIC_INTERFACE" False False "inet6"
839 fi
840
841 if is_provider_network && is_ironic_hardware; then
842 for IP in $(ip addr show dev $OVS_PHYSICAL_BRIDGE | grep ' inet ' | awk '{print $2}'); do
843 sudo ip addr del $IP dev $OVS_PHYSICAL_BRIDGE
844 sudo ip addr add $IP dev $PUBLIC_INTERFACE
845 done
846 sudo route del -net $FIXED_RANGE gw $NETWORK_GATEWAY dev $OVS_PHYSICAL_BRIDGE
847 fi
848 fi
849
850 if is_neutron_ovs_base_plugin; then
851 neutron_ovs_base_cleanup
852 fi
853
854 if [[ $Q_AGENT == "linuxbridge" ]]; then
855 neutron_lb_cleanup
856 fi
857
858 # delete all namespaces created by neutron
859 for ns in $(sudo ip netns list | grep -o -E '(qdhcp|qrouter|fip|snat)-[0-9a-f-]*'); do
860 sudo ip netns delete ${ns}
861 done
862
863 if [[ $Q_AGENT == "ovn" ]]; then
864 cleanup_ovn
865 fi
866}
867
868
869function _create_neutron_conf_dir {
870 # Put config files in ``NEUTRON_CONF_DIR`` for everyone to find
871 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
872}
873
874# _configure_neutron_common()
875# Set common config for all neutron server and agents.
876# This MUST be called before other ``_configure_neutron_*`` functions.
877function _configure_neutron_common {
878 _create_neutron_conf_dir
879
880 # Uses oslo config generator to generate core sample configuration files
881 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
882
883 cp $NEUTRON_DIR/etc/neutron.conf.sample $NEUTRON_CONF
884
885 Q_POLICY_FILE=$NEUTRON_CONF_DIR/policy.json
886
887 # allow neutron user to administer neutron to match neutron account
888 # NOTE(amotoki): This is required for nova works correctly with neutron.
889 if [ -f $NEUTRON_DIR/etc/policy.json ]; then
890 cp $NEUTRON_DIR/etc/policy.json $Q_POLICY_FILE
891 sed -i 's/"context_is_admin": "role:admin"/"context_is_admin": "role:admin or user_name:neutron"/g' $Q_POLICY_FILE
892 else
893 echo '{"context_is_admin": "role:admin or user_name:neutron"}' > $Q_POLICY_FILE
894 fi
895
896 # Set plugin-specific variables ``Q_DB_NAME``, ``Q_PLUGIN_CLASS``.
897 # For main plugin config file, set ``Q_PLUGIN_CONF_PATH``, ``Q_PLUGIN_CONF_FILENAME``.
898 neutron_plugin_configure_common
899
900 if [[ "$Q_PLUGIN_CONF_PATH" == '' || "$Q_PLUGIN_CONF_FILENAME" == '' || "$Q_PLUGIN_CLASS" == '' ]]; then
901 die $LINENO "Neutron plugin not set.. exiting"
902 fi
903
904 # If needed, move config file from ``$NEUTRON_DIR/etc/neutron`` to ``NEUTRON_CONF_DIR``
905 mkdir -p /$Q_PLUGIN_CONF_PATH
906 Q_PLUGIN_CONF_FILE=$Q_PLUGIN_CONF_PATH/$Q_PLUGIN_CONF_FILENAME
907 # NOTE(slaweq): NEUTRON_CORE_PLUGIN_CONF is used e.g. in neutron repository,
908 # it was previously defined in the lib/neutron module which is now deleted.
909 NEUTRON_CORE_PLUGIN_CONF=$Q_PLUGIN_CONF_FILE
910 # NOTE(hichihara): Some neutron vendor plugins were already decomposed and
911 # there is no config file in Neutron tree. They should prepare the file in each plugin.
912 if [ -f "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" ]; then
913 cp "$NEUTRON_DIR/$Q_PLUGIN_CONF_FILE.sample" /$Q_PLUGIN_CONF_FILE
914 elif [ -f $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE ]; then
915 cp $NEUTRON_DIR/$Q_PLUGIN_CONF_FILE /$Q_PLUGIN_CONF_FILE
916 fi
917
918 iniset $NEUTRON_CONF database connection `database_connection_url $Q_DB_NAME`
919 iniset $NEUTRON_CONF DEFAULT state_path $DATA_DIR/neutron
920 iniset $NEUTRON_CONF DEFAULT use_syslog $SYSLOG
921 iniset $NEUTRON_CONF DEFAULT bind_host $Q_LISTEN_ADDRESS
922 iniset $NEUTRON_CONF oslo_concurrency lock_path $DATA_DIR/neutron/lock
923
924 # NOTE(freerunner): Need to adjust Region Name for nova in multiregion installation
925 iniset $NEUTRON_CONF nova region_name $REGION_NAME
926
927 if [ "$VIRT_DRIVER" = 'fake' ]; then
928 # Disable arbitrary limits
929 iniset $NEUTRON_CONF quotas quota_network -1
930 iniset $NEUTRON_CONF quotas quota_subnet -1
931 iniset $NEUTRON_CONF quotas quota_port -1
932 iniset $NEUTRON_CONF quotas quota_security_group -1
933 iniset $NEUTRON_CONF quotas quota_security_group_rule -1
934 fi
935
936 # Format logging
937 setup_logging $NEUTRON_CONF
938
939 if is_service_enabled tls-proxy && [ "$NEUTRON_DEPLOY_MOD_WSGI" == "False" ]; then
940 # Set the service port for a proxy to take the original
941 iniset $NEUTRON_CONF DEFAULT bind_port "$Q_PORT_INT"
942 iniset $NEUTRON_CONF oslo_middleware enable_proxy_headers_parsing True
943 fi
944
945 _neutron_setup_rootwrap
946}
947
948function _configure_neutron_dhcp_agent {
949
950 cp $NEUTRON_DIR/etc/dhcp_agent.ini.sample $Q_DHCP_CONF_FILE
951
952 iniset $Q_DHCP_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
953 # make it so we have working DNS from guests
954 iniset $Q_DHCP_CONF_FILE DEFAULT dnsmasq_local_resolv True
955 configure_root_helper_options $Q_DHCP_CONF_FILE
956
957 if ! is_service_enabled q-l3 neutron-l3; then
958 if [[ "$ENABLE_ISOLATED_METADATA" = "True" ]]; then
959 iniset $Q_DHCP_CONF_FILE DEFAULT enable_isolated_metadata $ENABLE_ISOLATED_METADATA
960 iniset $Q_DHCP_CONF_FILE DEFAULT enable_metadata_network $ENABLE_METADATA_NETWORK
961 else
962 if [[ "$ENABLE_METADATA_NETWORK" = "True" ]]; then
963 die "$LINENO" "Enable isolated metadata is a must for metadata network"
964 fi
965 fi
966 fi
967
968 _neutron_setup_interface_driver $Q_DHCP_CONF_FILE
969
970 neutron_plugin_configure_dhcp_agent $Q_DHCP_CONF_FILE
971}
972
973
974function _configure_neutron_metadata_agent {
975 cp $NEUTRON_DIR/etc/metadata_agent.ini.sample $Q_META_CONF_FILE
976
977 iniset $Q_META_CONF_FILE DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
978 iniset $Q_META_CONF_FILE DEFAULT nova_metadata_host $Q_META_DATA_IP
979 iniset $Q_META_CONF_FILE DEFAULT metadata_workers $API_WORKERS
980 configure_root_helper_options $Q_META_CONF_FILE
981}
982
983function _configure_neutron_ceilometer_notifications {
984 iniset $NEUTRON_CONF oslo_messaging_notifications driver messagingv2
985}
986
987function _configure_neutron_metering {
988 neutron_agent_metering_configure_common
989 neutron_agent_metering_configure_agent
990}
991
992function _configure_dvr {
993 iniset $NEUTRON_CONF DEFAULT router_distributed True
994 iniset $Q_L3_CONF_FILE DEFAULT agent_mode $Q_DVR_MODE
995}
996
997
998# _configure_neutron_plugin_agent() - Set config files for neutron plugin agent
999# It is called when q-agt is enabled.
1000function _configure_neutron_plugin_agent {
1001 # Specify the default root helper prior to agent configuration to
1002 # ensure that an agent's configuration can override the default
1003 configure_root_helper_options /$Q_PLUGIN_CONF_FILE
1004 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1005
1006 # Configure agent for plugin
1007 neutron_plugin_configure_plugin_agent
1008}
1009
1010function _replace_api_paste_composite {
1011 local sep
1012 sep=$(echo -ne "\x01")
1013 # Replace it
1014 $sudo sed -i -e "s/\/\: neutronversions_composite/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/\: neutronversions_composite/" "$Q_API_PASTE_FILE"
1015 $sudo sed -i -e "s/\/healthcheck\: healthcheck/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/healthcheck\: healthcheck/" "$Q_API_PASTE_FILE"
1016 $sudo sed -i -e "s/\/v2.0\: neutronapi_v2_0/\/"${NEUTRON_ENDPOINT_SERVICE_NAME}"\/v2.0\: neutronapi_v2_0/" "$Q_API_PASTE_FILE"
1017}
1018
1019# _configure_neutron_service() - Set config files for neutron service
1020# It is called when q-svc is enabled.
1021function _configure_neutron_service {
1022 Q_API_PASTE_FILE=$NEUTRON_CONF_DIR/api-paste.ini
1023 cp $NEUTRON_DIR/etc/api-paste.ini $Q_API_PASTE_FILE
1024
1025 if [[ -n "$NEUTRON_ENDPOINT_SERVICE_NAME" ]]; then
1026 _replace_api_paste_composite
1027 fi
1028
1029 # Update either configuration file with plugin
1030 iniset $NEUTRON_CONF DEFAULT core_plugin $Q_PLUGIN_CLASS
1031
1032 iniset $NEUTRON_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
1033 iniset $NEUTRON_CONF oslo_policy policy_file $Q_POLICY_FILE
1034
1035 iniset $NEUTRON_CONF DEFAULT auth_strategy $Q_AUTH_STRATEGY
1036 configure_keystone_authtoken_middleware $NEUTRON_CONF $Q_ADMIN_USERNAME
1037
1038 # Configuration for neutron notifications to nova.
1039 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_status_changes $Q_NOTIFY_NOVA_PORT_STATUS_CHANGES
1040 iniset $NEUTRON_CONF DEFAULT notify_nova_on_port_data_changes $Q_NOTIFY_NOVA_PORT_DATA_CHANGES
1041
1042 configure_keystone_authtoken_middleware $NEUTRON_CONF nova nova
1043
1044 # Configuration for placement client
1045 configure_keystone_authtoken_middleware $NEUTRON_CONF placement placement
1046
1047 # Configure plugin
1048 neutron_plugin_configure_service
1049}
1050
1051# Utility Functions
1052#------------------
1053
1054# neutron_service_plugin_class_add() - add service plugin class
1055function neutron_service_plugin_class_add {
1056 local service_plugin_class=$1
1057 if [[ $Q_SERVICE_PLUGIN_CLASSES == '' ]]; then
1058 Q_SERVICE_PLUGIN_CLASSES=$service_plugin_class
1059 elif [[ ! ,${Q_SERVICE_PLUGIN_CLASSES}, =~ ,${service_plugin_class}, ]]; then
1060 Q_SERVICE_PLUGIN_CLASSES="$Q_SERVICE_PLUGIN_CLASSES,$service_plugin_class"
1061 fi
1062}
1063
1064# neutron_ml2_extension_driver_add() - add ML2 extension driver
1065function neutron_ml2_extension_driver_add {
1066 local extension=$1
1067 if [[ $Q_ML2_PLUGIN_EXT_DRIVERS == '' ]]; then
1068 Q_ML2_PLUGIN_EXT_DRIVERS=$extension
1069 elif [[ ! ,${Q_ML2_PLUGIN_EXT_DRIVERS}, =~ ,${extension}, ]]; then
1070 Q_ML2_PLUGIN_EXT_DRIVERS="$Q_ML2_PLUGIN_EXT_DRIVERS,$extension"
1071 fi
1072}
1073
1074# neutron_server_config_add() - add server config file
1075function neutron_server_config_add {
1076 _Q_PLUGIN_EXTRA_CONF_FILES_ABS+=($1)
1077}
1078
1079# neutron_deploy_rootwrap_filters() - deploy rootwrap filters to $Q_CONF_ROOTWRAP_D (owned by root).
1080function neutron_deploy_rootwrap_filters {
1081 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1082 return
1083 fi
1084 local srcdir=$1
1085 sudo install -d -o root -m 755 $Q_CONF_ROOTWRAP_D
1086 sudo install -o root -m 644 $srcdir/etc/neutron/rootwrap.d/* $Q_CONF_ROOTWRAP_D/
1087}
1088
1089# _neutron_setup_rootwrap() - configure Neutron's rootwrap
1090function _neutron_setup_rootwrap {
1091 if [[ "$Q_USE_ROOTWRAP" == "False" ]]; then
1092 return
1093 fi
1094 # Wipe any existing ``rootwrap.d`` files first
1095 Q_CONF_ROOTWRAP_D=$NEUTRON_CONF_DIR/rootwrap.d
1096 if [[ -d $Q_CONF_ROOTWRAP_D ]]; then
1097 sudo rm -rf $Q_CONF_ROOTWRAP_D
1098 fi
1099
1100 neutron_deploy_rootwrap_filters $NEUTRON_DIR
1101
1102 # Set up ``rootwrap.conf``, pointing to ``$NEUTRON_CONF_DIR/rootwrap.d``
1103 # location moved in newer versions, prefer new location
1104 if test -r $NEUTRON_DIR/etc/neutron/rootwrap.conf; then
1105 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/neutron/rootwrap.conf $Q_RR_CONF_FILE
1106 else
1107 sudo install -o root -g root -m 644 $NEUTRON_DIR/etc/rootwrap.conf $Q_RR_CONF_FILE
1108 fi
1109 sudo sed -e "s:^filters_path=.*$:filters_path=$Q_CONF_ROOTWRAP_D:" -i $Q_RR_CONF_FILE
yatinkarelffc1b762023-08-28 10:52:26 +05301110 # Rely on $PATH set by devstack to determine what is safe to execute
1111 # by rootwrap rather than use explicit whitelist of paths in
1112 # rootwrap.conf
1113 sudo sed -e 's/^exec_dirs=.*/#&/' -i $Q_RR_CONF_FILE
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001114
1115 # Specify ``rootwrap.conf`` as first parameter to neutron-rootwrap
1116 ROOTWRAP_SUDOER_CMD="$NEUTRON_ROOTWRAP $Q_RR_CONF_FILE *"
1117 ROOTWRAP_DAEMON_SUDOER_CMD="$NEUTRON_ROOTWRAP-daemon $Q_RR_CONF_FILE"
1118
1119 # Set up the rootwrap sudoers for neutron
1120 TEMPFILE=`mktemp`
1121 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_SUDOER_CMD" >$TEMPFILE
1122 echo "$STACK_USER ALL=(root) NOPASSWD: $ROOTWRAP_DAEMON_SUDOER_CMD" >>$TEMPFILE
1123 chmod 0440 $TEMPFILE
1124 sudo chown root:root $TEMPFILE
1125 sudo mv $TEMPFILE /etc/sudoers.d/neutron-rootwrap
1126
1127 # Update the root_helper
1128 configure_root_helper_options $NEUTRON_CONF
1129}
1130
1131function configure_root_helper_options {
1132 local conffile=$1
1133 iniset $conffile agent root_helper "$Q_RR_COMMAND"
1134 if [[ "$Q_USE_ROOTWRAP_DAEMON" == "True" ]]; then
1135 iniset $conffile agent root_helper_daemon "$Q_RR_DAEMON_COMMAND"
1136 fi
1137}
1138
1139function _neutron_setup_interface_driver {
1140
1141 # ovs_use_veth needs to be set before the plugin configuration
1142 # occurs to allow plugins to override the setting.
1143 iniset $1 DEFAULT ovs_use_veth $Q_OVS_USE_VETH
1144
1145 neutron_plugin_setup_interface_driver $1
1146}
1147# Functions for Neutron Exercises
1148#--------------------------------
1149
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001150# ssh check
1151function _ssh_check_neutron {
1152 local from_net=$1
1153 local key_file=$2
1154 local ip=$3
1155 local user=$4
1156 local timeout_sec=$5
1157 local probe_cmd = ""
1158 probe_cmd=`_get_probe_cmd_prefix $from_net`
1159 local testcmd="$probe_cmd ssh -o StrictHostKeyChecking=no -i $key_file ${user}@$ip echo success"
1160 test_with_retry "$testcmd" "server $ip didn't become ssh-able" $timeout_sec
1161}
1162
1163function plugin_agent_add_l2_agent_extension {
1164 local l2_agent_extension=$1
1165 if [[ -z "$L2_AGENT_EXTENSIONS" ]]; then
1166 L2_AGENT_EXTENSIONS=$l2_agent_extension
1167 elif [[ ! ,${L2_AGENT_EXTENSIONS}, =~ ,${l2_agent_extension}, ]]; then
1168 L2_AGENT_EXTENSIONS+=",$l2_agent_extension"
YAMAMOTO Takashic043b6f2017-02-23 22:30:08 -05001169 fi
1170}
1171
Sean M. Collins2a242512016-05-03 09:03:09 -04001172# Restore xtrace
Slawek Kaplonskia52041c2022-11-18 11:39:56 +01001173$_XTRACE_NEUTRON
1174
1175# Tell emacs to use shell-script-mode
1176## Local variables:
1177## mode: shell-script
1178## End: