A) Add/move functions to 'functions' file

Add ini*() and tests
Add GetOSVersion()
Add install_package(), yum_install()
Add *_service()

Rebased

Change-Id: I570dba5ed4d2b988cdd1771cf6bed0aaf8e0fe27
diff --git a/stack.sh b/stack.sh
index 1fb9564..60e9c72 100755
--- a/stack.sh
+++ b/stack.sh
@@ -107,7 +107,7 @@
 
     # since this script runs as a normal user, we need to give that user
     # ability to run sudo
-    dpkg -l sudo || apt_get update && apt_get install sudo
+    dpkg -l sudo || apt_get update && install_package sudo
 
     if ! getent passwd stack >/dev/null; then
         echo "Creating a user called stack"
@@ -268,6 +268,7 @@
     set -o xtrace
 }
 
+
 # Nova Network Configuration
 # --------------------------
 
@@ -590,7 +591,7 @@
 
 # install apt requirements
 apt_get update
-apt_get install $(get_packages $FILES/apts)
+install_package $(get_packages $FILES/apts)
 
 # install python requirements
 pip_install $(get_packages $FILES/pips | sort -u)
@@ -677,7 +678,7 @@
 # ------
 
 if [[ $SYSLOG != "False" ]]; then
-    apt_get install -y rsyslog-relp
+    install_package rsyslog-relp
     if [[ "$SYSLOG_HOST" = "$HOST_IP" ]]; then
         # Configure the master host to receive
         cat <<EOF >/tmp/90-stack-m.conf
@@ -692,7 +693,7 @@
 EOF
         sudo mv /tmp/90-stack-s.conf /etc/rsyslog.d
     fi
-    sudo /usr/sbin/service rsyslog restart
+    restart_service rsyslog
 fi
 
 
@@ -703,7 +704,7 @@
     # Install and start rabbitmq-server
     # the temp file is necessary due to LP: #878600
     tfile=$(mktemp)
-    apt_get install rabbitmq-server > "$tfile" 2>&1
+    install_package rabbitmq-server > "$tfile" 2>&1
     cat "$tfile"
     rm -f "$tfile"
     # change the rabbit password since the default is "guest"
@@ -738,13 +739,13 @@
     fi
 
     # Install and start mysql-server
-    apt_get install mysql-server
+    install_package mysql-server
     # Update the DB to give user ‘$MYSQL_USER’@’%’ full control of the all databases:
     sudo mysql -uroot -p$MYSQL_PASSWORD -h127.0.0.1 -e "GRANT ALL PRIVILEGES ON *.* TO '$MYSQL_USER'@'%' identified by '$MYSQL_PASSWORD';"
 
     # Edit /etc/mysql/my.cnf to change ‘bind-address’ from localhost (127.0.0.1) to any (0.0.0.0) and restart the mysql service:
     sudo sed -i 's/127.0.0.1/0.0.0.0/g' /etc/mysql/my.cnf
-    sudo service mysql restart
+    restart_service mysql
 fi
 
 # Our screenrc file builder
@@ -801,7 +802,7 @@
 if is_service_enabled horizon; then
 
     # Install apache2, which is NOPRIME'd
-    apt_get install apache2 libapache2-mod-wsgi
+    install_package apache2 libapache2-mod-wsgi
 
 
     # Remove stale session database.
@@ -826,7 +827,7 @@
         s,%GROUP%,$APACHE_GROUP,g;
         s,%HORIZON_DIR%,$HORIZON_DIR,g;
     " -i /etc/apache2/sites-enabled/000-default
-    sudo service apache2 restart
+    restart_service apache2
 fi
 
 
@@ -905,8 +906,7 @@
         # Install deps
         # FIXME add to files/apts/quantum, but don't install if not needed!
         kernel_version=`cat /proc/version | cut -d " " -f3`
-        apt_get install linux-headers-$kernel_version
-        apt_get install openvswitch-switch openvswitch-datapath-dkms
+        install_package openvswitch-switch openvswitch-datapath-dkms linux-headers-$kernel_version
         # Create database for the plugin/agent
         if is_service_enabled mysql; then
             mysql -u$MYSQL_USER -p$MYSQL_PASSWORD -e 'DROP DATABASE IF EXISTS ovs_quantum;'
@@ -1019,7 +1019,7 @@
 
     # Virtualization Configuration
     # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-    apt_get install libvirt-bin
+    install_package libvirt-bin
 
     # Force IP forwarding on, just on case
     sudo sysctl -w net.ipv4.ip_forward=1
@@ -1043,7 +1043,7 @@
     # to simulate multiple systems.
     if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then
         if [[ "$DISTRO" > natty ]]; then
-            apt_get install cgroup-lite
+            install_package cgroup-lite
         else
             cgline="none /cgroup cgroup cpuacct,memory,devices,cpu,freezer,blkio 0 0"
             sudo mkdir -p /cgroup
@@ -1062,7 +1062,7 @@
     # libvirt detects various settings on startup, as we potentially changed
     # the system configuration (modules, filesystems), we need to restart
     # libvirt to detect those changes.
-    sudo /etc/init.d/libvirt-bin restart
+    restart_service libvirt-bin
 
 
     # Instance Storage
@@ -1113,7 +1113,7 @@
 # Storage Service
 if is_service_enabled swift; then
     # Install memcached for swift.
-    apt_get install memcached
+    install_package memcached
 
     # We first do a bit of setup by creating the directories and
     # changing the permissions so we can run it as our user.
@@ -1297,7 +1297,7 @@
     # By default, the backing file is 2G in size, and is stored in /opt/stack.
 
     # install the package
-    apt_get install tgt
+    install_package tgt
 
     if ! sudo vgs $VOLUME_GROUP; then
         VOLUME_BACKING_FILE=${VOLUME_BACKING_FILE:-$DEST/nova-volumes-backing-file}