From 5941f835ac48ff2d744191550e6c831650a01d7d Mon Sep 17 00:00:00 2001
From: Matthew Treinish <mtreinish@kortar.org>
Date: Wed, 3 Dec 2014 15:44:42 -0500
Subject: [PATCH] Switch subunit2sql to use decomposed uri

This commit switches the subunit2sql_uri which get's passed into the
config file template to use decomposed values. The advantage of this
is that it enables using subsets of the information elsewhere.

Change-Id: I30b5117c12897fa3a1cb1e2579b4eec59ba57b2b
---
 manifests/site.pp                                 |  6 ++++--
 modules/openstack_project/manifests/logstash.pp   |  6 ++++--
 .../openstack_project/manifests/subunit_worker.pp | 15 ++++++++++-----
 modules/subunit2sql/manifests/server.pp           |  7 ++++++-
 modules/subunit2sql/manifests/worker.pp           |  7 ++++++-
 .../subunit2sql/templates/subunit2sql.conf.erb    |  2 +-
 6 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/manifests/site.pp b/manifests/site.pp
index a427e55c9e..9996fd4bba 100644
--- a/manifests/site.pp
+++ b/manifests/site.pp
@@ -325,7 +325,8 @@ node 'logstash.openstack.org' {
       'elasticsearch06.openstack.org:9200',
       'elasticsearch07.openstack.org:9200',
     ],
-    subunit2sql_db_uri  => hiera('subunit2sql_db_uri', ''),
+    subunit2sql_db_host  => hiera('subunit2sql_db_host', ''),
+    subunit2sql_db_pass  => hiera('subunit2sql_db_password', ''),
   }
 }
 
@@ -343,7 +344,8 @@ node /^logstash-worker\d+\.openstack\.org$/ {
 node /^subunit-worker\d+\.openstack\.org$/ {
   class { 'openstack_project::subunit_worker':
     sysadmins             => hiera('sysadmins', []),
-    subunit2sql_db_uri    => hiera('subunit2sql_db_uri', ''),
+    subunit2sql_db_host => hiera('subunit2sql_db_host', ''),
+    subunit2sql_db_pass => hiera('subunit2sql_db_password', ''),
   }
 }
 
diff --git a/modules/openstack_project/manifests/logstash.pp b/modules/openstack_project/manifests/logstash.pp
index 09591ad28b..f4b0583f86 100644
--- a/modules/openstack_project/manifests/logstash.pp
+++ b/modules/openstack_project/manifests/logstash.pp
@@ -20,7 +20,8 @@ class openstack_project::logstash (
   $discover_nodes = ['elasticsearch01.openstack.org:9200'],
   $statsd_host = 'graphite.openstack.org',
   $sysadmins = [],
-  $subunit2sql_db_uri= ''
+  $subunit2sql_db_host,
+  $subunit2sql_db_pass,
 ) {
   $iptables_es_rule = regsubst ($elasticsearch_nodes, '^(.*)$', '-m state --state NEW -m tcp -p tcp --dport 9200:9400 -s \1 -j ACCEPT')
   $iptables_gm_rule = regsubst ($gearman_workers, '^(.*)$', '-m state --state NEW -m tcp -p tcp --dport 4730 -s \1 -j ACCEPT')
@@ -48,6 +49,7 @@ class openstack_project::logstash (
   include 'subunit2sql'
 
   class { 'subunit2sql::server':
-    subunit2sql_db_uri => $subunit2sql_db_uri,
+    db_host => $subunit2sql_db_host,
+    db_pass => $subunit2sql_db_pass,
   }
 }
diff --git a/modules/openstack_project/manifests/subunit_worker.pp b/modules/openstack_project/manifests/subunit_worker.pp
index 07f7e04af3..3b4040ebc2 100644
--- a/modules/openstack_project/manifests/subunit_worker.pp
+++ b/modules/openstack_project/manifests/subunit_worker.pp
@@ -16,7 +16,8 @@
 #
 class openstack_project::subunit_worker (
   $sysadmins = [],
-  $subunit2sql_db_uri
+  $subunit2sql_db_host,
+  $subunit2sql_db_pass,
 ) {
   class { 'openstack_project::server':
     iptables_public_tcp_ports => [22],
@@ -26,18 +27,22 @@ class openstack_project::subunit_worker (
   include subunit2sql
   subunit2sql::worker { 'A':
     config_file        => 'puppet:///modules/openstack_project/logstash/jenkins-subunit-worker.yaml',
-    subunit2sql_db_uri => $subunit2sql_db_uri,
+    db_host            => $subunit2sql_db_host,
+    db_pass            => $subunit2sql_db_pass,
   }
   subunit2sql::worker { 'B':
     config_file        => 'puppet:///modules/openstack_project/logstash/jenkins-subunit-worker.yaml',
-    subunit2sql_db_uri => $subunit2sql_db_uri,
+    db_host            => $subunit2sql_db_host,
+    db_pass            => $subunit2sql_db_pass,
   }
   subunit2sql::worker { 'C':
     config_file        => 'puppet:///modules/openstack_project/logstash/jenkins-subunit-worker.yaml',
-    subunit2sql_db_uri => $subunit2sql_db_uri,
+    db_host            => $subunit2sql_db_host,
+    db_pass            => $subunit2sql_db_pass,
   }
   subunit2sql::worker { 'D':
     config_file        => 'puppet:///modules/openstack_project/logstash/jenkins-subunit-worker.yaml',
-    subunit2sql_db_uri => $subunit2sql_db_uri,
+    db_host            => $subunit2sql_db_host,
+    db_pass            => $subunit2sql_db_pass,
   }
 }
diff --git a/modules/subunit2sql/manifests/server.pp b/modules/subunit2sql/manifests/server.pp
index 864e06c2c9..a825468836 100644
--- a/modules/subunit2sql/manifests/server.pp
+++ b/modules/subunit2sql/manifests/server.pp
@@ -16,7 +16,12 @@
 # == Class: subunit2sql
 #
 class subunit2sql::server (
-  $subunit2sql_db_uri,
+  $db_dialect = 'mysql',
+  $db_user = 'subunit2sql',
+  $db_pass,
+  $db_host,
+  $db_port = '3306',
+  $db_name = 'subunit2sql',
 ) {
 
   file { '/etc/subunit2sql.conf':
diff --git a/modules/subunit2sql/manifests/worker.pp b/modules/subunit2sql/manifests/worker.pp
index 3b7752d892..d03038a5e2 100644
--- a/modules/subunit2sql/manifests/worker.pp
+++ b/modules/subunit2sql/manifests/worker.pp
@@ -17,7 +17,12 @@
 #
 define subunit2sql::worker (
   $config_file,
-  $subunit2sql_db_uri,
+  $db_dialect = 'mysql',
+  $db_user = 'subunit2sql',
+  $db_pass,
+  $db_host,
+  $db_port = '3306',
+  $db_name = 'subunit2sql'
 ) {
   $suffix = "-${name}"
 
diff --git a/modules/subunit2sql/templates/subunit2sql.conf.erb b/modules/subunit2sql/templates/subunit2sql.conf.erb
index 3d16db6db1..70c0166907 100644
--- a/modules/subunit2sql/templates/subunit2sql.conf.erb
+++ b/modules/subunit2sql/templates/subunit2sql.conf.erb
@@ -1,4 +1,4 @@
 [DEFAULT]
 
 [database]
-connection = <%= subunit2sql_db_uri %>
+connection = <%= @db_dialect %>://<%= @db_user %>:<%= @db_pass %>@<%= @db_host %>:<%= @db_port %>/<%= @db_name %>