]> git.proxmox.com Git - mirror_ovs.git/blame - tutorial/ovs-sandbox
sandbox: disable ssl for backup ovn southbound db
[mirror_ovs.git] / tutorial / ovs-sandbox
CommitLineData
eeecce05
BP
1#! /bin/sh
2#
fa183acc 3# Copyright (c) 2013, 2015, 2016 Nicira, Inc.
eeecce05
BP
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at:
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17set -e
18
8da7cd8c 19run() {
eeecce05
BP
20 (cd "$sandbox" && "$@") || exit 1
21}
22
8da7cd8c 23run_xterm() {
4cf272aa
AZ
24 title=$1;
25 shift
26 run xterm -T "$title" -e "$@" &
8da7cd8c
AZ
27}
28
29rungdb() {
30 under_gdb=$1
60ceeb6c 31 gdb_run=$2
8da7cd8c 32 shift
60ceeb6c
AZ
33 shift
34
8da7cd8c
AZ
35 # Remove the --detach and to put the process under gdb control.
36 # Also remove --vconsole:off to allow error message to show up
37 # on the console.
38 # Use "DISPLAY" variable to determine out if X is supported
39 if $under_gdb && [ "$DISPLAY" ]; then
40 args=`echo $@ |sed s/--detach//g | sed s/--vconsole:off//g`
30a67866 41 xterm_title=$1
60ceeb6c
AZ
42
43 gdb_cmd=""
44 if $gdb_run; then
45 gdb_cmd="-ex run"
46 fi
47
48 run_xterm $xterm_title gdb $gdb_cmd --args $args
8da7cd8c
AZ
49 else
50 run $@
51 fi
52}
53
4b814d41
AZ
54gdb_vswitchd=false
55gdb_ovsdb=false
60ceeb6c
AZ
56gdb_vswitchd_ex=false
57gdb_ovsdb_ex=false
91ae2065 58gdb_ovn_northd=false
2c6bcfa2 59gdb_ovn_northd_ex=false
717c7fc5 60gdb_ovn_controller=false
2c6bcfa2 61gdb_ovn_controller_ex=false
36561090
RB
62gdb_ovn_controller_vtep=false
63gdb_ovn_controller_vtep_ex=false
eeecce05
BP
64builddir=
65srcdir=
66schema=
67installed=false
68built=false
ff358c71 69ovn=false
1369720c
JP
70ovnsb_schema=
71ovnnb_schema=
e170fc09 72ovn_rbac=true
24d04cff 73dummy=override
8da7cd8c 74
eeecce05
BP
75for option; do
76 # This option-parsing mechanism borrowed from a Autoconf-generated
77 # configure script under the following license:
78
79 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
80 # 2002, 2003, 2004, 2005, 2006, 2009, 2013 Free Software Foundation, Inc.
81 # This configure script is free software; the Free Software Foundation
82 # gives unlimited permission to copy, distribute and modify it.
83
84 # If the previous option needs an argument, assign it.
85 if test -n "$prev"; then
86 eval $prev=\$option
87 prev=
88 continue
89 fi
90 case $option in
91 *=*) optarg=`expr "X$option" : '[^=]*=\(.*\)'` ;;
92 *) optarg=yes ;;
93 esac
94
95 case $dashdash$option in
96 --)
97 dashdash=yes ;;
98 -h|--help)
99 cat <<EOF
100ovs-sandbox, for starting a sandboxed dummy Open vSwitch environment
101usage: $0 [OPTION...]
102
103If you run ovs-sandbox from an OVS build directory, it uses the OVS that
104you built. Otherwise, if you have an installed Open vSwitch, it uses
105the installed version.
106
107These options force ovs-sandbox to use a particular OVS build:
108 -b, --builddir=DIR specify Open vSwitch build directory
109 -s, --srcdir=DIR specify Open vSwitch source directory
110These options force ovs-sandbox to use an installed Open vSwitch:
111 -i, --installed use installed Open vSwitch
8da7cd8c 112 -g, --gdb-vswitchd run ovs-vswitchd under gdb
4b814d41 113 -d, --gdb-ovsdb run ovsdb-server under gdb
91ae2065 114 --gdb-ovn-northd run ovn-northd under gdb
717c7fc5 115 --gdb-ovn-controller run ovn-controller under gdb
36561090 116 --gdb-ovn-controller-vtep run ovn-controller-vtep under gdb
24d04cff 117 --dummy=ARG pass --enable-dummy=ARG to vswitchd (default: override)
2c6bcfa2
RB
118 -R, --gdb-run automatically start running the daemon in gdb
119 for any daemon set to run under gdb
eeecce05 120 -S, --schema=FILE use FILE as vswitch.ovsschema
ff358c71 121 -o, --ovn enable OVN
e170fc09 122 --no-ovn-rbac disable role-based access control for OVN
eeecce05
BP
123
124Other options:
125 -h, --help Print this usage message.
126EOF
127 exit 0
128 ;;
129
130 --b*=*)
131 builddir=$optarg
132 built=:
133 ;;
134 -b|--b*)
135 prev=builddir
136 built=:
137 ;;
138 --sr*=*)
139 srcdir=$optarg
140 built=false
141 ;;
24d04cff 142 --dummy)
143 prev=dummy
144 ;;
145 --dummy=*)
146 dummy=$optarg
147 ;;
eeecce05
BP
148 -s|--sr*)
149 prev=srcdir
150 built=false
151 ;;
152 -i|--installed)
153 installed=:
154 ;;
155 --sc*=*)
156 schema=$optarg
157 installed=:
158 ;;
159 -S|--sc*)
160 prev=schema
161 installed=:
162 ;;
8da7cd8c
AZ
163 -g|--gdb-v*)
164 gdb_vswitchd=true
60ceeb6c
AZ
165 gdb_vswitchd_ex=false
166 ;;
167 -e|--gdb-ex-v*)
168 gdb_vswitchd=true
169 gdb_vswitchd_ex=true
8da7cd8c 170 ;;
30a67866 171 -d|--gdb-ovsdb)
4b814d41 172 gdb_ovsdb=true
60ceeb6c
AZ
173 gdb_ovsdb_ex=false
174 ;;
175 -r|--gdb-ex-o*)
176 gdb_ovsdb=true
177 gdb_ovsdb_ex=true
4b814d41 178 ;;
91ae2065
RB
179 --gdb-ovn-northd)
180 gdb_ovn_northd=true
30a67866 181 ;;
717c7fc5
JP
182 --gdb-ovn-controller)
183 gdb_ovn_controller=true
184 ;;
36561090
RB
185 --gdb-ovn-controller-vtep)
186 gdb_ovn_controller_vtep=true
187 ;;
ff358c71
RB
188 -o|--ovn)
189 ovn=true
190 ;;
e170fc09
LR
191 --no-ovn-rbac)
192 ovn_rbac=false
193 ;;
2c6bcfa2
RB
194 -R|--gdb-run)
195 gdb_vswitchd_ex=true
196 gdb_ovsdb_ex=true
197 gdb_ovn_northd_ex=true
198 gdb_ovn_controller_ex=true
36561090 199 gdb_ovn_controller_vtep_ex=true
2c6bcfa2 200 ;;
eeecce05
BP
201 -*)
202 echo "unrecognized option $option (use --help for help)" >&2
203 exit 1
204 ;;
205 *)
206 echo "$option: non-option arguments not supported (use --help for help)" >&2
207 exit 1
208 ;;
209 esac
210 shift
211done
212
213if $installed && $built; then
214 echo "sorry, conflicting options (use --help for help)" >&2
215 exit 1
216elif $installed || $built; then
217 :
218elif test -e vswitchd/ovs-vswitchd; then
219 built=:
220 builddir=.
221elif (ovs-vswitchd --version) >/dev/null 2>&1; then
222 installed=:
223else
224 echo "can't find an OVS build or install (use --help for help)" >&2
225 exit 1
226fi
227
228if $built; then
229 if test ! -e "$builddir"/vswitchd/ovs-vswitchd; then
230 echo "$builddir does not appear to be an OVS build directory" >&2
231 exit 1
232 fi
233 builddir=`cd $builddir && pwd`
234
235 # Find srcdir.
236 case $srcdir in
237 '')
238 srcdir=$builddir
3c8a3b31 239 if test ! -e "$srcdir"/README.rst; then
eeecce05
BP
240 srcdir=`cd $builddir/.. && pwd`
241 fi
242 ;;
243 /*) ;;
244 *) srcdir=`pwd`/$srcdir ;;
245 esac
246 schema=$srcdir/vswitchd/vswitch.ovsschema
247 if test ! -e "$schema"; then
248 echo >&2 'source directory not found, please use --srcdir'
249 exit 1
250 fi
ff358c71 251 if $ovn; then
1369720c
JP
252 ovnsb_schema=$srcdir/ovn/ovn-sb.ovsschema
253 if test ! -e "$ovnsb_schema"; then
ff358c71
RB
254 echo >&2 'source directory not found, please use --srcdir'
255 exit 1
256 fi
1369720c
JP
257 ovnnb_schema=$srcdir/ovn/ovn-nb.ovsschema
258 if test ! -e "$ovnnb_schema"; then
ff358c71
RB
259 echo >&2 'source directory not found, please use --srcdir'
260 exit 1
261 fi
36561090
RB
262 vtep_schema=$srcdir/vtep/vtep.ovsschema
263 if test ! -e "$vtep_schema"; then
264 echo >&2 'source directory not found, please use --srcdir'
265 exit 1
266 fi
ff358c71 267 fi
eeecce05
BP
268
269 # Put built tools early in $PATH.
270 if test ! -e $builddir/vswitchd/ovs-vswitchd; then
271 echo >&2 'build not found, please change set $builddir or change directory'
272 exit 1
273 fi
8013510c 274 PATH=$builddir/ovsdb:$builddir/vswitchd:$builddir/utilities:$builddir/vtep:$PATH
ff358c71 275 if $ovn; then
72eaa2ba 276 PATH=$builddir/ovn/controller:$builddir/ovn/controller-vtep:$builddir/ovn/northd:$builddir/ovn/utilities:$PATH
ff358c71 277 fi
eeecce05
BP
278 export PATH
279else
280 case $schema in
281 '')
282 for schema in \
283 /usr/local/share/openvswitch/vswitch.ovsschema \
284 /usr/share/openvswitch/vswitch.ovsschema \
285 none; do
286 if test -r $schema; then
287 break
288 fi
289 done
290 ;;
291 /*) ;;
292 *) schema=`pwd`/$schema ;;
293 esac
294 if test ! -r "$schema"; then
295 echo "can't find vswitch.ovsschema, please specify --schema" >&2
296 exit 1
297 fi
ff358c71
RB
298 if $ovn; then
299 echo "running with ovn is only supported from the build dir." >&2
300 exit 1
301 fi
eeecce05
BP
302fi
303
304# Create sandbox.
305rm -rf sandbox
306mkdir sandbox
307sandbox=`cd sandbox && pwd`
308
309# Set up environment for OVS programs to sandbox themselves.
310OVS_RUNDIR=$sandbox; export OVS_RUNDIR
311OVS_LOGDIR=$sandbox; export OVS_LOGDIR
312OVS_DBDIR=$sandbox; export OVS_DBDIR
313OVS_SYSCONFDIR=$sandbox; export OVS_SYSCONFDIR
314
315if $built; then
316 # Easy access to OVS manpages.
211d89b2 317 (cd "$builddir" && ${MAKE-make} install-man mandir="$sandbox"/man)
eeecce05
BP
318 MANPATH=$sandbox/man:; export MANPATH
319fi
320
321# Ensure cleanup.
322trap 'kill `cat "$sandbox"/*.pid`' 0 1 2 3 13 14 15
323
324# Create database and start ovsdb-server.
325touch "$sandbox"/.conf.db.~lock~
431ad535 326run ovsdb-tool create conf.db "$schema"
ff358c71
RB
327ovsdb_server_args=
328if $ovn; then
1369720c 329 touch "$sandbox"/.ovnsb.db.~lock~
ff358c71 330 touch "$sandbox"/.ovnnb.db.~lock~
1369720c 331 run ovsdb-tool create ovnsb.db "$ovnsb_schema"
9ec13182 332 run ovsdb-tool create ovnsb2.db "$ovnsb_schema"
1369720c 333 run ovsdb-tool create ovnnb.db "$ovnnb_schema"
36561090 334 run ovsdb-tool create vtep.db "$vtep_schema"
60bdd011
RM
335 ovsdb_server_args="vtep.db conf.db"
336 ovsdb_sb_server_args="ovnsb.db"
9ec13182 337 ovsdb_sb_backup_server_args="ovnsb2.db"
60bdd011 338 ovsdb_nb_server_args="ovnnb.db"
0ced2a5c
LR
339
340 if [ "$HAVE_OPENSSL" = yes ]; then
341 OVS_PKI="run ovs-pki --dir=$sandbox/pki --log=$sandbox/ovs-pki.log"
342 $OVS_PKI -B 1024 init
343 $OVS_PKI -B 1024 req+sign ovnsb switch
344 $OVS_PKI -B 1024 req+sign ovnnb switch
e170fc09 345 $OVS_PKI -B 1024 -u req+sign chassis-1 switch
0ced2a5c 346 fi
ff358c71 347fi
60ceeb6c 348rungdb $gdb_ovsdb $gdb_ovsdb_ex ovsdb-server --detach --no-chdir --pidfile -vconsole:off --log-file \
ff358c71 349 --remote=punix:"$sandbox"/db.sock $ovsdb_server_args
60bdd011
RM
350if $ovn; then
351 rungdb $gdb_ovsdb $gdb_ovsdb_ex ovsdb-server --detach --no-chdir \
352 --pidfile="$sandbox"/ovnnb_db.pid -vconsole:off \
353 --log-file="$sandbox"/ovnnb_db.log \
0ced2a5c
LR
354 --remote=db:OVN_Northbound,NB_Global,connections \
355 --private-key=db:OVN_Northbound,SSL,private_key \
356 --certificate=db:OVN_Northbound,SSL,certificate \
357 --ca-cert=db:OVN_Northbound,SSL,ca_cert \
51af591b
LR
358 --ssl-protocols=db:OVN_Northbound,SSL,ssl_protocols \
359 --ssl-ciphers=db:OVN_Northbound,SSL,ssl_ciphers \
60bdd011
RM
360 --remote=punix:"$sandbox"/ovnnb_db.sock $ovsdb_nb_server_args
361 rungdb $gdb_ovsdb $gdb_ovsdb_ex ovsdb-server --detach --no-chdir \
362 --pidfile="$sandbox"/ovnsb_db.pid -vconsole:off \
363 --log-file="$sandbox"/ovnsb_db.log \
0ced2a5c
LR
364 --remote=db:OVN_Southbound,SB_Global,connections \
365 --private-key=db:OVN_Southbound,SSL,private_key \
366 --certificate=db:OVN_Southbound,SSL,certificate \
367 --ca-cert=db:OVN_Southbound,SSL,ca_cert \
51af591b
LR
368 --ssl-protocols=db:OVN_Southbound,SSL,ssl_protocols \
369 --ssl-ciphers=db:OVN_Southbound,SSL,ssl_ciphers \
60bdd011 370 --remote=punix:"$sandbox"/ovnsb_db.sock $ovsdb_sb_server_args
9ec13182
AZ
371 # Start SB back up server
372 rungdb $gdb_ovsdb $gdb_ovsdb_ex ovsdb-server --detach --no-chdir \
373 --pidfile="$sandbox"/ovnsb_db2.pid -vconsole:off \
374 --log-file="$sandbox"/ovnsb_db2.log \
0ced2a5c
LR
375 --private-key=db:OVN_Southbound,SSL,private_key \
376 --certificate=db:OVN_Southbound,SSL,certificate \
377 --ca-cert=db:OVN_Southbound,SSL,ca_cert \
9ec13182
AZ
378 --remote=punix:"$sandbox"/ovnsb_db2.sock \
379 --unixctl="$sandbox"/sb_backup_unixctl \
380 --sync-from=unix:"$sandbox"/ovnsb_db.sock $ovsdb_sb_backup_server_args
60bdd011 381fi
eeecce05 382
e43a07ba
AZ
383#Add a small delay to allow ovsdb-server to launch.
384sleep 0.1
385
386#Wait for ovsdb-server to finish launching.
387if test ! -e "$sandbox"/db.sock; then
388 echo -n "Waiting for ovsdb-server to start..."
389 while test ! -e "$sandbox"/db.sock; do
390 sleep 1;
391 done
392 echo " Done"
393fi
394
6b2771c3
BP
395# Initialize database.
396run ovs-vsctl --no-wait -- init
397
eeecce05 398# Start ovs-vswitchd.
60ceeb6c 399rungdb $gdb_vswitchd $gdb_vswitchd_ex ovs-vswitchd --detach --no-chdir --pidfile -vconsole:off --log-file \
24d04cff 400 --enable-dummy=$dummy -vvconn -vnetdev_dummy
eeecce05 401
30a67866 402if $ovn; then
0ced2a5c
LR
403 ovn-nbctl init
404 ovn-sbctl init
405
e170fc09 406 ovs-vsctl set open . external-ids:system-id=chassis-1
9e6ec60a 407 ovs-vsctl set open . external-ids:hostname=sandbox
b705f9ea 408 ovs-vsctl set open . external-ids:ovn-encap-type=geneve
717c7fc5 409 ovs-vsctl set open . external-ids:ovn-encap-ip=127.0.0.1
717c7fc5 410
0ced2a5c
LR
411 if [ "$HAVE_OPENSSL" = yes ]; then
412 ovn-nbctl set-ssl $sandbox/ovnnb-privkey.pem $sandbox/ovnnb-cert.pem $sandbox/pki/switchca/cacert.pem
413 ovn-nbctl set-connection pssl:6641
414 ovn-sbctl set-ssl $sandbox/ovnsb-privkey.pem $sandbox/ovnsb-cert.pem $sandbox/pki/switchca/cacert.pem
e170fc09
LR
415 if $ovn_rbac; then
416 ovn-sbctl set-connection role=ovn-controller pssl:6642
417 else
418 ovn-sbctl set-connection pssl:6642
419 fi
0ced2a5c 420 ovs-vsctl set open . external-ids:ovn-remote=ssl:127.0.0.1:6642
e170fc09 421 OVN_CTRLR_PKI="-p $sandbox/chassis-1-privkey.pem -c $sandbox/chassis-1-cert.pem -C $sandbox/pki/switchca/cacert.pem"
0ced2a5c
LR
422 else
423 ovs-vsctl set open . external-ids:ovn-remote=unix:"$sandbox"/ovnsb_db.sock
424 OVN_CTRLR_PKI=""
425 fi
60bdd011
RM
426 rungdb $gdb_ovn_northd $gdb_ovn_northd_ex ovn-northd --detach \
427 --no-chdir --pidfile -vconsole:off --log-file \
428 --ovnsb-db=unix:"$sandbox"/ovnsb_db.sock \
429 --ovnnb-db=unix:"$sandbox"/ovnnb_db.sock
430 rungdb $gdb_ovn_controller $gdb_ovn_controller_ex ovn-controller \
0ced2a5c 431 $OVN_CTRLR_PKI --detach --no-chdir --pidfile -vconsole:off --log-file
60bdd011
RM
432 rungdb $gdb_ovn_controller_vtep $gdb_ovn_controller_vtep_ex \
433 ovn-controller-vtep --detach --no-chdir --pidfile -vconsole:off \
0ced2a5c 434 $OVN_CTRLR_PKI --log-file --ovnsb-db=unix:"$sandbox"/ovnsb_db.sock
30a67866
RB
435fi
436
eeecce05
BP
437cat <<EOF
438
439
440
441----------------------------------------------------------------------
442You are running in a dummy Open vSwitch environment. You can use
443ovs-vsctl, ovs-ofctl, ovs-appctl, and other tools to work with the
79b4e6dc 444dummy switch.
eeecce05 445
79b4e6dc
RB
446EOF
447if $ovn; then cat << EOF
448This environment also has the OVN daemons and databases enabled.
449You can use ovn-nbctl and ovn-sbctl to interact with the OVN databases.
450
9ec13182
AZ
451The backup server of OVN SB can be accessed by:
452* ovn-sbctl --db=unix:`pwd`/sandbox/ovnsb_db2.sock
453* ovs-appctl -t `pwd`/sandbox/sb_backup_unixctl
454The backup database file is "sandbox"/ovnsb2.db
455
456
79b4e6dc
RB
457EOF
458fi
459cat <<EOF
eeecce05
BP
460Log files, pidfiles, and the configuration database are in the
461"sandbox" subdirectory.
462
463Exit the shell to kill the running daemons.
464EOF
465
466status=0; $SHELL || status=$?
467
468cat <<EOF
469----------------------------------------------------------------------
470
471
472
473EOF
474
475exit $status