mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
Exclude pre releases when checking if the update is targetting a major release in the plugin manager, as bundler is not going to update anyway to this version without an explicit install command.
Fixes #3826
This commit is contained in:
parent
568231816e
commit
ae4c49be3b
3 changed files with 73 additions and 11 deletions
|
@ -44,7 +44,7 @@ class LogStash::PluginManager::Update < LogStash::PluginManager::Command
|
|||
filtered_plugins = plugins.map { |plugin| gemfile.find(plugin) }
|
||||
.compact
|
||||
.reject { |plugin| REJECTED_OPTIONS.any? { |key| plugin.options.has_key?(key) } }
|
||||
.select { |plugin| validate_major_version(plugin.name) }
|
||||
.select { |plugin| validates_version(plugin.name) }
|
||||
.each { |plugin| gemfile.update(plugin.name) }
|
||||
|
||||
# force a disk sync before running bundler
|
||||
|
@ -67,16 +67,8 @@ class LogStash::PluginManager::Update < LogStash::PluginManager::Command
|
|||
|
||||
# validate if there is any major version update so then we can ask the user if he is
|
||||
# sure to update or not.
|
||||
def validate_major_version(plugin)
|
||||
require "gems"
|
||||
latest_version = Gems.versions(plugin)[0]['number'].split(".")
|
||||
current_version = Gem::Specification.find_by_name(plugin).version.version.split(".")
|
||||
if (latest_version[0].to_i > current_version[0].to_i)
|
||||
## warn if users want to continue
|
||||
puts("You are updating #{plugin} to a new version #{latest_version.join('.')}, which may not be compatible with #{current_version.join('.')}. are you sure you want to proceed (Y/N)?")
|
||||
return ( "y" == STDIN.gets.strip.downcase ? true : false)
|
||||
end
|
||||
true
|
||||
def validates_version(plugin)
|
||||
LogStash::PluginManager.update_to_major_version?(plugin)
|
||||
end
|
||||
|
||||
# create list of plugins to update
|
||||
|
|
|
@ -37,6 +37,34 @@ module LogStash::PluginManager
|
|||
end
|
||||
end
|
||||
|
||||
# Fetch latest version information as in rubygems
|
||||
# @param [String] The plugin name
|
||||
# @param [Hash] Set of available options when fetching the information
|
||||
# @option options [Boolean] :pre Include pre release versions in the search (default: false)
|
||||
# @return [Hash] The plugin version information as returned by rubygems
|
||||
def self.fetch_latest_version_info(plugin, options={})
|
||||
require "gems"
|
||||
exclude_prereleases = options.fetch(:pre, false)
|
||||
versions = Gems.versions(plugin)
|
||||
versions = versions.select { |version| !version["prerelease"] } if !exclude_prereleases
|
||||
versions.first
|
||||
end
|
||||
|
||||
# Let's you decide to update to the last version of a plugin if this is a major version
|
||||
# @param [String] A plugin name
|
||||
# @return [Boolean] True in case the update is moving forward, false otherwise
|
||||
def self.update_to_major_version?(plugin_name)
|
||||
plugin_version = fetch_latest_version_info(plugin_name)
|
||||
latest_version = plugin_version['number'].split(".")
|
||||
current_version = Gem::Specification.find_by_name(plugin_name).version.version.split(".")
|
||||
if (latest_version[0].to_i > current_version[0].to_i)
|
||||
## warn if users want to continue
|
||||
puts("You are updating #{plugin_name} to a new version #{latest_version.join('.')}, which may not be compatible with #{current_version.join('.')}. are you sure you want to proceed (Y/N)?")
|
||||
return ( "y" == STDIN.gets.strip.downcase ? true : false)
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
# @param spec [Gem::Specification] plugin gem specification
|
||||
# @return [Boolean] true if this spec is for an installable logstash plugin
|
||||
def self.logstash_plugin_gem_spec?(spec)
|
||||
|
|
42
spec/pluginmanager/util_spec.rb
Normal file
42
spec/pluginmanager/util_spec.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
# encoding: utf-8
|
||||
require "spec_helper"
|
||||
require "pluginmanager/util"
|
||||
require "gems"
|
||||
|
||||
describe LogStash::PluginManager do
|
||||
|
||||
let(:plugin_name) { "logstash-output-elasticsearch" }
|
||||
|
||||
let(:version_data) do
|
||||
[ { "authors"=>"Elastic", "built_at"=>"2015-08-11T00:00:00.000Z", "description"=>"Output events to elasticsearch",
|
||||
"downloads_count"=>1638, "metadata"=>{"logstash_group"=>"output", "logstash_plugin"=>"true"}, "number"=>"2.0.0.pre",
|
||||
"summary"=>"Logstash Output to Elasticsearch", "platform"=>"java", "ruby_version"=>">= 0", "prerelease"=>true,
|
||||
"licenses"=>["apache-2.0"], "requirements"=>[], "sha"=>"194b27099c13605a882a3669e2363fdecccaab1de48dd44b0cda648dd5516799"},
|
||||
{ "authors"=>"Elastic", "built_at"=>"2015-08-10T00:00:00.000Z", "description"=>"Output events to elasticsearch",
|
||||
"downloads_count"=>1638, "metadata"=>{"logstash_group"=>"output", "logstash_plugin"=>"true"}, "number"=>"1.0.7",
|
||||
"summary"=>"Logstash Output to Elasticsearch", "platform"=>"java", "ruby_version"=>">= 0", "prerelease"=>false,
|
||||
"licenses"=>["apache-2.0"], "requirements"=>[], "sha"=>"194b27099c13605a882a3669e2363fdecccaab1de48dd44b0cda648dd5516799"},
|
||||
{ "authors"=>"Elastic", "built_at"=>"2015-08-09T00:00:00.000Z", "description"=>"Output events to elasticsearch",
|
||||
"downloads_count"=>1638, "metadata"=>{"logstash_group"=>"output", "logstash_plugin"=>"true"}, "number"=>"1.0.4",
|
||||
"summary"=>"Logstash Output to Elasticsearch", "platform"=>"java", "ruby_version"=>">= 0", "prerelease"=>false,
|
||||
"licenses"=>["apache-2.0"], "requirements"=>[], "sha"=>"194b27099c13605a882a3669e2363fdecccaab1de48dd44b0cda648dd5516799"} ]
|
||||
end
|
||||
|
||||
before(:each) do
|
||||
allow(Gems).to receive(:versions).with(plugin_name).and_return(version_data)
|
||||
end
|
||||
|
||||
context "fetch plugin info" do
|
||||
|
||||
it "should search for the last version infomation non prerelease" do
|
||||
version_info = LogStash::PluginManager.fetch_latest_version_info(plugin_name)
|
||||
expect(version_info["number"]).to eq("1.0.7")
|
||||
end
|
||||
|
||||
|
||||
it "should search for the last version infomation with prerelease" do
|
||||
version_info = LogStash::PluginManager.fetch_latest_version_info(plugin_name, :pre => true)
|
||||
expect(version_info["number"]).to eq("2.0.0.pre")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue