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