xenserver: Fix syntax error in vswitch-xen.spec %pre fragment.
[sliver-openvswitch.git] / xenserver / vswitch-xen.spec
1 # Spec file for vswitch and related programs.
2
3 # Copyright (C) 2009 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 # vswitch_version, xen_version, and build_number using -D arguments.
12 # for example:
13 #
14 #    rpmbuild -D "vswitch_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/vswitch-xen.spec
15 #
16 %define version %{vswitch_version}-%{xen_version}
17 %define _prefix /root/vswitch
18
19 Name: vswitch
20 Summary: Virtual switch
21 Group: System Environment/Daemons
22 URL: http://www.openvswitch.org/
23 Version: %{vswitch_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-%{vswitch_version}.tar.gz
29 Buildroot: /tmp/vswitch-xen-rpm
30 Requires: kernel-xen = %(echo '%{xen_version}' | sed 's/xen$//')
31 # The following Conflicts prevents the "vswitch" package generated by
32 # this spec file from installing at the same time as the "openvswitch"
33 # package shipped with XenServer 5.5.900.  In fact, the packages
34 # contain some files with identical names anyhow, so they will not
35 # coexist, but adding an explicit Conflicts makes this conflict more
36 # obvious.
37 Conflicts: openvswitch
38
39 %description
40 The vswitch provides standard network bridging functions augmented with
41 support for the OpenFlow protocol for remote per-flow control of
42 traffic.
43
44 %prep
45 %setup -q -n openvswitch-%{vswitch_version}
46
47 %build
48 ./configure --prefix=%{_prefix} --localstatedir=%{_localstatedir} --with-l26=/lib/modules/%{xen_version}/build --enable-ssl %{build_number}
49 make %{_smp_mflags}
50
51 %install
52 rm -rf $RPM_BUILD_ROOT
53 make install DESTDIR=$RPM_BUILD_ROOT prefix=%{_prefix}
54 install -d -m 755 $RPM_BUILD_ROOT/etc
55 install -d -m 755 $RPM_BUILD_ROOT/etc/init.d
56 install -m 755 xenserver/etc_init.d_vswitch \
57          $RPM_BUILD_ROOT/etc/init.d/vswitch
58 install -m 755 xenserver/etc_init.d_vswitch-xapi-update \
59          $RPM_BUILD_ROOT/etc/init.d/vswitch-xapi-update
60 install -d -m 755 $RPM_BUILD_ROOT/etc/sysconfig
61 install -d -m 755 $RPM_BUILD_ROOT/etc/logrotate.d
62 install -m 755 xenserver/etc_logrotate.d_vswitch \
63          $RPM_BUILD_ROOT/etc/logrotate.d/vswitch
64 install -d -m 755 $RPM_BUILD_ROOT/etc/profile.d
65 install -m 755 xenserver/etc_profile.d_vswitch.sh \
66          $RPM_BUILD_ROOT/etc/profile.d/vswitch.sh
67 install -d -m 755 $RPM_BUILD_ROOT/etc/xapi.d/plugins
68 install -m 755 xenserver/etc_xapi.d_plugins_vswitch-cfg-update \
69          $RPM_BUILD_ROOT/etc/xapi.d/plugins/vswitch-cfg-update
70 install -d -m 755 $RPM_BUILD_ROOT%{_prefix}/scripts
71 install -m 755 xenserver/opt_xensource_libexec_interface-reconfigure \
72              $RPM_BUILD_ROOT%{_prefix}/scripts/interface-reconfigure
73 install -m 755 xenserver/etc_xensource_scripts_vif \
74              $RPM_BUILD_ROOT%{_prefix}/scripts/vif
75 install -m 755 xenserver/root_vswitch_scripts_dump-vif-details \
76                $RPM_BUILD_ROOT%{_prefix}/scripts/dump-vif-details
77 install -m 755 xenserver/usr_sbin_xen-bugtool \
78              $RPM_BUILD_ROOT%{_prefix}/scripts/xen-bugtool
79 install -m 755 xenserver/usr_sbin_brctl \
80              $RPM_BUILD_ROOT%{_prefix}/scripts/brctl
81 install -m 755 xenserver/root_vswitch_scripts_sysconfig.template \
82          $RPM_BUILD_ROOT/root/vswitch/scripts/sysconfig.template
83 install -m 644 \
84         xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py \
85                $RPM_BUILD_ROOT%{_prefix}/scripts/XSFeatureVSwitch.py
86
87 install -d -m 755 $RPM_BUILD_ROOT%{_prefix}/kernel_modules
88 find datapath/linux-2.6 -name *.ko -exec install -m 755  \{\} $RPM_BUILD_ROOT%{_prefix}/kernel_modules/ \;
89
90 # Get rid of stuff we don't want to make RPM happy.
91 rm -rf \
92     $RPM_BUILD_ROOT/root/vswitch/bin/ezio-term \
93     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-controller \
94     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-discover \
95     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-kill \
96     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-openflowd \
97     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-pki \
98     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-switchui \
99     $RPM_BUILD_ROOT/root/vswitch/bin/ovs-wdt \
100     $RPM_BUILD_ROOT/root/vswitch/kernel_modules/veth_mod.ko \
101     $RPM_BUILD_ROOT/root/vswitch/sbin/ovs-monitor \
102     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-controller.8 \
103     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-discover.8 \
104     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-kill.8 \
105     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-openflowd.8 \
106     $RPM_BUILD_ROOT/root/vswitch/share/man/man8/ovs-pki.8 \
107     $RPM_BUILD_ROOT/root/vswitch/share/openvswitch
108
109 %clean
110 rm -rf $RPM_BUILD_ROOT
111
112 %pre
113 if [ ! -f /etc/xensource-inventory ]; then
114     printf "XenSource inventory not present in /etc/xensource-inventory"
115     exit 1
116 fi
117
118 if [ "$1" = "1" ]; then
119     if md5sum -c --status <<EOF
120 ca141d60061dcfdade73e75abc6529b5  /usr/sbin/brctl
121 b8e9835862ef1a9cec2a3f477d26c989  /etc/xensource/scripts/vif
122 51970ad613a3996d5997e18e44db47da  /opt/xensource/libexec/interface-reconfigure
123 5654c8c36699fcc8744ca9cd5b855414  /usr/sbin/xen-bugtool
124 EOF
125     then
126         printf "\nVerified host scripts from XenServer 5.5.0.\n\n"
127     elif md5sum -c --status <<EOF
128 ca141d60061dcfdade73e75abc6529b5  /usr/sbin/brctl
129 b8e9835862ef1a9cec2a3f477d26c989  /etc/xensource/scripts/vif
130 ce451d3c985fd1db6497a363f0d9dedb  /opt/xensource/libexec/interface-reconfigure
131 2b53f500431fcba5276c896e9e4281b9  /usr/sbin/xen-bugtool
132 EOF
133     then
134         printf "\nVerified host scripts from XenServer 5.5.900.\n\n"
135     else
136 cat <<EOF
137
138 The original XenServer scripts replaced by this package are not those
139 of any supported version of XenServer.  This could lead to unexpected
140 behavior of your server.  Unless you are sure you know what you are
141 doing, it is highly recommended that you remove this package
142 immediately after the install completes, which will restore the
143 XenServer scripts that you were previously using.
144
145 EOF
146     fi
147 fi
148
149 if test ! -e /etc/ovs-vswitch.dbcache; then
150     if test "$1" = 1; then
151         printf "Creating xapi database cache...  "
152     else
153         printf "warning: Open vSwitch is being re-installed or upgraded,\n"
154         printf "         but the xapi database cache is missing.\n"
155         printf "Re-creating xapi database cache...  "
156     fi
157
158     source /etc/xensource-inventory
159     if python - "$INSTALLATION_UUID" <<EOF
160 import XenAPI
161 import pickle
162 import sys
163
164 session = XenAPI.xapi_local()
165 try:
166     session.xenapi.login_with_password("root", "")
167
168     vlans = session.xenapi.VLAN.get_all_records()
169     bonds = session.xenapi.Bond.get_all_records()
170     pifs = session.xenapi.PIF.get_all_records()
171     networks = session.xenapi.network.get_all_records()
172     host = session.xenapi.host.get_by_uuid(sys.argv[1])
173 finally:
174     session.xenapi.session.logout()
175
176 dbcache_file = "/etc/ovs-vswitch.dbcache"
177 f = open(dbcache_file, 'w')
178 pickle.dump({'vlans': vlans,
179              'bonds': bonds,
180              'pifs': pifs,
181              'networks': networks}, f)
182 pickle.dump({'host': host}, f)
183 f.close()
184 EOF
185     then
186         printf "done.\n"
187     else
188         printf "FAILED\n"
189         printf "Open vSwitch can only be installed on a XenServer that\n"
190         printf "has connectivity to xapi on the pool master.  Please\n"
191         printf "fix connectivity to the pool master, then try again.\n"
192         exit 1
193     fi
194 fi
195
196 %post
197 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
198     cat >>/etc/sysctl.conf <<EOF
199 # This works around an issue in xhad, which binds to a particular
200 # Ethernet device, which in turn causes ICMP port unreachable messages
201 # if packets are received are on the wrong interface, which in turn
202 # can happen if we send out ARP replies on every interface (as Linux
203 # does by default) instead of just on the interface that has the IP
204 # address being ARPed for, which this sysctl setting in turn works
205 # around.
206 #
207 # Bug #1378.
208 net.ipv4.conf.all.arp_filter = 1
209 EOF
210 fi
211
212 # Ensure ovs-vswitchd.conf exists
213 touch /etc/ovs-vswitchd.conf
214
215 # Create default or update existing /etc/sysconfig/vswitch.
216 SYSCONFIG=/etc/sysconfig/vswitch
217 TEMPLATE=/root/vswitch/scripts/sysconfig.template
218 if [ ! -e $SYSCONFIG ]; then
219     cp $TEMPLATE $SYSCONFIG
220 else
221     for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
222     do
223         if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
224             echo >> $SYSCONFIG
225             sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
226         fi
227     done
228 fi
229
230 # Replace XenServer files by our versions.
231 mkdir -p %{_prefix}/xs-original \
232     || printf "Could not create script backup directory.\n"
233 for f in \
234     /opt/xensource/libexec/interface-reconfigure \
235     /etc/xensource/scripts/vif \
236     /usr/sbin/xen-bugtool \
237     /usr/sbin/brctl
238 do
239     s=$(basename "$f")
240     t=$(readlink "$f")
241     if [ "$t" != "%{_prefix}/scripts/$s" ]; then
242         mv "$f" %{_prefix}/xs-original/ \
243             || printf "Could not save original XenServer $s script\n"
244         ln -s "%{_prefix}/scripts/$s" "$f" \
245             || printf "Could not link to vSwitch $s script\n"
246     fi
247 done
248
249 # Install xsconsole plugin
250 plugin=$(readlink /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py)
251 if [ "$plugin" != "/root/vswitch/scripts/XSFeatureVSwitch.py" ]; then
252     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
253     ln -s /root/vswitch/scripts/XSFeatureVSwitch.py /usr/lib/xsconsole/plugins-base/ || printf "Could not link to vSswitch xsconsole plugin.\n"
254 fi
255
256 # Ensure all required services are set to run
257 for s in vswitch vswitch-xapi-update; do
258     if chkconfig --list $s >/dev/null 2>&1; then
259         chkconfig --del $s || printf "Could not remove $s init script."
260     fi
261     chkconfig --add $s || printf "Could not add $s init script."
262     chkconfig $s on || printf "Could not enable $s init script."
263 done
264
265 if [ "$1" = "1" ]; then    # $1 = 2 for upgrade
266     printf "\nYou MUST reboot the server NOW to complete the change to the\n"
267     printf "the vSwitch.  Attempts to modify networking on the server\n"
268     printf "or any hosted VM will fail until after the reboot and could\n"
269     printf "leave the server in an state requiring manual recovery.\n\n"
270 else
271     printf "\nTo use the new vSwitch, you should reboot the server\n"
272     printf "now.  Failure to do so may result in incorrect operation.\n\n"
273 fi
274
275 %preun
276 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
277     for s in vswitch vswitch-xapi-update; do
278         chkconfig --del $s || printf "Could not remove $s init script."
279     done
280 fi
281
282
283 %postun
284 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
285
286     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py \
287         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
288         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo \
289         || printf "Could not remove vSwitch xsconsole plugin.\n"
290
291     # Restore original XenServer scripts
292     for f in \
293         /opt/xensource/libexec/interface-reconfigure \
294         /etc/xensource/scripts/vif \
295         /usr/sbin/xen-bugtool \
296         /usr/sbin/brctl
297     do
298         s=$(basename "$f")
299         if [ ! -f "%{_prefix}/xs-original/$s" ]; then
300             printf "Original XenServer $s script not present in %{_prefix}/xs-original\n"
301             printf "Could not restore original XenServer script.\n"
302         else
303             (rm -f "$f" \
304                 && mv "%{_prefix}/xs-original/$s" "$f") \
305                 || printf "Could not restore original XenServer $s script.\n"
306         fi
307     done
308
309     find  %{_prefix} -type d -depth -exec rmdir \{\} \; \
310         || printf "Could not remove vSwitch install directory.\n"
311
312     # Remove all configuration files
313     rm -f /etc/ovs-vswitchd.conf
314     rm -f /etc/sysconfig/vswitch
315     rm -f /etc/ovs-vswitchd.cacert
316
317     printf "\nYou MUST reboot the server now to complete the change to\n"
318     printf "standard Xen networking.  Attempts to modify networking on the\n"
319     printf "server or any hosted VM will fail until after the reboot and\n"
320     printf "could leave the server in a state requiring manual recovery.\n\n"
321 fi
322
323
324 %files
325 %defattr(-,root,root)
326 /etc/init.d/vswitch
327 /etc/init.d/vswitch-xapi-update
328 /etc/xapi.d/plugins/vswitch-cfg-update
329 /etc/logrotate.d/vswitch
330 /etc/profile.d/vswitch.sh
331 /root/vswitch/kernel_modules/brcompat_mod.ko
332 /root/vswitch/kernel_modules/openvswitch_mod.ko
333 /root/vswitch/scripts/dump-vif-details
334 /root/vswitch/scripts/interface-reconfigure
335 /root/vswitch/scripts/vif
336 /root/vswitch/scripts/xen-bugtool
337 /root/vswitch/scripts/XSFeatureVSwitch.py
338 /root/vswitch/scripts/brctl
339 /root/vswitch/scripts/sysconfig.template
340 # Following two files are generated automatically by rpm.  We don't
341 # really need them and they won't be used on the XenServer, but there
342 # isn't an obvious place to get rid of them since they are generated
343 # after the install script runs.  Since they are small, we just
344 # include them.
345 /root/vswitch/scripts/XSFeatureVSwitch.pyc
346 /root/vswitch/scripts/XSFeatureVSwitch.pyo
347 /root/vswitch/sbin/ovs-brcompatd
348 /root/vswitch/sbin/ovs-vswitchd
349 /root/vswitch/bin/ovs-appctl
350 /root/vswitch/bin/ovs-cfg-mod
351 /root/vswitch/bin/ovs-dpctl
352 /root/vswitch/bin/ovs-ofctl
353 /root/vswitch/share/man/man5/ovs-vswitchd.conf.5
354 /root/vswitch/share/man/man8/ovs-appctl.8
355 /root/vswitch/share/man/man8/ovs-brcompatd.8
356 /root/vswitch/share/man/man8/ovs-cfg-mod.8
357 /root/vswitch/share/man/man8/ovs-dpctl.8
358 /root/vswitch/share/man/man8/ovs-ofctl.8
359 /root/vswitch/share/man/man8/ovs-vswitchd.8