Page MenuHomeSoftware Heritage

No OneTemporary

diff --git a/Rakefile b/Rakefile
index 8d896f4..c9a7738 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,215 +1,217 @@
require 'digest/sha1'
require 'rubygems'
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet_blacksmith/rake_tasks'
require 'net/http'
require 'uri'
require 'fileutils'
require 'rspec/core/rake_task'
require 'open-uri'
require 'puppet-strings'
require 'puppet-strings/tasks'
require 'yaml'
require 'json'
require_relative 'spec/spec_utilities'
# Workaround for certain rspec/beaker versions
module TempFixForRakeLastComment
def last_comment
last_description
end
end
Rake::Application.send :include, TempFixForRakeLastComment
exclude_paths = [
'pkg/**/*',
'vendor/**/*',
'spec/**/*'
]
require 'puppet-lint/tasks/puppet-lint'
require 'puppet-syntax/tasks/puppet-syntax'
PuppetSyntax.exclude_paths = exclude_paths
PuppetSyntax.future_parser = true if ENV['FUTURE_PARSER'] == 'true'
%w[
80chars
class_inherits_from_params_class
class_parameter_defaults
single_quote_string_with_variable
].each do |check|
PuppetLint.configuration.send("disable_#{check}")
end
PuppetLint.configuration.ignore_paths = exclude_paths
PuppetLint.configuration.log_format = \
'%{path}:%{line}:%{check}:%{KIND}:%{message}'
# Append custom cleanup tasks to :clean
task :clean => [
:'artifact:clean',
:spec_clean
]
desc 'remove outdated module fixtures'
task :spec_prune do
mods = 'spec/fixtures/modules'
fixtures = YAML.load_file '.fixtures.yml'
fixtures['fixtures']['forge_modules'].each do |mod, params|
next unless params.is_a? Hash \
and params.key? 'ref' \
and File.exist? "#{mods}/#{mod}"
metadata = JSON.parse(File.read("#{mods}/#{mod}/metadata.json"))
FileUtils.rm_rf "#{mods}/#{mod}" unless metadata['version'] == params['ref']
end
end
task :spec_prep => [:spec_prune]
RSpec::Core::RakeTask.new(:spec_verbose) do |t|
t.pattern = 'spec/{classes,defines,unit,functions,templates}/**/*_spec.rb'
t.rspec_opts = [
'--format documentation',
'--require "ci/reporter/rspec"',
'--format CI::Reporter::RSpecFormatter',
'--color'
]
end
task :spec_verbose => :spec_prep
RSpec::Core::RakeTask.new(:spec_puppet) do |t|
t.pattern = 'spec/{classes,defines,functions,templates,unit/facter}/**/*_spec.rb'
t.rspec_opts = ['--color']
end
task :spec_puppet => :spec_prep
RSpec::Core::RakeTask.new(:spec_unit) do |t|
t.pattern = 'spec/unit/{type,provider}/**/*_spec.rb'
t.rspec_opts = ['--color']
end
task :spec_unit => :spec_prep
task :beaker => [:spec_prep, 'artifact:prep']
desc 'Run all linting/unit tests.'
task :intake => [
:syntax,
:rubocop,
:lint,
:validate,
:spec_unit,
:spec_puppet
]
# Plumbing for snapshot tests
desc 'Run the snapshot tests'
RSpec::Core::RakeTask.new('beaker:snapshot') do |task|
task.rspec_opts = ['--color']
task.pattern = 'spec/acceptance/snapshot.rb'
if Rake::Task.task_defined? 'artifact:snapshot:not_found'
puts 'No snapshot artifacts found, skipping snapshot tests.'
exit(0)
end
end
beaker_node_sets.each do |node|
desc "Run the snapshot tests against the #{node} nodeset"
task "beaker:#{node}:snapshot" => %w[
spec_prep
artifact:prep
artifact:snapshot:deb
artifact:snapshot:rpm
] do
ENV['BEAKER_set'] = node
Rake::Task['beaker:snapshot'].reenable
Rake::Task['beaker:snapshot'].invoke
end
end
desc 'Run acceptance tests'
-RSpec::Core::RakeTask.new('beaker:acceptance') do |c|
- c.pattern = 'spec/acceptance/0*_spec.rb'
+RSpec::Core::RakeTask.new(
+ 'beaker:acceptance', [:version] => [:spec_prep, 'artifact:prep']
+) do |task, args|
+ task.pattern = 'spec/acceptance/tests/acceptance_spec.rb'
+ ENV['ELASTICSEARCH_FULL_VERSION'] = args[:version]
end
-task 'beaker:acceptance' => [:spec_prep, 'artifact:prep']
desc 'Setup a dummy host only, do not run any tests'
RSpec::Core::RakeTask.new('beaker:noop') do |c|
ENV['BEAKER_destroy'] = 'no'
c.pattern = 'spec/acceptance/*basic_spec.rb'
end
task 'beaker:noop' => [:spec_prep]
namespace :artifact do
desc 'Fetch artifacts for tests'
task :prep do
dl_base = 'https://download.elastic.co/elasticsearch/elasticsearch'
fetch_archives(
'https://github.com/lmenezes/elasticsearch-kopf/archive/v2.1.1.zip' => \
'elasticsearch-kopf.zip',
"#{dl_base}/elasticsearch-2.3.5.deb" => 'elasticsearch-2.3.5.deb',
"#{dl_base}/elasticsearch-2.3.5.rpm" => 'elasticsearch-2.3.5.rpm',
'https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/analysis-icu/2.4.1/analysis-icu-2.4.1.zip' => \
'elasticsearch-plugin-2.x_analysis-icu.zip'
)
end
namespace :snapshot do
catalog = JSON.parse(
open('https://0ym978vhv1.execute-api.us-east-1.amazonaws.com/dev/branches/6.2').read
)['latest']
ENV['snapshot_version'] = catalog['version']
downloads = catalog['projects']['elasticsearch']['packages'].select do |pkg, _|
pkg =~ /(?:deb|rpm)/
end.map do |package, urls|
[package.split('.').last, urls]
end.to_h
# We end up with something like:
# {
# 'rpm' => {'url' => 'https://...', 'sha_url' => 'https://...'},
# 'deb' => {'url' => 'https://...', 'sha_url' => 'https://...'}
# }
# Note that checksums are currently broken on the Elastic unified release
# side; once they start working we can verify them.
if downloads.empty?
puts 'No snapshot release available; skipping snapshot download'
%w[deb rpm].each { |ext| task ext }
task 'not_found'
else
# Download snapshot files
downloads.each_pair do |extension, urls|
filename = artifact urls['url']
checksum = artifact urls['sha_url']
link = artifact "elasticsearch-snapshot.#{extension}"
task extension => link
file link => filename do
unless File.exist?(link) and File.symlink?(link) \
and File.readlink(link) == filename
File.delete link if File.exist? link
File.symlink File.basename(filename), link
end
end
# file filename => checksum do
file filename do
get urls['url'], filename
end
task checksum do
File.delete checksum if File.exist? checksum
get urls['sha_url'], checksum
end
end
end
end
desc 'Purge fetched artifacts'
task :clean do
FileUtils.rm_rf(Dir.glob('spec/fixtures/artifacts/*'))
end
end
diff --git a/spec/acceptance/tests/v2_spec.rb b/spec/acceptance/tests/acceptance_spec.rb
similarity index 91%
rename from spec/acceptance/tests/v2_spec.rb
rename to spec/acceptance/tests/acceptance_spec.rb
index 2c0896a..5beaa49 100644
--- a/spec/acceptance/tests/v2_spec.rb
+++ b/spec/acceptance/tests/acceptance_spec.rb
@@ -1,96 +1,96 @@
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/plugin_shared_examples.rb'
require 'helpers/acceptance/tests/snapshot_repository_shared_examples.rb'
require 'helpers/acceptance/tests/datadir_shared_examples.rb'
-describe 'elasticsearch class v2' do
+describe "elasticsearch v#{RSpec.configuration.elasticsearch_full_version} class" do
local_plugin_path = Dir[
"#{RSpec.configuration.test_settings['files_dir']}/elasticsearch-plugin-2*"
].first
local_plugin_name = File.basename(local_plugin_path).split('_').last.split('.').first
let(:manifest) do
<<-MANIFEST
config => {
'cluster.name' => '#{test_settings['cluster_name']}',
'network.host' => '0.0.0.0',
},
- repo_version => '2.x',
+ repo_version => '#{RSpec.configuration.elasticsearch_major_version}.x',
# Hard version set here due to plugin incompatibilities.
- version => '2.4.1',
+ version => '#{RSpec.configuration.elasticsearch_full_version}',
MANIFEST
end
# Single-node
include_examples(
'basic acceptance tests',
'es-01' => {
'http.port' => 9200,
'node.name' => 'elasticsearch001'
}
)
# Dual-node
include_examples(
'basic acceptance tests',
'es-01' => {
'http.port' => 9200,
'node.name' => 'elasticsearch001'
},
'es-02' => {
'http.port' => 9201,
'node.name' => 'elasticsearch002'
}
)
include_examples 'module removal', %w[es-01 es-02]
include_examples(
'template operations',
{
'es-01' => {
'http.port' => 9200,
'node.name' => 'elasticsearch001'
}
},
test_settings['template']
)
context 'with restart_on_changes' do
let(:manifest_class_parameters) { 'restart_on_change => true' }
include_examples(
'plugin acceptance tests',
{
'es-01' => {
'http.port' => 9200,
'node.name' => 'elasticsearch001'
}
},
:github => {
:name => 'kopf',
:initial => '2.0.1',
:upgraded => '2.1.2',
:repository => 'lmenezes/elasticsearch-'
},
:official => 'analysis-icu',
:offline => {
:name => local_plugin_name,
:path => local_plugin_path
},
:remote => {
:url => 'https://github.com/royrusso/elasticsearch-HQ/archive/v2.0.3.zip',
:name => 'hq'
}
)
end
# Tests for elasticsearch::snapshot resources
include_examples 'snapshot repository acceptance tests'
# `datadir` tests
include_examples 'datadir acceptance tests'
end
diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb
index 89efaa0..56e1b16 100644
--- a/spec/spec_helper_acceptance.rb
+++ b/spec/spec_helper_acceptance.rb
@@ -1,222 +1,229 @@
require 'beaker-rspec'
require 'securerandom'
require 'thread'
require 'infrataster/rspec'
require 'rspec/retry'
require_relative 'spec_helper_tls'
require_relative 'spec_utilities'
def test_settings
RSpec.configuration.test_settings
end
def f
RSpec.configuration.fact
end
RSpec.configure do |c|
c.add_setting :test_settings, :default => {}
unless ENV['snapshot_version'].nil?
c.add_setting :snapshot_version
c.snapshot_version = ENV['snapshot_version']
end
+ unless ENV['ELASTICSEARCH_FULL_VERSION'].nil?
+ c.add_setting :elasticsearch_full_version
+ c.add_setting :elasticsearch_major_version
+ c.elasticsearch_full_version = ENV['ELASTICSEARCH_FULL_VERSION']
+ c.elasticsearch_major_version = c.elasticsearch_full_version.split('.').first
+ end
+
# rspec-retry
c.display_try_failure_messages = true
c.default_sleep_interval = 5
# General-case retry keyword for unstable tests
c.around :each, :with_retries do |example|
example.run_with_retry retry: 4
end
# More forgiving retry config for really flaky tests
c.around :each, :with_generous_retries do |example|
example.run_with_retry retry: 10
end
# Helper hook for module cleanup
c.after :context, :with_cleanup do
apply_manifest <<-EOS
class { 'elasticsearch':
ensure => 'absent',
manage_repo => true,
}
elasticsearch::instance { 'es-01': ensure => 'absent' }
file { '/usr/share/elasticsearch/plugin':
ensure => 'absent',
force => true,
recurse => true,
require => Class['elasticsearch'],
}
EOS
end
c.before :context, :with_certificates do
@keystore_password = SecureRandom.hex
@role = [*('a'..'z')].sample(8).join
# Setup TLS cert placement
@tls = gen_certs(2, '/tmp')
create_remote_file hosts, @tls[:ca][:cert][:path], @tls[:ca][:cert][:pem]
@tls[:clients].each do |node|
node.each do |_type, params|
create_remote_file hosts, params[:path], params[:pem]
end
end
end
c.after :context, :then_purge do
shell 'rm -rf {/usr/share,/etc,/var/lib}/elasticsearch*'
end
end
files_dir = ENV['files_dir'] || './spec/fixtures/artifacts'
RSpec.configuration.test_settings['files_dir'] = files_dir
# General bootstrapping steps for each host
hosts.each do |host|
# Set the host to 'aio' in order to adopt the puppet-agent style of
# installation, and configure paths/etc.
host[:type] = 'aio'
configure_defaults_on host, 'aio'
# Install Puppet
#
# We spawn a thread to print dots periodically while installing puppet to
# avoid inactivity timeouts in Travis. Don't judge me.
progress = Thread.new do
print 'Installing puppet..'
print '.' while sleep 5
end
case host.name
when /debian-9/, /opensuse/
# A few special cases need to be installed from gems (if the distro is
# very new and has no puppet repo package or has no upstream packages).
install_puppet_from_gem(
host,
version: Gem.loaded_specs['puppet'].version
)
else
# Otherwise, just use the all-in-one agent package.
install_puppet_agent_on(
host,
puppet_agent_version: to_agent_version(Gem.loaded_specs['puppet'].version)
)
end
# Quit the print thread and include some debugging.
progress.exit
puts "done. Installed version #{shell('puppet --version').output}"
RSpec.configure do |c|
c.add_setting :fact, :default => JSON.parse(fact('', '-j'))
end
if f['os']['family'] == 'Suse'
install_package host,
'--force-resolution augeas-devel libxml2-devel ruby-devel'
on host, 'gem install ruby-augeas --no-ri --no-rdoc'
end
ext = case f['os']['family']
when 'Debian'
'deb'
else
'rpm'
end
snapshot_package = {
:src => "#{files_dir}/elasticsearch-2.3.5.#{ext}",
:dst => "/tmp/elasticsearch-2.3.5.#{ext}"
}
scp_to host,
snapshot_package[:src],
snapshot_package[:dst]
RSpec.configuration.test_settings['snapshot_package'] = \
"file:#{snapshot_package[:dst]}"
test_settings['integration_package'] = {
:src => "#{files_dir}/elasticsearch-snapshot.#{ext}",
:dst => "/tmp/elasticsearch-snapshot.#{ext}",
:file => "file:/tmp/elasticsearch-snapshot.#{ext}"
}
Infrataster::Server.define(:docker) do |server|
server.address = host[:ip]
server.ssh = host[:ssh].tap { |s| s.delete :forward_agent }
end
Infrataster::Server.define(:container) do |server|
server.address = host[:vm_ip] # this gets ignored anyway
server.from = :docker
end
end
RSpec.configure do |c|
c.before :suite do
# Install module and dependencies
install_dev_puppet_module :ignore_list => [
'junit'
] + Beaker::DSL::InstallUtils::ModuleUtils::PUPPET_MODULE_INSTALL_IGNORE
hosts.each do |host|
copy_hiera_data_to(host, 'spec/fixtures/hiera/hieradata/')
modules = %w[archive datacat java java_ks stdlib]
dist_module = {
'Debian' => ['apt'],
'Suse' => ['zypprepo'],
'RedHat' => ['concat']
}[f['os']['family']]
modules += dist_module unless dist_module.nil?
modules.each do |mod|
copy_module_to(
host,
:module_name => mod,
:source => "spec/fixtures/modules/#{mod}"
)
end
on(host, 'mkdir -p etc/puppet/modules/another/files/')
# Apt doesn't update package caches sometimes, ensure we're caught up.
shell 'apt-get update' if f['os']['family'] == 'Debian'
end
# Use the Java class once before the suite of tests
unless shell('command -v java', :accept_all_exit_codes => true).exit_code.zero?
apply_manifest <<-MANIFEST
class { "java" :
distribution => "jre",
}
MANIFEST
end
end
c.after :suite do
if ENV['ES_VERSION']
hosts.each do |host|
timestamp = Time.now
log_dir = File.join('./spec/logs', timestamp.strftime('%F_%H_%M_%S'))
FileUtils.mkdir_p(log_dir) unless File.directory?(log_dir)
scp_from(host, '/var/log/elasticsearch', log_dir)
end
end
end
end
require_relative 'spec_acceptance_common'
# Java 8 is only easy to manage on recent distros
def v5x_capable?
(f['os']['family'] == 'RedHat' and \
not (f['os']['name'] == 'OracleLinux' and \
f['os']['release']['major'] == '6')) or \
f.dig 'os', 'distro', 'codename' == 'xenial'
end

File Metadata

Mime Type
text/x-diff
Expires
Wed, Mar 18, 2:14 AM (5 h, 15 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3342657

Event Timeline