Browse code

install ebtables locking workaround

ebtables is racing with itself when nova and libvirt attempt to create
rules at the same time in the nat table. ebtables now has an explicit
--concurrent flag, that all tools must opt into to prevent ebtables
from inherently being unsafe to run.

libvirt gained this support in 1.2.11, which is too new for our ubuntu
primary testing environment. Nova still hasn't added this support,
though even if it did, we'd run into the issue with libvirt.

We can do the most ghetto thing possible and create a wrapper for
ebtables that does explicit locking on it's own. It's pretty terrible,
but it should work. And it is the kind of work around that people
unable to upgrade libvirt will probably need to do.

This is an opt in value which we should set in the gate to True.

Related-Bug: #1501558

Change-Id: Ic6fa847eba34c21593b9df86a1c2c179534d0ba5

Sean Dague authored on 2015/11/18 01:59:07
Showing 4 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,23 @@
0
+#!/bin/bash
1
+#
2
+# Copyright 2015 Hewlett-Packard Development Company, L.P.
3
+#
4
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
+# not use this file except in compliance with the License. You may obtain
6
+# a copy of the License at
7
+#
8
+#    http://www.apache.org/licenses/LICENSE-2.0
9
+#
10
+# Unless required by applicable law or agreed to in writing, software
11
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+# License for the specific language governing permissions and limitations
14
+# under the License.
15
+#
16
+#
17
+# This is a terrible, terrible, truly terrible work around for
18
+# environments that have libvirt < 1.2.11. ebtables requires that you
19
+# specifically tell it you would like to not race and get punched in
20
+# the face when 2 run at the same time with a --concurrent flag.
21
+
22
+flock -w 300 /var/lock/ebtables.nova /sbin/ebtables.real $@
... ...
@@ -31,6 +31,11 @@ function install_libvirt {
31 31
         fi
32 32
         install_package libvirt-bin libvirt-dev
33 33
         pip_install_gr libvirt-python
34
+        if [[ "$EBTABLES_RACE_FIX" == "True" ]]; then
35
+            # Work around for bug #1501558. We can remove this once we
36
+            # get to a version of Ubuntu that has new enough libvirt.
37
+            TOP_DIR=$TOP_DIR $TOP_DIR/tools/install_ebtables_workaround.sh
38
+        fi
34 39
         #pip_install_gr <there-si-no-guestfs-in-pypi>
35 40
     elif is_fedora || is_suse; then
36 41
         install_package kvm
... ...
@@ -769,6 +769,16 @@ GIT_DEPTH=${GIT_DEPTH:-0}
769 769
 # Use native SSL for servers in ``SSL_ENABLED_SERVICES``
770 770
 USE_SSL=$(trueorfalse False USE_SSL)
771 771
 
772
+# ebtables is inherently racey. If you run it by two or more processes
773
+# simultaneously it will collide, badly, in the kernel and produce
774
+# failures or corruption of ebtables. The only way around it is for
775
+# all tools running ebtables to only ever do so with the --concurrent
776
+# flag. This requires libvirt >= 1.2.11.
777
+#
778
+# If you don't have this then the following work around will replace
779
+# ebtables with a wrapper script so that it is safe to run without
780
+# that flag.
781
+EBTABLES_RACE_FIX=$(trueorfalse False EBTABLES_RACE_FIX)
772 782
 
773 783
 # Following entries need to be last items in file
774 784
 
775 785
new file mode 100755
... ...
@@ -0,0 +1,31 @@
0
+#!/bin/bash -eu
1
+#
2
+# Copyright 2015 Hewlett-Packard Development Company, L.P.
3
+#
4
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
+# not use this file except in compliance with the License. You may obtain
6
+# a copy of the License at
7
+#
8
+#    http://www.apache.org/licenses/LICENSE-2.0
9
+#
10
+# Unless required by applicable law or agreed to in writing, software
11
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+# License for the specific language governing permissions and limitations
14
+# under the License.
15
+#
16
+#
17
+# This replaces the ebtables on your system with a wrapper script that
18
+# does implicit locking. This is needed if libvirt < 1.2.11 on your platform.
19
+
20
+EBTABLES=/sbin/ebtables
21
+EBTABLESREAL=/sbin/ebtables.real
22
+FILES=$TOP_DIR/files
23
+
24
+if [[ -f "$EBTABLES" ]]; then
25
+    if file $EBTABLES | grep ELF; then
26
+        sudo mv $EBTABLES $EBTABLESREAL
27
+        sudo install -m 0755 $FILES/ebtables.workaround $EBTABLES
28
+        echo "Replaced ebtables with locking workaround"
29
+    fi
30
+fi