diff --git a/manifests/plugin.pp b/manifests/plugin.pp index d0bd8be..e6453b6 100644 --- a/manifests/plugin.pp +++ b/manifests/plugin.pp @@ -1,144 +1,145 @@ # This define allows you to install arbitrary Elasticsearch plugins # either by using the default repositories or by specifying an URL # # @example install from official repository # elasticsearch::plugin {'mobz/elasticsearch-head': module_dir => 'head'} # # @example installation using a custom URL # elasticsearch::plugin { 'elasticsearch-jetty': # module_dir => 'elasticsearch-jetty', # url => 'https://oss-es-plugins.s3.amazonaws.com/elasticsearch-jetty/elasticsearch-jetty-0.90.0.zip', # } # # @param ensure # Whether the plugin will be installed or removed. # Set to 'absent' to ensure a plugin is not installed # # @param configdir # Path to the elasticsearch configuration directory (ES_PATH_CONF) # to which the plugin should be installed. # # @param java_opts # Array of Java options to be passed to `ES_JAVA_OPTS` # # @param java_home # Path to JAVA_HOME, if Java is installed in a non-standard location. # # @param module_dir # Directory name where the module has been installed # This is automatically generated based on the module name # Specify a value here to override the auto generated value # # @param proxy_host # Proxy host to use when installing the plugin # # @param proxy_password # Proxy auth password to use when installing the plugin # # @param proxy_port # Proxy port to use when installing the plugin # # @param proxy_username # Proxy auth username to use when installing the plugin # # @param source # Specify the source of the plugin. # This will copy over the plugin to the node and use it for installation. # Useful for offline installation # # @param url # Specify an URL where to download the plugin from. # # @author Richard Pijnenburg # @author Matteo Sessa # @author Dennis Konert # @author Tyler Langlois +# @author Gavin Williams # define elasticsearch::plugin ( Enum['absent', 'present'] $ensure = 'present', Stdlib::Absolutepath $configdir = $::elasticsearch::configdir, Array[String] $java_opts = [], Optional[Stdlib::Absolutepath] $java_home = undef, Optional[String] $module_dir = undef, Optional[String] $proxy_host = undef, Optional[String] $proxy_password = undef, Optional[Integer[0, 65535]] $proxy_port = undef, Optional[String] $proxy_username = undef, Optional[String] $source = undef, Optional[Stdlib::HTTPUrl] $url = undef, ) { include elasticsearch case $ensure { 'present': { $_file_ensure = 'directory' $_file_before = [] } 'absent': { $_file_ensure = $ensure $_file_before = File[$elasticsearch::_plugindir] } default: { } } # set proxy by override or parse and use proxy_url from # elasticsearch::proxy_url or use no proxy at all if ($proxy_host != undef and $proxy_port != undef) { if ($proxy_username != undef and $proxy_password != undef) { $_proxy_auth = "${proxy_username}:${proxy_password}@" } else { $_proxy_auth = undef } $_proxy = "http://${_proxy_auth}${proxy_host}:${proxy_port}" } elsif ($elasticsearch::proxy_url != undef) { $_proxy = $elasticsearch::proxy_url } else { $_proxy = undef } if ($source != undef) { $filename_array = split($source, '/') $basefilename = $filename_array[-1] $file_source = "${elasticsearch::package_dir}/${basefilename}" file { $file_source: ensure => 'file', source => $source, before => Elasticsearch_plugin[$name], } } else { $file_source = undef } $_module_dir = es_plugin_name($module_dir, $name) elasticsearch_plugin { $name: ensure => $ensure, configdir => $configdir, elasticsearch_package_name => 'elasticsearch', java_opts => $java_opts, java_home => $java_home, source => $file_source, url => $url, proxy => $_proxy, plugin_dir => $::elasticsearch::_plugindir, plugin_path => $module_dir, } -> file { "${::elasticsearch::_plugindir}/${_module_dir}": ensure => $_file_ensure, mode => 'o+Xr', recurse => true, before => $_file_before, } if $::elasticsearch::restart_plugin_change { Elasticsearch_plugin[$name] { notify +> Service['elasticsearch'], } } } diff --git a/spec/acceptance/tests/acceptance_spec.rb b/spec/acceptance/tests/acceptance_spec.rb index 13d0706..e92cbcf 100644 --- a/spec/acceptance/tests/acceptance_spec.rb +++ b/spec/acceptance/tests/acceptance_spec.rb @@ -1,92 +1,82 @@ require 'spec_helper_acceptance' require 'helpers/acceptance/tests/basic_shared_examples.rb' require 'helpers/acceptance/tests/template_shared_examples.rb' require 'helpers/acceptance/tests/removal_shared_examples.rb' require 'helpers/acceptance/tests/pipeline_shared_examples.rb' require 'helpers/acceptance/tests/plugin_shared_examples.rb' require 'helpers/acceptance/tests/plugin_upgrade_shared_examples.rb' require 'helpers/acceptance/tests/snapshot_repository_shared_examples.rb' require 'helpers/acceptance/tests/datadir_shared_examples.rb' require 'helpers/acceptance/tests/package_url_shared_examples.rb' require 'helpers/acceptance/tests/hiera_shared_examples.rb' require 'helpers/acceptance/tests/usergroup_shared_examples.rb' require 'helpers/acceptance/tests/security_shared_examples.rb' describe "elasticsearch v#{v[:elasticsearch_full_version]} class" do es_config = { - 'http.port' => 9200, - 'node.name' => 'elasticsearch01' + 'cluster.name' => v[:cluster_name], + 'http.bind_host' => '0.0.0.0', + 'http.port' => 9200, + 'node.name' => 'elasticsearch01' } let(:elastic_repo) { not v[:is_snapshot] } let(:manifest) do package = if not v[:is_snapshot] <<-MANIFEST # Hard version set here due to plugin incompatibilities. version => '#{v[:elasticsearch_full_version]}', MANIFEST else <<-MANIFEST manage_repo => false, package_url => '#{v[:snapshot_package]}', MANIFEST end <<-MANIFEST api_timeout => 60, config => { - 'cluster.name' => '#{v[:cluster_name]}', - 'http.bind_host' => '0.0.0.0', #{es_config.map { |k, v| " '#{k}' => '#{v}'," }.join("\n")} }, jvm_options => [ '-Xms128m', '-Xmx128m', ], oss => #{v[:oss]}, #{package} MANIFEST end context 'testing with' do describe 'simple config' do include_examples('basic acceptance tests', es_config) end include_examples('module removal', es_config) end include_examples('template operations', es_config, v[:template]) include_examples('pipeline operations', es_config, v[:pipeline]) include_examples('plugin acceptance tests', es_config, v[:elasticsearch_plugins]) unless v[:elasticsearch_plugins].empty? - # # Only pre-5.x versions supported versions differing from core ES - # if semver(v[:elasticsearch_full_version]) < semver('5.0.0') - # include_examples( - # 'plugin upgrade acceptance tests', - # :name => 'kopf', - # :initial => '2.0.1', - # :upgraded => '2.1.2', - # :repository => 'lmenezes/elasticsearch' - # ) - # end include_examples('snapshot repository acceptance tests') include_examples('datadir acceptance tests', es_config) # Skip this for snapshot testing, as we only have package files anyway. include_examples('package_url acceptance tests', es_config) unless v[:is_snapshot] - # include_examples 'hiera acceptance tests', v[:elasticsearch_plugins] + include_examples('hiera acceptance tests', es_config, v[:elasticsearch_plugins]) # include_examples 'user/group acceptance tests' # Security-related tests (shield/x-pack). # # Skip OSS-only distributions since they do not bundle x-pack, and skip # snapshots since we they don't recognize prod licenses. include_examples('security acceptance tests', es_config) unless v[:oss] or v[:is_snapshot] end diff --git a/spec/helpers/acceptance/tests/hiera_shared_examples.rb b/spec/helpers/acceptance/tests/hiera_shared_examples.rb index e56e64c..b857dbd 100644 --- a/spec/helpers/acceptance/tests/hiera_shared_examples.rb +++ b/spec/helpers/acceptance/tests/hiera_shared_examples.rb @@ -1,109 +1,81 @@ require 'tempfile' require 'helpers/acceptance/tests/basic_shared_examples' require 'helpers/acceptance/tests/plugin_shared_examples' agents = only_host_with_role(hosts, 'agent') -shared_examples 'hiera tests with' do |instances, additional_yaml = {}| +shared_examples 'hiera tests with' do |es_config, additional_yaml = {}| hieradata = { - 'elasticsearch::instances' => instances + 'elasticsearch::config' => es_config }.merge(additional_yaml).to_yaml before :all do write_hieradata_to(agents, hieradata) end - include_examples( - 'basic acceptance tests', - instances - ) + include_examples('basic acceptance tests', es_config) end -shared_examples 'hiera acceptance tests' do |plugins| - describe 'hiera', :then_purge do - let(:skip_instance_manifests) { true } +shared_examples 'hiera acceptance tests' do |es_config, plugins| + describe 'hiera', :with_cleanup, :then_purge do + let(:manifest) do + package = if not v[:is_snapshot] + <<-MANIFEST + # Hard version set here due to plugin incompatibilities. + version => '#{v[:elasticsearch_full_version]}', + MANIFEST + else + <<-MANIFEST + manage_repo => false, + package_url => '#{v[:snapshot_package]}', + MANIFEST + end + + <<-MANIFEST + api_timeout => 60, + jvm_options => [ + '-Xms128m', + '-Xmx128m', + ], + oss => #{v[:oss]}, + #{package} + MANIFEST + end + let(:manifest_class_parameters) { 'restart_on_change => true' } - describe 'with one instance' do + describe 'with hieradata' do + nodename = SecureRandom.hex(10) include_examples( 'hiera tests with', - 'es-hiera-single' => { - 'config' => { - 'node.name' => 'es-hiera-single', - 'http.port' => 9200 - } - } + es_config.merge('node.name' => nodename) ) end plugins.each_pair do |plugin, _meta| describe "with plugin #{plugin}" do + nodename = SecureRandom.hex(10) include_examples( 'hiera tests with', - { - 'es-hiera-single' => { - 'config' => { - 'node.name' => 'es-hiera-single', - 'http.port' => 9200 - } - } - }, + es_config.merge('node.name' => nodename), 'elasticsearch::plugins' => { plugin => { - 'ensure' => 'present', - 'instances' => [ - 'es-hiera-single' - ] + 'ensure' => 'present' } } ) include_examples( 'plugin API response', - { - 'es-hiera-single' => { - 'config' => { - 'node.name' => 'es-hiera-single', - 'http.port' => 9200 - } - } - }, - 'installs the plugin', + es_config.merge('node.name' => nodename), + 'reports the plugin as installed', 'name' => plugin ) end end - describe 'with two instances' do - include_examples( - 'hiera tests with', - 'es-hiera-multiple-1' => { - 'config' => { - 'node.name' => 'es-hiera-multiple-1', - 'http.bind_host' => '0.0.0.0', - 'http.port' => 9201 - } - }, - 'es-hiera-multiple-2' => { - 'config' => { - 'node.name' => 'es-hiera-multiple-2', - 'http.bind_host' => '0.0.0.0', - 'http.port' => 9202 - } - } - ) - end - after :all do write_hieradata_to(agents, {}) - - apply_manifest <<-EOS - class { 'elasticsearch': ensure => 'absent', oss => #{v[:oss]} } - Elasticsearch::Instance { ensure => 'absent' } - elasticsearch::instance { 'es-hiera-single': } - elasticsearch::instance { 'es-hiera-multiple-1': } - elasticsearch::instance { 'es-hiera-multiple-2': } - EOS end end end