From c2acaba000ca22d28f6807942f9a5fed3cb6fb90 Mon Sep 17 00:00:00 2001
From: ZhongShengping <chdzsp@163.com>
Date: Wed, 8 Jun 2016 13:52:19 +0800
Subject: [PATCH] Provide default service_name for keystone endpoint

This change updates the zaqar::keystone::auth class to include a default
service_name of 'zaqar' so that if a user changes the auth_name, the
service is still created as being related to 'zaqar'.  This improves the
user experiance when they want to customize the usernames for services.

Change-Id: I2977790c3558732c2a1773aa3ede834c1d62ca16
Closes-Bug: #1590040
---
 manifests/keystone/auth.pp                        | 15 +++++----------
 .../keystone-auth-name-a147ec123b16221d.yaml      |  5 +++++
 spec/classes/zaqar_keystone_auth_spec.rb          |  4 ++--
 3 files changed, 12 insertions(+), 12 deletions(-)
 create mode 100644 releasenotes/notes/keystone-auth-name-a147ec123b16221d.yaml

diff --git a/manifests/keystone/auth.pp b/manifests/keystone/auth.pp
index 6c00afe..3d3fe2c 100644
--- a/manifests/keystone/auth.pp
+++ b/manifests/keystone/auth.pp
@@ -43,7 +43,7 @@
 #
 # [*service_name*]
 #   (optional) Name of the service.
-#   Defaults to the value of auth_name.
+#   Defaults to 'zaqar'
 #
 # [*configure_service*]
 #   Should zaqar service be configured? Defaults to 'true'.
@@ -60,7 +60,7 @@ class zaqar::keystone::auth(
   $password,
   $email                  = 'zaqar@localhost',
   $auth_name              = 'zaqar',
-  $service_name           = undef,
+  $service_name           = 'zaqar',
   $service_type           = 'messaging',
   $public_url             = 'http://127.0.0.1:8888',
   $admin_url              = 'http://127.0.0.1:8888',
@@ -76,19 +76,14 @@ class zaqar::keystone::auth(
 
   validate_string($password)
 
-  if $service_name == undef {
-    $real_service_name = $auth_name
-  } else {
-    $real_service_name = $service_name
-  }
-
-  keystone::resource::service_identity { $auth_name:
+  keystone::resource::service_identity { 'zaqar':
     configure_user      => $configure_user,
     configure_user_role => $configure_user_role,
     configure_endpoint  => $configure_endpoint,
     service_type        => $service_type,
     service_description => $service_description,
-    service_name        => $real_service_name,
+    service_name        => $service_name,
+    auth_name           => $auth_name,
     region              => $region,
     password            => $password,
     email               => $email,
diff --git a/releasenotes/notes/keystone-auth-name-a147ec123b16221d.yaml b/releasenotes/notes/keystone-auth-name-a147ec123b16221d.yaml
new file mode 100644
index 0000000..835c883
--- /dev/null
+++ b/releasenotes/notes/keystone-auth-name-a147ec123b16221d.yaml
@@ -0,0 +1,5 @@
+---
+fixes:
+  - The keystone auth class has been updated to provide a default service_name
+    to allow a user to specify a custom auth_name that may not contain the
+    name of the service.
diff --git a/spec/classes/zaqar_keystone_auth_spec.rb b/spec/classes/zaqar_keystone_auth_spec.rb
index 24c3cd7..7a53e94 100644
--- a/spec/classes/zaqar_keystone_auth_spec.rb
+++ b/spec/classes/zaqar_keystone_auth_spec.rb
@@ -62,8 +62,8 @@ describe 'zaqar::keystone::auth' do
 
       it { is_expected.to contain_keystone_user('zaqary') }
       it { is_expected.to contain_keystone_user_role('zaqary@services') }
-      it { is_expected.to contain_keystone_service('zaqary::messaging') }
-      it { is_expected.to contain_keystone_endpoint('RegionOne/zaqary::messaging') }
+      it { is_expected.to contain_keystone_service('zaqar::messaging') }
+      it { is_expected.to contain_keystone_endpoint('RegionOne/zaqar::messaging') }
     end
 
     describe 'when overriding service name' do