Skip to content

Commit

Permalink
Make port and host optional for mysql plugin
Browse files Browse the repository at this point in the history
When we use a socket, the host and port should be empty (or omitted).

Signed-off-by: Jo Vandeginste <[email protected]>
  • Loading branch information
jovandeginste committed Sep 20, 2021
1 parent acd970c commit 590d2be
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions manifests/plugin/mysql/database.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
define collectd::plugin::mysql::database (
Enum['present', 'absent'] $ensure = 'present',
String $database = $name,
Stdlib::Host $host = 'localhost',
Stdlib::Port $port = 3306,
Optional[Stdlib::Host] $host = undef,
Optional[Stdlib::Port] $port = undef,
Boolean $masterstats = false,
Boolean $slavestats = false,
Optional[String[1]] $username = undef,
Expand Down
37 changes: 37 additions & 0 deletions spec/classes/collectd_plugin_mysql_database_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@
facts.merge(collectd_version: '5.6')
end

let :params do
{
'host' => 'localhost',
'port' => 3306,
}
end

it 'creates an mysql database' do
content_database_file = <<EOS
# Generated by Puppet
Expand All @@ -96,6 +103,36 @@
SlaveStats false
</Database>
</Plugin>
EOS
is_expected.to compile.with_all_deps
is_expected.to contain_class('collectd')
is_expected.to contain_class('collectd::plugin::mysql')
is_expected.to contain_file('dbname.conf').with(
content: content_database_file,
path: "#{options[:plugin_conf_dir]}/mysql-dbname.conf"
)
end
end

context 'default options' do
let :title do
'dbname'
end

let :facts do
facts.merge(collectd_version: '5.6')
end

it 'creates an mysql database' do
content_database_file = <<EOS
# Generated by Puppet
<Plugin mysql>
<Database "dbname">
MasterStats false
SlaveStats false
</Database>
</Plugin>
EOS
is_expected.to compile.with_all_deps
is_expected.to contain_class('collectd')
Expand Down
4 changes: 4 additions & 0 deletions templates/mysql-database.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

<Plugin mysql>
<Database "<%= @database %>">
<%- if @host -%>
Host "<%= @host %>"
<%- end -%>
<%- if @username -%>
User "<%= @username %>"
<%- end -%>
<%- if @password -%>
Password "<%= @password %>"
<%- end -%>
<%- if @port -%>
<% if scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '5.0']) >= 0 -%>
Port "<%= @port %>"
<% else -%>
Port <%= @port %>
<%- end -%>
<%- end -%>
MasterStats <%= @masterstats %>
SlaveStats <%= @slavestats %>
Expand Down

0 comments on commit 590d2be

Please sign in to comment.