1 # Spec file for Open vSwitch.
3 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
5 # Copying and distribution of this file, with or without modification,
6 # are permitted in any medium without royalty provided the copyright
7 # notice and this notice are preserved. This file is offered as-is,
8 # without warranty of any kind.
10 # For XenServer version < 6.5, when building, the rpmbuild command line
11 # should define openvswitch_version, kernel_name, kernel_version and
12 # kernel_flavor using -D arguments.
15 # rpmbuild -D "openvswitch_version 1.1.0+build123"
16 # -D "kernel_name NAME-xen"
17 # -D "kernel_version 2.6.32.12-0.7.1.xs5.6.100.323.170596"
18 # -D "kernel_flavor xen"
19 # -bb /usr/src/redhat/SPECS/openvswitch-xen.spec
21 # For XenServer version >= 6.5, replace kernel_flavor with xen_version which
22 # should be the `uname -r` output.
25 # rpmbuild -D "openvswitch_version 2.3.0+build123"
26 # -D "kernel_name NAME-xen"
27 # -D "kernel_version 3.10.41-323.380416"
28 # -D "xen_version 3.10.0+2"
29 # -bb /usr/src/redhat/SPECS/openvswitch-xen.spec
31 # If tests have to be skipped while building, specify the '--without check'
32 # option. For example:
33 # rpmbuild -bb --without check xenserver/openvswitch-xen.spec
35 %if %{?openvswitch_version:0}%{!?openvswitch_version:1}
36 %define openvswitch_version @VERSION@
39 %if %{?kernel_name:0}%{!?kernel_name:1}
40 %define kernel %(rpm -qa 'kernel*xen-devel' | head -1)
41 %define kernel_name %(rpm -q --queryformat "%%{Name}" %{kernel} | sed 's/-devel//' | sed 's/kernel-//')
42 %define kernel_version %(rpm -q --queryformat "%%{Version}-%%{Release}" %{kernel})
43 %define kernel_flavor xen
46 %if %{?xen_version:0}%{!?xen_version:1}
47 %define xen_version %{kernel_version}%{kernel_flavor}
50 # bump this when breaking compatibility with userspace
51 %define module_abi_version 0
53 # build-supplemental-pack.sh requires this naming for kernel module packages
54 %define module_package modules%{?kernel_flavor:-%{kernel_flavor}}-%{kernel_version}
59 Summary: Open vSwitch daemon/database/utilities
60 Group: System Environment/Daemons
61 URL: http://www.openvswitch.org/
63 Version: %{openvswitch_version}
67 Source: openvswitch-%{openvswitch_version}.tar.gz
68 Buildroot: /tmp/openvswitch-xen-rpm
69 Requires: openvswitch.ko.%{module_abi_version}
72 Open vSwitch provides standard network bridging functions augmented with
73 support for the OpenFlow protocol for remote per-flow control of
76 %package %{module_package}
77 Summary: Open vSwitch kernel module
78 Group: System Environment/Kernel
80 Provides: %{name}-modules%{?kernel_flavor:-%{kernel_flavor}} = %{kernel_version}, openvswitch.ko.%{module_abi_version}
81 Requires: kernel%{?kernel_flavor:-%{kernel_flavor}} = %{kernel_version}
83 %description %{module_package}
84 Open vSwitch Linux kernel module compiled against kernel version
85 %{kernel_version}%{?kernel_flavor:%{kernel_flavor}}.
88 %setup -q -n openvswitch-%{openvswitch_version}
91 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=%{_localstatedir} --with-linux=/lib/modules/%{xen_version}/build --enable-ssl
95 rm -rf $RPM_BUILD_ROOT
96 make install DESTDIR=$RPM_BUILD_ROOT
97 install -d -m 755 $RPM_BUILD_ROOT/etc
98 install -d -m 755 $RPM_BUILD_ROOT/etc/init.d
99 install -m 755 xenserver/etc_init.d_openvswitch \
100 $RPM_BUILD_ROOT/etc/init.d/openvswitch
101 install -m 755 xenserver/etc_init.d_openvswitch-xapi-update \
102 $RPM_BUILD_ROOT/etc/init.d/openvswitch-xapi-update
103 install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
104 install -d -m 755 $RPM_BUILD_ROOT/etc/logrotate.d
105 install -m 755 xenserver/etc_logrotate.d_openvswitch \
106 $RPM_BUILD_ROOT/etc/logrotate.d/openvswitch
107 install -d -m 755 $RPM_BUILD_ROOT/etc/profile.d
108 install -m 755 xenserver/etc_profile.d_openvswitch.sh \
109 $RPM_BUILD_ROOT/etc/profile.d/openvswitch.sh
110 install -d -m 755 $RPM_BUILD_ROOT/etc/xapi.d/plugins
111 install -m 755 xenserver/etc_xapi.d_plugins_openvswitch-cfg-update \
112 $RPM_BUILD_ROOT/etc/xapi.d/plugins/openvswitch-cfg-update
113 install -d -m 755 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts
114 install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \
115 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/interface-reconfigure
116 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigure.py \
117 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigure.py
118 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureBridge.py \
119 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
120 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py \
121 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
122 install -m 755 xenserver/etc_xensource_scripts_vif \
123 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/vif
124 install -m 755 xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync \
125 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/ovs-xapi-sync
126 install -m 755 xenserver/usr_share_openvswitch_scripts_sysconfig.template \
127 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/sysconfig.template
128 install -d -m 755 $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base
130 xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
131 $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
133 install -d -m 755 $RPM_BUILD_ROOT/lib/modules/%{xen_version}/extra/openvswitch
134 find datapath/linux -name *.ko -exec install -m 755 \{\} $RPM_BUILD_ROOT/lib/modules/%{xen_version}/extra/openvswitch \;
135 install python/compat/uuid.py $RPM_BUILD_ROOT/usr/share/openvswitch/python
136 install python/compat/argparse.py $RPM_BUILD_ROOT/usr/share/openvswitch/python
138 install -d -m 755 $RPM_BUILD_ROOT/etc/xensource/bugtool
139 cp -rf $RPM_BUILD_ROOT/usr/share/openvswitch/bugtool-plugins/* $RPM_BUILD_ROOT/etc/xensource/bugtool
141 # Get rid of stuff we don't want to make RPM happy.
143 $RPM_BUILD_ROOT/usr/bin/ovs-benchmark \
144 $RPM_BUILD_ROOT/usr/bin/ovs-l3ping \
145 $RPM_BUILD_ROOT/usr/bin/ovs-pki \
146 $RPM_BUILD_ROOT/usr/bin/ovs-test \
147 $RPM_BUILD_ROOT/usr/share/man/man1/ovs-benchmark.1 \
148 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-l3ping.8 \
149 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-pki.8 \
150 $RPM_BUILD_ROOT/usr/share/man/man8/ovs-test.8
151 (cd "$RPM_BUILD_ROOT" && rm -f usr/lib/lib*)
153 install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
157 if make check TESTSUITEFLAGS='%{_smp_mflags}' ||
158 make check TESTSUITEFLAGS='--recheck'; then :;
160 cat tests/testsuite.log
166 rm -rf $RPM_BUILD_ROOT
169 # A list of Citrix XenServer scripts that we might need to replace
170 # with our own versions.
172 /etc/xensource/scripts/vif
173 /opt/xensource/libexec/InterfaceReconfigure.py
174 /opt/xensource/libexec/InterfaceReconfigureBridge.py
175 /opt/xensource/libexec/InterfaceReconfigureVswitch.py
176 /opt/xensource/libexec/interface-reconfigure"
178 # Calculate into $md5sums a comma-separated set of md5sums of the
179 # Citrix XenServer scripts that we might need to replace. We might be
180 # upgrading an older version of the package that moved the files out
181 # of the way, so we need to look for the files in those out-of-the-way
184 for script in $scripts; do
185 b=$(basename "$script")
186 if test -e /usr/lib/openvswitch/xs-saved/"$b"; then
187 f=/usr/lib/openvswitch/xs-saved/"$b"
188 elif test -e /usr/lib/openvswitch/xs-original/"$b"; then
189 f=/usr/lib/openvswitch/xs-original/"$b"
190 elif test -e "$script" && test ! -h "$script"; then
193 printf "\n$script: not found\n"
196 md5sums="$md5sums,$(md5sum $f | awk '{print $1}')"
200 # Now check the md5sums against the known sets of md5sums:
202 # - If they are known to be a version of XenServer scripts that we should
203 # replace, we replace them (by putting $scripts into $replace_files).
205 # - Otherwise, we guess that it's better not to replace them, because the
206 # improvements that our versions of the scripts provide are minimal, so
207 # it's better to avoid possibly breaking any changes made upstream by
210 cf09a68d9f8b434e79a4c83b01a3bb4b,395866df1b0b20c12c4dd2f7de0ecdb4,9d493545ae81463239d3162cbc798852,862d0939b441de9264a900628e950fe9,21f85db25599d7f026cd489385d58aa6)
212 replace_files=$scripts
213 printf "\nVerified host scripts from XenServer 6.0.0.\n"
216 c5f48246577a17cf1b971fb5ce4e920b,2e2c912f86f9c536c89adc34ff3c2b2b,28d3ff72d72bdec4f37d70699f5edb76,67e1d0af16fc1ddf10009c5c063ad2ba,f3feff30aa3b3f8b514664a96a8dc0ab)
218 replace_files=$scripts
219 printf "\nVerified host scripts from XenServer 5.6-SP2.\n"
222 c5f48246577a17cf1b971fb5ce4e920b,2e2c912f86f9c536c89adc34ff3c2b2b,28d3ff72d72bdec4f37d70699f5edb76,67e1d0af16fc1ddf10009c5c063ad2ba,24bae6906d182ba47668174f8e480cc6)
224 replace_files=$scripts
225 printf "\nVerified host scripts from XenServer 5.6-FP1.\n"
233 The host scripts on this machine are not those of any supported
234 version of XenServer. On XenServer earlier than 5.6-FP1, your Open
235 vSwitch installation will not work. On XenServer 5.6-FP1 or later,
236 Open vSwitch is not verified to work, which could lead to unexpected
243 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
244 cat >>/etc/sysctl.conf <<EOF
245 # This works around an issue in xhad, which binds to a particular
246 # Ethernet device, which in turn causes ICMP port unreachable messages
247 # if packets are received are on the wrong interface, which in turn
248 # can happen if we send out ARP replies on every interface (as Linux
249 # does by default) instead of just on the interface that has the IP
250 # address being ARPed for, which this sysctl setting in turn works
254 net.ipv4.conf.all.arp_filter = 1
258 if test ! -e /etc/openvswitch/conf.db; then
259 install -d -m 755 -o root -g root /etc/openvswitch
261 # Create ovs-vswitchd config database
262 ovsdb-tool -vconsole:off create /etc/openvswitch/conf.db \
263 /usr/share/openvswitch/vswitch.ovsschema
265 # Create initial table in config database
266 ovsdb-tool -vconsole:off transact /etc/openvswitch/conf.db \
267 '[{"op": "insert", "table": "Open_vSwitch", "row": {}}]' \
271 # Create default or update existing /etc/sysconfig/openvswitch.
272 SYSCONFIG=/etc/sysconfig/openvswitch
273 TEMPLATE=/usr/share/openvswitch/scripts/sysconfig.template
274 if [ ! -e $SYSCONFIG ]; then
275 cp $TEMPLATE $SYSCONFIG
277 for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
279 if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
281 sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
286 # Deliberately break %postun in broken OVS builds that revert original
287 # XenServer scripts during rpm -U by moving the directory where it thinks
289 if [ -d /usr/lib/openvswitch/xs-original ]; then
290 mkdir -p /usr/lib/openvswitch/xs-saved
291 mv /usr/lib/openvswitch/xs-original/* /usr/lib/openvswitch/xs-saved/ &&
292 rmdir /usr/lib/openvswitch/xs-original
295 # Replace XenServer files by our versions.
296 mkdir -p /usr/lib/openvswitch/xs-saved \
297 || printf "Could not create script backup directory.\n"
298 for f in $replace_files; do
301 if [ -f "$f" ] && [ "$t" != "/usr/share/openvswitch/scripts/$s" ]; then
302 mv "$f" /usr/lib/openvswitch/xs-saved/ \
303 || printf "Could not save original XenServer $s script\n"
304 ln -s "/usr/share/openvswitch/scripts/$s" "$f" \
305 || printf "Could not link to Open vSwitch $s script\n"
309 # Clean up dangling symlinks to removed OVS replacement scripts no longer
310 # provided by OVS. Any time a replacement script is removed from OVS,
311 # it should be added here to ensure correct reversion from old versions of
312 # OVS that don't clean up dangling symlinks during the uninstall phase.
313 for orig in /usr/sbin/xen-bugtool $keep_files; do
314 saved=/usr/lib/openvswitch/xs-saved/$(basename "$orig")
315 [ -e "$saved" ] && mv -f "$saved" "$orig"
318 # Ensure all required services are set to run
319 for s in openvswitch openvswitch-xapi-update; do
320 if chkconfig --list $s >/dev/null 2>&1; then
321 chkconfig --del $s || printf "Could not remove $s init script.\n"
323 chkconfig --add $s || printf "Could not add $s init script.\n"
324 chkconfig $s on || printf "Could not enable $s init script.\n"
327 if [ "$1" = "1" ]; then # $1 = 1 for install
328 # Configure system to use Open vSwitch
329 /opt/xensource/bin/xe-switch-network-backend vswitch
330 else # $1 = 2 for upgrade
332 mode=$(cat /etc/xensource/network.conf)
333 if [ "$mode" != "vswitch" ] && [ "$mode" != "openvswitch" ]; then
334 printf "\nThe server is not configured to run Open vSwitch. To run in\n"
335 printf "vswitch mode, you must run the following command:\n\n"
336 printf "\txe-switch-network-backend vswitch"
341 %posttrans %{module_package}
342 # Ensure that modprobe will find our modules.
344 # This has to be in %posttrans instead of %post because older versions
345 # installed modules into a different directory and "rpm -U" runs the
346 # new version's %post before removing the old version's files, so if
347 # we use %post then depmod may find the old versions that are about to
349 depmod %{xen_version}
351 mode=$(cat /etc/xensource/network.conf)
352 if [ "$mode" = "vswitch" ] || [ "$mode" = "openvswitch" ]; then
353 printf "\nTo use the newly installed Open vSwitch kernel module, you\n"
354 printf "will either have to reboot the hypervisor or follow any\n"
355 printf "workarounds provided by your administration guide. Failure to do\n"
356 printf "so may result in incorrect operation."
361 if [ "$1" = "0" ]; then # $1 = 0 for uninstall
362 # Configure system to use bridge
363 /opt/xensource/bin/xe-switch-network-backend bridge
365 # The "openvswitch" service should have been removed from
366 # "xe-switch-network-backend bridge".
367 for s in openvswitch openvswitch-xapi-update; do
368 if chkconfig --list $s >/dev/null 2>&1; then
369 chkconfig --del $s || printf "Could not remove $s init script."
375 # Restore original XenServer scripts if the OVS equivalent no longer exists.
376 # This works both in the upgrade and erase cases.
377 # This lists every file that every version of OVS has ever replaced. Never
378 # remove old files that OVS no longer replaces, or upgrades from old versions
379 # will fail to restore the XS originals, leaving the system in a broken state.
380 # Also be sure to add removed script paths to the %post scriptlet above to
381 # prevent the same problem when upgrading from old versions of OVS that lack
382 # this restore-on-upgrade logic.
384 /etc/xensource/scripts/vif \
385 /usr/sbin/xen-bugtool \
386 /opt/xensource/libexec/interface-reconfigure \
387 /opt/xensource/libexec/InterfaceReconfigure.py \
388 /opt/xensource/libexec/InterfaceReconfigureBridge.py \
389 /opt/xensource/libexec/InterfaceReconfigureVswitch.py
391 # Only revert dangling symlinks.
392 if [ -h "$f" ] && [ ! -e "$f" ]; then
394 if [ ! -f "/usr/lib/openvswitch/xs-saved/$s" ]; then
395 printf "Original XenServer $s script not present in /usr/lib/openvswitch/xs-saved\n" >&2
396 printf "Could not restore original XenServer script.\n" >&2
399 && mv "/usr/lib/openvswitch/xs-saved/$s" "$f") \
400 || printf "Could not restore original XenServer $s script.\n" >&2
405 if [ "$1" = "0" ]; then # $1 = 0 for uninstall
406 rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
407 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo
409 rm -f /usr/share/openvswitch/scripts/InterfaceReconfigure.pyc \
410 /usr/share/openvswitch/scripts/InterfaceReconfigure.pyo \
411 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyc \
412 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyo \
413 /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyc \
414 /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyo
416 # Remove all configuration files
417 rm -f /etc/openvswitch/conf.db
418 rm -f /etc/sysconfig/openvswitch
419 rm -f /etc/openvswitch/vswitchd.cacert
421 # Remove saved XenServer scripts directory, but only if it's empty
422 rmdir -p /usr/lib/openvswitch/xs-saved 2>/dev/null
428 %defattr(-,root,root)
429 /etc/init.d/openvswitch
430 /etc/init.d/openvswitch-xapi-update
431 /etc/xapi.d/plugins/openvswitch-cfg-update
432 /etc/xensource/bugtool/*
433 /etc/logrotate.d/openvswitch
434 /etc/profile.d/openvswitch.sh
435 /usr/share/openvswitch/python/
436 /usr/share/openvswitch/bugtool-plugins/*
437 /usr/share/openvswitch/scripts/ovs-check-dead-ifs
438 /usr/share/openvswitch/scripts/ovs-xapi-sync
439 /usr/share/openvswitch/scripts/interface-reconfigure
440 /usr/share/openvswitch/scripts/InterfaceReconfigure.py
441 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
442 /usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
443 /usr/share/openvswitch/scripts/vif
444 /usr/share/openvswitch/scripts/sysconfig.template
445 /usr/share/openvswitch/scripts/ovs-bugtool-*
446 /usr/share/openvswitch/scripts/ovs-save
447 /usr/share/openvswitch/scripts/ovs-ctl
448 /usr/share/openvswitch/scripts/ovs-lib
449 /usr/share/openvswitch/scripts/ovs-vtep
450 /usr/share/openvswitch/vswitch.ovsschema
451 /usr/share/openvswitch/vtep.ovsschema
452 /usr/sbin/ovs-bugtool
453 /usr/sbin/ovs-vlan-bug-workaround
454 /usr/sbin/ovs-vswitchd
455 /usr/sbin/ovsdb-server
458 /usr/bin/ovs-dpctl-top
460 /usr/bin/ovs-parse-backtrace
462 /usr/bin/ovs-tcpundump
463 /usr/bin/ovs-vlan-test
465 /usr/bin/ovsdb-client
468 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
469 /usr/share/man/man1/ovsdb-client.1.gz
470 /usr/share/man/man1/ovsdb-server.1.gz
471 /usr/share/man/man1/ovsdb-tool.1.gz
472 /usr/share/man/man5/ovs-vswitchd.conf.db.5.gz
473 /usr/share/man/man5/vtep.5.gz
474 /usr/share/man/man8/ovs-appctl.8.gz
475 /usr/share/man/man8/ovs-bugtool.8.gz
476 /usr/share/man/man8/ovs-ctl.8.gz
477 /usr/share/man/man8/ovs-dpctl.8.gz
478 /usr/share/man/man8/ovs-dpctl-top.8.gz
479 /usr/share/man/man8/ovs-ofctl.8.gz
480 /usr/share/man/man8/ovs-parse-backtrace.8.gz
481 /usr/share/man/man1/ovs-pcap.1.gz
482 /usr/share/man/man1/ovs-tcpundump.1.gz
483 /usr/share/man/man8/ovs-vlan-bug-workaround.8.gz
484 /usr/share/man/man8/ovs-vlan-test.8.gz
485 /usr/share/man/man8/ovs-vsctl.8.gz
486 /usr/share/man/man8/ovs-vswitchd.8.gz
487 /usr/share/man/man8/vtep-ctl.8.gz
490 %exclude /usr/lib/xsconsole/plugins-base/*.py[co]
491 %exclude /usr/share/openvswitch/scripts/*.py[co]
492 %exclude /usr/share/openvswitch/python/*.py[co]
493 %exclude /usr/share/openvswitch/python/ovs/*.py[co]
494 %exclude /usr/share/openvswitch/python/ovs/db/*.py[co]
496 %files %{module_package}
497 /lib/modules/%{xen_version}/extra/openvswitch/openvswitch.ko