blob: b7330db9db85b8b8522bace95a228bc7cd32f491 [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
24# Load devstack ovs base functions
25source $NEUTRON_DIR/devstack/lib/ovs
26
27
28# Defaults
29# --------
30
Slawek Kaplonski7ba26f52020-09-17 11:13:52 +020031Q_BUILD_OVS_FROM_GIT=$(trueorfalse True Q_BUILD_OVS_FROM_GIT)
32
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +010033# Set variables for building OVN from source
34OVN_REPO=${OVN_REPO:-https://github.com/ovn-org/ovn.git}
35OVN_REPO_NAME=$(basename ${OVN_REPO} | cut -f1 -d'.')
36OVN_REPO_NAME=${OVN_REPO_NAME:-ovn}
37OVN_BRANCH=${OVN_BRANCH:-v20.06.1}
38# The commit removing OVN bits from the OVS tree, it is the commit that is not
39# present in OVN tree and is used to distinguish if OVN is part of OVS or not.
40# https://github.com/openvswitch/ovs/commit/05bf1dbb98b0635a51f75e268ef8aed27601401d
41OVN_SPLIT_HASH=05bf1dbb98b0635a51f75e268ef8aed27601401d
42
43if is_service_enabled tls-proxy; then
44 OVN_PROTO=ssl
45else
46 OVN_PROTO=tcp
47fi
48
49# How to connect to ovsdb-server hosting the OVN SB database.
50OVN_SB_REMOTE=${OVN_SB_REMOTE:-$OVN_PROTO:$SERVICE_HOST:6642}
51
52# How to connect to ovsdb-server hosting the OVN NB database
53OVN_NB_REMOTE=${OVN_NB_REMOTE:-$OVN_PROTO:$SERVICE_HOST:6641}
54
55# ml2/config for neutron_sync_mode
56OVN_NEUTRON_SYNC_MODE=${OVN_NEUTRON_SYNC_MODE:-log}
57
58# Configured DNS servers to be used with internal_dns extension, only
59# if the subnet DNS is not configured.
60OVN_DNS_SERVERS=${OVN_DNS_SERVERS:-8.8.8.8}
61
62# The type of OVN L3 Scheduler to use. The OVN L3 Scheduler determines the
63# hypervisor/chassis where a routers gateway should be hosted in OVN. The
64# default OVN L3 scheduler is leastloaded
65OVN_L3_SCHEDULER=${OVN_L3_SCHEDULER:-leastloaded}
66
67# A UUID to uniquely identify this system. If one is not specified, a random
68# one will be generated. A randomly generated UUID will be saved in a file
69# 'ovn-uuid' so that the same one will be re-used if you re-run DevStack.
70OVN_UUID=${OVN_UUID:-}
71
72# Whether or not to build the openvswitch kernel module from ovs. This is required
73# unless the distro kernel includes ovs+conntrack support.
74OVN_BUILD_MODULES=$(trueorfalse False OVN_BUILD_MODULES)
75
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
88# The log level of the OVN databases (north and south)
89OVN_DBS_LOG_LEVEL=${OVN_DBS_LOG_LEVEL:-info}
90
91OVN_META_CONF=$NEUTRON_CONF_DIR/neutron_ovn_metadata_agent.ini
92OVN_META_DATA_HOST=${OVN_META_DATA_HOST:-$(ipv6_unquote $SERVICE_HOST)}
93
Lucas Alvares Gomes6ecfe672020-09-23 11:54:19 +010094export OVSDB_SERVER_LOCAL_HOST=$SERVICE_LOCAL_HOST
95if [[ "$SERVICE_IP_VERSION" == 6 ]]; then
96 OVSDB_SERVER_LOCAL_HOST=[$OVSDB_SERVER_LOCAL_HOST]
97fi
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +010098
99OVN_IGMP_SNOOPING_ENABLE=$(trueorfalse False OVN_IGMP_SNOOPING_ENABLE)
100
101OVS_PREFIX=/usr/local
102OVS_SBINDIR=$OVS_PREFIX/sbin
103OVS_BINDIR=$OVS_PREFIX/bin
104OVS_RUNDIR=$OVS_PREFIX/var/run/openvswitch
105OVS_SHAREDIR=$OVS_PREFIX/share/openvswitch
106OVS_SCRIPTDIR=$OVS_SHAREDIR/scripts
107OVS_DATADIR=$DATA_DIR/ovs
108
109OVN_DATADIR=$DATA_DIR/ovn
110OVN_SHAREDIR=$OVS_PREFIX/share/ovn
111OVN_SCRIPTDIR=$OVN_SHAREDIR/scripts
112OVN_RUNDIR=$OVS_PREFIX/var/run/ovn
113
114NEUTRON_OVN_BIN_DIR=$(get_python_exec_prefix)
115NEUTRON_OVN_METADATA_BINARY="neutron-ovn-metadata-agent"
116
117STACK_GROUP="$( id --group --name "$STACK_USER" )"
118
119# Defaults Overwrite
120# ------------------
121
122Q_ML2_PLUGIN_MECHANISM_DRIVERS=${Q_ML2_PLUGIN_MECHANISM_DRIVERS:-ovn,logger}
123Q_ML2_PLUGIN_TYPE_DRIVERS=${Q_ML2_PLUGIN_TYPE_DRIVERS:-local,flat,vlan,geneve}
124Q_ML2_TENANT_NETWORK_TYPE=${Q_ML2_TENANT_NETWORK_TYPE:-"geneve"}
125Q_ML2_PLUGIN_GENEVE_TYPE_OPTIONS=${Q_ML2_PLUGIN_GENEVE_TYPE_OPTIONS:-"vni_ranges=1:65536"}
Lucas Alvares Gomese7625fc2020-08-26 09:46:35 +0100126Q_ML2_PLUGIN_EXT_DRIVERS=${Q_ML2_PLUGIN_EXT_DRIVERS:-port_security,qos}
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100127# this one allows empty:
128ML2_L3_PLUGIN=${ML2_L3_PLUGIN-"ovn-router"}
129
130
131# Utility Functions
132# -----------------
133
134function use_new_ovn_repository {
135 if [ -z "$is_new_ovn" ]; then
136 local ovs_repo_dir=$DEST/$OVS_REPO_NAME
137 if [ ! -d $ovs_repo_dir ]; then
138 clone_repository $OVS_REPO $ovs_repo_dir $OVS_BRANCH
139 fi
140 # Check the split commit exists in the current branch
141 pushd $ovs_repo_dir
142 git log $OVS_BRANCH --pretty=format:"%H" | grep -q $OVN_SPLIT_HASH
143 is_new_ovn=$?
144 popd
145 fi
146 return $is_new_ovn
147}
148
149# NOTE(rtheis): Function copied from DevStack _neutron_ovs_base_setup_bridge
150# and _neutron_ovs_base_add_bridge with the call to neutron-ovs-cleanup
151# removed. The call is not relevant for OVN, as it is specific to the use
152# of Neutron's OVS agent and hangs when running stack.sh because
153# neutron-ovs-cleanup uses the OVSDB native interface.
154function ovn_base_setup_bridge {
155 local bridge=$1
156 local addbr_cmd="ovs-vsctl --no-wait -- --may-exist add-br $bridge -- set bridge $bridge protocols=OpenFlow13,OpenFlow15"
157
158 if [ "$OVS_DATAPATH_TYPE" != "system" ] ; then
159 addbr_cmd="$addbr_cmd -- set Bridge $bridge datapath_type=${OVS_DATAPATH_TYPE}"
160 fi
161
162 $addbr_cmd
163 ovs-vsctl --no-wait br-set-external-id $bridge bridge-id $bridge
164}
165
166function _start_process {
167 $SYSTEMCTL daemon-reload
168 $SYSTEMCTL enable $1
169 $SYSTEMCTL restart $1
170}
171
172function _run_process {
173 local service=$1
174 local cmd="$2"
175 local stop_cmd="$3"
176 local group=$4
177 local user=${5:-$STACK_USER}
178
179 local systemd_service="devstack@$service.service"
180 local unit_file="$SYSTEMD_DIR/$systemd_service"
181 local environment="OVN_RUNDIR=$OVS_RUNDIR OVN_DBDIR=$OVN_DATADIR OVN_LOGDIR=$LOGDIR OVS_RUNDIR=$OVS_RUNDIR OVS_DBDIR=$OVS_DATADIR OVS_LOGDIR=$LOGDIR"
182
183 echo "Starting $service executed command": $cmd
184
185 write_user_unit_file $systemd_service "$cmd" "$group" "$user"
186 iniset -sudo $unit_file "Service" "Type" "forking"
187 iniset -sudo $unit_file "Service" "RemainAfterExit" "yes"
188 iniset -sudo $unit_file "Service" "KillMode" "mixed"
189 iniset -sudo $unit_file "Service" "LimitNOFILE" "65536"
190 iniset -sudo $unit_file "Service" "Environment" "$environment"
191 if [ -n "$stop_cmd" ]; then
192 iniset -sudo $unit_file "Service" "ExecStop" "$stop_cmd"
193 fi
194
195 _start_process $systemd_service
196
197 local testcmd="test -e $OVS_RUNDIR/$service.pid"
198 test_with_retry "$testcmd" "$service did not start" $SERVICE_TIMEOUT 1
199 sudo ovs-appctl -t $service vlog/set console:off syslog:info file:info
200}
201
202function clone_repository {
203 local repo=$1
204 local dir=$2
205 local branch=$3
206 # Set ERROR_ON_CLONE to false to avoid the need of having the
207 # repositories like OVN and OVS in the required_projects of the job
208 # definition.
209 ERROR_ON_CLONE=false git_clone $repo $dir $branch
210}
211
212function get_ext_gw_interface {
213 # Get ext_gw_interface depending on value of Q_USE_PUBLIC_VETH
214 # This function is copied directly from the devstack neutron-legacy script
215 if [[ "$Q_USE_PUBLIC_VETH" == "True" ]]; then
216 echo $Q_PUBLIC_VETH_EX
217 else
218 # Disable in-band as we are going to use local port
219 # to communicate with VMs
220 sudo ovs-vsctl set Bridge $PUBLIC_BRIDGE \
221 other_config:disable-in-band=true
222 echo $PUBLIC_BRIDGE
223 fi
224}
225
226function create_public_bridge {
227 # Create the public bridge that OVN will use
228 # This logic is based on the devstack neutron-legacy _neutron_configure_router_v4 and _v6
229 local ext_gw_ifc
230 ext_gw_ifc=$(get_ext_gw_interface)
231
232 ovs-vsctl --may-exist add-br $ext_gw_ifc -- set bridge $ext_gw_ifc protocols=OpenFlow13,OpenFlow15
233 ovs-vsctl set open . external-ids:ovn-bridge-mappings=$PHYSICAL_NETWORK:$ext_gw_ifc
234 if [ -n "$FLOATING_RANGE" ]; then
235 local cidr_len=${FLOATING_RANGE#*/}
236 sudo ip addr flush dev $ext_gw_ifc
237 sudo ip addr add $PUBLIC_NETWORK_GATEWAY/$cidr_len dev $ext_gw_ifc
238 fi
239
240 # Ensure IPv6 RAs are accepted on the interface with the default route.
241 # This is needed for neutron-based devstack clouds to work in
242 # IPv6-only clouds in the gate. Please do not remove this without
243 # talking to folks in Infra. This fix is based on a devstack fix for
244 # neutron L3 agent: https://review.openstack.org/#/c/359490/.
245 default_route_dev=$(ip route | grep ^default | awk '{print $5}')
246 sudo sysctl -w net.ipv6.conf.$default_route_dev.accept_ra=2
247
248 sudo sysctl -w net.ipv6.conf.all.forwarding=1
249 if [ -n "$IPV6_PUBLIC_RANGE" ]; then
250 local ipv6_cidr_len=${IPV6_PUBLIC_RANGE#*/}
251 sudo ip -6 addr flush dev $ext_gw_ifc
252 sudo ip -6 addr add $IPV6_PUBLIC_NETWORK_GATEWAY/$ipv6_cidr_len dev $ext_gw_ifc
253 fi
254
255 sudo ip link set $ext_gw_ifc up
256}
257
258function _disable_libvirt_apparmor {
259 if ! sudo aa-status --enabled ; then
260 return 0
261 fi
262 # NOTE(arosen): This is used as a work around to allow newer versions
263 # of libvirt to work with ovs configured ports. See LP#1466631.
264 # requires the apparmor-utils
265 install_package apparmor-utils
266 # disables apparmor for libvirtd
267 sudo aa-complain /etc/apparmor.d/usr.sbin.libvirtd
268}
269
270
271# OVN compilation functions
272# -------------------------
273
274
275# compile_ovn() - Compile OVN from source and load needed modules
276# Accepts three parameters:
277# - first optional is False by default and means that
278# modules are built and installed.
279# - second optional parameter defines prefix for
280# ovn compilation
281# - third optional parameter defines localstatedir for
282# ovn single machine runtime
283function compile_ovn {
284 local build_modules=${1:-False}
285 local prefix=$2
286 local localstatedir=$3
287
288 if [ -n "$prefix" ]; then
289 prefix="--prefix=$prefix"
290 fi
291
292 if [ -n "$localstatedir" ]; then
293 localstatedir="--localstatedir=$localstatedir"
294 fi
295
296 clone_repository $OVN_REPO $DEST/$OVN_REPO_NAME $OVN_BRANCH
297 pushd $DEST/$OVN_REPO_NAME
298
299 if [ ! -f configure ] ; then
300 ./boot.sh
301 fi
302
303 if [ ! -f config.status ] || [ configure -nt config.status ] ; then
304 ./configure --with-ovs-source=$DEST/$OVS_REPO_NAME $prefix $localstatedir
305 fi
306 make -j$(($(nproc) + 1))
307 sudo make install
308 popd
309}
310
311
312# OVN Neutron driver functions
313# ----------------------------
314
315# OVN service sanity check
316function ovn_sanity_check {
317 if is_service_enabled q-agt neutron-agt; then
318 die $LINENO "The q-agt/neutron-agt service must be disabled with OVN."
319 elif is_service_enabled q-l3 neutron-l3; then
320 die $LINENO "The q-l3/neutron-l3 service must be disabled with OVN."
321 elif is_service_enabled q-svc neutron-api && [[ ! $Q_ML2_PLUGIN_MECHANISM_DRIVERS =~ "ovn" ]]; then
322 die $LINENO "OVN needs to be enabled in \$Q_ML2_PLUGIN_MECHANISM_DRIVERS"
323 elif is_service_enabled q-svc neutron-api && [[ ! $Q_ML2_PLUGIN_TYPE_DRIVERS =~ "geneve" ]]; then
324 die $LINENO "Geneve needs to be enabled in \$Q_ML2_PLUGIN_TYPE_DRIVERS to be used with OVN"
325 fi
326}
327
328# install_ovn() - Collect source and prepare
329function install_ovn {
Slawek Kaplonski7ba26f52020-09-17 11:13:52 +0200330 if [[ "$Q_BUILD_OVS_FROM_GIT" == "False" ]]; then
331 echo "Installation of OVS from source disabled."
332 return 0
333 fi
334
Lucas Alvares Gomes1d468d42020-06-09 14:35:52 +0100335 echo "Installing OVN and dependent packages"
336
337 # Check the OVN configuration
338 ovn_sanity_check
339
340 # If OVS is already installed, remove it, because we're about to re-install
341 # it from source.
342 for package in openvswitch openvswitch-switch openvswitch-common; do
343 if is_package_installed $package ; then
344 uninstall_package $package
345 fi
346 done
347
348 # Install tox, used to generate the config (see devstack/override-defaults)
349 pip_install tox
350 remove_ovs_packages
351 sudo rm -f $OVS_RUNDIR/*
352
353 compile_ovs $OVN_BUILD_MODULES
354 if use_new_ovn_repository; then
355 compile_ovn $OVN_BUILD_MODULES
356 fi
357
358 # Ensure that the OVS commands are accessible in the PATH
359 OVS_BINDIR=${OVS_BINDIR:-/usr/local/bin}
360 export PATH=$OVS_BINDIR:$PATH
361
362 sudo mkdir -p $OVS_RUNDIR
363 sudo chown $(whoami) $OVS_RUNDIR
364 sudo mkdir -p $OVS_PREFIX/var/log/openvswitch
365 sudo chown $(whoami) $OVS_PREFIX/var/log/openvswitch
366 sudo mkdir -p $OVS_PREFIX/var/log/ovn
367 sudo chown $(whoami) $OVS_PREFIX/var/log/ovn
368
369 # Archive log files and create new
370 local log_archive_dir=$LOGDIR/archive
371 mkdir -p $log_archive_dir
372 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
373 if [ -f "$LOGDIR/$logfile" ] ; then
374 mv "$LOGDIR/$logfile" "$log_archive_dir/$logfile.${CURRENT_LOG_TIME}"
375 fi
376 done
377
378 # Install ovsdbapp from source if requested
379 if use_library_from_git "ovsdbapp"; then
380 git_clone_by_name "ovsdbapp"
381 setup_dev_lib "ovsdbapp"
382 fi
383
384 # Install ovs python module from ovs source.
385 if [[ "$OVN_INSTALL_OVS_PYTHON_MODULE" == "True" ]]; then
386 sudo pip uninstall -y ovs
387 # Clone the OVS repository if it's not yet present
388 clone_repository $OVS_REPO $DEST/$OVS_REPO_NAME $OVS_BRANCH
389 sudo pip install -e $DEST/$OVS_REPO_NAME/python
390 fi
391}
392
393# filter_network_api_extensions() - Remove non-supported API extensions by
394# the OVN driver from the list of enabled API extensions
395function filter_network_api_extensions {
396 SUPPORTED_NETWORK_API_EXTENSIONS=$($PYTHON -c \
397 'from neutron.common.ovn import extensions ;\
398 print(",".join(extensions.ML2_SUPPORTED_API_EXTENSIONS))')
399 SUPPORTED_NETWORK_API_EXTENSIONS=$SUPPORTED_NETWORK_API_EXTENSIONS,$($PYTHON -c \
400 'from neutron.common.ovn import extensions ;\
401 print(",".join(extensions.ML2_SUPPORTED_API_EXTENSIONS_OVN_L3))')
402 if is_service_enabled q-qos neutron-qos ; then
403 SUPPORTED_NETWORK_API_EXTENSIONS="$SUPPORTED_NETWORK_API_EXTENSIONS,qos"
404 fi
405 NETWORK_API_EXTENSIONS=${NETWORK_API_EXTENSIONS:-$SUPPORTED_NETWORK_API_EXTENSIONS}
406 extensions=$(echo $NETWORK_API_EXTENSIONS | tr ', ' '\n' | sort -u)
407 supported_ext=$(echo $SUPPORTED_NETWORK_API_EXTENSIONS | tr ', ' '\n' | sort -u)
408 enabled_ext=$(comm -12 <(echo -e "$extensions") <(echo -e "$supported_ext"))
409 disabled_ext=$(comm -3 <(echo -e "$extensions") <(echo -e "$enabled_ext"))
410
411 # Log a message in case some extensions had to be disabled because
412 # they are not supported by the OVN driver
413 if [ ! -z "$disabled_ext" ]; then
414 _disabled=$(echo $disabled_ext | tr ' ' ',')
415 echo "The folling network API extensions have been disabled because they are not supported by OVN: $_disabled"
416 fi
417
418 # Export the final list of extensions that have been enabled and are
419 # supported by OVN
420 export NETWORK_API_EXTENSIONS=$(echo $enabled_ext | tr ' ' ',')
421}
422
423function configure_ovn_plugin {
424 echo "Configuring Neutron for OVN"
425
426 if is_service_enabled q-svc ; then
427 filter_network_api_extensions
428 populate_ml2_config /$Q_PLUGIN_CONF_FILE ml2_type_geneve max_header_size=$OVN_GENEVE_OVERHEAD
429 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_nb_connection="$OVN_NB_REMOTE"
430 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_sb_connection="$OVN_SB_REMOTE"
431 if is_service_enabled tls-proxy; then
432 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_sb_ca_cert="$INT_CA_DIR/ca-chain.pem"
433 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_sb_certificate="$INT_CA_DIR/$DEVSTACK_CERT_NAME.crt"
434 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_sb_private_key="$INT_CA_DIR/private/$DEVSTACK_CERT_NAME.key"
435 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_nb_ca_cert="$INT_CA_DIR/ca-chain.pem"
436 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_nb_certificate="$INT_CA_DIR/$DEVSTACK_CERT_NAME.crt"
437 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_nb_private_key="$INT_CA_DIR/private/$DEVSTACK_CERT_NAME.key"
438 fi
439 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn neutron_sync_mode="$OVN_NEUTRON_SYNC_MODE"
440 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_l3_scheduler="$OVN_L3_SCHEDULER"
441 populate_ml2_config /$Q_PLUGIN_CONF_FILE securitygroup enable_security_group="$Q_USE_SECGROUP"
442 inicomment /$Q_PLUGIN_CONF_FILE securitygroup firewall_driver
443
444 if is_service_enabled q-ovn-metadata-agent; then
445 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_metadata_enabled=True
446 else
447 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn ovn_metadata_enabled=False
448 fi
449
450 if is_service_enabled q-dns neutron-dns ; then
451 iniset $NEUTRON_CONF DEFAULT dns_domain openstackgate.local
452 populate_ml2_config /$Q_PLUGIN_CONF_FILE ovn dns_servers="$OVN_DNS_SERVERS"
453 fi
454
455 iniset $NEUTRON_CONF ovs igmp_snooping_enable $OVN_IGMP_SNOOPING_ENABLE
456 fi
457
458 if is_service_enabled q-dhcp neutron-dhcp ; then
459 iniset $NEUTRON_CONF DEFAULT dhcp_agent_notification True
460 else
461 iniset $NEUTRON_CONF DEFAULT dhcp_agent_notification False
462 fi
463
464 if is_service_enabled n-api-meta ; then
465 if is_service_enabled q-ovn-metadata-agent ; then
466 iniset $NOVA_CONF neutron service_metadata_proxy True
467 fi
468 fi
469}
470
471function configure_ovn {
472 echo "Configuring OVN"
473
474 if [ -z "$OVN_UUID" ] ; then
475 if [ -f ./ovn-uuid ] ; then
476 OVN_UUID=$(cat ovn-uuid)
477 else
478 OVN_UUID=$(uuidgen)
479 echo $OVN_UUID > ovn-uuid
480 fi
481 fi
482
483 # Metadata
484 if is_service_enabled q-ovn-metadata-agent && is_service_enabled ovn-controller; then
485 sudo install -d -o $STACK_USER $NEUTRON_CONF_DIR
486
487 mkdir -p $NEUTRON_DIR/etc/neutron/plugins/ml2
488 (cd $NEUTRON_DIR && exec ./tools/generate_config_file_samples.sh)
489
490 cp $NEUTRON_DIR/etc/neutron_ovn_metadata_agent.ini.sample $OVN_META_CONF
491 configure_root_helper_options $OVN_META_CONF
492
493 iniset $OVN_META_CONF DEFAULT debug $ENABLE_DEBUG_LOG_LEVEL
494 iniset $OVN_META_CONF DEFAULT nova_metadata_host $OVN_META_DATA_HOST
495 iniset $OVN_META_CONF DEFAULT metadata_workers $API_WORKERS
496 iniset $OVN_META_CONF DEFAULT state_path $NEUTRON_STATE_PATH
497 iniset $OVN_META_CONF ovs ovsdb_connection unix:$OVS_RUNDIR/db.sock
498 iniset $OVN_META_CONF ovn ovn_sb_connection $OVN_SB_REMOTE
499 if is_service_enabled tls-proxy; then
500 iniset $OVN_META_CONF ovn \
501 ovn_sb_ca_cert $INT_CA_DIR/ca-chain.pem
502 iniset $OVN_META_CONF ovn \
503 ovn_sb_certificate $INT_CA_DIR/$DEVSTACK_CERT_NAME.crt
504 iniset $OVN_META_CONF ovn \
505 ovn_sb_private_key $INT_CA_DIR/private/$DEVSTACK_CERT_NAME.key
506 fi
507 fi
508}
509
510function init_ovn {
511 # clean up from previous (possibly aborted) runs
512 # create required data files
513
514 # Assumption: this is a dedicated test system and there is nothing important
515 # in the ovn, ovn-nb, or ovs databases. We're going to trash them and
516 # create new ones on each devstack run.
517
518 _disable_libvirt_apparmor
519
520 mkdir -p $OVN_DATADIR
521 mkdir -p $OVS_DATADIR
522
523 rm -f $OVS_DATADIR/*.db
524 rm -f $OVS_DATADIR/.*.db.~lock~
525 rm -f $OVN_DATADIR/*.db
526 rm -f $OVN_DATADIR/.*.db.~lock~
527}
528
529function _start_ovs {
530 echo "Starting OVS"
531 if is_service_enabled ovn-controller ovn-controller-vtep ovn-northd; then
532 # ovsdb-server and ovs-vswitchd are used privately in OVN as openvswitch service names.
533 enable_service ovsdb-server
534 enable_service ovs-vswitchd
535
536 if [ ! -f $OVS_DATADIR/conf.db ]; then
537 ovsdb-tool create $OVS_DATADIR/conf.db $OVS_SHAREDIR/vswitch.ovsschema
538 fi
539
540 if is_service_enabled ovn-controller-vtep; then
541 if [ ! -f $OVS_DATADIR/vtep.db ]; then
542 ovsdb-tool create $OVS_DATADIR/vtep.db $OVS_SHAREDIR/vtep.ovsschema
543 fi
544 fi
545
546 local dbcmd="$OVS_SBINDIR/ovsdb-server --remote=punix:$OVS_RUNDIR/db.sock --remote=ptcp:6640:$OVSDB_SERVER_LOCAL_HOST --pidfile --detach --log-file"
547 dbcmd+=" --remote=db:Open_vSwitch,Open_vSwitch,manager_options"
548 if is_service_enabled ovn-controller-vtep; then
549 dbcmd+=" --remote=db:hardware_vtep,Global,managers $OVS_DATADIR/vtep.db"
550 fi
551 dbcmd+=" $OVS_DATADIR/conf.db"
552 _run_process ovsdb-server "$dbcmd"
553
554 echo "Configuring OVSDB"
555 if is_service_enabled tls-proxy; then
556 ovs-vsctl --no-wait set-ssl \
557 $INT_CA_DIR/private/$DEVSTACK_CERT_NAME.key \
558 $INT_CA_DIR/$DEVSTACK_CERT_NAME.crt \
559 $INT_CA_DIR/ca-chain.pem
560 fi
561 ovs-vsctl --no-wait set open_vswitch . system-type="devstack"
562 ovs-vsctl --no-wait set open_vswitch . external-ids:system-id="$OVN_UUID"
563 ovs-vsctl --no-wait set open_vswitch . external-ids:ovn-remote="$OVN_SB_REMOTE"
564 ovs-vsctl --no-wait set open_vswitch . external-ids:ovn-bridge="br-int"
565 ovs-vsctl --no-wait set open_vswitch . external-ids:ovn-encap-type="geneve"
566 ovs-vsctl --no-wait set open_vswitch . external-ids:ovn-encap-ip="$HOST_IP"
567 # Select this chassis to host gateway routers
568 if [[ "$ENABLE_CHASSIS_AS_GW" == "True" ]]; then
569 ovs-vsctl --no-wait set open_vswitch . external-ids:ovn-cms-options="enable-chassis-as-gw"
570 fi
571
572 # Note: ovn-controller will create and configure br-int once it is started.
573 # So, no need to create it now because nothing depends on that bridge here.
574
575 local ovscmd="$OVS_SBINDIR/ovs-vswitchd --log-file --pidfile --detach"
576 _run_process ovs-vswitchd "$ovscmd" "" "$STACK_GROUP" "root"
577
578 if is_provider_network || [[ $Q_USE_PROVIDERNET_FOR_PUBLIC == "True" ]]; then
579 ovn_base_setup_bridge $OVS_PHYSICAL_BRIDGE
580 ovs-vsctl set open . external-ids:ovn-bridge-mappings=${PHYSICAL_NETWORK}:${OVS_PHYSICAL_BRIDGE}
581 fi
582
583 if is_service_enabled ovn-controller-vtep ; then
584 ovn_base_setup_bridge br-v
585 vtep-ctl add-ps br-v
586 vtep-ctl set Physical_Switch br-v tunnel_ips=$HOST_IP
587
588 enable_service ovs-vtep
589 local vtepcmd="$OVS_SCRIPTDIR/ovs-vtep --log-file --pidfile --detach br-v"
590 _run_process ovs-vtep "$vtepcmd" "" "$STACK_GROUP" "root"
591
592 vtep-ctl set-manager tcp:$HOST_IP:6640
593 fi
594 fi
595}
596
597function _start_ovn_services {
598 _start_process "devstack@ovsdb-server.service"
599 _start_process "devstack@ovs-vswitchd.service"
600
601 if is_service_enabled ovs-vtep ; then
602 _start_process "devstack@ovs-vtep.service"
603 fi
604 if is_service_enabled ovn-northd ; then
605 _start_process "devstack@ovn-northd.service"
606 fi
607 if is_service_enabled ovn-controller ; then
608 _start_process "devstack@ovn-controller.service"
609 fi
610 if is_service_enabled ovn-controller-vtep ; then
611 _start_process "devstack@ovn-controller-vtep.service"
612 fi
613 if is_service_enabled q-ovn-metadata-agent; then
614 _start_process "devstack@q-ovn-metadata-agent.service"
615 fi
616}
617
618# start_ovn() - Start running processes, including screen
619function start_ovn {
620 echo "Starting OVN"
621
622 _start_ovs
623
624 local SCRIPTDIR=$OVN_SCRIPTDIR
625 if ! use_new_ovn_repository; then
626 SCRIPTDIR=$OVS_SCRIPTDIR
627 fi
628
629 if is_service_enabled ovn-northd ; then
630 if is_service_enabled tls-proxy; then
631 local tls_args="\
632 --ovn-nb-db-ssl-ca-cert=$INT_CA_DIR/ca-chain.pem \
633 --ovn-nb-db-ssl-cert=$INT_CA_DIR/$DEVSTACK_CERT_NAME.crt \
634 --ovn-nb-db-ssl-key=$INT_CA_DIR/private/$DEVSTACK_CERT_NAME.key \
635 --ovn-sb-db-ssl-ca-cert=$INT_CA_DIR/ca-chain.pem \
636 --ovn-sb-db-ssl-cert=$INT_CA_DIR/$DEVSTACK_CERT_NAME.crt \
637 --ovn-sb-db-ssl-key=$INT_CA_DIR/private/$DEVSTACK_CERT_NAME.key \
638 "
639 else
640 local tls_args=""
641 fi
642 local cmd="/bin/bash $SCRIPTDIR/ovn-ctl --no-monitor $tls_args start_northd"
643 local stop_cmd="/bin/bash $SCRIPTDIR/ovn-ctl stop_northd"
644
645 _run_process ovn-northd "$cmd" "$stop_cmd"
646 ovn-nbctl --db=unix:$OVS_RUNDIR/ovnnb_db.sock set-connection p${OVN_PROTO}:6641:$SERVICE_LISTEN_ADDRESS -- set connection . inactivity_probe=60000
647 ovn-sbctl --db=unix:$OVS_RUNDIR/ovnsb_db.sock set-connection p${OVN_PROTO}:6642:$SERVICE_LISTEN_ADDRESS -- set connection . inactivity_probe=60000
648 sudo ovs-appctl -t $OVS_RUNDIR/ovnnb_db.ctl vlog/set console:off syslog:$OVN_DBS_LOG_LEVEL file:$OVN_DBS_LOG_LEVEL
649 sudo ovs-appctl -t $OVS_RUNDIR/ovnsb_db.ctl vlog/set console:off syslog:$OVN_DBS_LOG_LEVEL file:$OVN_DBS_LOG_LEVEL
650 fi
651
652 if is_service_enabled ovn-controller ; then
653 local cmd="/bin/bash $SCRIPTDIR/ovn-ctl --no-monitor start_controller"
654 local stop_cmd="/bin/bash $SCRIPTDIR/ovn-ctl stop_controller"
655
656 _run_process ovn-controller "$cmd" "$stop_cmd" "$STACK_GROUP" "root"
657 fi
658
659 if is_service_enabled ovn-controller-vtep ; then
660 local cmd="$OVS_BINDIR/ovn-controller-vtep --log-file --pidfile --detach --ovnsb-db=$OVN_SB_REMOTE"
661
662 _run_process ovn-controller-vtep "$cmd" "" "$STACK_GROUP" "root"
663 fi
664
665 if is_service_enabled q-ovn-metadata-agent; then
666 run_process q-ovn-metadata-agent "$NEUTRON_OVN_BIN_DIR/$NEUTRON_OVN_METADATA_BINARY --config-file $OVN_META_CONF"
667 # Format logging
668 setup_logging $OVN_META_CONF
669 fi
670
671 # NOTE(lucasagomes): To keep things simpler, let's reuse the same
672 # RUNDIR for both OVS and OVN. This way we avoid having to specify the
673 # --db option in the ovn-{n,s}bctl commands while playing with DevStack
674 if use_new_ovn_repository; then
675 sudo ln -s $OVS_RUNDIR $OVN_RUNDIR
676 fi
677
678 _start_ovn_services
679}
680
681function _stop_ovs_dp {
682 sudo ovs-dpctl dump-dps | sudo xargs -n1 ovs-dpctl del-dp
683 modprobe -q -r vport_geneve vport_vxlan openvswitch || true
684}
685
686function stop_ovn {
687 if is_service_enabled q-ovn-metadata-agent; then
688 sudo pkill -9 -f haproxy || :
689 stop_process neutron-ovn-metadata-agent
690 fi
691 if is_service_enabled ovn-controller-vtep ; then
692 stop_process ovn-controller-vtep
693 fi
694 if is_service_enabled ovn-controller ; then
695 stop_process ovn-controller
696 fi
697 if is_service_enabled ovn-northd ; then
698 stop_process ovn-northd
699 fi
700 if is_service_enabled ovs-vtep ; then
701 stop_process ovs-vtep
702 fi
703
704 stop_process ovs-vswitchd
705 stop_process ovsdb-server
706
707 _stop_ovs_dp
708}
709
710function _cleanup {
711 local path=${1:-$DEST/$OVN_REPO_NAME}
712 pushd $path
713 cd $path
714 sudo make uninstall
715 sudo make distclean
716 popd
717}
718
719# cleanup_ovn() - Remove residual data files, anything left over from previous
720# runs that a clean run would need to clean up
721function cleanup_ovn {
722 local ovn_path=$DEST/$OVN_REPO_NAME
723 local ovs_path=$DEST/$OVS_REPO_NAME
724
725 if [ -d $ovn_path ]; then
726 _cleanup $ovn_path
727 fi
728
729 if [ -d $ovs_path ]; then
730 _cleanup $ovs_path
731 fi
732
733 sudo rm -f $OVN_RUNDIR
734}