Skip to content

Commit 6680068

Browse files
authored
Merge pull request #988 from kuleuven/master
Make port and host optional for mysql plugin
2 parents acd970c + 5813b65 commit 6680068

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

manifests/plugin/mysql/database.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
define collectd::plugin::mysql::database (
33
Enum['present', 'absent'] $ensure = 'present',
44
String $database = $name,
5-
Stdlib::Host $host = 'localhost',
6-
Stdlib::Port $port = 3306,
5+
Optional[Stdlib::Host] $host = undef,
6+
Optional[Stdlib::Port] $port = undef,
77
Boolean $masterstats = false,
88
Boolean $slavestats = false,
99
Optional[String[1]] $username = undef,

spec/classes/collectd_plugin_mysql_database_spec.rb

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
end
7676
end
7777

78-
context 'default options' do
78+
context 'specify host and port' do
7979
let :title do
8080
'dbname'
8181
end
@@ -84,6 +84,13 @@
8484
facts.merge(collectd_version: '5.6')
8585
end
8686

87+
let :params do
88+
{
89+
'host' => 'localhost',
90+
'port' => 3306,
91+
}
92+
end
93+
8794
it 'creates an mysql database' do
8895
content_database_file = <<EOS
8996
# Generated by Puppet
@@ -96,6 +103,36 @@
96103
SlaveStats false
97104
</Database>
98105
</Plugin>
106+
EOS
107+
is_expected.to compile.with_all_deps
108+
is_expected.to contain_class('collectd')
109+
is_expected.to contain_class('collectd::plugin::mysql')
110+
is_expected.to contain_file('dbname.conf').with(
111+
content: content_database_file,
112+
path: "#{options[:plugin_conf_dir]}/mysql-dbname.conf"
113+
)
114+
end
115+
end
116+
117+
context 'default options' do
118+
let :title do
119+
'dbname'
120+
end
121+
122+
let :facts do
123+
facts.merge(collectd_version: '5.6')
124+
end
125+
126+
it 'creates an mysql database' do
127+
content_database_file = <<EOS
128+
# Generated by Puppet
129+
130+
<Plugin mysql>
131+
<Database "dbname">
132+
MasterStats false
133+
SlaveStats false
134+
</Database>
135+
</Plugin>
99136
EOS
100137
is_expected.to compile.with_all_deps
101138
is_expected.to contain_class('collectd')

templates/mysql-database.conf.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@
22

33
<Plugin mysql>
44
<Database "<%= @database %>">
5+
<%- if @host -%>
56
Host "<%= @host %>"
7+
<%- end -%>
68
<%- if @username -%>
79
User "<%= @username %>"
810
<%- end -%>
911
<%- if @password -%>
1012
Password "<%= @password %>"
1113
<%- end -%>
14+
<%- if @port -%>
1215
<% if scope.function_versioncmp([scope.lookupvar('collectd::collectd_version_real'), '5.0']) >= 0 -%>
1316
Port "<%= @port %>"
1417
<% else -%>
1518
Port <%= @port %>
19+
<%- end -%>
1620
<%- end -%>
1721
MasterStats <%= @masterstats %>
1822
SlaveStats <%= @slavestats %>

0 commit comments

Comments
 (0)