Setting tag sliver-openvswitch-2.2.90-1
[sliver-openvswitch.git] / xenserver / openvswitch-xen.spec.in
1 # Spec file for Open vSwitch.
2
3 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Nicira, 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, and kernel_flavor
12 # 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 #      -bb /usr/src/redhat/SPECS/openvswitch-xen.spec
20
21 %if %{?openvswitch_version:0}%{!?openvswitch_version:1}
22 %define openvswitch_version @VERSION@
23 %endif
24
25 %if %{?kernel_name:0}%{!?kernel_name:1}
26 %define kernel %(rpm -qa 'kernel*xen-devel' | head -1)
27 %define kernel_name %(rpm -q --queryformat "%%{Name}" %{kernel} | sed 's/-devel//' | sed 's/kernel-//')
28 %define kernel_version %(rpm -q --queryformat "%%{Version}-%%{Release}" %{kernel})
29 %define kernel_flavor xen
30 %endif
31
32 %define xen_version %{kernel_version}%{kernel_flavor}
33
34 # bump this when breaking compatibility with userspace
35 %define module_abi_version 0
36
37 # build-supplemental-pack.sh requires this naming for kernel module packages
38 %define module_package modules-%{kernel_flavor}-%{kernel_version}
39
40 Name: openvswitch
41 Summary: Open vSwitch daemon/database/utilities
42 Group: System Environment/Daemons
43 URL: http://www.openvswitch.org/
44 Vendor: Nicira, Inc.
45 Version: %{openvswitch_version}
46
47 License: ASL 2.0
48 Release: 1
49 Source: openvswitch-%{openvswitch_version}.tar.gz
50 Buildroot: /tmp/openvswitch-xen-rpm
51 Requires: openvswitch.ko.%{module_abi_version}
52
53 %description
54 Open vSwitch provides standard network bridging functions augmented with
55 support for the OpenFlow protocol for remote per-flow control of
56 traffic.
57
58 %package %{module_package}
59 Summary: Open vSwitch kernel module
60 Group: System Environment/Kernel
61 License: GPLv2
62 Provides: %{name}-modules-%{kernel_flavor} = %{kernel_version}, openvswitch.ko.%{module_abi_version}
63 Requires: kernel-%{kernel_name} = %{kernel_version}
64
65 %description %{module_package}
66 Open vSwitch Linux kernel module compiled against kernel version
67 %{xen_version}.
68
69 %prep
70 %setup -q -n openvswitch-%{openvswitch_version}
71
72 %build
73 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=%{_localstatedir} --with-linux=/lib/modules/%{xen_version}/build --enable-ssl
74 make %{_smp_mflags}
75
76 %install
77 rm -rf $RPM_BUILD_ROOT
78 make install DESTDIR=$RPM_BUILD_ROOT
79 install -d -m 755 $RPM_BUILD_ROOT/etc
80 install -d -m 755 $RPM_BUILD_ROOT/etc/init.d
81 install -m 755 xenserver/etc_init.d_openvswitch \
82          $RPM_BUILD_ROOT/etc/init.d/openvswitch
83 install -m 755 xenserver/etc_init.d_openvswitch-xapi-update \
84          $RPM_BUILD_ROOT/etc/init.d/openvswitch-xapi-update
85 install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
86 install -d -m 755 $RPM_BUILD_ROOT/etc/logrotate.d
87 install -m 755 xenserver/etc_logrotate.d_openvswitch \
88          $RPM_BUILD_ROOT/etc/logrotate.d/openvswitch
89 install -d -m 755 $RPM_BUILD_ROOT/etc/profile.d
90 install -m 755 xenserver/etc_profile.d_openvswitch.sh \
91          $RPM_BUILD_ROOT/etc/profile.d/openvswitch.sh
92 install -d -m 755 $RPM_BUILD_ROOT/etc/xapi.d/plugins
93 install -m 755 xenserver/etc_xapi.d_plugins_openvswitch-cfg-update \
94          $RPM_BUILD_ROOT/etc/xapi.d/plugins/openvswitch-cfg-update
95 install -d -m 755 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts
96 install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \
97              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/interface-reconfigure
98 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigure.py \
99              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigure.py
100 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureBridge.py \
101              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
102 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py \
103              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
104 install -m 755 xenserver/etc_xensource_scripts_vif \
105              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/vif
106 install -m 755 xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync \
107                $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/ovs-xapi-sync
108 install -m 755 xenserver/usr_share_openvswitch_scripts_sysconfig.template \
109          $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/sysconfig.template
110 install -d -m 755 $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base
111 install -m 644 \
112         xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
113                $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
114
115 install -d -m 755 $RPM_BUILD_ROOT/lib/modules/%{xen_version}/extra/openvswitch
116 find datapath/linux -name *.ko -exec install -m 755  \{\} $RPM_BUILD_ROOT/lib/modules/%{xen_version}/extra/openvswitch \;
117 install python/compat/uuid.py $RPM_BUILD_ROOT/usr/share/openvswitch/python
118 install python/compat/argparse.py $RPM_BUILD_ROOT/usr/share/openvswitch/python
119
120 install -d -m 755 $RPM_BUILD_ROOT/etc/xensource/bugtool
121 cp -rf $RPM_BUILD_ROOT/usr/share/openvswitch/bugtool-plugins/* $RPM_BUILD_ROOT/etc/xensource/bugtool
122
123 # Get rid of stuff we don't want to make RPM happy.
124 rm \
125     $RPM_BUILD_ROOT/usr/bin/ovs-benchmark \
126     $RPM_BUILD_ROOT/usr/bin/ovs-l3ping \
127     $RPM_BUILD_ROOT/usr/bin/ovs-pki \
128     $RPM_BUILD_ROOT/usr/bin/ovs-test \
129     $RPM_BUILD_ROOT/usr/share/man/man1/ovs-benchmark.1 \
130     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-l3ping.8 \
131     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-pki.8 \
132     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-test.8
133 (cd "$RPM_BUILD_ROOT" && rm -f usr/lib/lib*)
134
135 install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
136
137 %clean
138 rm -rf $RPM_BUILD_ROOT
139
140 %post
141 # A list of Citrix XenServer scripts that we might need to replace
142 # with our own versions.
143 scripts="
144     /etc/xensource/scripts/vif
145     /opt/xensource/libexec/InterfaceReconfigure.py
146     /opt/xensource/libexec/InterfaceReconfigureBridge.py
147     /opt/xensource/libexec/InterfaceReconfigureVswitch.py
148     /opt/xensource/libexec/interface-reconfigure"
149
150 # Calculate into $md5sums a comma-separated set of md5sums of the
151 # Citrix XenServer scripts that we might need to replace.  We might be
152 # upgrading an older version of the package that moved the files out
153 # of the way, so we need to look for the files in those out-of-the-way
154 # locations first.
155 md5sums=
156 for script in $scripts; do
157     b=$(basename "$script")
158     if test -e /usr/lib/openvswitch/xs-saved/"$b"; then
159         f=/usr/lib/openvswitch/xs-saved/"$b"
160     elif test -e /usr/lib/openvswitch/xs-original/"$b"; then
161         f=/usr/lib/openvswitch/xs-original/"$b"
162     elif test -e "$script" && test ! -h "$script"; then
163         f=$script
164     else
165         printf "\n$script: not found\n"
166         f=/dev/null
167     fi
168     md5sums="$md5sums,$(md5sum $f | awk '{print $1}')"
169 done
170 md5sums=${md5sums#,}
171
172 # Now check the md5sums against the known sets of md5sums:
173 #
174 #   - If they are known to be a version of XenServer scripts that we should
175 #     replace, we replace them (by putting $scripts into $replace_files).
176 #
177 #   - Otherwise, we guess that it's better not to replace them, because the
178 #     improvements that our versions of the scripts provide are minimal, so
179 #     it's better to avoid possibly breaking any changes made upstream by
180 #     Citrix.
181 case $md5sums in
182     cf09a68d9f8b434e79a4c83b01a3bb4b,395866df1b0b20c12c4dd2f7de0ecdb4,9d493545ae81463239d3162cbc798852,862d0939b441de9264a900628e950fe9,21f85db25599d7f026cd489385d58aa6)
183         keep_files=
184         replace_files=$scripts
185         printf "\nVerified host scripts from XenServer 6.0.0.\n"
186         ;;
187
188     c5f48246577a17cf1b971fb5ce4e920b,2e2c912f86f9c536c89adc34ff3c2b2b,28d3ff72d72bdec4f37d70699f5edb76,67e1d0af16fc1ddf10009c5c063ad2ba,f3feff30aa3b3f8b514664a96a8dc0ab)
189         keep_files=
190         replace_files=$scripts
191         printf "\nVerified host scripts from XenServer 5.6-SP2.\n"
192         ;;
193         
194     c5f48246577a17cf1b971fb5ce4e920b,2e2c912f86f9c536c89adc34ff3c2b2b,28d3ff72d72bdec4f37d70699f5edb76,67e1d0af16fc1ddf10009c5c063ad2ba,24bae6906d182ba47668174f8e480cc6)
195         keep_files=
196         replace_files=$scripts
197         printf "\nVerified host scripts from XenServer 5.6-FP1.\n"
198         ;;
199
200     *)
201         keep_files=$scripts
202         replace_files=
203         cat <<EOF
204
205 The host scripts on this machine are not those of any supported
206 version of XenServer.  On XenServer earlier than 5.6-FP1, your Open
207 vSwitch installation will not work.  On XenServer 5.6-FP1 or later,
208 Open vSwitch is not verified to work, which could lead to unexpected
209 behavior.
210
211 EOF
212         ;;
213 esac
214
215 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
216     cat >>/etc/sysctl.conf <<EOF
217 # This works around an issue in xhad, which binds to a particular
218 # Ethernet device, which in turn causes ICMP port unreachable messages
219 # if packets are received are on the wrong interface, which in turn
220 # can happen if we send out ARP replies on every interface (as Linux
221 # does by default) instead of just on the interface that has the IP
222 # address being ARPed for, which this sysctl setting in turn works
223 # around.
224 #
225 # Bug #1378.
226 net.ipv4.conf.all.arp_filter = 1
227 EOF
228 fi
229
230 if test ! -e /etc/openvswitch/conf.db; then
231     install -d -m 755 -o root -g root /etc/openvswitch
232
233     # Create ovs-vswitchd config database
234     ovsdb-tool -vconsole:off create /etc/openvswitch/conf.db \
235             /usr/share/openvswitch/vswitch.ovsschema
236
237     # Create initial table in config database
238     ovsdb-tool -vconsole:off transact /etc/openvswitch/conf.db \
239             '[{"op": "insert", "table": "Open_vSwitch", "row": {}}]' \
240             > /dev/null
241 fi
242
243 # Create default or update existing /etc/sysconfig/openvswitch.
244 SYSCONFIG=/etc/sysconfig/openvswitch
245 TEMPLATE=/usr/share/openvswitch/scripts/sysconfig.template
246 if [ ! -e $SYSCONFIG ]; then
247     cp $TEMPLATE $SYSCONFIG
248 else
249     for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
250     do
251         if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
252             echo >> $SYSCONFIG
253             sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
254         fi
255     done
256 fi
257
258 # Deliberately break %postun in broken OVS builds that revert original
259 # XenServer scripts during rpm -U by moving the directory where it thinks
260 # they are saved.
261 if [ -d /usr/lib/openvswitch/xs-original ]; then
262     mkdir -p /usr/lib/openvswitch/xs-saved
263     mv /usr/lib/openvswitch/xs-original/* /usr/lib/openvswitch/xs-saved/ &&
264         rmdir /usr/lib/openvswitch/xs-original
265 fi
266
267 # Replace XenServer files by our versions.
268 mkdir -p /usr/lib/openvswitch/xs-saved \
269     || printf "Could not create script backup directory.\n"
270 for f in $replace_files; do
271     s=$(basename "$f")
272     t=$(readlink "$f")
273     if [ -f "$f" ] && [ "$t" != "/usr/share/openvswitch/scripts/$s" ]; then
274         mv "$f" /usr/lib/openvswitch/xs-saved/ \
275             || printf "Could not save original XenServer $s script\n"
276         ln -s "/usr/share/openvswitch/scripts/$s" "$f" \
277             || printf "Could not link to Open vSwitch $s script\n"
278     fi
279 done
280
281 # Clean up dangling symlinks to removed OVS replacement scripts no longer
282 # provided by OVS. Any time a replacement script is removed from OVS,
283 # it should be added here to ensure correct reversion from old versions of
284 # OVS that don't clean up dangling symlinks during the uninstall phase.
285 for orig in /usr/sbin/xen-bugtool $keep_files; do
286     saved=/usr/lib/openvswitch/xs-saved/$(basename "$orig")
287     [ -e "$saved" ] && mv -f "$saved" "$orig"
288 done
289
290 # Ensure all required services are set to run
291 for s in openvswitch openvswitch-xapi-update; do
292     if chkconfig --list $s >/dev/null 2>&1; then
293         chkconfig --del $s || printf "Could not remove $s init script.\n"
294     fi
295     chkconfig --add $s || printf "Could not add $s init script.\n"
296     chkconfig $s on || printf "Could not enable $s init script.\n"
297 done
298
299 if [ "$1" = "1" ]; then    # $1 = 1 for install
300     # Configure system to use Open vSwitch
301     /opt/xensource/bin/xe-switch-network-backend vswitch
302 else    # $1 = 2 for upgrade
303
304     mode=$(cat /etc/xensource/network.conf)
305     if [ "$mode" != "vswitch" ] && [ "$mode" != "openvswitch" ]; then
306         printf "\nThe server is not configured to run Open vSwitch.  To run in\n"
307         printf "vswitch mode, you must run the following command:\n\n"
308         printf "\txe-switch-network-backend vswitch"
309         printf "\n\n"
310     fi
311 fi
312
313 %posttrans %{module_package}
314 # Ensure that modprobe will find our modules.
315 #
316 # This has to be in %posttrans instead of %post because older versions
317 # installed modules into a different directory and "rpm -U" runs the
318 # new version's %post before removing the old version's files, so if
319 # we use %post then depmod may find the old versions that are about to
320 # be removed.
321 depmod %{xen_version}
322
323 mode=$(cat /etc/xensource/network.conf)
324 if [ "$mode" = "vswitch" ] || [ "$mode" = "openvswitch" ]; then
325     printf "\nTo use the newly installed Open vSwitch kernel module, you\n"
326     printf "will either have to reboot the hypervisor or follow any\n"
327     printf "workarounds provided by your administration guide. Failure to do\n"
328     printf "so may result in incorrect operation."
329     printf "\n\n"
330 fi
331
332 %preun
333 if [ "$1" = "0" ]; then     # $1 = 0 for uninstall
334     # Configure system to use bridge
335     /opt/xensource/bin/xe-switch-network-backend bridge
336
337     # The "openvswitch" service should have been removed from
338     # "xe-switch-network-backend bridge".
339     for s in openvswitch openvswitch-xapi-update; do
340         if chkconfig --list $s >/dev/null 2>&1; then
341             chkconfig --del $s || printf "Could not remove $s init script."
342         fi
343     done
344 fi
345
346 %postun
347 # Restore original XenServer scripts if the OVS equivalent no longer exists.
348 # This works both in the upgrade and erase cases.
349 # This lists every file that every version of OVS has ever replaced. Never
350 # remove old files that OVS no longer replaces, or upgrades from old versions
351 # will fail to restore the XS originals, leaving the system in a broken state.
352 # Also be sure to add removed script paths to the %post scriptlet above to
353 # prevent the same problem when upgrading from old versions of OVS that lack
354 # this restore-on-upgrade logic.
355 for f in \
356     /etc/xensource/scripts/vif \
357     /usr/sbin/xen-bugtool \
358     /opt/xensource/libexec/interface-reconfigure \
359     /opt/xensource/libexec/InterfaceReconfigure.py \
360     /opt/xensource/libexec/InterfaceReconfigureBridge.py \
361     /opt/xensource/libexec/InterfaceReconfigureVswitch.py
362 do
363     # Only revert dangling symlinks.
364     if [ -h "$f" ] && [ ! -e "$f" ]; then
365         s=$(basename "$f")
366         if [ ! -f "/usr/lib/openvswitch/xs-saved/$s" ]; then
367             printf "Original XenServer $s script not present in /usr/lib/openvswitch/xs-saved\n" >&2
368             printf "Could not restore original XenServer script.\n" >&2
369         else
370             (rm -f "$f" \
371                 && mv "/usr/lib/openvswitch/xs-saved/$s" "$f") \
372                 || printf "Could not restore original XenServer $s script.\n" >&2
373         fi
374     fi
375 done
376
377 if [ "$1" = "0" ]; then     # $1 = 0 for uninstall
378     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
379         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo
380
381     rm -f /usr/share/openvswitch/scripts/InterfaceReconfigure.pyc \
382         /usr/share/openvswitch/scripts/InterfaceReconfigure.pyo \
383         /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyc \
384         /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyo \
385         /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyc \
386         /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyo
387
388     # Remove all configuration files
389     rm -f /etc/openvswitch/conf.db
390     rm -f /etc/sysconfig/openvswitch
391     rm -f /etc/openvswitch/vswitchd.cacert
392
393     # Remove saved XenServer scripts directory, but only if it's empty
394     rmdir -p /usr/lib/openvswitch/xs-saved 2>/dev/null
395 fi
396
397 exit 0
398
399 %files
400 %defattr(-,root,root)
401 /etc/init.d/openvswitch
402 /etc/init.d/openvswitch-xapi-update
403 /etc/xapi.d/plugins/openvswitch-cfg-update
404 /etc/xensource/bugtool/*
405 /etc/logrotate.d/openvswitch
406 /etc/profile.d/openvswitch.sh
407 /usr/share/openvswitch/python/
408 /usr/share/openvswitch/bugtool-plugins/*
409 /usr/share/openvswitch/scripts/ovs-check-dead-ifs
410 /usr/share/openvswitch/scripts/ovs-xapi-sync
411 /usr/share/openvswitch/scripts/interface-reconfigure
412 /usr/share/openvswitch/scripts/InterfaceReconfigure.py
413 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
414 /usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
415 /usr/share/openvswitch/scripts/vif
416 /usr/share/openvswitch/scripts/sysconfig.template
417 /usr/share/openvswitch/scripts/ovs-bugtool-*
418 /usr/share/openvswitch/scripts/ovs-save
419 /usr/share/openvswitch/scripts/ovs-ctl
420 /usr/share/openvswitch/scripts/ovs-lib
421 /usr/share/openvswitch/scripts/ovs-vtep
422 /usr/share/openvswitch/vswitch.ovsschema
423 /usr/share/openvswitch/vtep.ovsschema
424 /usr/sbin/ovs-bugtool
425 /usr/sbin/ovs-vlan-bug-workaround
426 /usr/sbin/ovs-vswitchd
427 /usr/sbin/ovsdb-server
428 /usr/bin/ovs-appctl
429 /usr/bin/ovs-dpctl
430 /usr/bin/ovs-dpctl-top
431 /usr/bin/ovs-ofctl
432 /usr/bin/ovs-parse-backtrace
433 /usr/bin/ovs-pcap
434 /usr/bin/ovs-tcpundump
435 /usr/bin/ovs-vlan-test
436 /usr/bin/ovs-vsctl
437 /usr/bin/ovsdb-client
438 /usr/bin/ovsdb-tool
439 /usr/bin/vtep-ctl
440 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
441 /usr/share/man/man1/ovsdb-client.1.gz
442 /usr/share/man/man1/ovsdb-server.1.gz
443 /usr/share/man/man1/ovsdb-tool.1.gz
444 /usr/share/man/man5/ovs-vswitchd.conf.db.5.gz
445 /usr/share/man/man5/vtep.5.gz
446 /usr/share/man/man8/ovs-appctl.8.gz
447 /usr/share/man/man8/ovs-bugtool.8.gz
448 /usr/share/man/man8/ovs-ctl.8.gz
449 /usr/share/man/man8/ovs-dpctl.8.gz
450 /usr/share/man/man8/ovs-dpctl-top.8.gz
451 /usr/share/man/man8/ovs-ofctl.8.gz
452 /usr/share/man/man8/ovs-parse-backtrace.8.gz
453 /usr/share/man/man1/ovs-pcap.1.gz
454 /usr/share/man/man1/ovs-tcpundump.1.gz
455 /usr/share/man/man8/ovs-vlan-bug-workaround.8.gz
456 /usr/share/man/man8/ovs-vlan-test.8.gz
457 /usr/share/man/man8/ovs-vsctl.8.gz
458 /usr/share/man/man8/ovs-vswitchd.8.gz
459 /usr/share/man/man8/vtep-ctl.8.gz
460 /var/lib/openvswitch
461 /var/log/openvswitch
462 %exclude /usr/lib/xsconsole/plugins-base/*.py[co]
463 %exclude /usr/share/openvswitch/scripts/*.py[co]
464 %exclude /usr/share/openvswitch/python/*.py[co]
465 %exclude /usr/share/openvswitch/python/ovs/*.py[co]
466 %exclude /usr/share/openvswitch/python/ovs/db/*.py[co]
467
468 %files %{module_package}
469 /lib/modules/%{xen_version}/extra/openvswitch/openvswitch.ko