Skip to content

Commit bec95ae

Browse files
author
Gavin Williams
committed
Remove 'jvm.options' template, instead append to shipped file.
This removes the templated 'jvm.options' file, instead we append to the shipped 'jvm.options' file by using the `file_line` resource. Removed associated tests and template file. Add additional tests to cover specifying 'jvm_options'.
1 parent c5072d8 commit bec95ae

File tree

6 files changed

+56
-86
lines changed

6 files changed

+56
-86
lines changed

manifests/config.pp

+8-6
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,14 @@
243243
mode => '0440',
244244
}
245245

246-
# Configure JVM options
247-
file { "${::elasticsearch::configdir}/jvm.options":
248-
content => template("${module_name}/etc/elasticsearch/jvm.options.erb"),
249-
group => $::elasticsearch::elasticsearch_group,
250-
notify => $::elasticsearch::_notify_service,
251-
owner => $::elasticsearch::elasticsearch_user,
246+
# Add any additional JVM options
247+
$elasticsearch::jvm_options.each |String $jvm_option| {
248+
file_line { "jvm_option_${jvm_option}":
249+
ensure => present,
250+
path => "${elasticsearch::configdir}/jvm.options",
251+
line => $jvm_option,
252+
notify => $::elasticsearch::_notify_service,
253+
}
252254
}
253255

254256
if $::elasticsearch::system_key != undef {

spec/classes/000_elasticsearch_init_spec.rb

+46
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,52 @@
339339
.with(:owner => 'myesuser') if facts[:os]['family'] == 'RedHat' }
340340
end
341341

342+
describe 'setting jvm_options' do
343+
jvm_options = [
344+
'-Xms16g',
345+
'-Xmx16g'
346+
]
347+
348+
let(:params) do
349+
default_params.merge(
350+
:jvm_options => jvm_options
351+
)
352+
end
353+
354+
jvm_options.each do |jvm_option|
355+
it { should contain_file_line("jvm_option_#{jvm_option}")
356+
.with(
357+
:ensure => 'present',
358+
:path => '/etc/elasticsearch/jvm.options',
359+
:line => jvm_option
360+
)}
361+
end
362+
end
363+
364+
context 'with restart_on_change => true' do
365+
let(:params) do
366+
default_params.merge(
367+
:restart_on_change => true
368+
)
369+
end
370+
371+
describe 'should restart elasticsearch' do
372+
it { should contain_file('/etc/elasticsearch/elasticsearch.yml')
373+
.that_notifies('Service[elasticsearch]')}
374+
end
375+
376+
describe 'setting jvm_options triggers restart' do
377+
let(:params) do
378+
super().merge(
379+
:jvm_options => ['-Xmx16g']
380+
)
381+
end
382+
383+
it { should contain_file_line('jvm_option_-Xmx16g')
384+
.that_notifies('Service[elasticsearch]')}
385+
end
386+
end
387+
342388
# This check helps catch dependency cycles.
343389
context 'create_resource' do
344390
# Helper for these tests

spec/classes/001_hiera_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
:enable => true
5959
) }
6060

61-
%w[elasticsearch.yml jvm.options log4j2.properties].each do |file|
61+
%w[elasticsearch.yml log4j2.properties].each do |file|
6262
it { should contain_file("/etc/elasticsearch/#{file}") }
6363
end
6464
end # of config

spec/helpers/class_shared_examples.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
it { should contain_datacat_fragment('main_config') }
66
it { should contain_service('elasticsearch') }
77

8-
%w[elasticsearch.yml jvm.options log4j2.properties].each do |file|
8+
%w[elasticsearch.yml log4j2.properties].each do |file|
99
it { should contain_file("/etc/elasticsearch/#{file}") }
1010
end
1111

spec/templates/002_jvm.options.erb_spec.rb

-36
This file was deleted.

templates/etc/elasticsearch/jvm.options.erb

-42
This file was deleted.

0 commit comments

Comments
 (0)