From 21f9eff35c91b987803a9241f867b4443def6979 Mon Sep 17 00:00:00 2001
From: Sebastien Badia <sebastien.badia@enovance.com>
Date: Wed, 5 Mar 2014 23:57:26 +0100
Subject: [PATCH] Add client_package_ensure parameter and swift::client class

In the actual state of the manifest we can only setup package_ensure to
absent|present|latest. This commit allow end users to pin swift* and
swift-client to a specific version. (note that swift* and
python-swiftclient version are not the same).

A new class (swift::client) manage now client packages, and we keep the
retro-compatibility of commit 020b7723cbbe75fbcae89514a1e1882ae807fb27.

Change-Id: I9bcc5a0f9d0a93a812fb574c4571fb9584077e4a
---
 manifests/client.pp               | 20 ++++++++++++++++++++
 manifests/init.pp                 | 18 +++++++++++-------
 spec/classes/swift_client_spec.rb | 16 ++++++++++++++++
 spec/classes/swift_spec.rb        | 12 ++++++++++--
 4 files changed, 57 insertions(+), 9 deletions(-)
 create mode 100644 manifests/client.pp
 create mode 100644 spec/classes/swift_client_spec.rb

diff --git a/manifests/client.pp b/manifests/client.pp
new file mode 100644
index 00000000..c3a37cef
--- /dev/null
+++ b/manifests/client.pp
@@ -0,0 +1,20 @@
+# == Class: swift::client
+#
+# Installs swift client.
+#
+# === Parameters
+#
+# [*ensure*]
+#   (optional) Ensure state of the package.
+#   Defaults to 'present'.
+#
+class swift::client (
+  $ensure = 'present'
+) {
+
+  package { 'swiftclient':
+    ensure => $ensure,
+    name   => $::swift::params::client_package,
+  }
+
+}
diff --git a/manifests/init.pp b/manifests/init.pp
index 26374b81..3199fcf6 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -2,10 +2,14 @@
 #
 # == Parameters
 # [*swift_hash_suffix*] string of text to be used
-# as a salt when hashing to determine mappings in the ring.
-# This file should be the same on every node in the cluster.
+#   as a salt when hashing to determine mappings in the ring.
+#   This file should be the same on every node in the cluster.
+#
 # [*package_ensure*] The ensure state for the swift package.
-#   Optional. Defaults to present.
+#   (Optional) Defaults to present.
+#
+# [*client_package_ensure*] The ensure state for the swift client package.
+#   (Optional) Defaults to present.
 #
 # == Dependencies
 #
@@ -21,7 +25,8 @@
 #
 class swift(
   $swift_hash_suffix,
-  $package_ensure = 'present'
+  $package_ensure        = 'present',
+  $client_package_ensure = 'present',
 ) {
 
   include swift::params
@@ -36,9 +41,8 @@ class swift(
     }
   }
 
-  package { 'swiftclient':
-    ensure => $package_ensure,
-    name   => $::swift::params::client_package,
+  class { 'swift::client':
+    ensure => $client_package_ensure;
   }
 
   File { owner => 'swift', group => 'swift', require => Package['swift'] }
diff --git a/spec/classes/swift_client_spec.rb b/spec/classes/swift_client_spec.rb
new file mode 100644
index 00000000..1893829b
--- /dev/null
+++ b/spec/classes/swift_client_spec.rb
@@ -0,0 +1,16 @@
+require 'spec_helper'
+
+describe 'swift::client' do
+
+  describe "with default parameters" do
+    it { should contain_package('swiftclient').with_ensure('present') }
+  end
+
+  describe "with specified version" do
+    let :params do
+      {:ensure => '2.0.2-1'}
+    end
+
+    it { should contain_package('swiftclient').with_ensure(params[:ensure]) }
+  end
+end
diff --git a/spec/classes/swift_spec.rb b/spec/classes/swift_spec.rb
index a2d676d2..ad6c6c2a 100644
--- a/spec/classes/swift_spec.rb
+++ b/spec/classes/swift_spec.rb
@@ -60,9 +60,17 @@ describe 'swift' do
 
   describe 'when overriding package_ensure parameter' do
     it 'should effect ensure state of swift package' do
-      params[:package_ensure] = 'latest'
-      subject.should contain_package('swift').with_ensure('latest')
+      params[:package_ensure] = '1.12.0-1'
+      subject.should contain_package('swift').with_ensure(params[:package_ensure])
     end
   end
 
+  describe 'when overriding client_package_ensure parameter' do
+    it 'should effect ensure state of swift package' do
+      params[:client_package_ensure] = '2.0.2-1'
+      subject.should contain_package('swiftclient').with_ensure(params[:client_package_ensure])
+    end
+  end
+
+
 end