blob: 71b5e3350d39015f6d3c0f1a5cd547fd9d6b8efd [file] [log] [blame]
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +01001#!/bin/bash
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14#
15
16# Global Sources
17# --------------
18
19# There are some ovs functions OVN depends on that must be sourced from
20# the ovs neutron plugins.
21source ${TOP_DIR}/lib/neutron_plugins/ovs_base
22source ${TOP_DIR}/lib/neutron_plugins/openvswitch_agent
23
Ian Wienand77835632021-05-13 13:14:42 +100024# Load devstack ovs compliation and loading functions
25source ${TOP_DIR}/lib/neutron_plugins/ovs_source
26
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +010027# Set variables for building OVN from source
28OVN_REPO=${OVN_REPO:-https://github.com/ovn-org/ovn.git}
29OVN_REPO_NAME=$(basename ${OVN_REPO} | cut -f1 -d'.')
30OVN_REPO_NAME=${OVN_REPO_NAME:-ovn}
yatinkarelbf04bf52024-12-27 13:01:16 +053031OVN_BRANCH=${OVN_BRANCH:-branch-24.03}
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +010032# The commit removing OVN bits from the OVS tree, it is the commit that is not
33# present in OVN tree and is used to distinguish if OVN is part of OVS or not.
34# https://github.com/openvswitch/ovs/commit/05bf1dbb98b0635a51f75e268ef8aed27601401d
35OVN_SPLIT_HASH=05bf1dbb98b0635a51f75e268ef8aed27601401d
36
37if is_service_enabled tls-proxy; then
38 OVN_PROTO=ssl
39else
40 OVN_PROTO=tcp
41fi
42
43# How to connect to ovsdb-server hosting the OVN SB database.
44OVN_SB_REMOTE=${OVN_SB_REMOTE:-$OVN_PROTO:$SERVICE_HOST:6642}
45
46# How to connect to ovsdb-server hosting the OVN NB database
47OVN_NB_REMOTE=${OVN_NB_REMOTE:-$OVN_PROTO:$SERVICE_HOST:6641}
48
49# ml2/config for neutron_sync_mode
50OVN_NEUTRON_SYNC_MODE=${OVN_NEUTRON_SYNC_MODE:-log}
51
52# Configured DNS servers to be used with internal_dns extension, only
53# if the subnet DNS is not configured.
54OVN_DNS_SERVERS=${OVN_DNS_SERVERS:-8.8.8.8}
55
56# The type of OVN L3 Scheduler to use. The OVN L3 Scheduler determines the
57# hypervisor/chassis where a routers gateway should be hosted in OVN. The
58# default OVN L3 scheduler is leastloaded
59OVN_L3_SCHEDULER=${OVN_L3_SCHEDULER:-leastloaded}
60
61# A UUID to uniquely identify this system. If one is not specified, a random
62# one will be generated. A randomly generated UUID will be saved in a file
Slawek Kaplonski1ed276c2021-03-11 13:10:28 +010063# $OVS_SYSCONFDIR/system-id.conf (typically /etc/openvswitch/system-id.conf)
64# so that the same one will be re-used if you re-run DevStack or restart
65# Open vSwitch service.
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +010066OVN_UUID=${OVN_UUID:-}
67
68# Whether or not to build the openvswitch kernel module from ovs. This is required
69# unless the distro kernel includes ovs+conntrack support.
70OVN_BUILD_MODULES=$(trueorfalse False OVN_BUILD_MODULES)
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +000071OVN_BUILD_FROM_SOURCE=$(trueorfalse False OVN_BUILD_FROM_SOURCE)
Slawek Kaplonski41853582021-07-06 12:05:31 +020072if [[ "$OVN_BUILD_FROM_SOURCE" == "True" ]]; then
73 Q_BUILD_OVS_FROM_GIT=True
74fi
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +010075
76# Whether or not to install the ovs python module from ovs source. This can be
77# used to test and validate new ovs python features. This should only be used
78# for development purposes since the ovs python version is controlled by OpenStack
79# requirements.
80OVN_INSTALL_OVS_PYTHON_MODULE=$(trueorfalse False OVN_INSTALL_OVS_PYTHON_MODULE)
81
82# GENEVE overlay protocol overhead. Defaults to 38 bytes plus the IP version
83# overhead (20 bytes for IPv4 (default) or 40 bytes for IPv6) which is determined
84# based on the ML2 overlay_ip_version option. The ML2 framework will use this to
85# configure the MTU DHCP option.
86OVN_GENEVE_OVERHEAD=${OVN_GENEVE_OVERHEAD:-38}
87
Lucas Alvares Gomese38a39a2021-05-14 09:14:24 +010088# The log level of the OVN databases (north and south).
89# Supported log levels are: off, emer, err, warn, info or dbg.
90# More information about log levels can be found at
91# http://www.openvswitch.org/support/dist-docs/ovs-appctl.8.txt
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +010092OVN_DBS_LOG_LEVEL=${OVN_DBS_LOG_LEVEL:-info}
93
Rodolfo Alonso Hernandez6091df22023-12-20 23:06:18 +000094# OVN metadata agent configuration
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +010095OVN_META_CONF=$NEUTRON_CONF_DIR/neutron_ovn_metadata_agent.ini
96OVN_META_DATA_HOST=${OVN_META_DATA_HOST:-$(ipv6_unquote $SERVICE_HOST)}
97
Rodolfo Alonso Hernandez6091df22023-12-20 23:06:18 +000098# OVN agent configuration
99OVN_AGENT_CONF=$NEUTRON_CONF_DIR/plugins/ml2/ovn_agent.ini
100OVN_AGENT_EXTENSIONS=${OVN_AGENT_EXTENSIONS:-}
101
Lucas Alvares Gomese38a39a2021-05-14 09:14:24 +0100102# If True (default) the node will be considered a gateway node.
103ENABLE_CHASSIS_AS_GW=$(trueorfalse True ENABLE_CHASSIS_AS_GW)
Lucas Alvares Gomes22038a92021-05-27 13:44:20 +0100104OVN_L3_CREATE_PUBLIC_NETWORK=$(trueorfalse True OVN_L3_CREATE_PUBLIC_NETWORK)
Lucas Alvares Gomese38a39a2021-05-14 09:14:24 +0100105
Lucas Alvares Gomes6ecfe672020-09-23 11:54:19 +0100106export OVSDB_SERVER_LOCAL_HOST=$SERVICE_LOCAL_HOST
Brian Haleyc869d592020-02-28 14:55:08 -0500107TUNNEL_IP=$TUNNEL_ENDPOINT_IP
Lucas Alvares Gomes6ecfe672020-09-23 11:54:19 +0100108if [[ "$SERVICE_IP_VERSION" == 6 ]]; then
109 OVSDB_SERVER_LOCAL_HOST=[$OVSDB_SERVER_LOCAL_HOST]
Brian Haleyc869d592020-02-28 14:55:08 -0500110 TUNNEL_IP=[$TUNNEL_IP]
Lucas Alvares Gomes6ecfe672020-09-23 11:54:19 +0100111fi
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100112
113OVN_IGMP_SNOOPING_ENABLE=$(trueorfalse False OVN_IGMP_SNOOPING_ENABLE)
114
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000115OVS_PREFIX=
116if [[ "$OVN_BUILD_FROM_SOURCE" == "True" ]]; then
117 OVS_PREFIX=/usr/local
118fi
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100119OVS_SBINDIR=$OVS_PREFIX/sbin
120OVS_BINDIR=$OVS_PREFIX/bin
121OVS_RUNDIR=$OVS_PREFIX/var/run/openvswitch
122OVS_SHAREDIR=$OVS_PREFIX/share/openvswitch
123OVS_SCRIPTDIR=$OVS_SHAREDIR/scripts
124OVS_DATADIR=$DATA_DIR/ovs
Rodolfo Alonso Hernandez30819e62021-03-22 07:14:50 +0000125OVS_SYSCONFDIR=${OVS_SYSCONFDIR:-$OVS_PREFIX/etc/openvswitch}
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100126
Gregory Thiemonge6822ff32021-09-01 09:36:31 +0200127if [[ "$OVN_BUILD_FROM_SOURCE" == "True" ]]; then
128 OVN_DATADIR=$DATA_DIR/ovn
129else
130 # When using OVN from packages, the data dir for OVN DBs is
131 # /var/lib/ovn
132 OVN_DATADIR=/var/lib/ovn
133fi
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100134OVN_SHAREDIR=$OVS_PREFIX/share/ovn
135OVN_SCRIPTDIR=$OVN_SHAREDIR/scripts
136OVN_RUNDIR=$OVS_PREFIX/var/run/ovn
137
138NEUTRON_OVN_BIN_DIR=$(get_python_exec_prefix)
139NEUTRON_OVN_METADATA_BINARY="neutron-ovn-metadata-agent"
Rodolfo Alonso Hernandez6091df22023-12-20 23:06:18 +0000140NEUTRON_OVN_AGENT_BINARY="neutron-ovn-agent"
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100141
142STACK_GROUP="$( id --group --name "$STACK_USER" )"
143
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000144OVN_NORTHD_SERVICE=ovn-northd.service
145if is_ubuntu; then
146 # The ovn-central.service file on Ubuntu is responsible for starting
147 # ovn-northd and the OVN DBs (on CentOS this is done by ovn-northd.service)
148 OVN_NORTHD_SERVICE=ovn-central.service
149fi
150OVSDB_SERVER_SERVICE=ovsdb-server.service
151OVS_VSWITCHD_SERVICE=ovs-vswitchd.service
152OVN_CONTROLLER_SERVICE=ovn-controller.service
153OVN_CONTROLLER_VTEP_SERVICE=ovn-controller-vtep.service
154if [[ "$OVN_BUILD_FROM_SOURCE" == "True" ]]; then
155 OVSDB_SERVER_SERVICE=devstack@ovsdb-server.service
156 OVS_VSWITCHD_SERVICE=devstack@ovs-vswitchd.service
157 OVN_NORTHD_SERVICE=devstack@ovn-northd.service
158 OVN_CONTROLLER_SERVICE=devstack@ovn-controller.service
159 OVN_CONTROLLER_VTEP_SERVICE=devstack@ovn-controller-vtep.service
160fi
161
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100162# Defaults Overwrite
163# ------------------
Rodolfo Alonso Hernandez754f1c62025-02-13 08:39:24 +0000164# NOTE(ralonsoh): during the eventlet removal, the "logger" mech
165# driver has been removed from this list. Re-add it once the removal
166# is finished or the mech driver does not call monkey_patch().
167Q_ML2_PLUGIN_MECHANISM_DRIVERS=${Q_ML2_PLUGIN_MECHANISM_DRIVERS:-ovn}
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100168Q_ML2_PLUGIN_TYPE_DRIVERS=${Q_ML2_PLUGIN_TYPE_DRIVERS:-local,flat,vlan,geneve}
169Q_ML2_TENANT_NETWORK_TYPE=${Q_ML2_TENANT_NETWORK_TYPE:-"geneve"}
170Q_ML2_PLUGIN_GENEVE_TYPE_OPTIONS=${Q_ML2_PLUGIN_GENEVE_TYPE_OPTIONS:-"vni_ranges=1:65536"}
Lucas Alvares Gomese7625fc2020-08-26 09:46:35 +0100171Q_ML2_PLUGIN_EXT_DRIVERS=${Q_ML2_PLUGIN_EXT_DRIVERS:-port_security,qos}
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100172# this one allows empty:
173ML2_L3_PLUGIN=${ML2_L3_PLUGIN-"ovn-router"}
174
Flavio Fernandesa2273cc2021-02-06 16:23:36 -0500175Q_LOG_DRIVER_RATE_LIMIT=${Q_LOG_DRIVER_RATE_LIMIT:-100}
176Q_LOG_DRIVER_BURST_LIMIT=${Q_LOG_DRIVER_BURST_LIMIT:-25}
177Q_LOG_DRIVER_LOG_BASE=${Q_LOG_DRIVER_LOG_BASE:-acl_log_meter}
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100178
179# Utility Functions
180# -----------------
181
yatinkarel1baa8902022-05-06 17:53:54 +0530182function wait_for_db_file {
183 local count=0
184 while [ ! -f $1 ]; do
185 sleep 1
186 count=$((count+1))
Dr. Jens Harbottbd6e5202022-07-03 22:27:15 +0200187 if [ "$count" -gt 40 ]; then
yatinkarel1baa8902022-05-06 17:53:54 +0530188 die $LINENO "DB File $1 not found"
189 fi
190 done
191}
192
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000193function wait_for_sock_file {
194 local count=0
195 while [ ! -S $1 ]; do
196 sleep 1
197 count=$((count+1))
Dr. Jens Harbottbd6e5202022-07-03 22:27:15 +0200198 if [ "$count" -gt 40 ]; then
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000199 die $LINENO "Socket $1 not found"
200 fi
201 done
202}
203
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100204function use_new_ovn_repository {
Lucas Alvares Gomese38a39a2021-05-14 09:14:24 +0100205 if [[ "$OVN_BUILD_FROM_SOURCE" == "False" ]]; then
206 return 0
207 fi
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100208 if [ -z "$is_new_ovn" ]; then
209 local ovs_repo_dir=$DEST/$OVS_REPO_NAME
210 if [ ! -d $ovs_repo_dir ]; then
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000211 git_timed clone $OVS_REPO $ovs_repo_dir
212 pushd $ovs_repo_dir
213 git checkout $OVS_BRANCH
214 popd
215 else
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100216 clone_repository $OVS_REPO $ovs_repo_dir $OVS_BRANCH
217 fi
218 # Check the split commit exists in the current branch
219 pushd $ovs_repo_dir
220 git log $OVS_BRANCH --pretty=format:"%H" | grep -q $OVN_SPLIT_HASH
221 is_new_ovn=$?
222 popd
223 fi
224 return $is_new_ovn
225}
226
227# NOTE(rtheis): Function copied from DevStack _neutron_ovs_base_setup_bridge
228# and _neutron_ovs_base_add_bridge with the call to neutron-ovs-cleanup
229# removed. The call is not relevant for OVN, as it is specific to the use
230# of Neutron's OVS agent and hangs when running stack.sh because
231# neutron-ovs-cleanup uses the OVSDB native interface.
232function ovn_base_setup_bridge {
233 local bridge=$1
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000234 local addbr_cmd="sudo ovs-vsctl --no-wait -- --may-exist add-br $bridge -- set bridge $bridge protocols=OpenFlow13,OpenFlow15"
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100235
236 if [ "$OVS_DATAPATH_TYPE" != "system" ] ; then
237 addbr_cmd="$addbr_cmd -- set Bridge $bridge datapath_type=${OVS_DATAPATH_TYPE}"
238 fi
239
240 $addbr_cmd
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000241 sudo ovs-vsctl --no-wait br-set-external-id $bridge bridge-id $bridge
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100242}
243
244function _start_process {
245 $SYSTEMCTL daemon-reload
246 $SYSTEMCTL enable $1
247 $SYSTEMCTL restart $1
248}
249
250function _run_process {
251 local service=$1
252 local cmd="$2"
253 local stop_cmd="$3"
254 local group=$4
Brian Haley71c99652022-10-19 14:08:43 -0400255 local user=$5
256 local rundir=${6:-$OVS_RUNDIR}
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100257
258 local systemd_service="devstack@$service.service"
259 local unit_file="$SYSTEMD_DIR/$systemd_service"
Brian Haley71c99652022-10-19 14:08:43 -0400260 local environment="OVN_RUNDIR=$OVN_RUNDIR OVN_DBDIR=$OVN_DATADIR OVN_LOGDIR=$LOGDIR OVS_RUNDIR=$OVS_RUNDIR OVS_DBDIR=$OVS_DATADIR OVS_LOGDIR=$LOGDIR"
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100261
262 echo "Starting $service executed command": $cmd
263
264 write_user_unit_file $systemd_service "$cmd" "$group" "$user"
265 iniset -sudo $unit_file "Service" "Type" "forking"
266 iniset -sudo $unit_file "Service" "RemainAfterExit" "yes"
267 iniset -sudo $unit_file "Service" "KillMode" "mixed"
268 iniset -sudo $unit_file "Service" "LimitNOFILE" "65536"
269 iniset -sudo $unit_file "Service" "Environment" "$environment"
270 if [ -n "$stop_cmd" ]; then
271 iniset -sudo $unit_file "Service" "ExecStop" "$stop_cmd"
272 fi
273
274 _start_process $systemd_service
275
Brian Haley71c99652022-10-19 14:08:43 -0400276 local testcmd="test -e $rundir/$service.pid"
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100277 test_with_retry "$testcmd" "$service did not start" $SERVICE_TIMEOUT 1
Rodolfo Alonso Hernandez8c671032022-02-09 18:01:46 +0000278 local service_ctl_file
Brian Haley71c99652022-10-19 14:08:43 -0400279 service_ctl_file=$(ls $rundir | grep $service | grep ctl)
Rodolfo Alonso Hernandez8c671032022-02-09 18:01:46 +0000280 if [ -z "$service_ctl_file" ]; then
281 die $LINENO "ctl file for service $service is not present."
282 fi
Brian Haley71c99652022-10-19 14:08:43 -0400283 sudo ovs-appctl -t $rundir/$service_ctl_file vlog/set console:off syslog:info file:info
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100284}
285
286function clone_repository {
287 local repo=$1
288 local dir=$2
289 local branch=$3
290 # Set ERROR_ON_CLONE to false to avoid the need of having the
291 # repositories like OVN and OVS in the required_projects of the job
292 # definition.
293 ERROR_ON_CLONE=false git_clone $repo $dir $branch
294}
295
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100296function create_public_bridge {
297 # Create the public bridge that OVN will use
Radosław Piliszek95298782021-06-08 16:19:40 +0000298 sudo ovs-vsctl --may-exist add-br $PUBLIC_BRIDGE -- set bridge $PUBLIC_BRIDGE protocols=OpenFlow13,OpenFlow15
Harald Jensås16ac21f2023-08-31 15:06:52 +0200299 sudo ovs-vsctl set open . external-ids:ovn-bridge-mappings=${OVN_BRIDGE_MAPPINGS}
Slawek Kaplonskib1a89eb2021-08-26 21:42:32 +0200300 _configure_public_network_connectivity
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100301}
302
303function _disable_libvirt_apparmor {
304 if ! sudo aa-status --enabled ; then
305 return 0
306 fi
307 # NOTE(arosen): This is used as a work around to allow newer versions
308 # of libvirt to work with ovs configured ports. See LP#1466631.
309 # requires the apparmor-utils
310 install_package apparmor-utils
311 # disables apparmor for libvirtd
312 sudo aa-complain /etc/apparmor.d/usr.sbin.libvirtd
313}
314
315
316# OVN compilation functions
317# -------------------------
318
319
320# compile_ovn() - Compile OVN from source and load needed modules
321# Accepts three parameters:
Slawek Kaplonski58889472021-12-22 16:00:29 +0100322# - first optional parameter defines prefix for
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100323# ovn compilation
Slawek Kaplonski58889472021-12-22 16:00:29 +0100324# - second optional parameter defines localstatedir for
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100325# ovn single machine runtime
326function compile_ovn {
Slawek Kaplonski58889472021-12-22 16:00:29 +0100327 local prefix=$1
328 local localstatedir=$2
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100329
330 if [ -n "$prefix" ]; then
331 prefix="--prefix=$prefix"
332 fi
333
334 if [ -n "$localstatedir" ]; then
335 localstatedir="--localstatedir=$localstatedir"
336 fi
337
338 clone_repository $OVN_REPO $DEST/$OVN_REPO_NAME $OVN_BRANCH
339 pushd $DEST/$OVN_REPO_NAME
340
341 if [ ! -f configure ] ; then
342 ./boot.sh
343 fi
344
Mohammed Naser7fa24752022-04-20 15:42:43 -0400345 # NOTE(mnaser): OVN requires that you build using the OVS from the
346 # submodule.
347 #
348 # https://github.com/ovn-org/ovn/blob/3fb397b63663297acbcbf794e1233951222ae5af/Documentation/intro/install/general.rst#bootstrapping
349 # https://github.com/ovn-org/ovn/issues/128
350 git submodule update --init
351 pushd ovs
352 if [ ! -f configure ] ; then
353 ./boot.sh
354 fi
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100355 if [ ! -f config.status ] || [ configure -nt config.status ] ; then
Mohammed Naser7fa24752022-04-20 15:42:43 -0400356 ./configure
357 fi
358 make -j$(($(nproc) + 1))
359 popd
360
361 if [ ! -f config.status ] || [ configure -nt config.status ] ; then
362 ./configure $prefix $localstatedir
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100363 fi
364 make -j$(($(nproc) + 1))
365 sudo make install
366 popd
367}
368
369
370# OVN Neutron driver functions
371# ----------------------------
372
373# OVN service sanity check
374function ovn_sanity_check {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100375 if is_service_enabled q-agt neutron-agent; then
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100376 die $LINENO "The q-agt/neutron-agt service must be disabled with OVN."
377 elif is_service_enabled q-l3 neutron-l3; then
378 die $LINENO "The q-l3/neutron-l3 service must be disabled with OVN."
379 elif is_service_enabled q-svc neutron-api && [[ ! $Q_ML2_PLUGIN_MECHANISM_DRIVERS =~ "ovn" ]]; then
380 die $LINENO "OVN needs to be enabled in \$Q_ML2_PLUGIN_MECHANISM_DRIVERS"
381 elif is_service_enabled q-svc neutron-api && [[ ! $Q_ML2_PLUGIN_TYPE_DRIVERS =~ "geneve" ]]; then
382 die $LINENO "Geneve needs to be enabled in \$Q_ML2_PLUGIN_TYPE_DRIVERS to be used with OVN"
383 fi
384}
385
386# install_ovn() - Collect source and prepare
387function install_ovn {
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100388 echo "Installing OVN and dependent packages"
389
390 # Check the OVN configuration
391 ovn_sanity_check
392
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100393 # Install tox, used to generate the config (see devstack/override-defaults)
394 pip_install tox
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100395
396 sudo mkdir -p $OVS_RUNDIR
397 sudo chown $(whoami) $OVS_RUNDIR
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000398
399 if [[ "$OVN_BUILD_FROM_SOURCE" == "True" ]]; then
400 # If OVS is already installed, remove it, because we're about to
401 # re-install it from source.
402 for package in openvswitch openvswitch-switch openvswitch-common; do
403 if is_package_installed $package ; then
404 uninstall_package $package
405 fi
406 done
407
408 remove_ovs_packages
409 sudo rm -f $OVS_RUNDIR/*
410
411 compile_ovs $OVN_BUILD_MODULES
412 if use_new_ovn_repository; then
Slawek Kaplonski58889472021-12-22 16:00:29 +0100413 compile_ovn
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000414 fi
415
416 sudo mkdir -p $OVS_PREFIX/var/log/openvswitch
417 sudo chown $(whoami) $OVS_PREFIX/var/log/openvswitch
418 sudo mkdir -p $OVS_PREFIX/var/log/ovn
419 sudo chown $(whoami) $OVS_PREFIX/var/log/ovn
420 else
yatinkarel6dd896f2022-04-26 16:37:07 +0530421 # Load fixup_ovn_centos
422 source ${TOP_DIR}/tools/fixup_stuff.sh
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000423 fixup_ovn_centos
424 install_package $(get_packages openvswitch)
425 install_package $(get_packages ovn)
426 fi
427
428 # Ensure that the OVS commands are accessible in the PATH
429 export PATH=$OVS_BINDIR:$PATH
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100430
431 # Archive log files and create new
432 local log_archive_dir=$LOGDIR/archive
433 mkdir -p $log_archive_dir
434 for logfile in ovs-vswitchd.log ovn-northd.log ovn-controller.log ovn-controller-vtep.log ovs-vtep.log ovsdb-server.log ovsdb-server-nb.log ovsdb-server-sb.log; do
435 if [ -f "$LOGDIR/$logfile" ] ; then
436 mv "$LOGDIR/$logfile" "$log_archive_dir/$logfile.${CURRENT_LOG_TIME}"
437 fi
438 done
439
440 # Install ovsdbapp from source if requested
441 if use_library_from_git "ovsdbapp"; then
442 git_clone_by_name "ovsdbapp"
443 setup_dev_lib "ovsdbapp"
444 fi
445
446 # Install ovs python module from ovs source.
447 if [[ "$OVN_INSTALL_OVS_PYTHON_MODULE" == "True" ]]; then
448 sudo pip uninstall -y ovs
449 # Clone the OVS repository if it's not yet present
450 clone_repository $OVS_REPO $DEST/$OVS_REPO_NAME $OVS_BRANCH
451 sudo pip install -e $DEST/$OVS_REPO_NAME/python
452 fi
453}
454
455# filter_network_api_extensions() - Remove non-supported API extensions by
456# the OVN driver from the list of enabled API extensions
457function filter_network_api_extensions {
458 SUPPORTED_NETWORK_API_EXTENSIONS=$($PYTHON -c \
459 'from neutron.common.ovn import extensions ;\
460 print(",".join(extensions.ML2_SUPPORTED_API_EXTENSIONS))')
461 SUPPORTED_NETWORK_API_EXTENSIONS=$SUPPORTED_NETWORK_API_EXTENSIONS,$($PYTHON -c \
462 'from neutron.common.ovn import extensions ;\
463 print(",".join(extensions.ML2_SUPPORTED_API_EXTENSIONS_OVN_L3))')
464 if is_service_enabled q-qos neutron-qos ; then
465 SUPPORTED_NETWORK_API_EXTENSIONS="$SUPPORTED_NETWORK_API_EXTENSIONS,qos"
466 fi
467 NETWORK_API_EXTENSIONS=${NETWORK_API_EXTENSIONS:-$SUPPORTED_NETWORK_API_EXTENSIONS}
468 extensions=$(echo $NETWORK_API_EXTENSIONS | tr ', ' '\n' | sort -u)
469 supported_ext=$(echo $SUPPORTED_NETWORK_API_EXTENSIONS | tr ', ' '\n' | sort -u)
470 enabled_ext=$(comm -12 <(echo -e "$extensions") <(echo -e "$supported_ext"))
471 disabled_ext=$(comm -3 <(echo -e "$extensions") <(echo -e "$enabled_ext"))
472
473 # Log a message in case some extensions had to be disabled because
474 # they are not supported by the OVN driver
475 if [ ! -z "$disabled_ext" ]; then
476 _disabled=$(echo $disabled_ext | tr ' ' ',')
477 echo "The folling network API extensions have been disabled because they are not supported by OVN: $_disabled"
478 fi
479
480 # Export the final list of extensions that have been enabled and are
481 # supported by OVN
482 export NETWORK_API_EXTENSIONS=$(echo $enabled_ext | tr ' ' ',')
483}
484
485function configure_ovn_plugin {
486 echo "Configuring Neutron for OVN"
487
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100488 if is_service_enabled q-svc neutron-api; then
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100489 filter_network_api_extensions
490 populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_type_geneve max_header_size=$OVN_GENEVE_OVERHEAD
491 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_nb_connection="$OVN_NB_REMOTE"
492 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_sb_connection="$OVN_SB_REMOTE"
493 if is_service_enabled tls-proxy; then
494 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_sb_ca_cert="$INT_CA_DIR/ca-chain.pem"
495 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_sb_certificate="$INT_CA_DIR/$DEVSTACK_CERT_NAME.crt"
496 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_sb_private_key="$INT_CA_DIR/private/$DEVSTACK_CERT_NAME.key"
497 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_nb_ca_cert="$INT_CA_DIR/ca-chain.pem"
498 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_nb_certificate="$INT_CA_DIR/$DEVSTACK_CERT_NAME.crt"
499 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_nb_private_key="$INT_CA_DIR/private/$DEVSTACK_CERT_NAME.key"
500 fi
501 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn neutron_sync_mode="$OVN_NEUTRON_SYNC_MODE"
502 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_l3_scheduler="$OVN_L3_SCHEDULER"
503 populate_ml2_config /$Q_PLUGIN_CONF_FILE securitygroup enable_security_group="$Q_USE_SECGROUP"
504 inicomment /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver
505
Flavio Fernandesa2273cc2021-02-06 16:23:36 -0500506 if is_service_enabled q-log neutron-log; then
507 populate_ml2_config /$Q_PLUGIN_CONF_FILE network_log rate_limit="$Q_LOG_DRIVER_RATE_LIMIT"
508 populate_ml2_config /$Q_PLUGIN_CONF_FILE network_log burst_limit="$Q_LOG_DRIVER_BURST_LIMIT"
509 inicomment /$Q_PLUGIN_CONF_FILE network_log local_output_log_base="$Q_LOG_DRIVER_LOG_BASE"
510 fi
511
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100512 if is_service_enabled q-ovn-metadata-agent neutron-ovn-metadata-agent; then
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100513 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_metadata_enabled=True
Rodolfo Alonso Hernandez6091df22023-12-20 23:06:18 +0000514 elif is_service_enabled q-ovn-agent neutron-ovn-agent && [[ "$OVN_AGENT_EXTENSIONS" =~ 'metadata' ]]; then
515 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_metadata_enabled=True
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100516 else
517 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_metadata_enabled=False
518 fi
519
520 if is_service_enabled q-dns neutron-dns ; then
521 iniset $NEUTRON_CONF DEFAULT dns_domain openstackgate.local
522 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn dns_servers="$OVN_DNS_SERVERS"
523 fi
524
525 iniset $NEUTRON_CONF ovs igmp_snooping_enable $OVN_IGMP_SNOOPING_ENABLE
526 fi
527
528 if is_service_enabled q-dhcp neutron-dhcp ; then
529 iniset $NEUTRON_CONF DEFAULT dhcp_agent_notification True
530 else
531 iniset $NEUTRON_CONF DEFAULT dhcp_agent_notification False
532 fi
533
534 if is_service_enabled n-api-meta ; then
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100535 if is_service_enabled q-ovn-metadata-agent neutron-ovn-metadata-agent; then
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100536 iniset $NOVA_CONF neutron service_metadata_proxy True
Rodolfo Alonso Hernandez6091df22023-12-20 23:06:18 +0000537 elif is_service_enabled q-ovn-agent neutron-ovn-agent && [[ "$OVN_AGENT_EXTENSIONS" =~ 'metadata' ]]; then
538 iniset $NOVA_CONF neutron service_metadata_proxy True
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100539 fi
540 fi
541}
542
543function configure_ovn {
544 echo "Configuring OVN"
545
546 if [ -z "$OVN_UUID" ] ; then
Slawek Kaplonski1ed276c2021-03-11 13:10:28 +0100547 if [ -f $OVS_SYSCONFDIR/system-id.conf ]; then
548 OVN_UUID=$(cat $OVS_SYSCONFDIR/system-id.conf)
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100549 else
550 OVN_UUID=$(uuidgen)
Slawek Kaplonski1ed276c2021-03-11 13:10:28 +0100551 echo $OVN_UUID | sudo tee $OVS_SYSCONFDIR/system-id.conf
552 fi
553 else
554 local ovs_uuid
555 ovs_uuid=$(cat $OVS_SYSCONFDIR/system-id.conf)
556 if [ "$ovs_uuid" != $OVN_UUID ]; then
557 echo $OVN_UUID | sudo tee $OVS_SYSCONFDIR/system-id.conf
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100558 fi
559 fi
560
Lucas Alvares Gomes8903d8c2021-01-15 09:26:44 +0000561 # Erase the pre-set configurations from packages. DevStack will
562 # configure OVS and OVN accordingly for its use.
563 if [[ "$OVN_BUILD_FROM_SOURCE" == "False" ]] && is_fedora; then
564 sudo truncate -s 0 /etc/openvswitch/default.conf
565 sudo truncate -s 0 /etc/sysconfig/openvswitch
566 sudo truncate -s 0 /etc/sysconfig/ovn
567 fi
568
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100569 # Metadata
Rodolfo Alonso Hernandez6091df22023-12-20 23:06:18 +0000570 local sample_file=""
571 local config_file=""
572 if is_service_enabled q-ovn-agent neutron-ovn-agent && [[ "$OVN_AGENT_EXTENSIONS" =~ 'metadata' ]] && is_service_enabled ovn-controller; then
573 sample_file=$NEUTRON_DIR/etc/neutron/plugins/ml2/ovn_agent.ini.sample
574 config_file=$OVN_AGENT_CONF
575 elif is_service_enabled q-ovn-metadata-agent neutron-ovn-metadata-agent && is_service_enabled ovn-controller; then
576 sample_file=$NEUTRON_DIR/etc/neutron_ovn_metadata_agent.ini.sample
577 config_file=$OVN_META_CONF
578 fi
Jaromir Wysogladc336b872024-03-27 11:36:26 +0100579 if [ -n "$config_file" ]; then
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100580 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
581
582 mkdir -p $NEUTRON_DIR/etc/neutron/plugins/ml2
583 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
584
Rodolfo Alonso Hernandez6091df22023-12-20 23:06:18 +0000585 cp $sample_file $config_file
586 configure_root_helper_options $config_file
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100587
Rodolfo Alonso Hernandez6091df22023-12-20 23:06:18 +0000588 iniset $config_file DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
589 iniset $config_file DEFAULT nova_metadata_host $OVN_META_DATA_HOST
590 iniset $config_file DEFAULT metadata_workers $API_WORKERS
591 iniset $config_file DEFAULT state_path $DATA_DIR/neutron
592 iniset $config_file ovs ovsdb_connection tcp:$OVSDB_SERVER_LOCAL_HOST:6640
593 iniset $config_file ovn ovn_sb_connection $OVN_SB_REMOTE
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100594 if is_service_enabled tls-proxy; then
Rodolfo Alonso Hernandez6091df22023-12-20 23:06:18 +0000595 iniset $config_file ovn \
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100596 ovn_sb_ca_cert $INT_CA_DIR/ca-chain.pem
Rodolfo Alonso Hernandez6091df22023-12-20 23:06:18 +0000597 iniset $config_file ovn \
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100598 ovn_sb_certificate $INT_CA_DIR/$DEVSTACK_CERT_NAME.crt
Rodolfo Alonso Hernandez6091df22023-12-20 23:06:18 +0000599 iniset $config_file ovn \
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100600 ovn_sb_private_key $INT_CA_DIR/private/$DEVSTACK_CERT_NAME.key
601 fi
Rodolfo Alonso Hernandez6091df22023-12-20 23:06:18 +0000602 if [[ $config_file == $OVN_AGENT_CONF ]]; then
603 iniset $config_file agent extensions $OVN_AGENT_EXTENSIONS
604 iniset $config_file ovn ovn_nb_connection $OVN_NB_REMOTE
605 fi
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100606 fi
607}
608
609function init_ovn {
610 # clean up from previous (possibly aborted) runs
611 # create required data files
612
613 # Assumption: this is a dedicated test system and there is nothing important
614 # in the ovn, ovn-nb, or ovs databases. We're going to trash them and
615 # create new ones on each devstack run.
616
617 _disable_libvirt_apparmor
Roman Doboszbd682512021-11-26 15:34:50 +0100618 local mkdir_cmd="mkdir -p ${OVN_DATADIR}"
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100619
Roman Doboszbd682512021-11-26 15:34:50 +0100620 if [[ "$OVN_BUILD_FROM_SOURCE" == "False" ]]; then
621 mkdir_cmd="sudo ${mkdir_cmd}"
yatinkarelb575af02021-11-26 12:44:41 +0530622 fi
Roman Doboszbd682512021-11-26 15:34:50 +0100623
624 $mkdir_cmd
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100625 mkdir -p $OVS_DATADIR
626
627 rm -f $OVS_DATADIR/*.db
628 rm -f $OVS_DATADIR/.*.db.~lock~
Gregory Thiemonge6822ff32021-09-01 09:36:31 +0200629 sudo rm -f $OVN_DATADIR/*.db
630 sudo rm -f $OVN_DATADIR/.*.db.~lock~
yatinkarel7fecba22023-01-12 17:31:36 +0530631 sudo rm -f $OVN_RUNDIR/*.sock
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100632}
633
634function _start_ovs {
635 echo "Starting OVS"
636 if is_service_enabled ovn-controller ovn-controller-vtep ovn-northd; then
637 # ovsdb-server and ovs-vswitchd are used privately in OVN as openvswitch service names.
638 enable_service ovsdb-server
639 enable_service ovs-vswitchd
640
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000641 if [[ "$OVN_BUILD_FROM_SOURCE" == "True" ]]; then
642 if [ ! -f $OVS_DATADIR/conf.db ]; then
643 ovsdb-tool create $OVS_DATADIR/conf.db $OVS_SHAREDIR/vswitch.ovsschema
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100644 fi
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100645
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000646 if is_service_enabled ovn-controller-vtep; then
647 if [ ! -f $OVS_DATADIR/vtep.db ]; then
648 ovsdb-tool create $OVS_DATADIR/vtep.db $OVS_SHAREDIR/vtep.ovsschema
649 fi
650 fi
651
652 local dbcmd="$OVS_SBINDIR/ovsdb-server --remote=punix:$OVS_RUNDIR/db.sock --remote=ptcp:6640:$OVSDB_SERVER_LOCAL_HOST --pidfile --detach --log-file"
653 dbcmd+=" --remote=db:Open_vSwitch,Open_vSwitch,manager_options"
654 if is_service_enabled ovn-controller-vtep; then
655 dbcmd+=" --remote=db:hardware_vtep,Global,managers $OVS_DATADIR/vtep.db"
656 fi
657 dbcmd+=" $OVS_DATADIR/conf.db"
Brian Haley71c99652022-10-19 14:08:43 -0400658 _run_process ovsdb-server "$dbcmd" "" "$STACK_GROUP" "root" "$OVS_RUNDIR"
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000659
660 # Note: ovn-controller will create and configure br-int once it is started.
661 # So, no need to create it now because nothing depends on that bridge here.
662 local ovscmd="$OVS_SBINDIR/ovs-vswitchd --log-file --pidfile --detach"
Brian Haley71c99652022-10-19 14:08:43 -0400663 _run_process ovs-vswitchd "$ovscmd" "" "$STACK_GROUP" "root" "$OVS_RUNDIR"
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000664 else
665 _start_process "$OVSDB_SERVER_SERVICE"
666 _start_process "$OVS_VSWITCHD_SERVICE"
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100667 fi
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100668
669 echo "Configuring OVSDB"
670 if is_service_enabled tls-proxy; then
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000671 sudo ovs-vsctl --no-wait set-ssl \
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100672 $INT_CA_DIR/private/$DEVSTACK_CERT_NAME.key \
673 $INT_CA_DIR/$DEVSTACK_CERT_NAME.crt \
674 $INT_CA_DIR/ca-chain.pem
675 fi
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000676
677 sudo ovs-vsctl --no-wait set-manager ptcp:6640:$OVSDB_SERVER_LOCAL_HOST
678 sudo ovs-vsctl --no-wait set open_vswitch . system-type="devstack"
679 sudo ovs-vsctl --no-wait set open_vswitch . external-ids:system-id="$OVN_UUID"
680 sudo ovs-vsctl --no-wait set open_vswitch . external-ids:ovn-remote="$OVN_SB_REMOTE"
681 sudo ovs-vsctl --no-wait set open_vswitch . external-ids:ovn-bridge="br-int"
682 sudo ovs-vsctl --no-wait set open_vswitch . external-ids:ovn-encap-type="geneve"
Brian Haleyc869d592020-02-28 14:55:08 -0500683 sudo ovs-vsctl --no-wait set open_vswitch . external-ids:ovn-encap-ip="$TUNNEL_IP"
Vladislav Belogrudov8a38a732022-05-25 12:58:52 +0300684 sudo ovs-vsctl --no-wait set open_vswitch . external-ids:hostname=$(hostname)
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100685 # Select this chassis to host gateway routers
686 if [[ "$ENABLE_CHASSIS_AS_GW" == "True" ]]; then
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000687 sudo ovs-vsctl --no-wait set open_vswitch . external-ids:ovn-cms-options="enable-chassis-as-gw"
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100688 fi
689
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100690 if is_provider_network || [[ $Q_USE_PROVIDERNET_FOR_PUBLIC == "True" ]]; then
691 ovn_base_setup_bridge $OVS_PHYSICAL_BRIDGE
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000692 sudo ovs-vsctl set open . external-ids:ovn-bridge-mappings=${PHYSICAL_NETWORK}:${OVS_PHYSICAL_BRIDGE}
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100693 fi
694
695 if is_service_enabled ovn-controller-vtep ; then
696 ovn_base_setup_bridge br-v
697 vtep-ctl add-ps br-v
Brian Haleyc869d592020-02-28 14:55:08 -0500698 vtep-ctl set Physical_Switch br-v tunnel_ips=$TUNNEL_IP
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100699
700 enable_service ovs-vtep
701 local vtepcmd="$OVS_SCRIPTDIR/ovs-vtep --log-file --pidfile --detach br-v"
Brian Haley71c99652022-10-19 14:08:43 -0400702 _run_process ovs-vtep "$vtepcmd" "" "$STACK_GROUP" "root" "$OVS_RUNDIR"
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100703
704 vtep-ctl set-manager tcp:$HOST_IP:6640
705 fi
706 fi
707}
708
Fernando Royoa9761682024-12-04 16:44:52 +0100709function _wait_for_ovn_and_set_custom_config {
710 # Wait for the service to be ready
711 # Check for socket and db files for both OVN NB and SB
712 wait_for_sock_file $OVN_RUNDIR/ovnnb_db.sock
713 wait_for_sock_file $OVN_RUNDIR/ovnsb_db.sock
714 wait_for_db_file $OVN_DATADIR/ovnnb_db.db
715 wait_for_db_file $OVN_DATADIR/ovnsb_db.db
716
717 if is_service_enabled tls-proxy; then
718 sudo ovn-nbctl --db=unix:$OVN_RUNDIR/ovnnb_db.sock set-ssl $INT_CA_DIR/private/$DEVSTACK_CERT_NAME.key $INT_CA_DIR/$DEVSTACK_CERT_NAME.crt $INT_CA_DIR/ca-chain.pem
719 sudo ovn-sbctl --db=unix:$OVN_RUNDIR/ovnsb_db.sock set-ssl $INT_CA_DIR/private/$DEVSTACK_CERT_NAME.key $INT_CA_DIR/$DEVSTACK_CERT_NAME.crt $INT_CA_DIR/ca-chain.pem
720 fi
721
722 sudo ovn-nbctl --db=unix:$OVN_RUNDIR/ovnnb_db.sock set-connection p${OVN_PROTO}:6641:$SERVICE_LISTEN_ADDRESS -- set connection . inactivity_probe=60000
723 sudo ovn-sbctl --db=unix:$OVN_RUNDIR/ovnsb_db.sock set-connection p${OVN_PROTO}:6642:$SERVICE_LISTEN_ADDRESS -- set connection . inactivity_probe=60000
724 sudo ovs-appctl -t $OVN_RUNDIR/ovnnb_db.ctl vlog/set console:off syslog:$OVN_DBS_LOG_LEVEL file:$OVN_DBS_LOG_LEVEL
725 sudo ovs-appctl -t $OVN_RUNDIR/ovnsb_db.ctl vlog/set console:off syslog:$OVN_DBS_LOG_LEVEL file:$OVN_DBS_LOG_LEVEL
726}
727
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100728# start_ovn() - Start running processes, including screen
729function start_ovn {
730 echo "Starting OVN"
731
732 _start_ovs
733
734 local SCRIPTDIR=$OVN_SCRIPTDIR
735 if ! use_new_ovn_repository; then
736 SCRIPTDIR=$OVS_SCRIPTDIR
737 fi
738
739 if is_service_enabled ovn-northd ; then
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000740 if [[ "$OVN_BUILD_FROM_SOURCE" == "True" ]]; then
741 local cmd="/bin/bash $SCRIPTDIR/ovn-ctl --no-monitor start_northd"
742 local stop_cmd="/bin/bash $SCRIPTDIR/ovn-ctl stop_northd"
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100743
Brian Haley71c99652022-10-19 14:08:43 -0400744 _run_process ovn-northd "$cmd" "$stop_cmd" "$STACK_GROUP" "root" "$OVN_RUNDIR"
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000745 else
746 _start_process "$OVN_NORTHD_SERVICE"
747 fi
748
Fernando Royoa9761682024-12-04 16:44:52 +0100749 _wait_for_ovn_and_set_custom_config
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000750
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100751 fi
752
753 if is_service_enabled ovn-controller ; then
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000754 if [[ "$OVN_BUILD_FROM_SOURCE" == "True" ]]; then
755 local cmd="/bin/bash $SCRIPTDIR/ovn-ctl --no-monitor start_controller"
756 local stop_cmd="/bin/bash $SCRIPTDIR/ovn-ctl stop_controller"
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100757
Brian Haley71c99652022-10-19 14:08:43 -0400758 _run_process ovn-controller "$cmd" "$stop_cmd" "$STACK_GROUP" "root" "$OVN_RUNDIR"
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000759 else
760 _start_process "$OVN_CONTROLLER_SERVICE"
761 fi
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100762 fi
763
764 if is_service_enabled ovn-controller-vtep ; then
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000765 if [[ "$OVN_BUILD_FROM_SOURCE" == "True" ]]; then
766 local cmd="$OVS_BINDIR/ovn-controller-vtep --log-file --pidfile --detach --ovnsb-db=$OVN_SB_REMOTE"
Brian Haley71c99652022-10-19 14:08:43 -0400767 _run_process ovn-controller-vtep "$cmd" "" "$STACK_GROUP" "root" "$OVN_RUNDIR"
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000768 else
769 _start_process "$OVN_CONTROLLER_VTEP_SERVICE"
770 fi
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100771 fi
772
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100773 if is_service_enabled q-ovn-metadata-agent neutron-ovn-metadata-agent; then
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100774 run_process q-ovn-metadata-agent "$NEUTRON_OVN_BIN_DIR/$NEUTRON_OVN_METADATA_BINARY --config-file $OVN_META_CONF"
775 # Format logging
776 setup_logging $OVN_META_CONF
777 fi
778
Rodolfo Alonso Hernandez6091df22023-12-20 23:06:18 +0000779 if is_service_enabled q-ovn-agent neutron-ovn-agent; then
780 run_process q-ovn-agent "$NEUTRON_OVN_BIN_DIR/$NEUTRON_OVN_AGENT_BINARY --config-file $OVN_AGENT_CONF"
781 # Format logging
782 setup_logging $OVN_AGENT_CONF
783 fi
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100784}
785
786function _stop_ovs_dp {
787 sudo ovs-dpctl dump-dps | sudo xargs -n1 ovs-dpctl del-dp
788 modprobe -q -r vport_geneve vport_vxlan openvswitch || true
789}
790
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000791function _stop_process {
792 local service=$1
793 echo "Stopping process $service"
794 if $SYSTEMCTL is-enabled $service; then
795 $SYSTEMCTL stop $service
796 $SYSTEMCTL disable $service
797 fi
798}
799
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100800function stop_ovn {
Slawek Kaplonskia52041c2022-11-18 11:39:56 +0100801 if is_service_enabled q-ovn-metadata-agent neutron-ovn-metadata-agent; then
Bence Romsics71c3c402022-12-21 13:50:54 +0100802 # pkill takes care not to kill itself, but it may kill its parent
803 # sudo unless we use the "ps | grep [f]oo" trick
804 sudo pkill -9 -f "[h]aproxy" || :
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000805 _stop_process "devstack@q-ovn-metadata-agent.service"
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100806 fi
Rodolfo Alonso Hernandez6091df22023-12-20 23:06:18 +0000807 if is_service_enabled q-ovn-agent neutron-ovn-agent; then
808 # pkill takes care not to kill itself, but it may kill its parent
809 # sudo unless we use the "ps | grep [f]oo" trick
810 sudo pkill -9 -f "[h]aproxy" || :
811 _stop_process "devstack@q-ovn-agent.service"
812 fi
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100813 if is_service_enabled ovn-controller-vtep ; then
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000814 _stop_process "$OVN_CONTROLLER_VTEP_SERVICE"
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100815 fi
816 if is_service_enabled ovn-controller ; then
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000817 _stop_process "$OVN_CONTROLLER_SERVICE"
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100818 fi
819 if is_service_enabled ovn-northd ; then
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000820 _stop_process "$OVN_NORTHD_SERVICE"
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100821 fi
822 if is_service_enabled ovs-vtep ; then
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000823 _stop_process "devstack@ovs-vtep.service"
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100824 fi
825
Lucas Alvares Gomese651d9e2020-11-19 14:50:01 +0000826 _stop_process "$OVS_VSWITCHD_SERVICE"
827 _stop_process "$OVSDB_SERVER_SERVICE"
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100828
829 _stop_ovs_dp
830}
831
832function _cleanup {
833 local path=${1:-$DEST/$OVN_REPO_NAME}
834 pushd $path
835 cd $path
836 sudo make uninstall
837 sudo make distclean
838 popd
839}
840
841# cleanup_ovn() - Remove residual data files, anything left over from previous
842# runs that a clean run would need to clean up
843function cleanup_ovn {
844 local ovn_path=$DEST/$OVN_REPO_NAME
845 local ovs_path=$DEST/$OVS_REPO_NAME
846
847 if [ -d $ovn_path ]; then
848 _cleanup $ovn_path
849 fi
850
851 if [ -d $ovs_path ]; then
852 _cleanup $ovs_path
853 fi
854
Artur Angielbfbd2be2022-04-10 11:31:21 +0200855 sudo rm -rf $OVN_RUNDIR
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100856}