xenserver: Make RPM install work again.
[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 install -d -m 755 $RPM_BUILD_ROOT/var/lib/openvswitch
110
111 %clean
112 rm -rf $RPM_BUILD_ROOT
113
114 %post
115 if [ ! -f /etc/xensource-inventory ]; then
116     printf "XenSource inventory not present in /etc/xensource-inventory"
117     exit 1
118 fi
119
120 if [ "$1" = "1" ]; then
121     if md5sum -c --status <<EOF
122 ca141d60061dcfdade73e75abc6529b5  /usr/sbin/brctl
123 b8e9835862ef1a9cec2a3f477d26c989  /etc/xensource/scripts/vif
124 51970ad613a3996d5997e18e44db47da  /opt/xensource/libexec/interface-reconfigure
125 5654c8c36699fcc8744ca9cd5b855414  /usr/sbin/xen-bugtool
126 EOF
127     then
128         printf "\nVerified host scripts from XenServer 5.5.0.\n\n"
129     elif md5sum -c --status <<EOF
130 ca141d60061dcfdade73e75abc6529b5  /usr/sbin/brctl
131 b8e9835862ef1a9cec2a3f477d26c989  /etc/xensource/scripts/vif
132 ce451d3c985fd1db6497a363f0d9dedb  /opt/xensource/libexec/interface-reconfigure
133 2b53f500431fcba5276c896e9e4281b9  /usr/sbin/xen-bugtool
134 EOF
135     then
136         printf "\nVerified host scripts from XenServer 5.5.900.\n\n"
137     else
138 cat <<EOF
139
140 The original XenServer scripts replaced by this package are not those
141 of any supported version of XenServer.  This could lead to unexpected
142 behavior of your server.  Unless you are sure you know what you are
143 doing, it is highly recommended that you remove this package
144 immediately after the install completes, which will restore the
145 XenServer scripts that you were previously using.
146
147 EOF
148     fi
149 fi
150
151 if test ! -e /var/lib/openvswitch/dbcache; then
152     if test "$1" = 1; then
153         printf "Creating xapi database cache...  "
154     else
155         printf "warning: Open vSwitch is being re-installed or upgraded,\n"
156         printf "         but the xapi database cache is missing.\n"
157         printf "Re-creating xapi database cache...  "
158     fi
159
160     if /root/vswitch/scripts/interface-reconfigure init-dbcache; then
161         printf "done.\n"
162     else
163         printf "FAILED\n"
164         printf "Open vSwitch can only be installed on a XenServer that\n"
165         printf "has connectivity to xapi on the pool master.  Please\n"
166         printf "fix connectivity to the pool master, then try again.\n"
167         exit 1
168     fi
169 fi
170
171 if grep -F net.ipv4.conf.all.arp_filter /etc/sysctl.conf >/dev/null 2>&1; then :; else
172     cat >>/etc/sysctl.conf <<EOF
173 # This works around an issue in xhad, which binds to a particular
174 # Ethernet device, which in turn causes ICMP port unreachable messages
175 # if packets are received are on the wrong interface, which in turn
176 # can happen if we send out ARP replies on every interface (as Linux
177 # does by default) instead of just on the interface that has the IP
178 # address being ARPed for, which this sysctl setting in turn works
179 # around.
180 #
181 # Bug #1378.
182 net.ipv4.conf.all.arp_filter = 1
183 EOF
184 fi
185
186 # Ensure ovs-vswitchd.conf exists
187 touch /etc/ovs-vswitchd.conf
188
189 # Create default or update existing /etc/sysconfig/vswitch.
190 SYSCONFIG=/etc/sysconfig/vswitch
191 TEMPLATE=/root/vswitch/scripts/sysconfig.template
192 if [ ! -e $SYSCONFIG ]; then
193     cp $TEMPLATE $SYSCONFIG
194 else
195     for var in $(awk -F'[ :]' '/^# [_A-Z0-9]+:/{print $2}' $TEMPLATE)
196     do
197         if ! grep $var $SYSCONFIG >/dev/null 2>&1; then
198             echo >> $SYSCONFIG
199             sed -n "/$var:/,/$var=/p" $TEMPLATE >> $SYSCONFIG
200         fi
201     done
202 fi
203
204 # Replace XenServer files by our versions.
205 mkdir -p %{_prefix}/xs-original \
206     || printf "Could not create script backup directory.\n"
207 for f in \
208     /opt/xensource/libexec/interface-reconfigure \
209     /etc/xensource/scripts/vif \
210     /usr/sbin/xen-bugtool \
211     /usr/sbin/brctl
212 do
213     s=$(basename "$f")
214     t=$(readlink "$f")
215     if [ "$t" != "%{_prefix}/scripts/$s" ]; then
216         mv "$f" %{_prefix}/xs-original/ \
217             || printf "Could not save original XenServer $s script\n"
218         ln -s "%{_prefix}/scripts/$s" "$f" \
219             || printf "Could not link to vSwitch $s script\n"
220     fi
221 done
222
223 # Install xsconsole plugin
224 plugin=$(readlink /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py)
225 if [ "$plugin" != "/root/vswitch/scripts/XSFeatureVSwitch.py" ]; then
226     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py
227     ln -s /root/vswitch/scripts/XSFeatureVSwitch.py /usr/lib/xsconsole/plugins-base/ || printf "Could not link to vSswitch xsconsole plugin.\n"
228 fi
229
230 # Ensure all required services are set to run
231 for s in vswitch vswitch-xapi-update; do
232     if chkconfig --list $s >/dev/null 2>&1; then
233         chkconfig --del $s || printf "Could not remove $s init script."
234     fi
235     chkconfig --add $s || printf "Could not add $s init script."
236     chkconfig $s on || printf "Could not enable $s init script."
237 done
238
239 if [ "$1" = "1" ]; then    # $1 = 2 for upgrade
240     printf "\nYou MUST reboot the server NOW to complete the change to the\n"
241     printf "the vSwitch.  Attempts to modify networking on the server\n"
242     printf "or any hosted VM will fail until after the reboot and could\n"
243     printf "leave the server in an state requiring manual recovery.\n\n"
244 else
245     printf "\nTo use the new vSwitch, you should reboot the server\n"
246     printf "now.  Failure to do so may result in incorrect operation.\n\n"
247 fi
248
249 %preun
250 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
251     for s in vswitch vswitch-xapi-update; do
252         chkconfig --del $s || printf "Could not remove $s init script."
253     done
254 fi
255
256
257 %postun
258 if [ "$1" = "0" ]; then     # $1 = 1 for upgrade
259
260     rm -f /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.py \
261         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyc \
262         /usr/lib/xsconsole/plugins-base/XSFeatureVSwitch.pyo \
263         || printf "Could not remove vSwitch xsconsole plugin.\n"
264
265     # Restore original XenServer scripts
266     for f in \
267         /opt/xensource/libexec/interface-reconfigure \
268         /etc/xensource/scripts/vif \
269         /usr/sbin/xen-bugtool \
270         /usr/sbin/brctl
271     do
272         s=$(basename "$f")
273         if [ ! -f "%{_prefix}/xs-original/$s" ]; then
274             printf "Original XenServer $s script not present in %{_prefix}/xs-original\n"
275             printf "Could not restore original XenServer script.\n"
276         else
277             (rm -f "$f" \
278                 && mv "%{_prefix}/xs-original/$s" "$f") \
279                 || printf "Could not restore original XenServer $s script.\n"
280         fi
281     done
282
283     find  %{_prefix} -type d -depth -exec rmdir \{\} \; \
284         || printf "Could not remove vSwitch install directory.\n"
285
286     # Remove all configuration files
287     rm -f /etc/ovs-vswitchd.conf
288     rm -f /etc/sysconfig/vswitch
289     rm -f /etc/ovs-vswitchd.cacert
290
291     printf "\nYou MUST reboot the server now to complete the change to\n"
292     printf "standard Xen networking.  Attempts to modify networking on the\n"
293     printf "server or any hosted VM will fail until after the reboot and\n"
294     printf "could leave the server in a state requiring manual recovery.\n\n"
295 fi
296
297
298 %files
299 %defattr(-,root,root)
300 /etc/init.d/vswitch
301 /etc/init.d/vswitch-xapi-update
302 /etc/xapi.d/plugins/vswitch-cfg-update
303 /etc/logrotate.d/vswitch
304 /etc/profile.d/vswitch.sh
305 /root/vswitch/kernel_modules/brcompat_mod.ko
306 /root/vswitch/kernel_modules/openvswitch_mod.ko
307 /root/vswitch/scripts/dump-vif-details
308 /root/vswitch/scripts/interface-reconfigure
309 /root/vswitch/scripts/vif
310 /root/vswitch/scripts/xen-bugtool
311 /root/vswitch/scripts/XSFeatureVSwitch.py
312 /root/vswitch/scripts/brctl
313 /root/vswitch/scripts/sysconfig.template
314 # Following two files are generated automatically by rpm.  We don't
315 # really need them and they won't be used on the XenServer, but there
316 # isn't an obvious place to get rid of them since they are generated
317 # after the install script runs.  Since they are small, we just
318 # include them.
319 /root/vswitch/scripts/XSFeatureVSwitch.pyc
320 /root/vswitch/scripts/XSFeatureVSwitch.pyo
321 /root/vswitch/sbin/ovs-brcompatd
322 /root/vswitch/sbin/ovs-vswitchd
323 /root/vswitch/bin/ovs-appctl
324 /root/vswitch/bin/ovs-cfg-mod
325 /root/vswitch/bin/ovs-dpctl
326 /root/vswitch/bin/ovs-ofctl
327 /root/vswitch/share/man/man5/ovs-vswitchd.conf.5
328 /root/vswitch/share/man/man8/ovs-appctl.8
329 /root/vswitch/share/man/man8/ovs-brcompatd.8
330 /root/vswitch/share/man/man8/ovs-cfg-mod.8
331 /root/vswitch/share/man/man8/ovs-dpctl.8
332 /root/vswitch/share/man/man8/ovs-ofctl.8
333 /root/vswitch/share/man/man8/ovs-vswitchd.8
334 /var/lib/openvswitch