mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
Introduce the use of a platforms.json file where to keep all platforms information to simplify the vagrantfile structure. Also make the vagrant execution more elegant under rake
Fixes #5350
This commit is contained in:
parent
5ccc705a67
commit
0afbb50cac
10 changed files with 127 additions and 69 deletions
24
qa/Rakefile
24
qa/Rakefile
|
@ -2,17 +2,19 @@ require "rspec"
|
|||
require "rspec/core/runner"
|
||||
require "rspec/core/rake_task"
|
||||
require_relative "vagrant-helpers"
|
||||
require_relative "platform_config"
|
||||
|
||||
platforms = PlatformConfig.new
|
||||
|
||||
task :spec => 'spec:all'
|
||||
task :default => :spec
|
||||
|
||||
namespace :test do
|
||||
|
||||
desc "Generate a valid ssh-config"
|
||||
task :ssh_config do
|
||||
require "json"
|
||||
cd "acceptance" do
|
||||
raw_ssh_config = LogStash::VagrantHelpers.fetch_config[:stdout].split("\n");
|
||||
raw_ssh_config = LogStash::VagrantHelpers.fetch_config.stdout.split("\n");
|
||||
parsed_ssh_config = LogStash::VagrantHelpers.parse(raw_ssh_config)
|
||||
File.write("../.vm_ssh_config", parsed_ssh_config.to_json)
|
||||
end
|
||||
|
@ -21,26 +23,20 @@ namespace :test do
|
|||
desc "Bootstrap all the VM's used for this tests"
|
||||
task "setup" do
|
||||
puts "bootstraping all VM's defined in acceptance/Vagrantfile"
|
||||
cd "acceptance" do
|
||||
LogStash::VagrantHelpers.bootstrap
|
||||
end
|
||||
LogStash::VagrantHelpers.bootstrap
|
||||
end
|
||||
|
||||
namespace :acceptance do
|
||||
|
||||
desc "Run all acceptance"
|
||||
task :all do
|
||||
exit(RSpec::Core::Runner.run([Rake::FileList["acceptance/spec/**/*_spec.rb"]]))
|
||||
end
|
||||
|
||||
desc "Run acceptance test in debian machines"
|
||||
task :debian do
|
||||
exit(RSpec::Core::Runner.run([Rake::FileList["acceptance/spec/debian/**/*_spec.rb"]]))
|
||||
end
|
||||
|
||||
desc "Run acceptance test in centos machines"
|
||||
task :centos do
|
||||
exit(RSpec::Core::Runner.run([Rake::FileList["acceptance/spec/centos/**/*_spec.rb"]]))
|
||||
platforms.types.each do |type|
|
||||
desc "Run acceptance test in #{type} machines"
|
||||
task type do
|
||||
exit(RSpec::Core::Runner.run([Rake::FileList["acceptance/spec/#{type}/**/*_spec.rb"]]))
|
||||
end
|
||||
end
|
||||
|
||||
desc "Run one single machine acceptance test"
|
||||
|
|
27
qa/Vagrantfile
vendored
Normal file
27
qa/Vagrantfile
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
require_relative "./platform_config.rb"
|
||||
|
||||
Vagrant.configure(2) do |config|
|
||||
platforms = PlatformConfig.new
|
||||
|
||||
platforms.each do |platform|
|
||||
config.vm.define platform.name do |machine|
|
||||
machine.vm.box = platform.box
|
||||
machine.vm.provider "virtualbox" do |v|
|
||||
v.memory = 2096
|
||||
v.cpus = 4
|
||||
end
|
||||
machine.vm.synced_folder "../../build", "/logstash-build", create: true
|
||||
machine.vm.provision :shell do |sh|
|
||||
sh.path = "sys/#{platform.type}/bootstrap.sh"
|
||||
sh.privileged = true
|
||||
end
|
||||
|
||||
machine.vm.provision :shell do |sh|
|
||||
sh.path = "sys/#{platform.type}/user_bootstrap.sh"
|
||||
sh.privileged = false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
43
qa/acceptance/Vagrantfile
vendored
43
qa/acceptance/Vagrantfile
vendored
|
@ -1,43 +0,0 @@
|
|||
# -*- mode: ruby -*-
|
||||
# vi: set ft=ruby :
|
||||
|
||||
Vagrant.configure(2) do |config|
|
||||
|
||||
config.vm.define "ubuntu-1204" do |machine|
|
||||
machine.vm.box = "elastic/ubuntu-12.04-x86_64"
|
||||
common_config(machine, "ubuntu")
|
||||
end
|
||||
|
||||
config.vm.define "ubuntu-1404" do |machine|
|
||||
machine.vm.box = "elastic/ubuntu-14.04-x86_64"
|
||||
common_config(machine, "ubuntu")
|
||||
end
|
||||
|
||||
config.vm.define "centos-6" do |machine|
|
||||
machine.vm.box = "elastic/centos-6-x86_64"
|
||||
common_config(machine, "ubuntu")
|
||||
end
|
||||
|
||||
config.vm.define "centos-7" do |machine|
|
||||
machine.vm.box = "elastic/centos-7-x86_64"
|
||||
common_config(machine, "ubuntu")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def common_config(machine, type)
|
||||
machine.vm.provider "virtualbox" do |v|
|
||||
v.memory = 4096
|
||||
v.cpus = 4
|
||||
end
|
||||
machine.vm.synced_folder "../../build", "/logstash-build", create: true
|
||||
machine.vm.provision :shell do |sh|
|
||||
sh.path = "sys/#{type}/bootstrap.sh"
|
||||
sh.privileged = true
|
||||
end
|
||||
|
||||
machine.vm.provision :shell do |sh|
|
||||
sh.path = "sys/#{type}/user_bootstrap.sh"
|
||||
sh.privileged = false
|
||||
end
|
||||
end
|
41
qa/platform_config.rb
Normal file
41
qa/platform_config.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
# encoding: utf-8
|
||||
require "json"
|
||||
|
||||
class PlatformConfig
|
||||
Platform = Struct.new(:name, :box, :type)
|
||||
|
||||
DEFAULT_CONFIG_LOCATION = File.join(File.dirname(__FILE__), "platforms.json")
|
||||
|
||||
def initialize(config_path = DEFAULT_CONFIG_LOCATION)
|
||||
@config_path = config_path
|
||||
@platforms = []
|
||||
|
||||
data = JSON.parse(File.read(@config_path))
|
||||
data.each do |k, v|
|
||||
@platforms << Platform.new(k, v["box"], v["type"])
|
||||
end
|
||||
|
||||
@platforms.sort! { |a, b| a.name <=> b.name }
|
||||
end
|
||||
|
||||
def find!(platform_name)
|
||||
result = @platforms.find { |platform| platform.name == platform_name }.first
|
||||
if result.nil?
|
||||
raise "Cannot find platform named: #{platform_name} in @config_path"
|
||||
else
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
def each(&block)
|
||||
@platforms.each(&block)
|
||||
end
|
||||
|
||||
def filter_type(type_name)
|
||||
@platforms.select { |platform| platform.type == type_name }
|
||||
end
|
||||
|
||||
def types
|
||||
@platforms.collect(&:type).uniq.sort
|
||||
end
|
||||
end
|
6
qa/platforms.json
Normal file
6
qa/platforms.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"ubuntu-1204": { "box": "elastic/ubuntu-12.04-x86_64", "type": "ubuntu" },
|
||||
"ubuntu-1404": { "box": "elastic/ubuntu-14.04-x86_64", "type": "ubuntu" },
|
||||
"centos-6": { "box": "elastic/centos-6-x86_64", "type": "centos" },
|
||||
"centos-7": { "box": "elastic/centos-7-x86_64", "type": "centos" }
|
||||
}
|
|
@ -1,15 +1,56 @@
|
|||
# encoding: utf-8
|
||||
require "open3"
|
||||
require "bundler"
|
||||
|
||||
module LogStash
|
||||
class CommandExecutor
|
||||
class CommandError < StandardError; end
|
||||
|
||||
class CommandResponse
|
||||
attr_reader :stdin, :stdout, :stderr, :exitstatus
|
||||
|
||||
def initialize(stdin, stdout, stderr, exitstatus)
|
||||
@stdin = stdin,
|
||||
@stdout = stdout
|
||||
@stderr = stderr
|
||||
@exitstatus = exitstatus
|
||||
end
|
||||
|
||||
def success?
|
||||
exitstatus == 0
|
||||
end
|
||||
end
|
||||
|
||||
def self.run(cmd)
|
||||
# This block is require to be able to launch a ruby subprocess
|
||||
# that use bundler.
|
||||
Bundler.with_clean_env do
|
||||
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
|
||||
CommandResponse.new(stdin, stdout.read.chomp, stderr.read.chomp, wait_thr.value.exitstatus)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# This method will raise an exception if the `CMD`
|
||||
# was not run successfully and will display the content of STDERR
|
||||
def self.run!(cmd)
|
||||
response = run(cmd)
|
||||
|
||||
unless response.success?
|
||||
raise CommandError, "CMD: #{cmd} STDERR: #{response.stderr}"
|
||||
end
|
||||
response
|
||||
end
|
||||
end
|
||||
|
||||
class VagrantHelpers
|
||||
|
||||
def self.bootstrap
|
||||
execute("vagrant up")
|
||||
CommandExecutor.run!("vagrant up")
|
||||
end
|
||||
|
||||
def self.fetch_config
|
||||
execute("vagrant ssh-config")
|
||||
CommandExecutor.run!("vagrant ssh-config")
|
||||
end
|
||||
|
||||
def self.parse(lines)
|
||||
|
@ -29,15 +70,5 @@ module LogStash
|
|||
hosts << host
|
||||
hosts
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.execute(cmd)
|
||||
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
|
||||
{ :stdout => stdout.read.chomp, :stderr => stderr.read.chomp,
|
||||
:exit_status => wait_thr.value.exitstatus }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue