diff --git a/manifests/plugin.pp b/manifests/plugin.pp index 84e62d4..7f219c8 100644 --- a/manifests/plugin.pp +++ b/manifests/plugin.pp @@ -1,145 +1,146 @@ # 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::real_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::real_plugindir, plugin_path => $module_dir, + before => Service['elasticsearch'], } -> file { "${elasticsearch::real_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/defines/004_elasticsearch_plugin_spec.rb b/spec/defines/004_elasticsearch_plugin_spec.rb index 48a99af..f22e321 100644 --- a/spec/defines/004_elasticsearch_plugin_spec.rb +++ b/spec/defines/004_elasticsearch_plugin_spec.rb @@ -1,301 +1,307 @@ require 'spec_helper' describe 'elasticsearch::plugin', :type => 'define' do let(:title) { 'mobz/elasticsearch-head/1.0.0' } on_supported_os( :hardwaremodels => ['x86_64'], :supported_os => [ { 'operatingsystem' => 'CentOS', 'operatingsystemrelease' => ['6'] } ] ).each do |_os, facts| let(:facts) do facts.merge('scenario' => '', 'common' => '') end let(:pre_condition) do <<-EOS class { "elasticsearch": config => { "node" => { "name" => "test" } } } EOS end context 'default values' do context 'present' do let(:params) do { :ensure => 'present', :configdir => '/etc/elasticsearch' } end it { is_expected.to compile } end context 'absent' do let(:params) do { :ensure => 'absent' } end it { is_expected.to compile } end context 'configdir' do it { should contain_elasticsearch__plugin( 'mobz/elasticsearch-head/1.0.0' ).with_configdir('/etc/elasticsearch') } it { should contain_elasticsearch_plugin( 'mobz/elasticsearch-head/1.0.0' ).with_configdir('/etc/elasticsearch') } end end context 'with module_dir' do context 'add a plugin' do let(:params) do { :ensure => 'present', :module_dir => 'head' } end it { should contain_elasticsearch__plugin( 'mobz/elasticsearch-head/1.0.0' ) } it { should contain_elasticsearch_plugin( 'mobz/elasticsearch-head/1.0.0' ) } it { should contain_file( '/usr/share/elasticsearch/plugins/head' ).that_requires( 'Elasticsearch_plugin[mobz/elasticsearch-head/1.0.0]' ) } end context 'remove a plugin' do let(:params) do { :ensure => 'absent', :module_dir => 'head' } end it { should contain_elasticsearch__plugin( 'mobz/elasticsearch-head/1.0.0' ) } it { should contain_elasticsearch_plugin( 'mobz/elasticsearch-head/1.0.0' ).with( :ensure => 'absent' ) } it { should contain_file( '/usr/share/elasticsearch/plugins/head' ).that_requires( 'Elasticsearch_plugin[mobz/elasticsearch-head/1.0.0]' ) } end end context 'with url' do context 'add a plugin with full name' do let(:params) do { :ensure => 'present', :url => 'https://github.com/mobz/elasticsearch-head/archive/master.zip' } end it { should contain_elasticsearch__plugin('mobz/elasticsearch-head/1.0.0') } it { should contain_elasticsearch_plugin('mobz/elasticsearch-head/1.0.0').with(:ensure => 'present', :url => 'https://github.com/mobz/elasticsearch-head/archive/master.zip') } end end context 'offline plugin install' do let(:title) { 'head' } let(:params) do { :ensure => 'present', :source => 'puppet:///path/to/my/plugin.zip' } end it { should contain_elasticsearch__plugin('head') } it { should contain_file('/opt/elasticsearch/swdl/plugin.zip').with(:source => 'puppet:///path/to/my/plugin.zip', :before => 'Elasticsearch_plugin[head]') } it { should contain_elasticsearch_plugin('head').with(:ensure => 'present', :source => '/opt/elasticsearch/swdl/plugin.zip') } end describe 'service restarts' do let(:title) { 'head' } let(:params) do { :ensure => 'present', :module_dir => 'head' } end context 'restart_on_change set to false (default)' do let(:pre_condition) do <<-EOS class { "elasticsearch": } EOS end it { should_not contain_elasticsearch_plugin( 'head' ).that_notifies( 'Service[elasticsearch]' )} include_examples 'class', :sysv end context 'restart_on_change set to true' do let(:pre_condition) do <<-EOS class { "elasticsearch": restart_on_change => true, } EOS end it { should contain_elasticsearch_plugin( 'head' ).that_notifies( 'Service[elasticsearch]' )} include_examples('class') end context 'restart_plugin_change set to false (default)' do let(:pre_condition) do <<-EOS class { "elasticsearch": restart_plugin_change => false, } EOS end it { should_not contain_elasticsearch_plugin( 'head' ).that_notifies( 'Service[elasticsearch]' )} include_examples('class') end context 'restart_plugin_change set to true' do let(:pre_condition) do <<-EOS class { "elasticsearch": restart_plugin_change => true, } EOS end it { should contain_elasticsearch_plugin( 'head' ).that_notifies( 'Service[elasticsearch]' )} include_examples('class') end end describe 'proxy arguments' do let(:title) { 'head' } context 'unauthenticated' do context 'on define' do let(:params) do { :ensure => 'present', :proxy_host => 'es.local', :proxy_port => 8080 } end it { should contain_elasticsearch_plugin( 'head' ).with_proxy( 'http://es.local:8080' )} end context 'on main class' do let(:params) do { :ensure => 'present' } end let(:pre_condition) do <<-EOS class { 'elasticsearch': proxy_url => 'https://es.local:8080', } EOS end it { should contain_elasticsearch_plugin( 'head' ).with_proxy( 'https://es.local:8080' )} end end context 'authenticated' do context 'on define' do let(:params) do { :ensure => 'present', :proxy_host => 'es.local', :proxy_port => 8080, :proxy_username => 'elastic', :proxy_password => 'password' } end it { should contain_elasticsearch_plugin( 'head' ).with_proxy( 'http://elastic:password@es.local:8080' )} end context 'on main class' do let(:params) do { :ensure => 'present' } end let(:pre_condition) do <<-EOS class { 'elasticsearch': proxy_url => 'http://elastic:password@es.local:8080', } EOS end it { should contain_elasticsearch_plugin( 'head' ).with_proxy( 'http://elastic:password@es.local:8080' )} end end end describe 'collector ordering' do describe 'present' do let(:title) { 'head' } let(:pre_condition) do <<-EOS class { 'elasticsearch': } EOS end it { should contain_elasticsearch__plugin( 'head' ).that_requires( 'Class[elasticsearch::config]' )} - include_examples('class') + it { should contain_elasticsearch_plugin( + 'head' + ).that_comes_before( + 'Service[elasticsearch]' + )} + + include_examples 'class' end end end end