vlog: Add a new log level "off".
[sliver-openvswitch.git] / xenserver / openvswitch-xen.spec
1 # Spec file for Open vSwitch.
2
3 # Copyright (C) 2009, 2010, 2011 Nicira Networks, Inc.
4 #
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.
9
10 # When building, the rpmbuild command line should define
11 # openvswitch_version, kernel_name, kernel_version, kernel_flavor,
12 # and build_number using -D arguments.
13 # for example:
14 #
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 #      -D "build_number --with-build-number=123"
20 #      -bb /usr/src/redhat/SPECS/openvswitch-xen.spec
21
22 %define xen_version %{kernel_version}%{kernel_flavor}
23
24 # bump this when breaking compatibility with userspace
25 %define module_abi_version 0
26
27 # build-supplemental-pack.sh requires this naming for kernel module packages
28 %define module_package modules-%{kernel_flavor}-%{kernel_version}
29
30 Name: openvswitch
31 Summary: Open vSwitch daemon/database/utilities
32 Group: System Environment/Daemons
33 URL: http://www.openvswitch.org/
34 Vendor: Nicira Networks, Inc.
35 Version: %{openvswitch_version}
36
37 License: ASL 2.0
38 Release: 1
39 Source: openvswitch-%{openvswitch_version}.tar.gz
40 Buildroot: /tmp/openvswitch-xen-rpm
41 Requires: openvswitch_mod.ko.%{module_abi_version}
42
43 %description
44 Open vSwitch provides standard network bridging functions augmented with
45 support for the OpenFlow protocol for remote per-flow control of
46 traffic.
47
48 %package %{module_package}
49 Summary: Open vSwitch kernel module
50 Group: System Environment/Kernel
51 License: GPLv2
52 Provides: %{name}-modules-%{kernel_flavor} = %{kernel_version}, openvswitch_mod.ko.%{module_abi_version}
53 Requires: kernel-%{kernel_name} = %{kernel_version}
54
55 %description %{module_package}
56 Open vSwitch Linux kernel module compiled against kernel version
57 %{xen_version}.
58
59 %prep
60 %setup -q -n openvswitch-%{openvswitch_version}
61
62 %build
63 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=%{_localstatedir} --with-linux=/lib/modules/%{xen_version}/build --enable-ssl %{build_number}
64 make %{_smp_mflags}
65
66 %install
67 rm -rf $RPM_BUILD_ROOT
68 make install DESTDIR=$RPM_BUILD_ROOT
69 install -d -m 755 $RPM_BUILD_ROOT/etc
70 install -d -m 755 $RPM_BUILD_ROOT/etc/init.d
71 install -m 755 xenserver/etc_init.d_openvswitch \
72          $RPM_BUILD_ROOT/etc/init.d/openvswitch
73 install -m 755 xenserver/etc_init.d_openvswitch-xapi-update \
74          $RPM_BUILD_ROOT/etc/init.d/openvswitch-xapi-update
75 install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
76 install -d -m 755 $RPM_BUILD_ROOT/etc/logrotate.d
77 install -m 755 xenserver/etc_logrotate.d_openvswitch \
78          $RPM_BUILD_ROOT/etc/logrotate.d/openvswitch
79 install -d -m 755 $RPM_BUILD_ROOT/etc/profile.d
80 install -m 755 xenserver/etc_profile.d_openvswitch.sh \
81          $RPM_BUILD_ROOT/etc/profile.d/openvswitch.sh
82 install -d -m 755 $RPM_BUILD_ROOT/etc/xapi.d/plugins
83 install -m 755 xenserver/etc_xapi.d_plugins_openvswitch-cfg-update \
84          $RPM_BUILD_ROOT/etc/xapi.d/plugins/openvswitch-cfg-update
85 install -d -m 755 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts
86 install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \
87              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/interface-reconfigure
88 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigure.py \
89              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigure.py
90 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureBridge.py \
91              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
92 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py \
93              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
94 install -m 755 xenserver/etc_xensource_scripts_vif \
95              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/vif
96 install -m 755 xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync \
97                $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/ovs-xapi-sync
98 install -m 755 xenserver/usr_share_openvswitch_scripts_sysconfig.template \
99          $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/sysconfig.template
100 install -d -m 755 $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base
101 install -m 644 \
102         xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
103                $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
104
105 install -d -m 755 $RPM_BUILD_ROOT/lib/modules/%{xen_version}/extra/openvswitch
106 find datapath/linux -name *.ko -exec install -m 755  \{\} $RPM_BUILD_ROOT/lib/modules/%{xen_version}/extra/openvswitch \;
107 install xenserver/uuid.py $RPM_BUILD_ROOT/usr/share/openvswitch/python
108
109 install -d -m 755 $RPM_BUILD_ROOT/etc/xensource/bugtool
110 mv $RPM_BUILD_ROOT/etc/openvswitch/bugtool-plugins $RPM_BUILD_ROOT/etc/xensource/bugtool
111
112 # Get rid of stuff we don't want to make RPM happy.
113 rm \
114     $RPM_BUILD_ROOT/usr/bin/ovs-benchmark \
115     $RPM_BUILD_ROOT/usr/sbin/ovs-bugtool \
116     $RPM_BUILD_ROOT/usr/bin/ovs-controller \
117     $RPM_BUILD_ROOT/usr/bin/ovs-pki \
118     $RPM_BUILD_ROOT/usr/share/man/man1/ovs-benchmark.1 \
119     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-bugtool.8 \
120     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-controller.8 \
121     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-pki.8
122
123 install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
124
125 %clean
126 rm -rf $RPM_BUILD_ROOT
127
128 %post
129 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
130     cat >>/etc/sysctl.conf <<EOF
131 # This works around an issue in xhad, which binds to a particular
132 # Ethernet device, which in turn causes ICMP port unreachable messages
133 # if packets are received are on the wrong interface, which in turn
134 # can happen if we send out ARP replies on every interface (as Linux
135 # does by default) instead of just on the interface that has the IP
136 # address being ARPed for, which this sysctl setting in turn works
137 # around.
138 #
139 # Bug #1378.
140 net.ipv4.conf.all.arp_filter = 1
141 EOF
142 fi
143
144 if test ! -e /etc/openvswitch/conf.db; then
145     install -d -m 755 -o root -g root /etc/openvswitch
146
147     # Create ovs-vswitchd config database
148     ovsdb-tool -vANY:console:off create /etc/openvswitch/conf.db \
149             /usr/share/openvswitch/vswitch.ovsschema
150
151     # Create initial table in config database
152     ovsdb-tool -vANY:console:off transact /etc/openvswitch/conf.db \
153             '[{"op": "insert", "table": "Open_vSwitch", "row": {}}]' \
154             > /dev/null
155 fi
156
157 # Create default or update existing /etc/sysconfig/openvswitch.
158 SYSCONFIG=/etc/sysconfig/openvswitch
159 TEMPLATE=/usr/share/openvswitch/scripts/sysconfig.template
160 if [ ! -e $SYSCONFIG ]; then
161     cp $TEMPLATE $SYSCONFIG
162 else
163     for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
164     do
165         if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
166             echo >> $SYSCONFIG
167             sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
168         fi
169     done
170 fi
171
172 # Deliberately break %postun in broken OVS builds that revert original
173 # XenServer scripts during rpm -U by moving the directory where it thinks
174 # they are saved.
175 if [ -d /usr/lib/openvswitch/xs-original ]; then
176     mkdir -p /usr/lib/openvswitch/xs-saved
177     mv /usr/lib/openvswitch/xs-original/* /usr/lib/openvswitch/xs-saved/ &&
178         rmdir /usr/lib/openvswitch/xs-original
179 fi
180
181 # Replace XenServer files by our versions.
182 mkdir -p /usr/lib/openvswitch/xs-saved \
183     || printf "Could not create script backup directory.\n"
184 for f in \
185     /opt/xensource/libexec/interface-reconfigure \
186     /opt/xensource/libexec/InterfaceReconfigure.py \
187     /opt/xensource/libexec/InterfaceReconfigureBridge.py \
188     /opt/xensource/libexec/InterfaceReconfigureVswitch.py \
189     /etc/xensource/scripts/vif
190 do
191     s=$(basename "$f")
192     t=$(readlink "$f")
193     if [ -f "$f" ] && [ "$t" != "/usr/share/openvswitch/scripts/$s" ]; then
194         mv "$f" /usr/lib/openvswitch/xs-saved/ \
195             || printf "Could not save original XenServer $s script\n"
196         ln -s "/usr/share/openvswitch/scripts/$s" "$f" \
197             || printf "Could not link to Open vSwitch $s script\n"
198     fi
199 done
200
201 # Clean up dangling symlinks to removed OVS replacement scripts no longer
202 # provided by OVS. Any time a replacement script is removed from OVS,
203 # it should be added here to ensure correct reversion from old versions of
204 # OVS that don't clean up dangling symlinks during the uninstall phase.
205 for orig in \
206     /usr/sbin/brctl \
207     /usr/sbin/xen-bugtool
208 do
209     saved=/usr/lib/openvswitch/xs-saved/$(basename "$orig")
210     [ -e "$saved" ] && mv -f "$saved" "$orig"
211 done
212
213 # Ensure all required services are set to run
214 for s in openvswitch openvswitch-xapi-update; do
215     if chkconfig --list $s >/dev/null 2>&1; then
216         chkconfig --del $s || printf "Could not remove $s init script."
217     fi
218     chkconfig --add $s || printf "Could not add $s init script."
219     chkconfig $s on || printf "Could not enable $s init script."
220 done
221
222 if [ "$1" = "1" ]; then    # $1 = 1 for install
223     # Configure system to use Open vSwitch
224     /opt/xensource/bin/xe-switch-network-backend vswitch
225 else    # $1 = 2 for upgrade
226
227     mode=$(cat /etc/xensource/network.conf)
228     if [ "$mode" != "vswitch" ] && [ "$mode" != "openvswitch" ]; then
229         printf "\nThe server is not configured to run Open vSwitch.  To run in\n"
230         printf "vswitch mode, you must run the following command:\n\n"
231         printf "\txe-switch-network-backend vswitch"
232     else
233         printf "\nTo use the new Open vSwitch install, you should reboot the\n"
234         printf "server now.  Failure to do so may result in incorrect operation."
235     fi
236
237     printf "\n\n"
238 fi
239
240 %posttrans %{module_package}
241 # Ensure that modprobe will find our modules.
242 #
243 # This has to be in %posttrans instead of %post because older versions
244 # installed modules into a different directory and "rpm -U" runs the
245 # new version's %post before removing the old version's files, so if
246 # we use %post then depmod may find the old versions that are about to
247 # be removed.
248 depmod %{xen_version}
249
250 %preun
251 if [ "$1" = "0" ]; then     # $1 = 0 for uninstall
252     # Configure system to use bridge
253     /opt/xensource/bin/xe-switch-network-backend bridge
254
255     # The "openvswitch" service should have been removed from
256     # "xe-switch-network-backend bridge".
257     for s in openvswitch openvswitch-xapi-update; do
258         if chkconfig --list $s >/dev/null 2>&1; then
259             chkconfig --del $s || printf "Could not remove $s init script."
260         fi
261     done
262 fi
263
264 %postun
265 # Restore original XenServer scripts if the OVS equivalent no longer exists.
266 # This works both in the upgrade and erase cases.
267 # This lists every file that every version of OVS has ever replaced. Never
268 # remove old files that OVS no longer replaces, or upgrades from old versions
269 # will fail to restore the XS originals, leaving the system in a broken state.
270 # Also be sure to add removed script paths to the %post scriptlet above to
271 # prevent the same problem when upgrading from old versions of OVS that lack
272 # this restore-on-upgrade logic.
273 for f in \
274     /etc/xensource/scripts/vif \
275     /usr/sbin/brctl \
276     /usr/sbin/xen-bugtool \
277     /opt/xensource/libexec/interface-reconfigure \
278     /opt/xensource/libexec/InterfaceReconfigure.py \
279     /opt/xensource/libexec/InterfaceReconfigureBridge.py \
280     /opt/xensource/libexec/InterfaceReconfigureVswitch.py
281 do
282     # Only revert dangling symlinks.
283     if [ -h "$f" ] && [ ! -e "$f" ]; then
284         s=$(basename "$f")
285         if [ ! -f "/usr/lib/openvswitch/xs-saved/$s" ]; then
286             printf "Original XenServer $s script not present in /usr/lib/openvswitch/xs-saved\n" >&2
287             printf "Could not restore original XenServer script.\n" >&2
288         else
289             (rm -f "$f" \
290                 && mv "/usr/lib/openvswitch/xs-saved/$s" "$f") \
291                 || printf "Could not restore original XenServer $s script.\n" >&2
292         fi
293     fi
294 done
295
296 if [ "$1" = "0" ]; then     # $1 = 0 for uninstall
297     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
298         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo
299
300     rm -f /usr/share/openvswitch/scripts/InterfaceReconfigure.pyc \
301         /usr/share/openvswitch/scripts/InterfaceReconfigure.pyo \
302         /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyc \
303         /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyo \
304         /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyc \
305         /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyo
306
307     # Remove all configuration files
308     rm -f /etc/openvswitch/conf.db
309     rm -f /etc/sysconfig/openvswitch
310     rm -f /etc/openvswitch/vswitchd.cacert
311
312     # Remove saved XenServer scripts directory, but only if it's empty
313     rmdir -p /usr/lib/openvswitch/xs-saved 2>/dev/null
314 fi
315
316 exit 0
317
318 %files
319 %defattr(-,root,root)
320 /etc/init.d/openvswitch
321 /etc/init.d/openvswitch-xapi-update
322 /etc/xapi.d/plugins/openvswitch-cfg-update
323 /etc/xensource/bugtool/*
324 /etc/logrotate.d/openvswitch
325 /etc/profile.d/openvswitch.sh
326 /usr/share/openvswitch/python/ovs/__init__.py
327 /usr/share/openvswitch/python/ovs/daemon.py
328 /usr/share/openvswitch/python/ovs/db/__init__.py
329 /usr/share/openvswitch/python/ovs/db/data.py
330 /usr/share/openvswitch/python/ovs/db/error.py
331 /usr/share/openvswitch/python/ovs/db/idl.py
332 /usr/share/openvswitch/python/ovs/db/parser.py
333 /usr/share/openvswitch/python/ovs/db/schema.py
334 /usr/share/openvswitch/python/ovs/db/types.py
335 /usr/share/openvswitch/python/ovs/dirs.py
336 /usr/share/openvswitch/python/ovs/fatal_signal.py
337 /usr/share/openvswitch/python/ovs/json.py
338 /usr/share/openvswitch/python/ovs/jsonrpc.py
339 /usr/share/openvswitch/python/ovs/ovsuuid.py
340 /usr/share/openvswitch/python/ovs/poller.py
341 /usr/share/openvswitch/python/ovs/process.py
342 /usr/share/openvswitch/python/ovs/reconnect.py
343 /usr/share/openvswitch/python/ovs/socket_util.py
344 /usr/share/openvswitch/python/ovs/stream.py
345 /usr/share/openvswitch/python/ovs/timeval.py
346 /usr/share/openvswitch/python/ovs/util.py
347 /usr/share/openvswitch/python/uuid.py
348 /usr/share/openvswitch/scripts/ovs-xapi-sync
349 /usr/share/openvswitch/scripts/interface-reconfigure
350 /usr/share/openvswitch/scripts/InterfaceReconfigure.py
351 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
352 /usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
353 /usr/share/openvswitch/scripts/vif
354 /usr/share/openvswitch/scripts/sysconfig.template
355 /usr/share/openvswitch/scripts/ovs-bugtool-*
356 /usr/share/openvswitch/scripts/ovs-save
357 /usr/share/openvswitch/scripts/ovs-ctl
358 /usr/share/openvswitch/scripts/ovs-lib.sh
359 /usr/share/openvswitch/vswitch.ovsschema
360 /usr/sbin/ovs-vlan-bug-workaround
361 /usr/sbin/ovs-vswitchd
362 /usr/sbin/ovsdb-server
363 /usr/bin/ovs-appctl
364 /usr/bin/ovs-dpctl
365 /usr/bin/ovs-ofctl
366 /usr/bin/ovs-parse-leaks
367 /usr/bin/ovs-pcap
368 /usr/bin/ovs-tcpundump
369 /usr/bin/ovs-vlan-test
370 /usr/bin/ovs-vsctl
371 /usr/bin/ovsdb-client
372 /usr/bin/ovsdb-tool
373 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
374 /usr/share/man/man1/ovsdb-client.1.gz
375 /usr/share/man/man1/ovsdb-server.1.gz
376 /usr/share/man/man1/ovsdb-tool.1.gz
377 /usr/share/man/man5/ovs-vswitchd.conf.db.5.gz
378 /usr/share/man/man8/ovs-appctl.8.gz
379 /usr/share/man/man8/ovs-ctl.8.gz
380 /usr/share/man/man8/ovs-dpctl.8.gz
381 /usr/share/man/man8/ovs-ofctl.8.gz
382 /usr/share/man/man8/ovs-parse-leaks.8.gz
383 /usr/share/man/man1/ovs-pcap.1.gz
384 /usr/share/man/man1/ovs-tcpundump.1.gz
385 /usr/share/man/man8/ovs-vlan-bug-workaround.8.gz
386 /usr/share/man/man8/ovs-vlan-test.8.gz
387 /usr/share/man/man8/ovs-vsctl.8.gz
388 /usr/share/man/man8/ovs-vswitchd.8.gz
389 /var/lib/openvswitch
390 %exclude /usr/lib/xsconsole/plugins-base/*.py[co]
391 %exclude /usr/sbin/ovs-brcompatd
392 %exclude /usr/share/man/man8/ovs-brcompatd.8.gz
393 %exclude /usr/share/openvswitch/scripts/*.py[co]
394 %exclude /usr/share/openvswitch/python/*.py[co]
395 %exclude /usr/share/openvswitch/python/ovs/*.py[co]
396 %exclude /usr/share/openvswitch/python/ovs/db/*.py[co]
397
398 %files %{module_package}
399 /lib/modules/%{xen_version}/extra/openvswitch/openvswitch_mod.ko
400 %exclude /lib/modules/%{xen_version}/extra/openvswitch/brcompat_mod.ko