Refactor initscripts into distro-independent and distro-specific pieces.
[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-l26=/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/etc/xensource/bugtool/network-status
86 install -m 644 xenserver/etc_xensource_bugtool_network-status_openvswitch.xml \
87          $RPM_BUILD_ROOT/etc/xensource/bugtool/network-status/openvswitch.xml
88 install -d -m 755 $RPM_BUILD_ROOT/etc/xensource/bugtool/kernel-info
89 install -m 644 xenserver/etc_xensource_bugtool_kernel-info_openvswitch.xml \
90          $RPM_BUILD_ROOT/etc/xensource/bugtool/kernel-info/openvswitch.xml
91 install -m 644 xenserver/etc_xensource_bugtool_system-configuration.xml \
92          $RPM_BUILD_ROOT/etc/xensource/bugtool/system-configuration.xml
93 install -d -m 755 $RPM_BUILD_ROOT/etc/xensource/bugtool/system-configuration
94 install -m 644 xenserver/etc_xensource_bugtool_system-configuration_openvswitch.xml \
95          $RPM_BUILD_ROOT/etc/xensource/bugtool/system-configuration/openvswitch.xml
96 install -d -m 755 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts
97 install -m 644 vswitchd/vswitch.ovsschema \
98          $RPM_BUILD_ROOT/usr/share/openvswitch/vswitch.ovsschema
99 install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \
100              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/interface-reconfigure
101 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigure.py \
102              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigure.py
103 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureBridge.py \
104              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
105 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py \
106              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
107 install -m 755 xenserver/etc_xensource_scripts_vif \
108              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/vif
109 install -m 755 xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync \
110                $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/ovs-xapi-sync
111 install -m 755 xenserver/usr_share_openvswitch_scripts_sysconfig.template \
112          $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/sysconfig.template
113 install -m 755 xenserver/usr_share_openvswitch_scripts_xen-bugtool-tc-class-show \
114          $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/xen-bugtool-tc-class-show
115 install -m 755 utilities/ovs-save \
116          $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/ovs-save
117 install -d -m 755 $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base
118 install -m 644 \
119         xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
120                $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
121
122 install -d -m 755 $RPM_BUILD_ROOT/lib/modules/%{xen_version}/extra/openvswitch
123 find datapath/linux-2.6 -name *.ko -exec install -m 755  \{\} $RPM_BUILD_ROOT/lib/modules/%{xen_version}/extra/openvswitch \;
124 install xenserver/uuid.py $RPM_BUILD_ROOT/usr/share/openvswitch/python
125
126 # Get rid of stuff we don't want to make RPM happy.
127 rm \
128     $RPM_BUILD_ROOT/usr/bin/ovs-controller \
129     $RPM_BUILD_ROOT/usr/bin/ovs-pki \
130     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-controller.8 \
131     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-pki.8
132
133 install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
134
135 %clean
136 rm -rf $RPM_BUILD_ROOT
137
138 %post
139 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
140     cat >>/etc/sysctl.conf <<EOF
141 # This works around an issue in xhad, which binds to a particular
142 # Ethernet device, which in turn causes ICMP port unreachable messages
143 # if packets are received are on the wrong interface, which in turn
144 # can happen if we send out ARP replies on every interface (as Linux
145 # does by default) instead of just on the interface that has the IP
146 # address being ARPed for, which this sysctl setting in turn works
147 # around.
148 #
149 # Bug #1378.
150 net.ipv4.conf.all.arp_filter = 1
151 EOF
152 fi
153
154 if test ! -e /etc/openvswitch/conf.db; then
155     install -d -m 755 -o root -g root /etc/openvswitch
156
157     # Create ovs-vswitchd config database
158     ovsdb-tool -vANY:console:emer create /etc/openvswitch/conf.db \
159             /usr/share/openvswitch/vswitch.ovsschema
160
161     # Create initial table in config database
162     ovsdb-tool -vANY:console:emer transact /etc/openvswitch/conf.db \
163             '[{"op": "insert", "table": "Open_vSwitch", "row": {}}]' \
164             > /dev/null
165 fi
166
167 # Create default or update existing /etc/sysconfig/openvswitch.
168 SYSCONFIG=/etc/sysconfig/openvswitch
169 TEMPLATE=/usr/share/openvswitch/scripts/sysconfig.template
170 if [ ! -e $SYSCONFIG ]; then
171     cp $TEMPLATE $SYSCONFIG
172 else
173     for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
174     do
175         if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
176             echo >> $SYSCONFIG
177             sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
178         fi
179     done
180 fi
181
182 # Deliberately break %postun in broken OVS builds that revert original
183 # XenServer scripts during rpm -U by moving the directory where it thinks
184 # they are saved.
185 if [ -d /usr/lib/openvswitch/xs-original ]; then
186     mkdir -p /usr/lib/openvswitch/xs-saved
187     mv /usr/lib/openvswitch/xs-original/* /usr/lib/openvswitch/xs-saved/ &&
188         rmdir /usr/lib/openvswitch/xs-original
189 fi
190
191 # Replace XenServer files by our versions.
192 mkdir -p /usr/lib/openvswitch/xs-saved \
193     || printf "Could not create script backup directory.\n"
194 for f in \
195     /opt/xensource/libexec/interface-reconfigure \
196     /opt/xensource/libexec/InterfaceReconfigure.py \
197     /opt/xensource/libexec/InterfaceReconfigureBridge.py \
198     /opt/xensource/libexec/InterfaceReconfigureVswitch.py \
199     /etc/xensource/scripts/vif
200 do
201     s=$(basename "$f")
202     t=$(readlink "$f")
203     if [ -f "$f" ] && [ "$t" != "/usr/share/openvswitch/scripts/$s" ]; then
204         mv "$f" /usr/lib/openvswitch/xs-saved/ \
205             || printf "Could not save original XenServer $s script\n"
206         ln -s "/usr/share/openvswitch/scripts/$s" "$f" \
207             || printf "Could not link to Open vSwitch $s script\n"
208     fi
209 done
210
211 # Clean up dangling symlinks to removed OVS replacement scripts no longer
212 # provided by OVS. Any time a replacement script is removed from OVS,
213 # it should be added here to ensure correct reversion from old versions of
214 # OVS that don't clean up dangling symlinks during the uninstall phase.
215 for orig in \
216     /usr/sbin/brctl \
217     /usr/sbin/xen-bugtool
218 do
219     saved=/usr/lib/openvswitch/xs-saved/$(basename "$orig")
220     [ -e "$saved" ] && mv -f "$saved" "$orig"
221 done
222
223 # Ensure all required services are set to run
224 for s in openvswitch openvswitch-xapi-update; do
225     if chkconfig --list $s >/dev/null 2>&1; then
226         chkconfig --del $s || printf "Could not remove $s init script."
227     fi
228     chkconfig --add $s || printf "Could not add $s init script."
229     chkconfig $s on || printf "Could not enable $s init script."
230 done
231
232 if [ "$1" = "1" ]; then    # $1 = 1 for install
233     # Configure system to use Open vSwitch
234     /opt/xensource/bin/xe-switch-network-backend vswitch
235 else    # $1 = 2 for upgrade
236
237     mode=$(cat /etc/xensource/network.conf)
238     if [ "$mode" != "vswitch" ] && [ "$mode" != "openvswitch" ]; then
239         printf "\nThe server is not configured to run Open vSwitch.  To run in\n"
240         printf "vswitch mode, you must run the following command:\n\n"
241         printf "\txe-switch-network-backend vswitch"
242     else
243         printf "\nTo use the new Open vSwitch install, you should reboot the\n"
244         printf "server now.  Failure to do so may result in incorrect operation."
245     fi
246
247     printf "\n\n"
248 fi
249
250 %posttrans %{module_package}
251 # Ensure that modprobe will find our modules.
252 #
253 # This has to be in %posttrans instead of %post because older versions
254 # installed modules into a different directory and "rpm -U" runs the
255 # new version's %post before removing the old version's files, so if
256 # we use %post then depmod may find the old versions that are about to
257 # be removed.
258 depmod %{xen_version}
259
260 %preun
261 if [ "$1" = "0" ]; then     # $1 = 0 for uninstall
262     # Configure system to use bridge
263     /opt/xensource/bin/xe-switch-network-backend bridge
264
265     # The "openvswitch" service should have been removed from
266     # "xe-switch-network-backend bridge".
267     for s in openvswitch openvswitch-xapi-update; do
268         if chkconfig --list $s >/dev/null 2>&1; then
269             chkconfig --del $s || printf "Could not remove $s init script."
270         fi
271     done
272 fi
273
274 %postun
275 # Restore original XenServer scripts if the OVS equivalent no longer exists.
276 # This works both in the upgrade and erase cases.
277 # This lists every file that every version of OVS has ever replaced. Never
278 # remove old files that OVS no longer replaces, or upgrades from old versions
279 # will fail to restore the XS originals, leaving the system in a broken state.
280 # Also be sure to add removed script paths to the %post scriptlet above to
281 # prevent the same problem when upgrading from old versions of OVS that lack
282 # this restore-on-upgrade logic.
283 for f in \
284     /etc/xensource/scripts/vif \
285     /usr/sbin/brctl \
286     /usr/sbin/xen-bugtool \
287     /opt/xensource/libexec/interface-reconfigure \
288     /opt/xensource/libexec/InterfaceReconfigure.py \
289     /opt/xensource/libexec/InterfaceReconfigureBridge.py \
290     /opt/xensource/libexec/InterfaceReconfigureVswitch.py
291 do
292     # Only revert dangling symlinks.
293     if [ -h "$f" ] && [ ! -e "$f" ]; then
294         s=$(basename "$f")
295         if [ ! -f "/usr/lib/openvswitch/xs-saved/$s" ]; then
296             printf "Original XenServer $s script not present in /usr/lib/openvswitch/xs-saved\n" >&2
297             printf "Could not restore original XenServer script.\n" >&2
298         else
299             (rm -f "$f" \
300                 && mv "/usr/lib/openvswitch/xs-saved/$s" "$f") \
301                 || printf "Could not restore original XenServer $s script.\n" >&2
302         fi
303     fi
304 done
305
306 if [ "$1" = "0" ]; then     # $1 = 0 for uninstall
307     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
308         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo
309
310     rm -f /usr/share/openvswitch/scripts/InterfaceReconfigure.pyc \
311         /usr/share/openvswitch/scripts/InterfaceReconfigure.pyo \
312         /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyc \
313         /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyo \
314         /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyc \
315         /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyo
316
317     # Remove all configuration files
318     rm -f /etc/openvswitch/conf.db
319     rm -f /etc/sysconfig/openvswitch
320     rm -f /etc/openvswitch/vswitchd.cacert
321
322     # Remove saved XenServer scripts directory, but only if it's empty
323     rmdir -p /usr/lib/openvswitch/xs-saved 2>/dev/null
324 fi
325
326 exit 0
327
328 %files
329 %defattr(-,root,root)
330 /etc/init.d/openvswitch
331 /etc/init.d/openvswitch-xapi-update
332 /etc/xapi.d/plugins/openvswitch-cfg-update
333 /etc/xensource/bugtool/network-status/openvswitch.xml
334 /etc/xensource/bugtool/kernel-info/openvswitch.xml
335 /etc/xensource/bugtool/system-configuration.xml
336 /etc/xensource/bugtool/system-configuration/openvswitch.xml
337 /etc/logrotate.d/openvswitch
338 /etc/profile.d/openvswitch.sh
339 /usr/share/openvswitch/python/ovs/__init__.py
340 /usr/share/openvswitch/python/ovs/daemon.py
341 /usr/share/openvswitch/python/ovs/db/__init__.py
342 /usr/share/openvswitch/python/ovs/db/data.py
343 /usr/share/openvswitch/python/ovs/db/error.py
344 /usr/share/openvswitch/python/ovs/db/idl.py
345 /usr/share/openvswitch/python/ovs/db/parser.py
346 /usr/share/openvswitch/python/ovs/db/schema.py
347 /usr/share/openvswitch/python/ovs/db/types.py
348 /usr/share/openvswitch/python/ovs/dirs.py
349 /usr/share/openvswitch/python/ovs/fatal_signal.py
350 /usr/share/openvswitch/python/ovs/json.py
351 /usr/share/openvswitch/python/ovs/jsonrpc.py
352 /usr/share/openvswitch/python/ovs/ovsuuid.py
353 /usr/share/openvswitch/python/ovs/poller.py
354 /usr/share/openvswitch/python/ovs/process.py
355 /usr/share/openvswitch/python/ovs/reconnect.py
356 /usr/share/openvswitch/python/ovs/socket_util.py
357 /usr/share/openvswitch/python/ovs/stream.py
358 /usr/share/openvswitch/python/ovs/timeval.py
359 /usr/share/openvswitch/python/ovs/util.py
360 /usr/share/openvswitch/python/uuid.py
361 /usr/share/openvswitch/scripts/ovs-xapi-sync
362 /usr/share/openvswitch/scripts/interface-reconfigure
363 /usr/share/openvswitch/scripts/InterfaceReconfigure.py
364 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
365 /usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
366 /usr/share/openvswitch/scripts/vif
367 /usr/share/openvswitch/scripts/sysconfig.template
368 /usr/share/openvswitch/scripts/xen-bugtool-tc-class-show
369 /usr/share/openvswitch/scripts/ovs-save
370 /usr/share/openvswitch/scripts/ovs-ctl
371 /usr/share/openvswitch/scripts/ovs-lib.sh
372 /usr/share/openvswitch/vswitch.ovsschema
373 /usr/sbin/ovs-vlan-bug-workaround
374 /usr/sbin/ovs-vswitchd
375 /usr/sbin/ovsdb-server
376 /usr/bin/ovs-appctl
377 /usr/bin/ovs-dpctl
378 /usr/bin/ovs-ofctl
379 /usr/bin/ovs-pcap
380 /usr/bin/ovs-tcpundump
381 /usr/bin/ovs-vlan-test
382 /usr/bin/ovs-vsctl
383 /usr/bin/ovsdb-client
384 /usr/bin/ovsdb-tool
385 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
386 /usr/share/man/man1/ovsdb-client.1.gz
387 /usr/share/man/man1/ovsdb-server.1.gz
388 /usr/share/man/man1/ovsdb-tool.1.gz
389 /usr/share/man/man5/ovs-vswitchd.conf.db.5.gz
390 /usr/share/man/man8/ovs-appctl.8.gz
391 /usr/share/man/man8/ovs-ctl.8.gz
392 /usr/share/man/man8/ovs-dpctl.8.gz
393 /usr/share/man/man8/ovs-ofctl.8.gz
394 /usr/share/man/man8/ovs-parse-leaks.8.gz
395 /usr/share/man/man1/ovs-pcap.1.gz
396 /usr/share/man/man1/ovs-tcpundump.1.gz
397 /usr/share/man/man8/ovs-vlan-bug-workaround.8.gz
398 /usr/share/man/man8/ovs-vlan-test.8.gz
399 /usr/share/man/man8/ovs-vsctl.8.gz
400 /usr/share/man/man8/ovs-vswitchd.8.gz
401 /var/lib/openvswitch
402 %exclude /usr/lib/xsconsole/plugins-base/*.py[co]
403 %exclude /usr/sbin/ovs-brcompatd
404 %exclude /usr/share/man/man8/ovs-brcompatd.8.gz
405 %exclude /usr/share/openvswitch/scripts/*.py[co]
406 %exclude /usr/share/openvswitch/python/*.py[co]
407 %exclude /usr/share/openvswitch/python/ovs/*.py[co]
408 %exclude /usr/share/openvswitch/python/ovs/db/*.py[co]
409
410 %files %{module_package}
411 /lib/modules/%{xen_version}/extra/openvswitch/openvswitch_mod.ko
412 %exclude /lib/modules/%{xen_version}/extra/openvswitch/brcompat_mod.ko