diff --git a/manifests/config.pp b/manifests/config.pp index fd72a3a..2fe00d5 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -1,253 +1,260 @@ # 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, } } # 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 } if $elasticsearch::security_plugin == 'shield' { $_tls_config = { 'shield.transport.ssl' => true, 'shield.http.ssl' => true, 'shield.ssl.keystore.path' => $_keystore_path, 'shield.ssl.keystore.password' => $elasticsearch::keystore_password, } } elsif $elasticsearch::security_plugin == 'x-pack' { $_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'] + 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_${name}": + 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, + } + if $::elasticsearch::system_key != undef { file { "${::elasticsearch::configdir}/${::elasticsearch::security_plugin}/system_key": ensure => 'file', source => $::elasticsearch::system_key, mode => '0400', - before => Elasticsearch::Service[$::elasticsearch::service_name], 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 6356e2e..cbeb1f3 100644 --- a/spec/classes/000_elasticsearch_init_spec.rb +++ b/spec/classes/000_elasticsearch_init_spec.rb @@ -1,405 +1,397 @@ 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 => false).with(:enable => 'mask') } + 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 => '' ) } context '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/templates_import') } - it { should contain_file('/usr/share/elasticsearch/scripts') } 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') } - - # file removal from package - it { should contain_file('/etc/elasticsearch/elasticsearch.yml') - .with(:ensure => 'absent') } - it { should contain_file('/etc/elasticsearch/jvm.options') - .with(:ensure => 'absent') } - it { should contain_file('/etc/elasticsearch/logging.yml') - .with(:ensure => 'absent') } - it { should contain_file('/etc/elasticsearch/log4j2.properties') - .with(:ensure => 'absent') } - it { should contain_file('/etc/elasticsearch/log4j2.properties') - .with(:ensure => 'absent') } end context 'package installation' do context 'with default package' do it { should contain_package('elasticsearch') .with(:ensure => 'present') } it { should_not contain_package('my-elasticsearch') .with(:ensure => 'present') } end context '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 context 'with auto upgrade enabled' do let(:params) do default_params.merge( :autoupgrade => true ) end it { should contain_package('elasticsearch') .with(:ensure => 'latest') } end end context '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 # 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' => {} }, + # '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, :security_plugin => 'x-pack' ) 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 499838d..984d8ac 100644 --- a/spec/classes/001_hiera_spec.rb +++ b/spec/classes/001_hiera_spec.rb @@ -1,235 +1,256 @@ 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 - describe 'instances' do - context 'single instance' do - let(:facts) { facts.merge(:scenario => 'singleinstance') } - - include_examples 'instance', 'es-hiera-single', :systemd - end - - context 'multiple instances' do - let(:facts) { facts.merge(:scenario => 'multipleinstances') } - - include_examples 'instance', 'es-hiera-multiple-1', :systemd - include_examples 'instance', 'es-hiera-multiple-2', :systemd + context 'config' do + let(:facts) { facts.merge(:scenario => 'singleinstance') } + + 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| + it { should contain_file("/etc/elasticsearch/#{file}") } end - context 'no instances' do - let(:facts) { facts.merge(:scenario => '') } - - it { should_not contain_elasticsearch__instance('es-hiera-multiple-1') } - it { should_not contain_elasticsearch__instance('es-hiera-multiple-2') } - end - - context 'multiple instances using lookup_options' do - let(:facts) do - facts.merge( - :common => 'defaultinstance-merged', - :scenario => 'singleinstance' - ) - end - - include_examples 'instance', 'default', :systemd - include_examples 'instance', 'es-hiera-single', :systemd - end - end # of instances + # 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-#{name}") } + # when :systemd + # it { should contain_elasticsearch__service__systemd(name) } + # it { should contain_elasticsearch_service_file("/lib/systemd/system/elasticsearch-#{name}.service") } + # it { should contain_file("/lib/systemd/system/elasticsearch-#{name}.service") } + # it { should contain_exec("systemd_reload_#{name}") } + # end + + + # context 'multiple instances' do + # let(:facts) { facts.merge(:scenario => 'multipleinstances') } + + # include_examples 'instance', 'es-hiera-multiple-1', :systemd + # include_examples 'instance', 'es-hiera-multiple-2', :systemd + # end + + # context 'no instances' do + # let(:facts) { facts.merge(:scenario => '') } + + # it { should_not contain_elasticsearch__instance('es-hiera-multiple-1') } + # it { should_not contain_elasticsearch__instance('es-hiera-multiple-2') } + # end + + # context 'multiple instances using lookup_options' do + # let(:facts) do + # facts.merge( + # :common => 'defaultinstance-merged', + # :scenario => 'singleinstance' + # ) + # end + + # include_examples 'instance', 'default', :systemd + # include_examples 'instance', 'es-hiera-single', :systemd + # 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', :instances => ['es-hiera-single'] ) } 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.merge(:security_plugin => 'x-pack') 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.merge(:security_plugin => 'x-pack') 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/defines/005_elasticsearch_instance_spec.rb b/spec/defines/005_elasticsearch_instance_spec.rb deleted file mode 100644 index 57a1d93..0000000 --- a/spec/defines/005_elasticsearch_instance_spec.rb +++ /dev/null @@ -1,942 +0,0 @@ -require 'spec_helper' - -describe 'elasticsearch::instance', :type => 'define' do - let(:title) { 'es-instance' } - let(:pre_condition) { 'class { "elasticsearch": }' } - - on_supported_os.each do |os, facts| - context "on #{os}" do - shared_examples 'systemd' do - it { should contain_elasticsearch__service__systemd(title) } - it { should contain_elasticsearch_service_file("#{systemd_service_path}/elasticsearch-#{title}.service") } - it { should contain_file("#{systemd_service_path}/elasticsearch-#{title}.service") } - it { should contain_exec("systemd_reload_#{title}") } - end - - shared_examples 'init' do - it { should contain_elasticsearch__service__init(title) } - it { should contain_elasticsearch_service_file("/etc/init.d/elasticsearch-#{title}") } - it { should contain_file("/etc/init.d/elasticsearch-#{title}") } - end - - if (facts[:os]['name'] == 'OpenSuSE' and facts[:os]['release']['major'].to_i >= 13) or facts[:os]['name'] == 'SLES' - let(:systemd_service_path) { '/usr/lib/systemd/system' } - else - let(:systemd_service_path) { '/lib/systemd/system' } - end - - case facts[:os]['family'] - when 'Debian' - let(:defaults_path) { '/etc/default' } - let(:pkg_ext) { 'deb' } - let(:pkg_prov) { 'dpkg' } - case facts[:os]['name'] - when 'Debian' - if facts[:os]['release']['major'].to_i >= 8 - let(:initscript) { 'systemd' } - - include_examples 'systemd' - else - let(:initscript) { 'Debian' } - - include_examples 'init' - end - when 'Ubuntu' - if facts[:os]['release']['major'].to_i >= 15 - let(:initscript) { 'systemd' } - - include_examples 'systemd' - else - let(:initscript) { 'Debian' } - - include_examples 'init' - end - end - when 'RedHat' - let(:defaults_path) { '/etc/sysconfig' } - let(:pkg_ext) { 'rpm' } - let(:pkg_prov) { 'rpm' } - if facts[:os]['release']['major'].to_i >= 7 - let(:initscript) { 'systemd' } - - include_examples 'systemd' - else - let(:initscript) { 'RedHat' } - - include_examples 'init' - end - when 'Suse' - let(:defaults_path) { '/etc/sysconfig' } - let(:pkg_ext) { 'rpm' } - let(:pkg_prov) { 'rpm' } - let(:initscript) { 'systemd' } - - include_examples 'systemd' - end - - let(:facts) do - facts.merge('scenario' => '', 'common' => '') - end - - it { should contain_elasticsearch__service( - 'es-instance' - ).with( - :init_template => - "elasticsearch/etc/init.d/elasticsearch.#{initscript}.erb", - :init_defaults => { - 'CONF_DIR' => '/etc/elasticsearch/es-instance', - 'ES_PATH_CONF' => '/etc/elasticsearch/es-instance', - 'DATA_DIR' => '/var/lib/elasticsearch', - 'ES_JVM_OPTIONS' => '/etc/elasticsearch/es-instance/jvm.options', - 'LOG_DIR' => '/var/log/elasticsearch/es-instance', - 'ES_HOME' => '/usr/share/elasticsearch' - } - )} - end # of on os context - end # of on supported OSes loop - - # Test all non OS-specific functionality with just a single distro - on_supported_os( - :hardwaremodels => ['x86_64'], - :supported_os => [ - { - 'operatingsystem' => 'CentOS', - 'operatingsystemrelease' => ['6'] - } - ] - ).each do |os, facts| - context "on #{os}" do - let(:facts) { facts.merge( - :scenario => '', - :common => '' - ) } - - let(:params) do - { :config => { 'node' => { 'name' => 'test' } } } - end - - describe 'config file' do - it { should contain_augeas('defaults_es-instance') } - it { should contain_datacat_fragment('main_config_es-instance') } - it { should contain_datacat('/etc/elasticsearch/es-instance/elasticsearch.yml') } - it { should contain_datacat_collector( - '/etc/elasticsearch/es-instance/elasticsearch.yml' - ) } - it { should contain_file('/etc/elasticsearch/es-instance/elasticsearch.yml') } - end - - describe 'service restarts' do - context 'do not happen when restart_on_change is false (default)' do - it { should_not contain_datacat( - '/etc/elasticsearch/es-instance/elasticsearch.yml' - ).that_notifies('Elasticsearch::Service[es-instance]') } - it { should_not contain_file( - '/etc/elasticsearch/es-instance/jvm.options' - ).that_notifies('Elasticsearch::Service[es-instance]') } - it { should_not contain_package( - 'elasticsearch' - ).that_notifies('Elasticsearch::Service[es-instance]') } - end - - context 'happen when restart_on_change is true' do - let(:pre_condition) do - 'class { "elasticsearch": restart_on_change => true }' - end - - it { should contain_datacat( - '/etc/elasticsearch/es-instance/elasticsearch.yml' - ).that_notifies('Elasticsearch::Service[es-instance]') } - it { should contain_file( - '/etc/elasticsearch/es-instance/jvm.options' - ).that_notifies('Elasticsearch::Service[es-instance]') } - it { should contain_package( - 'elasticsearch' - ).that_notifies('Elasticsearch::Service[es-instance]') } - end - - context 'on package change' do - let(:pre_condition) do - 'class { "elasticsearch": restart_package_change => true }' - end - - it { should_not contain_datacat( - '/etc/elasticsearch/es-instance/elasticsearch.yml' - ).that_notifies('Elasticsearch::Service[es-instance]') } - it { should contain_package( - 'elasticsearch' - ).that_notifies('Elasticsearch::Service[es-instance]') } - end - - context 'on config change' do - let(:pre_condition) do - 'class { "elasticsearch": restart_config_change => true }' - end - - it { should contain_datacat( - '/etc/elasticsearch/es-instance/elasticsearch.yml' - ).that_notifies('Elasticsearch::Service[es-instance]') } - it { should contain_file( - '/etc/elasticsearch/es-instance/jvm.options' - ).that_notifies('Elasticsearch::Service[es-instance]') } - it { should_not contain_package( - 'elasticsearch' - ).that_notifies('Elasticsearch::Service[es-instance]') } - end - end - - context 'config dir' do - context 'default' do - it { should contain_exec('mkdir_configdir_elasticsearch_es-instance') } - it { should contain_file('/etc/elasticsearch/es-instance').with(:ensure => 'directory') } - it { should contain_datacat_fragment('main_config_es-instance') } - it { should contain_datacat('/etc/elasticsearch/es-instance/elasticsearch.yml') } - - it { should contain_file('/etc/elasticsearch/es-instance/logging.yml') } - it { should contain_file('/etc/elasticsearch/es-instance/log4j2.properties') } - it { should contain_file('/etc/elasticsearch/es-instance/jvm.options') } - it { should contain_file('/usr/share/elasticsearch/scripts') } - it do - should contain_file('/etc/elasticsearch/es-instance').with( - :source => '/etc/elasticsearch' - ) - end - end - - context 'set in main class' do - let(:pre_condition) { <<-EOS - class { "elasticsearch": - configdir => "/etc/elasticsearch-config" - } - EOS - } - - it { should contain_exec('mkdir_configdir_elasticsearch_es-instance') } - it { should contain_file('/etc/elasticsearch-config').with(:ensure => 'directory') } - it { should contain_file('/usr/share/elasticsearch/templates_import').with(:ensure => 'directory') } - it { should contain_file('/etc/elasticsearch-config/es-instance').with(:ensure => 'directory') } - it { should contain_datacat_fragment('main_config_es-instance') } - it { should contain_datacat('/etc/elasticsearch-config/es-instance/elasticsearch.yml') } - - it { should contain_file('/etc/elasticsearch-config/es-instance/jvm.options') } - it { should contain_file('/etc/elasticsearch-config/es-instance/logging.yml') } - it { should contain_file('/etc/elasticsearch-config/es-instance/log4j2.properties') } - it { should contain_file('/usr/share/elasticsearch/scripts') } - it do - should contain_file('/etc/elasticsearch-config/scripts').with( - :source => '/usr/share/elasticsearch/scripts' - ) - end - it do - should contain_file('/etc/elasticsearch-config/es-instance').with( - :source => '/etc/elasticsearch-config' - ) - end - end - - context 'set in instance' do - let(:params) do { - :configdir => '/etc/elasticsearch-config/es-instance' - } end - - it { should contain_exec('mkdir_configdir_elasticsearch_es-instance') } - it { should contain_file('/etc/elasticsearch').with(:ensure => 'directory') } - it { should contain_file('/etc/elasticsearch-config/es-instance').with(:ensure => 'directory') } - it { should contain_datacat_fragment('main_config_es-instance') } - it { should contain_datacat('/etc/elasticsearch-config/es-instance/elasticsearch.yml') } - - it { should contain_file('/etc/elasticsearch-config/es-instance/jvm.options') } - it { should contain_file('/etc/elasticsearch-config/es-instance/logging.yml') } - it { should contain_file('/etc/elasticsearch-config/es-instance/log4j2.properties') } - it { should contain_file('/usr/share/elasticsearch/scripts') } - it do - should contain_file('/etc/elasticsearch/scripts').with( - :source => '/usr/share/elasticsearch/scripts' - ) - end - it do - should contain_file('/etc/elasticsearch-config/es-instance').with( - :source => '/etc/elasticsearch' - ) - end - end - end - - context 'data directory' do - shared_examples 'data directories' do |data_dirs| - data_dirs.each do |dir| - it { should contain_exec('mkdir_logdir_elasticsearch_es-instance') } - it { should contain_exec('mkdir_datadir_elasticsearch_es-instance') } - it { should contain_file("/var/lib/#{dir}").with(:ensure => 'directory') } - end - end - - context 'default' do - include_examples 'data directories', ['elasticsearch'] - end - - context 'datadir_instance_directories' do - let(:pre_condition) do - <<-EOS - class { "elasticsearch": - datadir_instance_directories => false - } - EOS - end - - it { should contain_exec('mkdir_logdir_elasticsearch_es-instance') } - it { should_not contain_exec('mkdir_datadir_elasticsearch_es-instance') } - it { should_not contain_file('/var/lib/elasticsearch/es-instance').with(:ensure => 'directory') } - it { should contain_file('/var/lib/elasticsearch').with(:ensure => 'directory') } - end - - context 'single from main config ' do - let(:pre_condition) { <<-EOS - class { "elasticsearch": - datadir => "/var/lib/elasticsearch-data" - } - EOS - } - - include_examples 'data directories', - ['elasticsearch-data', 'elasticsearch-data/es-instance'] - end - - context 'single from instance config' do - let(:params) do { - :datadir => '/var/lib/elasticsearch/data' - } end - - include_examples 'data directories', ['elasticsearch/data'] - end - - context 'multiple from main config' do - let(:pre_condition) { <<-EOS - class { "elasticsearch": - datadir => [ - "/var/lib/elasticsearch-data01", - "/var/lib/elasticsearch-data02" - ] - } - EOS - } - - include_examples( - 'data directories', - (1..2).map do |n| - dir = "elasticsearch-data#{n.to_s.rjust(2, '0')}" - [dir, "#{dir}/es-instance"] - end.flatten - ) - end - - context 'multiple from instance config' do - let(:params) do { - :datadir => [ - '/var/lib/elasticsearch-data/01', - '/var/lib/elasticsearch-data/02' - ] - } end - - include_examples( - 'data directories', - (1..2).map { |n| "elasticsearch-data/#{n.to_s.rjust(2, '0')}" } - ) - end - - context 'conflicting setting path.data' do - let(:params) do { - :datadir => '/var/lib/elasticsearch/data', - :config => { 'path.data' => '/var/lib/elasticsearch/otherdata' } - } end - - include_examples 'data directories', ['elasticsearch/data'] - it { should_not contain_file('/var/lib/elasticsearch/otherdata').with(:ensure => 'directory') } - end - - context 'conflicting setting path => data' do - let(:params) do { - :datadir => '/var/lib/elasticsearch/data', - :config => { - 'path' => { 'data' => '/var/lib/elasticsearch/otherdata' } - } - } end - - include_examples 'data directories', ['elasticsearch/data'] - it { should_not contain_file('/var/lib/elasticsearch/otherdata').with(:ensure => 'directory') } - end - - context 'with other path options defined' do - let(:params) do { - :datadir => '/var/lib/elasticsearch/data', - :config => { 'path' => { 'home' => '/var/lib/elasticsearch' } } - } end - - include_examples 'data directories', ['elasticsearch/data'] - end - end - - context 'logs directory' do - context 'default' do - it { should contain_file('/var/log/elasticsearch/es-instance') - .with(:ensure => 'directory') } - it { should contain_file('/var/log/elasticsearch') - .with(:ensure => 'directory') } - end - - context 'single from main config ' do - let(:pre_condition) { <<-EOS - class { "elasticsearch": - logdir => "/var/log/elasticsearch-logs" - } - EOS - } - - it { should contain_file('/var/log/elasticsearch-logs') - .with(:ensure => 'directory') } - it { should contain_file('/var/log/elasticsearch-logs/es-instance') - .with(:ensure => 'directory') } - end - - context 'single from instance config' do - let(:params) do { - :logdir => '/var/log/elasticsearch/logs-a' - } end - - it { should contain_file('/var/log/elasticsearch/logs-a').with(:ensure => 'directory') } - end - - context 'Conflicting setting path.logs' do - let(:params) do { - :logdir => '/var/log/elasticsearch/logs-a', - :config => { 'path.logs' => '/var/log/elasticsearch/otherlogs' } - } end - - it { should contain_file('/var/log/elasticsearch/logs-a') - .with(:ensure => 'directory') } - it { should_not contain_file('/var/log/elasticsearch/otherlogs') - .with(:ensure => 'directory') } - end - - context 'Conflicting setting path => logs' do - let(:params) do { - :logdir => '/var/log/elasticsearch/logs-a', - :config => { 'path' => { 'logs' => '/var/log/elasticsearch/otherlogs' } } - } end - - it { should contain_file('/var/log/elasticsearch/logs-a') - .with(:ensure => 'directory') } - it { should_not contain_file('/var/log/elasticsearch/otherlogs') - .with(:ensure => 'directory') } - end - - context 'With other path options defined' do - let(:params) do { - :logdir => '/var/log/elasticsearch/logs-a', - :config => { 'path' => { 'home' => '/var/log/elasticsearch' } } - } end - - it { should contain_file('/var/log/elasticsearch/logs-a').with(:ensure => 'directory') } - end - end - - context 'logging' do - context 'default' do - it { should contain_file('/etc/elasticsearch/es-instance/logging.yml') - .with_content( - /^logger.index.search.slowlog: TRACE, index_search_slow_log_file$/, - /type: dailyRollingFile/, - /datePattern: "'.'yyyy-MM-dd"/ - ).with(:source => nil) - } - end - - context 'from main class' do - context 'config' do - let(:pre_condition) { <<-EOS - class { "elasticsearch": - logging_config => { - "index.search.slowlog" => "DEBUG, index_search_slow_log_file" - } - } - EOS - } - - it 'writes correct yaml' do - should contain_file('/etc/elasticsearch/es-instance/logging.yml') - .with_content( - /^logger.index.search.slowlog: DEBUG, index_search_slow_log_file$/ - ).with(:source => nil) - end - end - - context 'logging file ' do - let(:pre_condition) { <<-EOS - class { "elasticsearch": - logging_file => "puppet:///path/to/logging.yml" - } - EOS - } - - it 'sets the right source' do - should contain_file('/etc/elasticsearch/es-instance/logging.yml') - .with( - :source => 'puppet:///path/to/logging.yml', - :content => nil - ) - end - end - end - - context 'from instance' do - context 'config' do - let(:params) do { - :logging_config => { - 'index.search.slowlog' => 'INFO, index_search_slow_log_file' - } - } end - - it 'writes correct yaml' do - should contain_file('/etc/elasticsearch/es-instance/logging.yml') - .with_content(/^logger.index.search.slowlog: INFO, index_search_slow_log_file$/) - .with(:source => nil) - end - end - - context 'logging file' do - let(:params) do { - :logging_file => 'puppet:///path/to/logging.yml' - } end - - it 'sets the right source' do - should contain_file('/etc/elasticsearch/es-instance/logging.yml') - .with( - :source => 'puppet:///path/to/logging.yml', - :content => nil - ) - end - end - - context 'deprecation logging' do - let(:params) do { - :deprecation_logging => true - } end - - it 'writes correct yaml' do - should contain_file('/etc/elasticsearch/es-instance/logging.yml') - .with_content(/^logger.deprecation: DEBUG, deprecation_log_file$/) - .with(:source => nil) - end - it 'configures the deprecation log' do - should contain_file('/etc/elasticsearch/es-instance/logging.yml') - .with_content( - /deprecation_log_file:$/, - /type: dailyRollingFile$/, - %r(file: ${path.logs}/${cluster.name}_deprecation.log$), - /datePattern: "'.'yyyy-MM-dd"$/, - /layout:$/, - /type: pattern$/, - /conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n"$/ - ).with(:source => nil) - end - end - - context 'deprecation logging level' do - let(:params) do { - :deprecation_logging => true, - :deprecation_logging_level => 'INFO' - } end - - it 'writes correct yaml' do - should contain_file('/etc/elasticsearch/es-instance/logging.yml') - .with_content(/^logger.deprecation: INFO, deprecation_log_file$/) - .with(:source => nil) - end - end - end - - describe 'rollingFile apender' do - let(:pre_condition) do - %( - class { 'elasticsearch': - file_rolling_type => 'rollingFile', - rolling_file_max_backup_index => 10, - rolling_file_max_file_size => '100MB', - } - ) - end - - it { should contain_file('/etc/elasticsearch/es-instance/logging.yml') - .with_content( - /type: rollingFile/, - /maxBackupIndex: 10/, - /maxBackupIndex: 10/, - /maxFileSize: 100MB/ - ) - } - end - end - - shared_examples 'file permissions' do |owner, group| - it { should contain_file('/var/lib/elasticsearch/es-instance') - .with(:owner => owner) } - it { should contain_file('/etc/elasticsearch/es-instance') - .with( - :owner => owner, - :group => group - ) } - it { should contain_datacat('/etc/elasticsearch/es-instance/elasticsearch.yml') - .with( - :owner => owner, - :group => group, - :mode => '0440' - ) } - it { should contain_file('/etc/elasticsearch/es-instance/elasticsearch.yml') - .with( - :owner => owner, - :group => group, - :mode => '0440' - ) } - it { should contain_file('/etc/elasticsearch/es-instance/logging.yml') - .with( - :owner => owner, - :group => group, - :mode => '0644' - ) } - it { should contain_file('/etc/elasticsearch/es-instance/log4j2.properties') - .with( - :owner => owner, - :group => group, - :mode => '0644' - ) } - - it { should contain_file('/var/lib/elasticsearch/es-instance') - .with( - :owner => owner, - :group => nil, - :mode => '0755' - ) } - it { should contain_file('/var/log/elasticsearch/es-instance') - .with( - :owner => owner, - :group => group, - :mode => '0750' - ) } - end - - describe 'default file permissions' do - let(:pre_condition) { ' class { "elasticsearch":} ' } - - include_examples 'file permissions', 'elasticsearch', 'elasticsearch' - end - - context 'running as an other user' do - let(:pre_condition) { <<-EOS - class { "elasticsearch": - elasticsearch_user => "myesuser", - elasticsearch_group => "myesgroup" - } - EOS - } - - include_examples 'file permissions', 'myesuser', 'myesgroup' - end - - context 'setting different service status then main class' do - let(:pre_condition) { 'class {"elasticsearch": status => "enabled" }' } - - context 'status option' do - let(:params) do { - :status => 'running' - } end - - it { should contain_service('elasticsearch-instance-es-instance').with(:ensure => 'running', :enable => false) } - end - end - - context 'init_template' do - context 'default' do - it { should contain_elasticsearch__service('es-instance') - .with(:init_template => 'elasticsearch/etc/init.d/elasticsearch.RedHat.erb') } - end - - context 'override in main class' do - let(:pre_condition) { <<-EOS - class { "elasticsearch": - init_template => "elasticsearch/etc/init.d/elasticsearch.systemd.erb" - } - EOS - } - - it { should contain_elasticsearch__service('es-instance') - .with(:init_template => 'elasticsearch/etc/init.d/elasticsearch.systemd.erb') } - end - end - - describe 'security plugins' do - describe 'system_key' do - context 'inherited' do - let(:pre_condition) do - %( - class { 'elasticsearch': - security_plugin => 'shield', - system_key => '/tmp/key' - } - ) - end - - it { should contain_file('/etc/elasticsearch/es-instance/shield') } - it { should contain_file( - '/etc/elasticsearch/es-instance/shield/system_key' - ).with( - :source => '/tmp/key', - :mode => '0400', - :owner => 'elasticsearch' - ) } - end - - context 'from instance' do - let(:pre_condition) { "class { 'elasticsearch': security_plugin => 'x-pack' }" } - - let(:params) do { - :system_key => 'puppet:///test/key' - } end - - it { should contain_file('/etc/elasticsearch/es-instance/x-pack') } - it { should contain_file( - '/etc/elasticsearch/es-instance/x-pack/system_key' - ).with( - :source => 'puppet:///test/key', - :mode => '0400', - :owner => 'elasticsearch' - ) } - end - end - end - - describe 'recursive configuration directory management' do - ['shield', 'x-pack'].each do |plugin| - context 'shield' do - context 'without resource notifications' do - let(:pre_condition) do - %( - class { 'elasticsearch': - security_plugin => '#{plugin}', - } - ) - end - - it "copies the #{plugin} directory from the source" do - should( - contain_file( - "/etc/elasticsearch/es-instance/#{plugin}" - ).with( - :ensure => 'directory', - :mode => '0750', - :source => "/etc/elasticsearch/#{plugin}", - :recurse => 'remote', - :owner => 'root', - :group => 'elasticsearch', - :before => 'Elasticsearch::Service[es-instance]' - ) - ) - end - end - - context 'with resource notifications' do - let(:pre_condition) do - %( - class { 'elasticsearch': - security_plugin => '#{plugin}', - restart_on_change => true, - } - ) - end - - it "copies the #{plugin} directory from the source" do - should( - contain_file( - "/etc/elasticsearch/es-instance/#{plugin}" - ).with( - :ensure => 'directory', - :mode => '0750', - :source => "/etc/elasticsearch/#{plugin}", - :recurse => 'remote', - :owner => 'root', - :group => 'elasticsearch', - :before => 'Elasticsearch::Service[es-instance]', - :notify => 'Elasticsearch::Service[es-instance]' - ) - ) - end - end - end - end - end - - describe 'jvm.options' do - let(:pre_condition) do - %( - class { 'elasticsearch': - jvm_options => [ - '-Xms4g', - '-Xmx4g' - ] - } - ) - end - - context 'from parent class' do - it do - should contain_file('/etc/elasticsearch/es-instance/jvm.options') - .with_content(%r{ - -Dfile.encoding=UTF-8. - -Dio.netty.noKeySetOptimization=true. - -Dio.netty.noUnsafe=true. - -Dio.netty.recycler.maxCapacityPerThread=0. - -Djava.awt.headless=true. - -Djna.nosys=true. - -Dlog4j.shutdownHookEnabled=false. - -Dlog4j2.disable.jmx=true. - -XX:\+AlwaysPreTouch. - -XX:\+HeapDumpOnOutOfMemoryError. - -XX:\+PrintGCDateStamps. - -XX:\+PrintGCDetails. - -XX:\+PrintTenuringDistribution. - -XX:\+UseCMSInitiatingOccupancyOnly. - -XX:\+UseConcMarkSweepGC. - -XX:\+UseGCLogFileRotation. - -XX:-OmitStackTraceInFastThrow. - -XX:CMSInitiatingOccupancyFraction=75. - -XX:GCLogFileSize=64m. - -XX:NumberOfGCLogFiles=32. - -Xloggc:\/var\/log\/elasticsearch\/es-instance\/gc.log. - -Xms4g. - -Xmx4g. - -Xss1m. - -server. - }xm) - end - end - - context 'from instance' do - let(:params) do - { - :jvm_options => [ - '-Xms8g', - '-Xmx8g' - ] - } - end - - it do - should contain_file('/etc/elasticsearch/es-instance/jvm.options') - .with_content(%r{ - -Dfile.encoding=UTF-8. - -Dio.netty.noKeySetOptimization=true. - -Dio.netty.noUnsafe=true. - -Dio.netty.recycler.maxCapacityPerThread=0. - -Djava.awt.headless=true. - -Djna.nosys=true. - -Dlog4j.shutdownHookEnabled=false. - -Dlog4j2.disable.jmx=true. - -XX:\+AlwaysPreTouch. - -XX:\+HeapDumpOnOutOfMemoryError. - -XX:\+PrintGCDateStamps. - -XX:\+PrintGCDetails. - -XX:\+PrintTenuringDistribution. - -XX:\+UseCMSInitiatingOccupancyOnly. - -XX:\+UseConcMarkSweepGC. - -XX:\+UseGCLogFileRotation. - -XX:-OmitStackTraceInFastThrow. - -XX:CMSInitiatingOccupancyFraction=75. - -XX:GCLogFileSize=64m. - -XX:NumberOfGCLogFiles=32. - -Xloggc:\/var\/log\/elasticsearch\/es-instance\/gc.log. - -Xms8g. - -Xmx8g. - -Xss1m. - -server. - }xm) - end - end - end - - describe 'keystore' do - let(:settings) do { - 'cloud.aws.access_key' => 'AKIA...', - 'cloud.aws.secret_key' => 'AKIA...' - } end - - describe 'secrets' do - context 'inherited' do - let(:pre_condition) do - <<-EOS - class { 'elasticsearch': - secrets => #{settings} - } - EOS - end - - it { should contain_elasticsearch_keystore('es-instance').with_settings(settings) } - end - - context 'from instance' do - let :params do { - :secrets => settings - } end - - it { should contain_elasticsearch_keystore('es-instance').with_settings(settings) } - end - - context 'notify events' do - let(:pre_condition) do - <<-EOS - class { 'elasticsearch': - restart_on_change => true - } - EOS - end - - let :params do { - :secrets => {} - } end - - it { should contain_elasticsearch_keystore('es-instance').that_notifies('Elasticsearch::Service[es-instance]') } - end - end - - describe 'purge_secrets' do - context 'default' do - let :params do { - :secrets => settings - } end - - it { should contain_elasticsearch_keystore('es-instance').with_purge(false) } - end - - context 'inherited' do - let(:pre_condition) do - <<-EOS - class { 'elasticsearch': - purge_secrets => true, - secrets => #{settings} - } - EOS - end - - it { should contain_elasticsearch_keystore('es-instance').with_purge(true) } - end - - context 'from instance' do - let :params do { - :purge_secrets => true, - :secrets => settings - } end - - it { should contain_elasticsearch_keystore('es-instance').with_purge(true) } - end - end - end - end - end -end diff --git a/templates/etc/elasticsearch/jvm.options.erb b/templates/etc/elasticsearch/jvm.options.erb index c9b0dde..853f52d 100644 --- a/templates/etc/elasticsearch/jvm.options.erb +++ b/templates/etc/elasticsearch/jvm.options.erb @@ -1,42 +1,42 @@ # 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:#{@logdir}/gc.log", 'UseGCLogFileRotation' => '-XX:+UseGCLogFileRotation', 'NumberOfGCLogFiles' => '-XX:NumberOfGCLogFiles=32', 'GCLogFileSize' => '-XX:GCLogFileSize=64m', } -defaults.each {|k,v| set_default(@jvm_options, k, v)} +defaults.each {|k,v| set_default(scope['elasticsearch::jvm_options'], k, v)} -%> -<% @jvm_options.sort.each do |line| -%> +<% scope['elasticsearch::jvm_options'].sort.each do |line| -%> <%= line %> <% end -%>