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