diff --git a/manifests/config.pp b/manifests/config.pp index 86389e6..0a2258c 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,287 +1,289 @@ # This class exists to coordinate all configuration related actions, # functionality and logical units in a central place. # # It is not intended to be used directly by external resources like node # definitions or other modules. # # @example importing this class into other classes to use its functionality: # class { 'elasticsearch::config': } # # @author Richard Pijnenburg # @author Tyler Langlois # @author Gavin Williams # class elasticsearch::config { #### Configuration Exec { path => [ '/bin', '/usr/bin', '/usr/local/bin' ], cwd => '/', } if ( $elasticsearch::ensure == 'present' ) { file { $elasticsearch::homedir: ensure => 'directory', group => $elasticsearch::elasticsearch_group, owner => $elasticsearch::elasticsearch_user; $elasticsearch::configdir: ensure => 'directory', group => $elasticsearch::elasticsearch_group, owner => 'root', mode => '2750'; $elasticsearch::datadir: ensure => 'directory', group => $elasticsearch::elasticsearch_group, owner => $elasticsearch::elasticsearch_user; $elasticsearch::logdir: ensure => 'directory', group => $elasticsearch::elasticsearch_group, owner => $elasticsearch::elasticsearch_user, mode => '0750'; $elasticsearch::_plugindir: ensure => 'directory', group => $elasticsearch::elasticsearch_group, owner => $elasticsearch::elasticsearch_user, mode => 'o+Xr'; "${elasticsearch::homedir}/lib": ensure => 'directory', group => '0', owner => 'root', recurse => true; } if $elasticsearch::pid_dir { file { $elasticsearch::pid_dir: ensure => 'directory', group => undef, owner => $elasticsearch::elasticsearch_user, recurse => true, } if ($elasticsearch::service_provider == 'systemd') { $group = $elasticsearch::elasticsearch_group $user = $elasticsearch::elasticsearch_user $pid_dir = $elasticsearch::pid_dir file { '/usr/lib/tmpfiles.d/elasticsearch.conf': ensure => 'file', content => template("${module_name}/usr/lib/tmpfiles.d/elasticsearch.conf.erb"), group => '0', owner => 'root', } } } if $elasticsearch::defaults_location { augeas { "${elasticsearch::defaults_location}/elasticsearch": incl => "${elasticsearch::defaults_location}/elasticsearch", lens => 'Shellvars.lns', changes => [ 'rm CONF_FILE', 'rm CONF_DIR', 'rm ES_PATH_CONF', ], } file { "${elasticsearch::defaults_location}/elasticsearch": ensure => 'file', group => $elasticsearch::elasticsearch_group, owner => $elasticsearch::elasticsearch_user, mode => '0640'; } } if $::elasticsearch::security_plugin != undef and ($::elasticsearch::security_plugin in ['shield', 'x-pack']) { file { "${::elasticsearch::configdir}/${::elasticsearch::security_plugin}" : ensure => 'directory', owner => 'root', group => $elasticsearch::elasticsearch_group, mode => '0750', } } # Define logging config file for the in-use security plugin if $::elasticsearch::security_logging_content != undef or $::elasticsearch::security_logging_source != undef { if $::elasticsearch::security_plugin == undef or ! ($::elasticsearch::security_plugin in ['shield', 'x-pack']) { fail("\"${::elasticsearch::security_plugin}\" is not a valid security_plugin parameter value") } $_security_logging_file = $::elasticsearch::security_plugin ? { 'shield' => 'logging.yml', default => 'log4j2.properties' } file { "/etc/elasticsearch/${::elasticsearch::security_plugin}/${_security_logging_file}" : content => $::elasticsearch::security_logging_content, source => $::elasticsearch::security_logging_source, } } $init_defaults = merge( { 'MAX_OPEN_FILES' => '65535', }, $::elasticsearch::init_defaults ) # Setup init defaults if ($::elasticsearch::ensure == 'present') { # Defaults file, either from file source or from hash to augeas commands if ($::elasticsearch::init_defaults_file != undef) { file { "${::elasticsearch::defaults_location}/elasticsearch": ensure => $::elasticsearch::ensure, source => $::elasticsearch::init_defaults_file, owner => 'root', group => '0', mode => '0644', before => Service['elasticsearch'], notify => $::elasticsearch::_notify_service, } } else { augeas { 'init_defaults': incl => "${::elasticsearch::defaults_location}/elasticsearch", lens => 'Shellvars.lns', changes => template("${module_name}/etc/sysconfig/defaults.erb"), before => Service['elasticsearch'], notify => $::elasticsearch::_notify_service, } } } else { # absent file { "${elasticsearch::defaults_location}/elasticsearch": ensure => 'absent', subscribe => Service['elasticsearch'], } } # Generate config file $_config = deep_implode($elasticsearch::config) # Generate SSL config if $elasticsearch::ssl { if ($elasticsearch::keystore_password == undef) { fail('keystore_password required') } if ($elasticsearch::keystore_path == undef) { $_keystore_path = "${elasticsearch::configdir}/${elasticsearch::security_plugin}/${name}.ks" } else { $_keystore_path = $elasticsearch::keystore_path } $_tls_config = { 'xpack.security.transport.ssl.enabled' => true, 'xpack.security.http.ssl.enabled' => true, 'xpack.ssl.keystore.path' => $_keystore_path, 'xpack.ssl.keystore.password' => $elasticsearch::keystore_password, } # Trust CA Certificate java_ks { 'elasticsearch_ca': ensure => 'latest', certificate => $elasticsearch::ca_certificate, target => $_keystore_path, password => $elasticsearch::keystore_password, trustcacerts => true, } # Load node certificate and private key java_ks { 'elasticsearch_node': ensure => 'latest', certificate => $elasticsearch::certificate, private_key => $elasticsearch::private_key, target => $_keystore_path, password => $elasticsearch::keystore_password, } } else { $_tls_config = {} } # Logging file or hash if ($::elasticsearch::logging_file != undef) { $_log4j_content = undef } else { if ($::elasticsearch::logging_template != undef ) { $_log4j_content = template($::elasticsearch::logging_template) } else { $_log4j_content = template("${module_name}/etc/elasticsearch/log4j2.properties.erb") } $_logging_source = undef } file { "${::elasticsearch::configdir}/log4j2.properties": ensure => file, content => $_log4j_content, source => $_logging_source, mode => '0644', notify => $::elasticsearch::_notify_service, require => Class['elasticsearch::package'], before => Class['elasticsearch::service'], } # Generate Elasticsearch config $_es_config = merge( $::elasticsearch::config, { 'path.data' => $::elasticsearch::datadir }, { 'path.logs' => $::elasticsearch::logdir }, $_tls_config ) datacat_fragment { 'main_config': target => "${::elasticsearch::configdir}/elasticsearch.yml", data => $_es_config, } datacat { "${::elasticsearch::configdir}/elasticsearch.yml": template => "${module_name}/etc/elasticsearch/elasticsearch.yml.erb", notify => $::elasticsearch::_notify_service, require => Class['elasticsearch::package'], owner => $::elasticsearch::elasticsearch_user, group => $::elasticsearch::elasticsearch_group, mode => '0440', } - # Configure JVM options - file { "${::elasticsearch::configdir}/jvm.options": - content => template("${module_name}/etc/elasticsearch/jvm.options.erb"), - group => $::elasticsearch::elasticsearch_group, - notify => $::elasticsearch::_notify_service, - owner => $::elasticsearch::elasticsearch_user, + # Add any additional JVM options + $elasticsearch::jvm_options.each |String $jvm_option| { + file_line { "jvm_option_${jvm_option}": + ensure => present, + path => "${elasticsearch::configdir}/jvm.options", + line => $jvm_option, + notify => $::elasticsearch::_notify_service, + } } if $::elasticsearch::system_key != undef { file { "${::elasticsearch::configdir}/${::elasticsearch::security_plugin}/system_key": ensure => 'file', source => $::elasticsearch::system_key, mode => '0400', require => File["${::elasticsearch::configdir}/${::elasticsearch::security_plugin}"], } } # Add secrets to keystore if $::elasticsearch::secrets != undef { elasticsearch_keystore { 'elasticsearch_secrets': configdir => $::elasticsearch::configdir, purge => $::elasticsearch::purge_secrets, settings => $::elasticsearch::secrets, notify => $::elaticsearch::_notify_service, } } } elsif ( $elasticsearch::ensure == 'absent' ) { file { $elasticsearch::_plugindir: ensure => 'absent', force => true, backup => false, } file { "${elasticsearch::configdir}/jvm.options": ensure => 'absent', } } } diff --git a/spec/classes/000_elasticsearch_init_spec.rb b/spec/classes/000_elasticsearch_init_spec.rb index 673aca7..823c787 100644 --- a/spec/classes/000_elasticsearch_init_spec.rb +++ b/spec/classes/000_elasticsearch_init_spec.rb @@ -1,396 +1,442 @@ require 'spec_helper' describe 'elasticsearch', :type => 'class' do default_params = { :config => { 'node.name' => 'foo' } } on_supported_os.each do |os, facts| context "on #{os}" do case facts[:os]['family'] when 'Debian' let(:defaults_path) { '/etc/default' } let(:system_service_folder) { '/lib/systemd/system' } let(:pkg_ext) { 'deb' } let(:pkg_prov) { 'dpkg' } let(:version_add) { '' } if (facts[:os]['name'] == 'Debian' and \ facts[:os]['release']['major'].to_i >= 8) or \ (facts[:os]['name'] == 'Ubuntu' and \ facts[:os]['release']['major'].to_i >= 15) let(:systemd_service_path) { '/lib/systemd/system' } test_pid = true else test_pid = false end when 'RedHat' let(:defaults_path) { '/etc/sysconfig' } let(:system_service_folder) { '/lib/systemd/system' } let(:pkg_ext) { 'rpm' } let(:pkg_prov) { 'rpm' } let(:version_add) { '-1' } if facts[:os]['release']['major'].to_i >= 7 let(:systemd_service_path) { '/lib/systemd/system' } test_pid = true else test_pid = false end when 'Suse' let(:defaults_path) { '/etc/sysconfig' } let(:pkg_ext) { 'rpm' } let(:pkg_prov) { 'rpm' } let(:version_add) { '-1' } if facts[:os]['name'] == 'OpenSuSE' and facts[:os]['release']['major'].to_i <= 12 let(:systemd_service_path) { '/lib/systemd/system' } else let(:systemd_service_path) { '/usr/lib/systemd/system' } end end let(:facts) do facts.merge('scenario' => '', 'common' => '') end let(:params) do default_params.merge({}) end # Varies depending on distro it { should contain_augeas("#{defaults_path}/elasticsearch") } it do should contain_file("#{defaults_path}/elasticsearch").with( :ensure => 'file', :group => 'elasticsearch', :owner => 'elasticsearch', :mode => '0640' ) end # Systemd-specific files if test_pid == true it { should contain_service('elasticsearch').with( :ensure => 'running', :enable => true ) } it { should contain_file('/usr/lib/tmpfiles.d/elasticsearch.conf') } end context 'java installation' do let(:pre_condition) do <<-MANIFEST include ::java MANIFEST end it { should contain_class('elasticsearch::config') .that_requires('Class[java]') } end context 'package installation' do context 'via repository' do context 'with specified version' do let(:params) do default_params.merge( :version => '1.0' ) end it { should contain_package('elasticsearch') .with(:ensure => "1.0#{version_add}") } end if facts[:os]['family'] == 'RedHat' context 'Handle special CentOS/RHEL package versioning' do let(:params) do default_params.merge( :version => '1.1-2' ) end it { should contain_package('elasticsearch') .with(:ensure => '1.1-2') } end end end context 'when setting package version and package_url' do let(:params) do default_params.merge( :version => '0.90.10', :package_url => "puppet:///path/to/some/es-0.90.10.#{pkg_ext}" ) end it { expect { should raise_error(Puppet::Error) } } end context 'via package_url setting' do ['file:/', 'ftp://', 'http://', 'https://', 'puppet:///'].each do |schema| context "using #{schema} schema" do let(:params) do default_params.merge( :package_url => "#{schema}domain-or-path/pkg.#{pkg_ext}" ) end unless schema.start_with? 'puppet' it { should contain_exec('create_package_dir_elasticsearch') .with(:command => 'mkdir -p /opt/elasticsearch/swdl') } it { should contain_file('/opt/elasticsearch/swdl') .with( :purge => false, :force => false, :require => 'Exec[create_package_dir_elasticsearch]' ) } end case schema when 'file:/' it { should contain_file( "/opt/elasticsearch/swdl/pkg.#{pkg_ext}" ).with( :source => "/domain-or-path/pkg.#{pkg_ext}", :backup => false ) } when 'puppet:///' it { should contain_file( "/opt/elasticsearch/swdl/pkg.#{pkg_ext}" ).with( :source => "#{schema}domain-or-path/pkg.#{pkg_ext}", :backup => false ) } else [true, false].each do |verify_certificates| context "with download_tool_verify_certificates '#{verify_certificates}'" do let(:params) do default_params.merge( :package_url => "#{schema}domain-or-path/pkg.#{pkg_ext}", :download_tool_verify_certificates => verify_certificates ) end flag = (not verify_certificates) ? ' --no-check-certificate' : '' it { should contain_exec('download_package_elasticsearch') .with( :command => "wget#{flag} -O /opt/elasticsearch/swdl/pkg.#{pkg_ext} #{schema}domain-or-path/pkg.#{pkg_ext} 2> /dev/null", :require => 'File[/opt/elasticsearch/swdl]' ) } end end end it { should contain_package('elasticsearch') .with( :ensure => 'present', :source => "/opt/elasticsearch/swdl/pkg.#{pkg_ext}", :provider => pkg_prov ) } end end context 'using http:// schema with proxy_url' do let(:params) do default_params.merge( :package_url => "http://www.domain.com/package.#{pkg_ext}", :proxy_url => 'http://proxy.example.com:12345/' ) end it { should contain_exec('download_package_elasticsearch') .with( :environment => [ 'use_proxy=yes', 'http_proxy=http://proxy.example.com:12345/', 'https_proxy=http://proxy.example.com:12345/' ] ) } end end end # package context 'when setting the module to absent' do let(:params) do default_params.merge( :ensure => 'absent' ) end case facts[:os]['family'] when 'Suse' it { should contain_package('elasticsearch') .with(:ensure => 'absent') } else it { should contain_package('elasticsearch') .with(:ensure => 'purged') } end it { should contain_file('/usr/share/elasticsearch/plugins') .with(:ensure => 'absent') } end context 'When managing the repository' do let(:params) do default_params.merge( :manage_repo => true ) end it { should contain_class('elastic_stack::repo') } end context 'When not managing the repository' do let(:params) do default_params.merge( :manage_repo => false ) end it { should compile.with_all_deps } end end end on_supported_os( :hardwaremodels => ['x86_64'], :supported_os => [ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => ['7'] } ] ).each do |os, facts| context "on #{os}" do let(:facts) { facts.merge( :scenario => '', :common => '' ) } describe 'main class tests' do # init.pp it { should compile.with_all_deps } it { should contain_class('elasticsearch') } it { should contain_class('elasticsearch::package') } it { should contain_class('elasticsearch::config') .that_requires('Class[elasticsearch::package]') } it { should contain_class('elasticsearch::service') .that_requires('Class[elasticsearch::config]') } # Base directories it { should contain_file('/etc/elasticsearch') } it { should contain_file('/usr/share/elasticsearch') } it { should contain_file('/usr/share/elasticsearch/lib') } it { should contain_file('/var/lib/elasticsearch') } it { should contain_exec('remove_plugin_dir') } end context 'package installation' do describe 'with default package' do it { should contain_package('elasticsearch') .with(:ensure => 'present') } it { should_not contain_package('my-elasticsearch') .with(:ensure => 'present') } end describe 'with specified package name' do let(:params) do default_params.merge( :package_name => 'my-elasticsearch' ) end it { should contain_package('elasticsearch') .with(:ensure => 'present', :name => 'my-elasticsearch') } it { should_not contain_package('elasticsearch') .with(:ensure => 'present', :name => 'elasticsearch') } end describe 'with auto upgrade enabled' do let(:params) do default_params.merge( :autoupgrade => true ) end it { should contain_package('elasticsearch') .with(:ensure => 'latest') } end end describe 'running a a different user' do let(:params) do default_params.merge( :elasticsearch_user => 'myesuser', :elasticsearch_group => 'myesgroup' ) end it { should contain_file('/etc/elasticsearch') .with(:owner => 'root', :group => 'myesgroup') } it { should contain_file('/var/log/elasticsearch') .with(:owner => 'myesuser') } it { should contain_file('/usr/share/elasticsearch') .with(:owner => 'myesuser', :group => 'myesgroup') } it { should contain_file('/var/lib/elasticsearch') .with(:owner => 'myesuser', :group => 'myesgroup') } it { should contain_file('/var/run/elasticsearch') .with(:owner => 'myesuser') if facts[:os]['family'] == 'RedHat' } end + describe 'setting jvm_options' do + jvm_options = [ + '-Xms16g', + '-Xmx16g' + ] + + let(:params) do + default_params.merge( + :jvm_options => jvm_options + ) + end + + jvm_options.each do |jvm_option| + it { should contain_file_line("jvm_option_#{jvm_option}") + .with( + :ensure => 'present', + :path => '/etc/elasticsearch/jvm.options', + :line => jvm_option + )} + end + end + + context 'with restart_on_change => true' do + let(:params) do + default_params.merge( + :restart_on_change => true + ) + end + + describe 'should restart elasticsearch' do + it { should contain_file('/etc/elasticsearch/elasticsearch.yml') + .that_notifies('Service[elasticsearch]')} + end + + describe 'setting jvm_options triggers restart' do + let(:params) do + super().merge( + :jvm_options => ['-Xmx16g'] + ) + end + + it { should contain_file_line('jvm_option_-Xmx16g') + .that_notifies('Service[elasticsearch]')} + end + end + # This check helps catch dependency cycles. context 'create_resource' do # Helper for these tests def singular(s) case s when 'indices' 'index' when 'snapshot_repositories' 'snapshot_repository' else s[0..-2] end end { 'indices' => { 'test-index' => {} }, # 'instances' => { 'es-instance' => {} }, 'pipelines' => { 'testpipeline' => { 'content' => {} } }, 'plugins' => { 'head' => {} }, 'roles' => { 'elastic_role' => {} }, 'scripts' => { 'foo' => { 'source' => 'puppet:///path/to/foo.groovy' } }, 'snapshot_repositories' => { 'backup' => { 'location' => '/backups' } }, 'templates' => { 'foo' => { 'content' => {} } }, 'users' => { 'elastic' => { 'password' => 'foobar' } } }.each_pair do |deftype, params| describe deftype do let(:params) do default_params.merge( deftype => params ) end it { should compile } it { should send( "contain_elasticsearch__#{singular(deftype)}", params.keys.first ) } end end end describe 'oss' do let(:params) do default_params.merge(:oss => true) end it do should contain_package('elasticsearch').with( :name => 'elasticsearch-oss' ) end end end end end diff --git a/spec/classes/001_hiera_spec.rb b/spec/classes/001_hiera_spec.rb index 59484db..d48ba1b 100644 --- a/spec/classes/001_hiera_spec.rb +++ b/spec/classes/001_hiera_spec.rb @@ -1,217 +1,217 @@ require 'spec_helper' describe 'elasticsearch', :type => 'class' do default_params = { :config => { 'node.name' => 'foo' } } let(:params) do default_params.merge({}) end on_supported_os( :hardwaremodels => ['x86_64'], :supported_os => [ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => ['7'] } ] ).each do |os, facts| context "on #{os}" do context 'hiera' do describe 'indices' do context 'single indices' do let(:facts) { facts.merge(:scenario => 'singleindex') } it { should contain_elasticsearch__index('baz') .with( :ensure => 'present', :settings => { 'index' => { 'number_of_shards' => 1 } } ) } it { should contain_elasticsearch_index('baz') } it { should contain_es_instance_conn_validator( 'baz-index-conn-validator' ) } end context 'no indices' do let(:facts) { facts.merge(:scenario => '') } it { should_not contain_elasticsearch__index('baz') } end end context 'config' do let(:facts) { facts.merge(:scenario => 'singleinstance') } # TODO: Fix this # it { should contain_augeas('defaults') } it { should contain_datacat('/etc/elasticsearch/elasticsearch.yml') } it { should contain_datacat_fragment('main_config') } it { should contain_service('elasticsearch').with( :ensure => 'running', :enable => true ) } - %w[elasticsearch.yml jvm.options log4j2.properties].each do |file| + %w[elasticsearch.yml log4j2.properties].each do |file| it { should contain_file("/etc/elasticsearch/#{file}") } end end # of config describe 'pipelines' do context 'single pipeline' do let(:facts) { facts.merge(:scenario => 'singlepipeline') } it { should contain_elasticsearch__pipeline('testpipeline') .with( :ensure => 'present', :content => { 'description' => 'Add the foo field', 'processors' => [ { 'set' => { 'field' => 'foo', 'value' => 'bar' } } ] } ) } it { should contain_elasticsearch_pipeline('testpipeline') } end context 'no pipelines' do let(:facts) { facts.merge(:scenario => '') } it { should_not contain_elasticsearch__pipeline('testpipeline') } end end describe 'plugins' do context 'single plugin' do let(:facts) { facts.merge(:scenario => 'singleplugin') } it { should contain_elasticsearch__plugin('mobz/elasticsearch-head') .with( :ensure => 'present', :module_dir => 'head' ) } it { should contain_elasticsearch_plugin('mobz/elasticsearch-head') } end context 'no plugins' do let(:facts) { facts.merge(:scenario => '') } it { should_not contain_elasticsearch__plugin( 'mobz/elasticsearch-head/1.0.0' ) } end end describe 'roles' do context 'single roles' do let(:facts) { facts.merge(:scenario => 'singlerole') } let(:params) do default_params end it { should contain_elasticsearch__role('admin') .with( :ensure => 'present', :privileges => { 'cluster' => 'monitor', 'indices' => { '*' => 'all' } }, :mappings => [ 'cn=users,dc=example,dc=com' ] ) } it { should contain_elasticsearch_role('admin') } it { should contain_elasticsearch_role_mapping('admin') } end context 'no roles' do let(:facts) { facts.merge(:scenario => '') } it { should_not contain_elasticsearch__role('admin') } end end describe 'scripts' do context 'single scripts' do let(:facts) { facts.merge(:scenario => 'singlescript') } it { should contain_elasticsearch__script('myscript') .with( :ensure => 'present', :source => 'puppet:///file/here' ) } it { should contain_file('/usr/share/elasticsearch/scripts/here') } end context 'no roles' do let(:facts) { facts.merge(:scenario => '') } it { should_not contain_elasticsearch__script('myscript') } end end describe 'templates' do context 'single template' do let(:facts) { facts.merge(:scenario => 'singletemplate') } it { should contain_elasticsearch__template('foo') .with( :ensure => 'present', :content => { 'template' => 'foo-*', 'settings' => { 'index' => { 'number_of_replicas' => 0 } } } ) } it { should contain_elasticsearch_template('foo') } end context 'no templates' do let(:facts) { facts.merge(:scenario => '') } it { should_not contain_elasticsearch__template('foo') } end end describe 'users' do context 'single users' do let(:facts) { facts.merge(:scenario => 'singleuser') } let(:params) do default_params end it { should contain_elasticsearch__user('elastic') .with( :ensure => 'present', :roles => ['admin'], :password => 'password' ) } it { should contain_elasticsearch_user('elastic') } end context 'no users' do let(:facts) { facts.merge(:scenario => '') } it { should_not contain_elasticsearch__user('elastic') } end end end end end end diff --git a/spec/helpers/class_shared_examples.rb b/spec/helpers/class_shared_examples.rb index 3d389b0..e8cdc58 100644 --- a/spec/helpers/class_shared_examples.rb +++ b/spec/helpers/class_shared_examples.rb @@ -1,22 +1,22 @@ shared_examples 'class' do |init| it { should compile.with_all_deps } # it { should contain_augeas('defaults') } it { should contain_datacat('/etc/elasticsearch/elasticsearch.yml') } it { should contain_datacat_fragment('main_config') } it { should contain_service('elasticsearch') } - %w[elasticsearch.yml jvm.options log4j2.properties].each do |file| + %w[elasticsearch.yml log4j2.properties].each do |file| it { should contain_file("/etc/elasticsearch/#{file}") } end case init when :sysv # it { should contain_elasticsearch__service__init(name) } # it { should contain_elasticsearch_service_file("/etc/init.d/elasticsearch-#{name}") } # it { should contain_file('/etc/init.d/elasticsearch') } when :systemd # it { should contain_elasticsearch__service__systemd(name) } # it { should contain_file('/lib/systemd/system/elasticsearch.service') } # it { should contain_exec('systemd_reload') } end end diff --git a/spec/templates/002_jvm.options.erb_spec.rb b/spec/templates/002_jvm.options.erb_spec.rb deleted file mode 100644 index 83543b1..0000000 --- a/spec/templates/002_jvm.options.erb_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'spec_helper' -require 'yaml' - -describe 'jvm.options.erb' do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - before(:each) do - allow(scope).to receive(:lookupvar).with('elasticsearch::logdir', {}).and_return('/var/log/elasticsearch') - end - - let(:template) { 'templates/etc/elasticsearch/jvm.options.erb' } - - it 'render the same string each time' do - harness = TemplateHarness.new(template, scope) - allow(scope).to receive(:lookupvar).with('elasticsearch::jvm_options', {}).and_return([]) - - first_render = harness.run - second_render = harness.run - - expect(first_render).to eq(second_render) - end - - it 'removes overriden default values' do - harness = TemplateHarness.new(template, scope) - allow(scope).to receive(:lookupvar).with('elasticsearch::jvm_options', {}) - .and_return(['-Xms12g', '-Xmx12g']) - - first_render = harness.run - second_render = harness.run - - expect(first_render).to eq(second_render) - - expect(first_render).to_not match(/-Xms2g.*-Xmx2g/m) - expect(first_render).to match(/-Xms12g.*-Xmx12g/m) - end -end diff --git a/templates/etc/elasticsearch/jvm.options.erb b/templates/etc/elasticsearch/jvm.options.erb deleted file mode 100644 index 43cf6b8..0000000 --- a/templates/etc/elasticsearch/jvm.options.erb +++ /dev/null @@ -1,42 +0,0 @@ -# This file is managed by Puppet -- <%= @name %> -# -# Set the 'jvm_options' parameter on the elasticsearch class to change this file. -<% -def set_default(options, match_string, default) - options.detect {|o| o.include?(match_string)} || options.push(default) -end - -defaults = { - '-Xms' => '-Xms2g', - '-Xmx' => '-Xmx2g', - 'UseConcMarkSweepGC' => '-XX:+UseConcMarkSweepGC', - 'CMSInitiatingOccupancyFraction=' => '-XX:CMSInitiatingOccupancyFraction=75', - 'UseCMSInitiatingOccupancyOnly' => '-XX:+UseCMSInitiatingOccupancyOnly', - 'AlwaysPreTouch' => '-XX:+AlwaysPreTouch', - 'server' => '-server', - '-Xss' => '-Xss1m', - '-Djava.awt.headless=' => '-Djava.awt.headless=true', - '-Dfile.encoding=' => '-Dfile.encoding=UTF-8', - '-Djna.nosys=' => '-Djna.nosys=true', - 'OmitStackTraceInFastThrow' => '-XX:-OmitStackTraceInFastThrow', - '-Dio.netty.noUnsafe' => '-Dio.netty.noUnsafe=true', - '-Dio.netty.noKeySetOptimization' => '-Dio.netty.noKeySetOptimization=true', - '-Dio.netty.recycler.maxCapacityPerThread' => '-Dio.netty.recycler.maxCapacityPerThread=0', - '-Dlog4j.shutdownHookEnabled' => '-Dlog4j.shutdownHookEnabled=false', - '-Dlog4j2.disable.jmx' => '-Dlog4j2.disable.jmx=true', - 'HeapDumpOnOutOfMemoryError' => '-XX:+HeapDumpOnOutOfMemoryError', - 'PrintGCDetails' => '-XX:+PrintGCDetails', - 'PrintGCDateStamps' => '-XX:+PrintGCDateStamps', - 'PrintTenuringDistribution' => '-XX:+PrintTenuringDistribution', - 'Xloggc' => "-Xloggc:#{scope['elasticsearch::logdir']}/gc.log", - 'UseGCLogFileRotation' => '-XX:+UseGCLogFileRotation', - 'NumberOfGCLogFiles' => '-XX:NumberOfGCLogFiles=32', - 'GCLogFileSize' => '-XX:GCLogFileSize=64m', -} -defaults.each {|k,v| set_default(scope['elasticsearch::jvm_options'], k, v)} - --%> - -<% scope['elasticsearch::jvm_options'].sort.each do |line| -%> -<%= line %> -<% end -%>