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