xenserver: Introduce "force-reload-kmod" to reload kernel module.
[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, 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 Name: openvswitch
19 Summary: Virtual switch
20 Group: System Environment/Daemons
21 URL: http://www.openvswitch.org/
22 Vendor: Nicira Networks, Inc.
23 Version: %{openvswitch_version}
24
25 # The entire source code is ASL 2.0 except datapath/ which is GPLv2
26 License: ASL 2.0 and GPLv2
27 Release: 1
28 Source: openvswitch-%{openvswitch_version}.tar.gz
29 Buildroot: /tmp/openvswitch-xen-rpm
30 Requires: kernel-xen = %(echo '%{xen_version}' | sed 's/xen$//')
31
32 %description
33 Open vSwitch provides standard network bridging functions augmented with
34 support for the OpenFlow protocol for remote per-flow control of
35 traffic.
36
37 %prep
38 %setup -q -n openvswitch-%{openvswitch_version}
39
40 %build
41 ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=%{_localstatedir} --with-l26=/lib/modules/%{xen_version}/build --enable-ssl %{build_number}
42 make %{_smp_mflags}
43
44 %install
45 rm -rf $RPM_BUILD_ROOT
46 make install DESTDIR=$RPM_BUILD_ROOT
47 install -d -m 755 $RPM_BUILD_ROOT/etc
48 install -d -m 755 $RPM_BUILD_ROOT/etc/init.d
49 install -m 755 xenserver/etc_init.d_openvswitch \
50          $RPM_BUILD_ROOT/etc/init.d/openvswitch
51 install -m 755 xenserver/etc_init.d_openvswitch-xapi-update \
52          $RPM_BUILD_ROOT/etc/init.d/openvswitch-xapi-update
53 install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
54 install -d -m 755 $RPM_BUILD_ROOT/etc/logrotate.d
55 install -m 755 xenserver/etc_logrotate.d_openvswitch \
56          $RPM_BUILD_ROOT/etc/logrotate.d/openvswitch
57 install -d -m 755 $RPM_BUILD_ROOT/etc/profile.d
58 install -m 755 xenserver/etc_profile.d_openvswitch.sh \
59          $RPM_BUILD_ROOT/etc/profile.d/openvswitch.sh
60 install -d -m 755 $RPM_BUILD_ROOT/etc/xapi.d/plugins
61 install -m 755 xenserver/etc_xapi.d_plugins_openvswitch-cfg-update \
62          $RPM_BUILD_ROOT/etc/xapi.d/plugins/openvswitch-cfg-update
63 install -d -m 755 $RPM_BUILD_ROOT/usr/share/openvswitch/scripts
64 install -m 644 vswitchd/vswitch.ovsschema \
65          $RPM_BUILD_ROOT/usr/share/openvswitch/vswitch.ovsschema
66 install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \
67              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/interface-reconfigure
68 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigure.py \
69              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigure.py
70 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureBridge.py \
71              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
72 install -m 644 xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py \
73              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
74 install -m 755 xenserver/etc_xensource_scripts_vif \
75              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/vif
76 install -m 755 xenserver/usr_share_openvswitch_scripts_ovs-external-ids \
77                $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/ovs-external-ids
78 install -m 755 xenserver/usr_share_openvswitch_scripts_refresh-xs-network-uuids \
79                $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/refresh-xs-network-uuids
80 install -m 755 xenserver/usr_sbin_xen-bugtool \
81              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/xen-bugtool
82 install -m 755 xenserver/usr_sbin_brctl \
83              $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/brctl
84 install -m 755 xenserver/usr_share_openvswitch_scripts_sysconfig.template \
85          $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/sysconfig.template
86 install -m 755 utilities/ovs-save \
87          $RPM_BUILD_ROOT/usr/share/openvswitch/scripts/ovs-save
88 install -d -m 755 $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base
89 install -m 644 \
90         xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
91                $RPM_BUILD_ROOT/usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
92
93 install -d -m 755 $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/extra/openvswitch
94 find datapath/linux-2.6 -name *.ko -exec install -m 755  \{\} $RPM_BUILD_ROOT/lib/modules/%{xen_version}/kernel/extra/openvswitch \;
95 install xenserver/uuid.py $RPM_BUILD_ROOT/usr/share/openvswitch/python
96
97 # Get rid of stuff we don't want to make RPM happy.
98 rm \
99     $RPM_BUILD_ROOT/usr/bin/ovs-controller \
100     $RPM_BUILD_ROOT/usr/bin/ovs-discover \
101     $RPM_BUILD_ROOT/usr/bin/ovs-kill \
102     $RPM_BUILD_ROOT/usr/bin/ovs-openflowd \
103     $RPM_BUILD_ROOT/usr/bin/ovs-pki \
104     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-controller.8 \
105     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-discover.8 \
106     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-kill.8 \
107     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-openflowd.8 \
108     $RPM_BUILD_ROOT/usr/share/man/man8/ovs-pki.8
109
110 install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
111
112 %clean
113 rm -rf $RPM_BUILD_ROOT
114
115 %post
116 if [ ! -f /etc/xensource-inventory ]; then
117     printf "XenSource inventory not present in /etc/xensource-inventory"
118     exit 1
119 fi
120 . /etc/xensource-inventory
121
122 if [ "$1" = "1" ]; then
123     if md5sum -c --status <<EOF
124 ca141d60061dcfdade73e75abc6529b5  /usr/sbin/brctl
125 b8e9835862ef1a9cec2a3f477d26c989  /etc/xensource/scripts/vif
126 51970ad613a3996d5997e18e44db47da  /opt/xensource/libexec/interface-reconfigure
127 5654c8c36699fcc8744ca9cd5b855414  /usr/sbin/xen-bugtool
128 EOF
129     then
130         printf "\nVerified host scripts from XenServer 5.5.0.\n\n"
131     elif md5sum -c --status <<EOF
132 ca141d60061dcfdade73e75abc6529b5  /usr/sbin/brctl
133 b8e9835862ef1a9cec2a3f477d26c989  /etc/xensource/scripts/vif
134 51970ad613a3996d5997e18e44db47da  /opt/xensource/libexec/interface-reconfigure
135 f6519085c2fc5f7bc4eccc294ed62000  /usr/sbin/xen-bugtool
136 EOF
137     then
138         printf "\nVerified host scripts from XenServer 5.5.0-24648p (Update 1)\n"
139         printf "or 5.5.0-25727p (Update 2).\n\n"
140     elif md5sum -c --status <<EOF
141 ca141d60061dcfdade73e75abc6529b5  /usr/sbin/brctl
142 02cf136237ed85fcbcc1efc15ce0591c  /opt/xensource/libexec/interface-reconfigure
143 3a192ee70ebf2153c90051b3af95f331  /opt/xensource/libexec/InterfaceReconfigureBridge.py
144 f71cadf1464caefa7943de0ab47fdd8a  /opt/xensource/libexec/InterfaceReconfigure.py
145 d70f08f235fb1bfd49a0580e440f15a0  /opt/xensource/libexec/InterfaceReconfigureVswitch.py
146 f5c85ca825b1e6f5a0845530981cd836  /etc/xensource/scripts/vif
147 facb851606f82ca2bcc760a4d91bbe33  /usr/sbin/xen-bugtool
148 EOF
149     then
150         printf "\nVerified host scripts from XenServer 5.5.900-29381p.\n\n"
151     else
152 cat <<EOF
153
154 The original XenServer scripts replaced by this package are not those
155 of any supported version of XenServer.  This could lead to unexpected
156 behavior of your server.  Unless you are sure you know what you are
157 doing, it is highly recommended that you remove this package
158 immediately after the install completes, which will restore the
159 XenServer scripts that you were previously using.
160
161 EOF
162     fi
163 fi
164
165 # On XenServer 5.5.0, we need refresh-xs-network-uuids to run whenever
166 # XAPI starts or restarts.  (On XenServer 5.6.0, XAPI calls the
167 # "update" method of the vswitch-cfg-update plugin whenever it starts
168 # or restarts, so this is no longer necessary.)
169 if test "$PRODUCT_VERSION" = "5.5.0"; then
170     RNU=/usr/share/openvswitch/scripts/refresh-xs-network-uuids
171     XSS=/opt/xensource/libexec/xapi-startup-script
172     if test -e $XSS && (test ! -L $XSS || test "`readlink $XSS`" != $RNU); then
173         echo "$XSS is already in use, refusing to overwrite"
174         exit 1
175     fi
176     rm -f $XSS
177     ln -s $RNU $XSS
178
179     # If /etc/xensource/network.conf doesn't exist (it was added in 5.6.0),
180     # then interface-reconfigure will be unhappy when we run it below.
181     if test ! -e /etc/xensource/network.conf; then
182         echo bridge > /etc/xensource/network.conf
183     fi
184 fi
185
186
187 if test ! -e /var/xapi/network.dbcache; then
188     if test "$1" = 1; then
189         printf "Creating xapi database cache...  "
190     else
191         printf "warning: Open vSwitch is being re-installed or upgraded,\n"
192         printf "         but the xapi database cache is missing.\n"
193         printf "Re-creating xapi database cache...  "
194     fi
195
196     if /usr/share/openvswitch/scripts/interface-reconfigure rewrite; then
197         printf "done.\n"
198     else
199         printf "FAILED\n"
200         printf "Open vSwitch can only be installed on a XenServer that\n"
201         printf "has connectivity to xapi on the pool master.  Please\n"
202         printf "fix connectivity to the pool master, then try again.\n"
203         exit 1
204     fi
205 fi
206
207 # Ensure that modprobe will find our modules.
208 depmod %{xen_version}
209
210 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
211     cat >>/etc/sysctl.conf <<EOF
212 # This works around an issue in xhad, which binds to a particular
213 # Ethernet device, which in turn causes ICMP port unreachable messages
214 # if packets are received are on the wrong interface, which in turn
215 # can happen if we send out ARP replies on every interface (as Linux
216 # does by default) instead of just on the interface that has the IP
217 # address being ARPed for, which this sysctl setting in turn works
218 # around.
219 #
220 # Bug #1378.
221 net.ipv4.conf.all.arp_filter = 1
222 EOF
223 fi
224
225 if test ! -e /etc/openvswitch/conf.db; then
226     install -d -m 755 -o root -g root /etc/openvswitch
227
228     # Create ovs-vswitchd config database
229     ovsdb-tool -vANY:console:emer create /etc/openvswitch/conf.db \
230             /usr/share/openvswitch/vswitch.ovsschema
231
232     # Create initial table in config database
233     ovsdb-tool -vANY:console:emer transact /etc/openvswitch/conf.db \
234             '[{"op": "insert", "table": "Open_vSwitch", "row": {}}]' \
235             > /dev/null
236 fi
237
238 # Create default or update existing /etc/sysconfig/openvswitch.
239 SYSCONFIG=/etc/sysconfig/openvswitch
240 TEMPLATE=/usr/share/openvswitch/scripts/sysconfig.template
241 if [ ! -e $SYSCONFIG ]; then
242     cp $TEMPLATE $SYSCONFIG
243 else
244     for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
245     do
246         if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
247             echo >> $SYSCONFIG
248             sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
249         fi
250     done
251 fi
252
253 # Replace XenServer files by our versions.
254 mkdir -p /usr/lib/openvswitch/xs-original \
255     || printf "Could not create script backup directory.\n"
256 for f in \
257     /opt/xensource/libexec/interface-reconfigure \
258     /opt/xensource/libexec/InterfaceReconfigure.py \
259     /opt/xensource/libexec/InterfaceReconfigureBridge.py \
260     /opt/xensource/libexec/InterfaceReconfigureVswitch.py \
261     /etc/xensource/scripts/vif \
262     /usr/sbin/xen-bugtool \
263     /usr/sbin/brctl
264 do
265     s=$(basename "$f")
266     t=$(readlink "$f")
267     if [ -f "$f" ] && [ "$t" != "/usr/share/openvswitch/scripts/$s" ]; then
268         mv "$f" /usr/lib/openvswitch/xs-original/ \
269             || printf "Could not save original XenServer $s script\n"
270         ln -s "/usr/share/openvswitch/scripts/$s" "$f" \
271             || printf "Could not link to Open vSwitch $s script\n"
272     fi
273 done
274
275 # Ensure all required services are set to run
276 for s in openvswitch openvswitch-xapi-update; do
277     if chkconfig --list $s >/dev/null 2>&1; then
278         chkconfig --del $s || printf "Could not remove $s init script."
279     fi
280     chkconfig --add $s || printf "Could not add $s init script."
281     chkconfig $s on || printf "Could not enable $s init script."
282 done
283
284 # Configure system to use Open vSwitch
285 echo vswitch > /etc/xensource/network.conf
286
287 if [ "$1" = "1" ]; then    # $1 = 2 for upgrade
288     printf "\nYou MUST reboot the server NOW to complete the change to\n"
289     printf "Open vSwitch.  Attempts to modify networking on the server\n"
290     printf "or any hosted VM will fail until after the reboot and could\n"
291     printf "leave the server in an state requiring manual recovery.\n\n"
292 else
293     printf "\nTo use the new Open vSwitch install, you should reboot the\n" 
294     printf "server now.  Failure to do so may result in incorrect operation."
295     printf "\n\n"
296 fi
297
298 %preun
299 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
300     for s in openvswitch openvswitch-xapi-update; do
301         chkconfig --del $s || printf "Could not remove $s init script."
302     done
303 fi
304
305
306 %postun
307 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
308     . /etc/xensource-inventory
309     if test "$PRODUCT_VERSION" = "5.5.0"; then
310         XSS=/opt/xensource/libexec/xapi-startup-script
311         rm -f $XSS
312     fi
313
314     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
315         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo
316
317     rm -f /usr/share/openvswitch/scripts/InterfaceReconfigure.pyc \
318         /usr/share/openvswitch/scripts/InterfaceReconfigure.pyo \
319         /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyc \
320         /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.pyo \
321         /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyc \
322         /usr/share/openvswitch/scripts/InterfaceReconfigureVSwitch.pyo 
323
324     # Restore original XenServer scripts
325     for f in \
326         /opt/xensource/libexec/interface-reconfigure \
327         /opt/xensource/libexec/InterfaceReconfigure.py \
328         /opt/xensource/libexec/InterfaceReconfigureBridge.py \
329         /opt/xensource/libexec/InterfaceReconfigureVswitch.py \
330         /etc/xensource/scripts/vif \
331         /usr/sbin/xen-bugtool \
332         /usr/sbin/brctl
333     do
334         s=$(basename "$f")
335         if [ ! -f "/usr/lib/openvswitch/xs-original/$s" ]; then
336             printf "Original XenServer $s script not present in /usr/lib/openvswitch/xs-original\n"
337             printf "Could not restore original XenServer script.\n"
338         else
339             (rm -f "$f" \
340                 && mv "/usr/lib/openvswitch/xs-original/$s" "$f") \
341                 || printf "Could not restore original XenServer $s script.\n"
342         fi
343     done
344
345     # Remove all configuration files
346     rm -f /etc/openvswitch/conf.db
347     rm -f /etc/sysconfig/openvswitch
348     rm -f /etc/openvswitch/vswitchd.cacert
349     rm -f /var/xapi/network.dbcache
350
351     if test "$PRODUCT_VERSION" != "5.5.0"; then
352         # Configure system to use bridge
353         echo bridge > /etc/xensource/network.conf
354     else
355         # Get rid of network.conf entirely, to make the system pristine.
356         rm -f /etc/xensource/network.conf
357     fi
358
359     printf "\nYou MUST reboot the server now to complete the change to\n"
360     printf "standard Xen networking.  Attempts to modify networking on the\n"
361     printf "server or any hosted VM will fail until after the reboot and\n"
362     printf "could leave the server in a state requiring manual recovery.\n\n"
363 fi
364
365
366 %files
367 %defattr(-,root,root)
368 /etc/init.d/openvswitch
369 /etc/init.d/openvswitch-xapi-update
370 /etc/xapi.d/plugins/openvswitch-cfg-update
371 /etc/logrotate.d/openvswitch
372 /etc/profile.d/openvswitch.sh
373 /lib/modules/%{xen_version}/kernel/extra/openvswitch/openvswitch_mod.ko
374 /lib/modules/%{xen_version}/kernel/extra/openvswitch/brcompat_mod.ko
375 /usr/share/openvswitch/python/ovs/__init__.py
376 /usr/share/openvswitch/python/ovs/daemon.py
377 /usr/share/openvswitch/python/ovs/db/__init__.py
378 /usr/share/openvswitch/python/ovs/db/data.py
379 /usr/share/openvswitch/python/ovs/db/error.py
380 /usr/share/openvswitch/python/ovs/db/idl.py
381 /usr/share/openvswitch/python/ovs/db/parser.py
382 /usr/share/openvswitch/python/ovs/db/schema.py
383 /usr/share/openvswitch/python/ovs/db/types.py
384 /usr/share/openvswitch/python/ovs/dirs.py
385 /usr/share/openvswitch/python/ovs/fatal_signal.py
386 /usr/share/openvswitch/python/ovs/json.py
387 /usr/share/openvswitch/python/ovs/jsonrpc.py
388 /usr/share/openvswitch/python/ovs/ovsuuid.py
389 /usr/share/openvswitch/python/ovs/poller.py
390 /usr/share/openvswitch/python/ovs/process.py
391 /usr/share/openvswitch/python/ovs/reconnect.py
392 /usr/share/openvswitch/python/ovs/socket_util.py
393 /usr/share/openvswitch/python/ovs/stream.py
394 /usr/share/openvswitch/python/ovs/timeval.py
395 /usr/share/openvswitch/python/ovs/util.py
396 /usr/share/openvswitch/python/uuid.py
397 /usr/share/openvswitch/scripts/ovs-external-ids
398 /usr/share/openvswitch/scripts/refresh-xs-network-uuids
399 /usr/share/openvswitch/scripts/interface-reconfigure
400 /usr/share/openvswitch/scripts/InterfaceReconfigure.py
401 /usr/share/openvswitch/scripts/InterfaceReconfigureBridge.py
402 /usr/share/openvswitch/scripts/InterfaceReconfigureVswitch.py
403 /usr/share/openvswitch/scripts/vif
404 /usr/share/openvswitch/scripts/xen-bugtool
405 /usr/share/openvswitch/scripts/brctl
406 /usr/share/openvswitch/scripts/sysconfig.template
407 /usr/share/openvswitch/scripts/ovs-save
408 /usr/share/openvswitch/vswitch.ovsschema
409 /usr/sbin/ovs-brcompatd
410 /usr/sbin/ovs-vswitchd
411 /usr/sbin/ovsdb-server
412 /usr/bin/ovs-appctl
413 /usr/bin/ovs-dpctl
414 /usr/bin/ovs-ofctl
415 /usr/bin/ovs-pcap
416 /usr/bin/ovs-tcpundump
417 /usr/bin/ovs-vlan-test
418 /usr/bin/ovs-vsctl
419 /usr/bin/ovsdb-client
420 /usr/bin/ovsdb-tool
421 /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
422 /usr/share/man/man1/ovsdb-client.1.gz
423 /usr/share/man/man1/ovsdb-server.1.gz
424 /usr/share/man/man1/ovsdb-tool.1.gz
425 /usr/share/man/man5/ovs-vswitchd.conf.db.5.gz
426 /usr/share/man/man8/ovs-appctl.8.gz
427 /usr/share/man/man8/ovs-brcompatd.8.gz
428 /usr/share/man/man8/ovs-dpctl.8.gz
429 /usr/share/man/man8/ovs-ofctl.8.gz
430 /usr/share/man/man8/ovs-parse-leaks.8.gz
431 /usr/share/man/man1/ovs-pcap.1.gz
432 /usr/share/man/man1/ovs-tcpundump.1.gz
433 /usr/share/man/man8/ovs-vlan-test.8.gz
434 /usr/share/man/man8/ovs-vsctl.8.gz
435 /usr/share/man/man8/ovs-vswitchd.8.gz
436 /var/lib/openvswitch
437 %exclude /usr/lib/xsconsole/plugins-base/*.py[co]
438 %exclude /usr/share/openvswitch/scripts/*.py[co]
439 %exclude /usr/share/openvswitch/python/*.py[co]
440 %exclude /usr/share/openvswitch/python/ovs/*.py[co]
441 %exclude /usr/share/openvswitch/python/ovs/db/*.py[co]