Browse code

Add partial openSUSE/SLE support

Note that this is the first part of the support. A second part involves
dealing with the package names.

Among the changes:
- add several functions to determine some distro-specific behavior (how
to call usermod, if some features are available on the distro, etc.)
- correctly detect openSUSE and SLE in GetOSVersion, and set DISTRO
accordingly
- new is_suse() function to check if running on a SUSE-based distro
- use zypper to install packages
- adapt apache virtual host configuration for openSUSE
- some simple fixes (path to pip, mysql service name)

Change-Id: Id2f7c9e18a1c4a7b7cea262ea7959d183e4b0cf0

Vincent Untz authored on 2012/11/22 00:04:12
Showing 6 changed files
... ...
@@ -223,6 +223,12 @@ GetOSVersion() {
223 223
         os_UPDATE=""
224 224
         if [[ "Debian,Ubuntu" =~ $os_VENDOR ]]; then
225 225
             os_PACKAGE="deb"
226
+        elif [[ "SUSE LINUX" =~ $os_VENDOR ]]; then
227
+            lsb_release -d -s | grep -q openSUSE
228
+            if [[ $? -eq 0 ]]; then
229
+                os_VENDOR="openSUSE"
230
+            fi
231
+            os_PACKAGE="rpm"
226 232
         else
227 233
             os_PACKAGE="rpm"
228 234
         fi
... ...
@@ -246,6 +252,23 @@ GetOSVersion() {
246 246
             os_VENDOR=""
247 247
         done
248 248
         os_PACKAGE="rpm"
249
+    elif [[ -r /etc/SuSE-release ]]; then
250
+        for r in openSUSE "SUSE Linux"; do
251
+            if [[ "$r" = "SUSE Linux" ]]; then
252
+                os_VENDOR="SUSE LINUX"
253
+            else
254
+                os_VENDOR=$r
255
+            fi
256
+
257
+            if [[ -n "`grep \"$r\" /etc/SuSE-release`" ]]; then
258
+                os_CODENAME=`grep "CODENAME = " /etc/SuSE-release | sed 's:.* = ::g'`
259
+                os_RELEASE=`grep "VERSION = " /etc/SuSE-release | sed 's:.* = ::g'`
260
+                os_UPDATE=`grep "PATCHLEVEL = " /etc/SuSE-release | sed 's:.* = ::g'`
261
+                break
262
+            fi
263
+            os_VENDOR=""
264
+        done
265
+        os_PACKAGE="rpm"
249 266
     fi
250 267
     export os_VENDOR os_RELEASE os_UPDATE os_PACKAGE os_CODENAME
251 268
 }
... ...
@@ -297,6 +320,15 @@ function GetDistro() {
297 297
     elif [[ "$os_VENDOR" =~ (Fedora) ]]; then
298 298
         # For Fedora, just use 'f' and the release
299 299
         DISTRO="f$os_RELEASE"
300
+    elif [[ "$os_VENDOR" =~ (openSUSE) ]]; then
301
+        DISTRO="opensuse-$os_RELEASE"
302
+    elif [[ "$os_VENDOR" =~ (SUSE LINUX) ]]; then
303
+        # For SLE, also use the service pack
304
+        if [[ -z "$os_UPDATE" ]]; then
305
+            DISTRO="sle${os_RELEASE}"
306
+        else
307
+            DISTRO="sle${os_RELEASE}sp${os_UPDATE}"
308
+        fi
300 309
     else
301 310
         # Catch-all for now is Vendor + Release + Update
302 311
         DISTRO="$os_VENDOR-$os_RELEASE.$os_UPDATE"
... ...
@@ -305,6 +337,19 @@ function GetDistro() {
305 305
 }
306 306
 
307 307
 
308
+# Determine if current distribution is a SUSE-based distribution
309
+# (openSUSE, SLE).
310
+# is_suse
311
+function is_suse {
312
+    if [[ -z "$os_VENDOR" ]]; then
313
+        GetOSVersion
314
+    fi
315
+
316
+    [[ "$os_VENDOR" = "openSUSE" || "$os_VENDOR" = "SUSE LINUX" ]]
317
+    return $?
318
+}
319
+
320
+
308 321
 # git clone only if directory doesn't exist already.  Since ``DEST`` might not
309 322
 # be owned by the installation user, we create the directory and change the
310 323
 # ownership to the proper user.
... ...
@@ -542,7 +587,11 @@ function install_package() {
542 542
 
543 543
         apt_get install "$@"
544 544
     else
545
-        yum_install "$@"
545
+        if is_suse; then
546
+            zypper_install "$@"
547
+        else
548
+            yum_install "$@"
549
+        fi
546 550
     fi
547 551
 }
548 552
 
... ...
@@ -593,7 +642,7 @@ function pip_install {
593 593
         SUDO_PIP="env"
594 594
     else
595 595
         SUDO_PIP="sudo"
596
-        if [[ "$os_PACKAGE" = "deb" ]]; then
596
+        if [[ "$os_PACKAGE" = "deb" || is_suse ]]; then
597 597
             CMD_PIP=/usr/bin/pip
598 598
         else
599 599
             CMD_PIP=/usr/bin/pip-python
... ...
@@ -946,6 +995,68 @@ function _ssh_check_novanet() {
946 946
     fi
947 947
 }
948 948
 
949
+
950
+# zypper wrapper to set arguments correctly
951
+# zypper_install package [package ...]
952
+function zypper_install() {
953
+    [[ "$OFFLINE" = "True" ]] && return
954
+    local sudo="sudo"
955
+    [[ "$(id -u)" = "0" ]] && sudo="env"
956
+    $sudo http_proxy=$http_proxy https_proxy=$https_proxy \
957
+        zypper --non-interactive install --auto-agree-with-licenses "$@"
958
+}
959
+
960
+
961
+# Add a user to a group.
962
+# add_user_to_group user group
963
+function add_user_to_group() {
964
+    local user=$1
965
+    local group=$2
966
+
967
+    if [[ -z "$os_VENDOR" ]]; then
968
+        GetOSVersion
969
+    fi
970
+
971
+    # SLE11 and openSUSE 12.2 don't have the usual usermod
972
+    if ! is_suse || [[ "$os_VENDOR" = "openSUSE" && "$os_RELEASE" != "12.2" ]]; then
973
+        sudo usermod -a -G "$group" "$user"
974
+    else
975
+        sudo usermod -A "$group" "$user"
976
+    fi
977
+}
978
+
979
+
980
+# Get the location of the $module-rootwrap executables, where module is cinder
981
+# or nova.
982
+# get_rootwrap_location module
983
+function get_rootwrap_location() {
984
+    local module=$1
985
+
986
+    if [[ -z "$os_PACKAGE" ]]; then
987
+        GetOSVersion
988
+    fi
989
+
990
+    if [[ "$os_PACKAGE" = "deb" || is_suse ]]; then
991
+        echo "/usr/local/bin/$module-rootwrap"
992
+    else
993
+        echo "/usr/bin/$module-rootwrap"
994
+    fi
995
+}
996
+
997
+
998
+# Check if qpid can be used on the current distro.
999
+# qpid_is_supported
1000
+function qpid_is_supported() {
1001
+    if [[ -z "$DISTRO" ]]; then
1002
+        GetDistro
1003
+    fi
1004
+
1005
+    # Qpid was introduced to Ubuntu in precise, disallow it on oneiric; it is
1006
+    # not in openSUSE either right now.
1007
+    [[ "$DISTRO" = "oneiric" || is_suse ]]
1008
+    return $?
1009
+}
1010
+
949 1011
 # Restore xtrace
950 1012
 $XTRACE
951 1013
 
... ...
@@ -63,11 +63,7 @@ function configure_cinder() {
63 63
     cp -p $CINDER_DIR/etc/cinder/policy.json $CINDER_CONF_DIR
64 64
 
65 65
     # Set the paths of certain binaries
66
-    if [[ "$os_PACKAGE" = "deb" ]]; then
67
-        CINDER_ROOTWRAP=/usr/local/bin/cinder-rootwrap
68
-    else
69
-        CINDER_ROOTWRAP=/usr/bin/cinder-rootwrap
70
-    fi
66
+    CINDER_ROOTWRAP=$(get_rootwrap_location cinder)
71 67
 
72 68
     # If Cinder ships the new rootwrap filters files, deploy them
73 69
     # (owned by root) and add a parameter to $CINDER_ROOTWRAP
... ...
@@ -25,7 +25,11 @@ function configure_database_mysql {
25 25
         MYSQL=mysql
26 26
     else
27 27
         MY_CONF=/etc/my.cnf
28
-        MYSQL=mysqld
28
+        if is_suse; then
29
+            MYSQL=mysql
30
+        else
31
+            MYSQL=mysqld
32
+        fi
29 33
     fi
30 34
 
31 35
     # Start mysql-server
... ...
@@ -81,9 +81,17 @@ function init_horizon() {
81 81
         sudo a2ensite horizon
82 82
     else
83 83
         # Install httpd, which is NOPRIME'd
84
-        APACHE_NAME=httpd
85
-        APACHE_CONF=conf.d/horizon.conf
86
-        sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
84
+        if is_suse; then
85
+            APACHE_NAME=apache2
86
+            APACHE_CONF=vhosts.d/horizon.conf
87
+            # Append wsgi to the list of modules to load
88
+            grep -q "^APACHE_MODULES=.*wsgi" /etc/sysconfig/apache2 ||
89
+                sudo sed '/^APACHE_MODULES=/s/^\(.*\)"$/\1 wsgi"/' -i /etc/sysconfig/apache2
90
+        else
91
+            APACHE_NAME=httpd
92
+            APACHE_CONF=conf.d/horizon.conf
93
+            sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
94
+        fi
87 95
     fi
88 96
 
89 97
     # Configure apache to run horizon
... ...
@@ -47,11 +47,7 @@ else
47 47
 fi
48 48
 
49 49
 # Set the paths of certain binaries
50
-if [[ "$os_PACKAGE" = "deb" ]]; then
51
-    NOVA_ROOTWRAP=/usr/local/bin/nova-rootwrap
52
-else
53
-    NOVA_ROOTWRAP=/usr/bin/nova-rootwrap
54
-fi
50
+NOVA_ROOTWRAP=$(get_rootwrap_location nova)
55 51
 
56 52
 # Allow rate limiting to be turned off for testing, like for Tempest
57 53
 # NOTE: Set API_RATE_LIMIT="False" to turn OFF rate limiting
... ...
@@ -252,7 +248,7 @@ EOF'
252 252
 
253 253
         # The user that nova runs as needs to be member of **libvirtd** group otherwise
254 254
         # nova-compute will be unable to use libvirt.
255
-        sudo usermod -a -G libvirtd `whoami`
255
+        add_user_to_group `whoami` libvirtd
256 256
 
257 257
         # libvirt detects various settings on startup, as we potentially changed
258 258
         # the system configuration (modules, filesystems), we need to restart
... ...
@@ -113,9 +113,8 @@ if [[ ! ${DISTRO} =~ (oneiric|precise|quantal|raring|f16|f17) ]]; then
113 113
     fi
114 114
 fi
115 115
 
116
-# Qpid was introduced to Ubuntu in precise, disallow it on oneiric
117
-if [ "${DISTRO}" = "oneiric" ] && is_service_enabled qpid ; then
118
-    echo "You must use Ubuntu Precise or newer for Qpid support."
116
+if is_service_enabled qpid && ! qpid_is_supported; then
117
+    echo "Qpid support is not available for this version of your distribution."
119 118
     exit 1
120 119
 fi
121 120