Browse code

Fix the OVS version check to work with upstream master versions of OVS.

This patch adds two functions to check version strings in the toplevel
functions file. The openvswitch_agent then uses these to compare versions
when checking for tunneling support. The tunneling version check now
also takes into account upstream master versions of Open vSwitch, which
the previous version check always failed on.

Fixes bug #1190734

Change-Id: I0102fb57f8ce5529169025efa21a0996ad68bef1

Kyle Mestery authored on 2013/06/13 20:47:56
Showing 2 changed files
... ...
@@ -1466,6 +1466,60 @@ function check_path_perm_sanity() {
1466 1466
 }
1467 1467
 
1468 1468
 
1469
+# This function recursively compares versions, and is not meant to be
1470
+# called by anything other than vercmp_numbers below. This function does
1471
+# not work with alphabetic versions.
1472
+#
1473
+# _vercmp_r sep ver1 ver2
1474
+function _vercmp_r {
1475
+  typeset sep
1476
+  typeset -a ver1=() ver2=()
1477
+  sep=$1; shift
1478
+  ver1=("${@:1:sep}")
1479
+  ver2=("${@:sep+1}")
1480
+
1481
+  if ((ver1 > ver2)); then
1482
+    echo 1; return 0
1483
+  elif ((ver2 > ver1)); then
1484
+    echo -1; return 0
1485
+  fi
1486
+
1487
+  if ((sep <= 1)); then
1488
+    echo 0; return 0
1489
+  fi
1490
+
1491
+  _vercmp_r $((sep-1)) "${ver1[@]:1}" "${ver2[@]:1}"
1492
+}
1493
+
1494
+
1495
+# This function compares two versions and is meant to be called by
1496
+# external callers. Please note the function assumes non-alphabetic
1497
+# versions. For example, this will work:
1498
+#
1499
+#   vercmp_numbers 1.10 1.4
1500
+#
1501
+# The above will return "1", as 1.10 is greater than 1.4.
1502
+#
1503
+#   vercmp_numbers 5.2 6.4
1504
+#
1505
+# The above will return "-1", as 5.2 is less than 6.4.
1506
+#
1507
+#   vercmp_numbers 4.0 4.0
1508
+#
1509
+# The above will return "0", as the versions are equal.
1510
+#
1511
+# vercmp_numbers ver1 ver2
1512
+vercmp_numbers() {
1513
+  typeset v1=$1 v2=$2 sep
1514
+  typeset -a ver1 ver2
1515
+
1516
+  IFS=. read -ra ver1 <<< "$v1"
1517
+  IFS=. read -ra ver2 <<< "$v2"
1518
+
1519
+  _vercmp_r "${#ver1[@]}" "${ver1[@]}" "${ver2[@]}"
1520
+}
1521
+
1522
+
1469 1523
 # Restore xtrace
1470 1524
 $XTRACE
1471 1525
 
... ...
@@ -43,8 +43,8 @@ function quantum_plugin_configure_plugin_agent() {
43 43
     if [[ "$OVS_ENABLE_TUNNELING" = "True" ]]; then
44 44
         # Verify tunnels are supported
45 45
         # REVISIT - also check kernel module support for GRE and patch ports
46
-        OVS_VERSION=`ovs-vsctl --version | head -n 1 | awk '{print $4;}'`
47
-        if [ $OVS_VERSION \< "1.4" ] && ! is_service_enabled q-svc ; then
46
+        OVS_VERSION=`ovs-vsctl --version | head -n 1 | grep -E -o "[0-9]+\.[0-9]+"`
47
+        if [ `vercmp_numbers "$OVS_VERSION" "1.4"` -lt "0" ] && ! is_service_enabled q-svc ; then
48 48
             die $LINENO "You are running OVS version $OVS_VERSION. OVS 1.4+ is required for tunneling between multiple hosts."
49 49
         fi
50 50
         iniset /$Q_PLUGIN_CONF_FILE OVS enable_tunneling True