diff --git a/spec/helpers/acceptance/tests/bad_manifest_shared_examples.rb b/spec/helpers/acceptance/tests/bad_manifest_shared_examples.rb index eb2f80b..9fc1a4b 100644 --- a/spec/helpers/acceptance/tests/bad_manifest_shared_examples.rb +++ b/spec/helpers/acceptance/tests/bad_manifest_shared_examples.rb @@ -1,18 +1,18 @@ shared_examples 'invalid manifest application' do - context "bad manifest" do + context 'bad manifest' do let(:applied_manifest) do <<-MANIFEST class { 'elasticsearch' : #{manifest} #{defined?(manifest_class_parameters) && manifest_class_parameters} } #{defined?(extra_manifest) && extra_manifest} MANIFEST end it 'fails to apply' do apply_manifest applied_manifest, :expect_failures => true end end end diff --git a/spec/helpers/acceptance/tests/basic_shared_examples.rb b/spec/helpers/acceptance/tests/basic_shared_examples.rb index c00a721..1f072f9 100644 --- a/spec/helpers/acceptance/tests/basic_shared_examples.rb +++ b/spec/helpers/acceptance/tests/basic_shared_examples.rb @@ -1,65 +1,65 @@ require 'json' require 'helpers/acceptance/tests/manifest_shared_examples' -shared_examples 'basic acceptance tests' do | config | +shared_examples 'basic acceptance tests' do |config| include_examples 'manifest application' describe package("elasticsearch#{v[:oss] ? '-oss' : ''}") do it { should be_installed } end %w[ /etc/elasticsearch /usr/share/elasticsearch /var/lib/elasticsearch ].each do |dir| describe file(dir) do it { should be_directory } end end - describe "resources for instance " do - describe service("elasticsearch") do + describe 'resources' do + describe service('elasticsearch') do it { send(config.empty? ? :should_not : :should, be_enabled) } it { send(config.empty? ? :should_not : :should, be_running) } end unless config.empty? - describe file(pid_file()) do + describe file(pid_file) do it { should be_file } its(:content) { should match(/[0-9]+/) } end - describe file("/etc/elasticsearch/elasticsearch.yml") do + describe file('/etc/elasticsearch/elasticsearch.yml') do it { should be_file } it { should contain "name: #{config['node.name']}" } end end unless config.empty? describe port(config['http.port']) do it 'open', :with_retries do should be_listening end end describe server :container do describe http("http://localhost:#{config['http.port']}/_nodes/_local") do it 'serves requests', :with_retries do expect(response.status).to eq(200) end it 'uses the default data path', :with_retries do json = JSON.parse(response.body)['nodes'].values.first data_dir = ['/var/lib/elasticsearch'] expect( json['settings']['path'] ).to include( 'data' => data_dir ) end end end end end end diff --git a/spec/helpers/acceptance/tests/manifest_shared_examples.rb b/spec/helpers/acceptance/tests/manifest_shared_examples.rb index 49c5597..3fdfaf0 100644 --- a/spec/helpers/acceptance/tests/manifest_shared_examples.rb +++ b/spec/helpers/acceptance/tests/manifest_shared_examples.rb @@ -1,37 +1,37 @@ shared_examples 'manifest application' do |idempotency_check = true| context '1-node manifest' do let(:applied_manifest) do repo = if elastic_repo <<-MANIFEST class { 'elastic_stack::repo': oss => #{v[:oss]}, version => #{v[:elasticsearch_major_version]}, } MANIFEST else '' end <<-MANIFEST #{repo} class { 'elasticsearch' : #{manifest} #{defined?(manifest_class_parameters) && manifest_class_parameters} } #{defined?(extra_manifest) && extra_manifest} MANIFEST end it 'applies cleanly' do - apply_manifest(applied_manifest, {:catch_failures => true, :debug => v[:puppet_debug]}) + apply_manifest(applied_manifest, :catch_failures => true, :debug => v[:puppet_debug]) end if idempotency_check it 'is idempotent', :logs_on_failure do - apply_manifest(applied_manifest, {:catch_changes => true, :debug => v[:puppet_debug]}) + apply_manifest(applied_manifest, :catch_changes => true, :debug => v[:puppet_debug]) end end end end diff --git a/spec/helpers/acceptance/tests/removal_shared_examples.rb b/spec/helpers/acceptance/tests/removal_shared_examples.rb index fa12824..52e7ac6 100644 --- a/spec/helpers/acceptance/tests/removal_shared_examples.rb +++ b/spec/helpers/acceptance/tests/removal_shared_examples.rb @@ -1,31 +1,30 @@ shared_examples 'module removal' do |es_config| describe 'uninstalling' do let(:manifest) do <<-MANIFEST class { 'elasticsearch': ensure => 'absent', oss => #{v[:oss]} } MANIFEST end it 'should run successfully' do apply_manifest manifest, :catch_failures => true end it 'is idempotent' do apply_manifest manifest, :catch_changes => true end describe service('elasticsearch') do it { should_not be_enabled } it { should_not be_running } end unless es_config.empty? describe port(es_config['http.port']) do it 'closed' do should_not be_listening end end end - end end diff --git a/spec/spec_utilities.rb b/spec/spec_utilities.rb index 1e8035c..462c273 100644 --- a/spec/spec_utilities.rb +++ b/spec/spec_utilities.rb @@ -1,149 +1,149 @@ require 'bcrypt' require 'open-uri' def to_agent_version(puppet_version) # REF: https://docs.puppet.com/puppet/latest/reference/about_agent.html { # Puppet => Agent '4.10.4' => '1.10.4', '4.10.3' => '1.10.3', '4.10.2' => '1.10.2', '4.10.1' => '1.10.1', '4.10.0' => '1.10.0', '4.9.4' => '1.9.3', '4.8.2' => '1.8.3', '4.7.1' => '1.7.2', '4.7.0' => '1.7.1', '4.6.2' => '1.6.2', '4.5.3' => '1.5.3', '4.4.2' => '1.4.2', '4.4.1' => '1.4.1', '4.4.0' => '1.4.0', '4.3.2' => '1.3.6', '4.3.1' => '1.3.2', '4.3.0' => '1.3.0', '4.2.3' => '1.2.7', '4.2.2' => '1.2.6', '4.2.1' => '1.2.2', '4.2.0' => '1.2.1', '4.1.0' => '1.1.1', '4.0.0' => '1.0.1' }[puppet_version] end def derive_artifact_urls_for(full_version, plugins = ['analysis-icu']) derive_full_package_url(full_version).merge( derive_plugin_urls_for(full_version, plugins) ) end def derive_full_package_url(full_version, extensions = %w[deb rpm]) extensions.map do |ext| url = if full_version.start_with? '2' "https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-#{full_version}.#{ext}" else "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-#{full_version}.#{ext}" end [url, File.basename(url)] end.to_h end def derive_plugin_urls_for(full_version, plugins = ['analysis-icu']) plugins.map do |plugin| url = if full_version.start_with? '2' "https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/plugin/#{plugin}/#{full_version}/#{plugin}-#{full_version}.zip" else "https://artifacts.elastic.co/downloads/elasticsearch-plugins/#{plugin}/#{plugin}-#{full_version}.zip" end [url, File.join('plugins', File.basename(url))] end.to_h end def artifact(file, fixture_path = []) File.join(%w[spec fixtures artifacts] + fixture_path + [File.basename(file)]) end def get(url, file_path) puts "Fetching #{url}..." found = false until found uri = URI.parse(url) conn = Net::HTTP.new(uri.host, uri.port) conn.use_ssl = true res = conn.get(uri.path) if res.header['location'] url = res.header['location'] else found = true end end File.open(file_path, 'w+') { |fh| fh.write res.body } end def fetch_archives(archives) archives.each do |url, orig_fp| fp = "spec/fixtures/artifacts/#{orig_fp}" if File.exist? fp if fp.end_with? 'tar.gz' and !system("tar -tzf #{fp} &>/dev/null") puts "Archive #{fp} corrupt, re-fetching..." File.delete fp else puts "Already retrieved intact archive #{fp}..." next end end get url, fp end end def pid_file if fact('operatingsystem') == 'Ubuntu' \ and Gem::Version.new(fact('operatingsystemrelease')) \ < Gem::Version.new('15.04') - "/var/run/elasticsearch.pid" + '/var/run/elasticsearch.pid' elsif fact('operatingsystem') == 'Debian' \ and fact('lsbmajdistrelease').to_i <= 7 - "/var/run/elasticsearch.pid" + '/var/run/elasticsearch.pid' else - "/var/run/elasticsearch/elasticsearch.pid" + '/var/run/elasticsearch/elasticsearch.pid' end end def pid_for(instance) if fact('operatingsystem') == 'Ubuntu' \ and Gem::Version.new(fact('operatingsystemrelease')) \ < Gem::Version.new('15.04') "/var/run/elasticsearch-#{instance}.pid" elsif fact('operatingsystem') == 'Debian' \ and fact('lsbmajdistrelease').to_i <= 7 "/var/run/elasticsearch-#{instance}.pid" else "/var/run/elasticsearch/elasticsearch-#{instance}.pid" end end def vault_available? %w[VAULT_ADDR VAULT_APPROLE_ROLE_ID VAULT_APPROLE_SECRET_ID VAULT_PATH].select do |var| ENV[var].nil? end.empty? end def http_retry(url) retries ||= 0 open(url).read rescue retry if (retries += 1) < 3 end # Helper to store arbitrary testing setting values def v RSpec.configuration.v end def semver(version) Gem::Version.new version end def bcrypt(value) BCrypt::Password.create(value) end