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