From 51a3f1f6369d27193daa6132fd8bcf6ba1972bd2 Mon Sep 17 00:00:00 2001 From: Kyle Mestery Date: Thu, 13 Jun 2013 11:47:56 +0000 Subject: [PATCH] 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 --- functions | 54 +++++++++++++++++++++++++++ lib/quantum_plugins/openvswitch_agent | 4 +- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/functions b/functions index 1257024838..8aba10da5a 100644 --- a/functions +++ b/functions @@ -1466,6 +1466,60 @@ function check_path_perm_sanity() { } +# This function recursively compares versions, and is not meant to be +# called by anything other than vercmp_numbers below. This function does +# not work with alphabetic versions. +# +# _vercmp_r sep ver1 ver2 +function _vercmp_r { + typeset sep + typeset -a ver1=() ver2=() + sep=$1; shift + ver1=("${@:1:sep}") + ver2=("${@:sep+1}") + + if ((ver1 > ver2)); then + echo 1; return 0 + elif ((ver2 > ver1)); then + echo -1; return 0 + fi + + if ((sep <= 1)); then + echo 0; return 0 + fi + + _vercmp_r $((sep-1)) "${ver1[@]:1}" "${ver2[@]:1}" +} + + +# This function compares two versions and is meant to be called by +# external callers. Please note the function assumes non-alphabetic +# versions. For example, this will work: +# +# vercmp_numbers 1.10 1.4 +# +# The above will return "1", as 1.10 is greater than 1.4. +# +# vercmp_numbers 5.2 6.4 +# +# The above will return "-1", as 5.2 is less than 6.4. +# +# vercmp_numbers 4.0 4.0 +# +# The above will return "0", as the versions are equal. +# +# vercmp_numbers ver1 ver2 +vercmp_numbers() { + typeset v1=$1 v2=$2 sep + typeset -a ver1 ver2 + + IFS=. read -ra ver1 <<< "$v1" + IFS=. read -ra ver2 <<< "$v2" + + _vercmp_r "${#ver1[@]}" "${ver1[@]}" "${ver2[@]}" +} + + # Restore xtrace $XTRACE diff --git a/lib/quantum_plugins/openvswitch_agent b/lib/quantum_plugins/openvswitch_agent index ee761edf66..7e83428a20 100644 --- a/lib/quantum_plugins/openvswitch_agent +++ b/lib/quantum_plugins/openvswitch_agent @@ -43,8 +43,8 @@ function quantum_plugin_configure_plugin_agent() { if [[ "$OVS_ENABLE_TUNNELING" = "True" ]]; then # Verify tunnels are supported # REVISIT - also check kernel module support for GRE and patch ports - OVS_VERSION=`ovs-vsctl --version | head -n 1 | awk '{print $4;}'` - if [ $OVS_VERSION \< "1.4" ] && ! is_service_enabled q-svc ; then + OVS_VERSION=`ovs-vsctl --version | head -n 1 | grep -E -o "[0-9]+\.[0-9]+"` + if [ `vercmp_numbers "$OVS_VERSION" "1.4"` -lt "0" ] && ! is_service_enabled q-svc ; then die $LINENO "You are running OVS version $OVS_VERSION. OVS 1.4+ is required for tunneling between multiple hosts." fi iniset /$Q_PLUGIN_CONF_FILE OVS enable_tunneling True