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