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