Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow installation of plugins on 2.x #477

Merged
merged 1 commit into from Nov 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/facter/elasticsearch_version.rb
@@ -0,0 +1,21 @@
# Fact: elasticsearch_version
#
# Purpose: get elasticsearch's current version
#
# Resolution:
# Uses elasticsearch's version flag and parses the result from 'version'
#
# Caveats:
# none
#
# Notes:
# None
Facter.add(:elasticsearch_version) do
setcode do
es_exec = Facter::Core::Execution.which('elasticsearch') || '/usr/share/elasticsearch/bin/elasticsearch'
es_ver = Facter::Core::Execution.exec("#{es_exec} -v")
es_ver = Facter::Core::Execution.exec("#{es_exec} --version") if es_ver == ""
es_ver.to_s.lines.first.strip.split[1].chop unless (es_ver.nil? || es_ver == "")
end
end

23 changes: 17 additions & 6 deletions manifests/plugin.pp
Expand Up @@ -77,7 +77,7 @@
$proxy_port = undef,
) {

include elasticsearch
include ::elasticsearch

Exec {
path => [ '/bin', '/usr/bin', '/usr/local/bin' ],
Expand All @@ -93,6 +93,12 @@
default => Elasticsearch::Service[$instances],
}

if versioncmp($::elasticsearch_version, '2.0.0') < 0 {
$remove_cmd = '--remove'
} else {
$remove_cmd = 'remove'
}

if ($module_dir != undef) {
warning("module_dir settings is deprecated for plugin ${name}. The directory is now auto detected.")
$plugin_dir = $module_dir
Expand Down Expand Up @@ -121,8 +127,8 @@

if ($source != undef) {

$filenameArray = split($source, '/')
$basefilename = $filenameArray[-1]
$filename_array = split($source, '/')
$basefilename = $filename_array[-1]

file { "/tmp/${basefilename}":
ensure => 'file',
Expand All @@ -141,15 +147,19 @@
$install_cmd = "${elasticsearch::plugintool}${proxy} install ${name}"
$exec_rets = [0,]
} else {
$install_cmd = "${elasticsearch::plugintool}${proxy} install ${name} --url ${real_url}"
if versioncmp($::elasticsearch_version, '2.0.0') < 0 {
$install_cmd = "${elasticsearch::plugintool}${proxy} install ${name} --url ${real_url}"
} else {
$install_cmd = "${elasticsearch::plugintool}${proxy} install ${real_url}"
}
$exec_rets = [0,1]
}

case $ensure {
'installed', 'present': {
$name_file_path = "${elasticsearch::plugindir}/${plugin_dir}/.name"
exec {"purge_plugin_${plugin_dir}_old":
command => "${elasticsearch::plugintool} --remove ${plugin_dir}",
command => "${elasticsearch::plugintool} ${remove_cmd} ${plugin_dir}",
onlyif => "test -e ${elasticsearch::plugindir}/${plugin_dir} && test \"$(cat ${name_file_path})\" != '${name}'",
before => Exec["install_plugin_${name}"],
}
Expand All @@ -167,8 +177,9 @@
}
}
'absent': {
$remove = $::elasticsearch
exec {"remove_plugin_${name}":
command => "${elasticsearch::plugintool} --remove ${plugin_dir}",
command => "${elasticsearch::plugintool} ${remove_cmd} ${plugin_dir}",
onlyif => "test -d ${elasticsearch::plugindir}/${plugin_dir}",
notify => $notify_service,
}
Expand Down
36 changes: 36 additions & 0 deletions spec/unit/facter/elasticsearch_version_spec.rb
@@ -0,0 +1,36 @@
require "spec_helper"

describe Facter::Util::Fact do
before {
Facter.clear
}

describe "elasticsearch_version" do
context 'returns elasticsearch version when elasticsearch < 2.0.0 present' do
it do
es_version_output = <<-EOS
Version: 1.4.7, Build: de54438/2015-10-22T08:09:48Z, JVM: 1.7.0_71
EOS
Facter::Core::Execution.expects(:exec).with("/usr/share/elasticsearch/bin/elasticsearch -v").returns(es_version_output)
expect(Facter.value(:elasticsearch_version)).to eq("1.4.7")
end
end
context 'returns elasticsearch version when elasticsearch >= 2.0.0 present' do
it do
es_version_output = <<-EOS
Version: 2.0.0, Build: de54438/2015-10-22T08:09:48Z, JVM: 1.8.0_66
EOS
Facter::Core::Execution.expects(:exec).with("/usr/share/elasticsearch/bin/elasticsearch -v").returns("")
Facter::Core::Execution.expects(:exec).with("/usr/share/elasticsearch/bin/elasticsearch --version").returns(es_version_output)
expect(Facter.value(:elasticsearch_version)).to eq("2.0.0")
end
end

context 'returns nil when elasticsearch not present' do
it do
Facter::Core::Execution.stubs(:exec)
expect(Facter.value(:elasticsearch_version)).to be_nil
end
end
end
end