From 750628b2b1048482c26468629e80e31375e8d614 Mon Sep 17 00:00:00 2001
From: Mark Vanderwiel <vanderwl@us.ibm.com>
Date: Mon, 8 Sep 2014 14:19:21 -0500
Subject: [PATCH] Set ruby and gem default to 1.9.1 for cookbook jobs on
 precise

For berkshelf 3.x and openstack cookbooks, we need precise and ruby 1.9.1.
Default for precise is ruby 1.8. Ruby 1.9 is installed on the precise
images but it's not set to the default.
Use update-alternatives to set Ruby 1.9.1 as the default.

Change-Id: I464b3e44a0ba860129f22f306c63e415fd4925ff
Closes-Bug: #1357439
---
 .../jenkins_job_builder/config/chef-jobs.yaml |  6 +++-
 .../jenkins_job_builder/config/macros.yaml    | 31 +++++++++++++------
 2 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/modules/openstack_project/files/jenkins_job_builder/config/chef-jobs.yaml b/modules/openstack_project/files/jenkins_job_builder/config/chef-jobs.yaml
index c1b3e6bbc5..26cf7afba7 100644
--- a/modules/openstack_project/files/jenkins_job_builder/config/chef-jobs.yaml
+++ b/modules/openstack_project/files/jenkins_job_builder/config/chef-jobs.yaml
@@ -9,6 +9,7 @@
 
     builders:
       - gerrit-git-prep
+      - ruby-191-prep
       - chef-bundler-prep
       - revoke-sudo
       - chef-berkshelf-prep
@@ -28,6 +29,7 @@
 
     builders:
       - gerrit-git-prep
+      - ruby-191-prep
       - chef-bundler-prep
       - revoke-sudo
       - chef-berkshelf-prep
@@ -47,6 +49,7 @@
 
     builders:
       - gerrit-git-prep
+      - ruby-191-prep
       - chef-bundler-prep
       - revoke-sudo
       - chef-berkshelf-prep
@@ -61,13 +64,14 @@
 
     builders:
       - gerrit-git-prep
+      - ruby-191-prep
       - chef-bundler-prep
       - revoke-sudo
       - chef-berkshelf-prep
       - shell: |
           #!/bin/bash -xe
           # Validates roles
-          ruby1.9.1 `which bundle` exec spiceweasel infrastructure.yml --debug
+          bundle exec spiceweasel infrastructure.yml --debug
 
     publishers:
       - console-log
diff --git a/modules/openstack_project/files/jenkins_job_builder/config/macros.yaml b/modules/openstack_project/files/jenkins_job_builder/config/macros.yaml
index 054b693e76..0d925ae548 100644
--- a/modules/openstack_project/files/jenkins_job_builder/config/macros.yaml
+++ b/modules/openstack_project/files/jenkins_job_builder/config/macros.yaml
@@ -123,6 +123,17 @@
     builders:
       - shell: "./test.sh"
 
+- builder:
+    name: ruby-191-prep
+    builders:
+      - shell: |
+          #!/bin/bash -x
+          sudo update-alternatives --install /usr/bin/ruby ruby /usr/bin/ruby1.9.1 20
+          sudo update-alternatives --set ruby /usr/bin/ruby1.9.1
+          sudo update-alternatives --install /usr/bin/gem gem /usr/bin/gem1.9.1 10
+          sudo update-alternatives --set gem /usr/bin/gem1.9.1
+          sudo gem update --no-rdoc --no-ri
+
 - builder:
     name: chef-bundler-prep
     builders:
@@ -133,9 +144,9 @@
           if [ $? -eq 0 ]; then
             # For Berkshelf 3.x use the system gecode 3.x libraries
             sudo apt-get install -y libgecode-dev
-            USE_SYSTEM_GECODE=1 ruby1.9.1 `which bundle` install --path=.bundle --jobs 1 --retry 3 --verbose
+            USE_SYSTEM_GECODE=1 bundle install --path=.bundle --jobs 1 --retry 3 --verbose
           else
-            ruby1.9.1 `which bundle` install --path=.bundle --jobs 1 --retry 3 --verbose
+            bundle install --path=.bundle --jobs 1 --retry 3 --verbose
           fi
 
 - builder:
@@ -145,10 +156,10 @@
           #!/bin/bash -x
           grep -E .*berkshelf.*3\.\d*\.\d*.* Gemfile
           if [ $? -eq 0 ]; then
-            ruby1.9.1 `which bundle` exec berks vendor .cookbooks
+            bundle exec berks vendor .cookbooks
           else
             mkdir -p .cookbooks
-            ruby1.9.1 `which bundle` exec berks install --path=.cookbooks
+            bundle exec berks install --path=.cookbooks
           fi
           COOKBOOK=$(awk '/^name/ {print $NF}' metadata.rb |tr -d \"\')
           if [ -z $COOKBOOK ]; then
@@ -162,9 +173,9 @@
       - shell: |
           #!/bin/bash -x
           if grep rubocop: Strainerfile; then
-              ruby1.9.1 `which bundle` exec strainer test --cookbooks-path=.cookbooks --only=rubocop
+              bundle exec strainer test --cookbooks-path=.cookbooks --only=rubocop
           else
-              ruby1.9.1 `which bundle` exec rubocop
+              bundle exec rubocop
           fi
 
 - builder:
@@ -173,9 +184,9 @@
       - shell: |
           #!/bin/bash -x
           if grep foodcritic: Strainerfile; then
-              ruby1.9.1 `which bundle` exec strainer test --cookbooks-path=.cookbooks --only=foodcritic
+              bundle exec strainer test --cookbooks-path=.cookbooks --only=foodcritic
           else
-              ruby1.9.1 `which bundle` exec foodcritic -f any -t ~FC003 -t ~FC023 .
+              bundle exec foodcritic -f any -t ~FC003 -t ~FC023 .
           fi
 
 - builder:
@@ -185,9 +196,9 @@
           #!/bin/bash -x
           COOKBOOK=$(awk '/^name/ {print $NF}' metadata.rb |tr -d \"\')
           if grep chefspec: Strainerfile; then
-              ruby1.9.1 `which bundle` exec strainer test --cookbooks-path=.cookbooks --only=chefspec
+              bundle exec strainer test --cookbooks-path=.cookbooks --only=chefspec
           else
-              ruby1.9.1 `which bundle` exec rspec .cookbooks/$COOKBOOK/spec
+              bundle exec rspec .cookbooks/$COOKBOOK/spec
           fi
 
 - builder: