From a39a44faf9c5cb03960f1037e8ab0671d4a33420 Mon Sep 17 00:00:00 2001
From: Benedikt Trefzer <benedikt.trefzer@cirrax.com>
Date: Fri, 31 Aug 2018 17:26:19 +0200
Subject: [PATCH] make openstackclient package name configurable

Change-Id: Ie7d770af6d1238c3f68b7c743e8fa5255a9a5995
---
 manifests/openstackclient.pp                      | 14 +++++++-------
 manifests/params.pp                               | 12 ++++++++++++
 spec/classes/openstacklib_openstackclient_spec.rb | 13 +++++++++++++
 3 files changed, 32 insertions(+), 7 deletions(-)
 create mode 100644 manifests/params.pp

diff --git a/manifests/openstackclient.pp b/manifests/openstackclient.pp
index 47ba1148..ade510d2 100644
--- a/manifests/openstackclient.pp
+++ b/manifests/openstackclient.pp
@@ -8,16 +8,16 @@
 #    (Optional) Ensure state of the openstackclient package.
 #    Defaults to 'present'
 #
+#  [*package_name*]
+#    (Optional) The name of the package to install
+#    Defaults to $::openstacklib::params::openstackclient_package_name
+#
 class openstacklib::openstackclient(
+  $package_name   = $::openstacklib::params::openstackclient_package_name,
   $package_ensure = 'present',
-){
+) inherits ::openstacklib::params {
 
-  $openstackclient_package_name = $::os_package_type ? {
-    'debian' => 'python3-openstackclient',
-    default  => 'python-openstackclient',
-  }
-
-  ensure_packages($openstackclient_package_name, {
+  ensure_packages($package_name, {
     'ensure' => $package_ensure,
     'tag'    => 'openstack'
   })
diff --git a/manifests/params.pp b/manifests/params.pp
new file mode 100644
index 00000000..69f2b2b8
--- /dev/null
+++ b/manifests/params.pp
@@ -0,0 +1,12 @@
+# == Class: openstacklib::params
+#
+# These parameters need to be accessed from several locations and
+# should be considered to be constant
+#
+class openstacklib::params {
+
+  $openstackclient_package_name = $::os_package_type ? {
+    'debian' => 'python3-openstackclient',
+    default  => 'python-openstackclient',
+  }
+}
diff --git a/spec/classes/openstacklib_openstackclient_spec.rb b/spec/classes/openstacklib_openstackclient_spec.rb
index cfcfdde0..201db1d8 100644
--- a/spec/classes/openstacklib_openstackclient_spec.rb
+++ b/spec/classes/openstacklib_openstackclient_spec.rb
@@ -11,6 +11,19 @@ describe 'openstacklib::openstackclient' do
         )
       end
     end
+
+    context 'with non default package name' do
+      let :params do
+        { :package_name => 'my-openstackclient' }
+      end
+
+      it 'installs my-openstackclient' do
+        is_expected.to contain_package('my-openstackclient').with(
+          :ensure => 'present',
+          :tag    => 'openstack'
+        )
+      end
+    end
   end
 
   on_supported_os({