Move generic tests into a shared spec file

This commit is contained in:
Michael Russell 2018-06-19 12:15:10 +02:00
parent da58c5f0dd
commit c8197ee82a
No known key found for this signature in database
GPG key ID: A90C1696496085FE
4 changed files with 132 additions and 92 deletions

View file

@ -4,22 +4,9 @@ vars = JSON.parse(File.read('/tmp/vars.json'))
shared_examples 'multi::init' do |vars|
describe user('elasticsearch') do
it { should exist }
end
describe service('node1_elasticsearch') do
it { should be_running }
end
describe service('master_elasticsearch') do
it { should be_running }
end
describe package(vars['es_package_name']) do
it { should be_installed }
end
#test configuration parameters have been set - test all appropriately set in config file
describe file('/etc/elasticsearch/node1/elasticsearch.yml') do
it { should be_file }
@ -63,17 +50,10 @@ shared_examples 'multi::init' do |vars|
end
end
describe 'Node listening' do
it 'node should be listening in port 9201' do
expect(port 9201).to be_listening
end
end
#test we started on the correct port was used for master
describe 'master started' do
it 'master node should be running', :retry => 3, :retry_wait => 10 do
command = command('curl "localhost:9200" | grep name')
#expect(command.stdout).should match '/*master_localhost*/'
expect(json_curl('http://localhost:9200')['name']).to eq('localhost-node1')
expect(command.exit_status).to eq(0)
end
end
@ -87,43 +67,7 @@ shared_examples 'multi::init' do |vars|
end
end
describe file('/etc/elasticsearch/templates') do
it { should be_directory }
it { should be_owned_by 'elasticsearch' }
end
describe file('/etc/elasticsearch/templates/basic.json') do
it { should be_file }
it { should be_owned_by 'elasticsearch' }
end
describe 'Template Installed' do
it 'should be reported as being installed', :retry => 3, :retry_wait => 10 do
command = command('curl localhost:9200/_template/basic')
expect(command.stdout).to match(/basic/)
expect(command.exit_status).to eq(0)
end
end
describe 'Template Installed' do
it 'should be reported as being installed', :retry => 3, :retry_wait => 10 do
command = command('curl localhost:9201/_template/basic')
expect(command.stdout).to match(/basic/)
expect(command.exit_status).to eq(0)
end
end
#Confirm scripts are on both nodes
describe file('/etc/elasticsearch/node1/scripts') do
it { should be_directory }
it { should be_owned_by 'elasticsearch' }
end
describe file('/etc/elasticsearch/node1/scripts/calculate-score.groovy') do
it { should be_file }
it { should be_owned_by 'elasticsearch' }
end
describe file('/etc/elasticsearch/master/scripts') do
it { should be_directory }
it { should be_owned_by 'elasticsearch' }
@ -195,29 +139,4 @@ shared_examples 'multi::init' do |vars|
it { should be_owned_by 'elasticsearch' }
end
end
describe file('/etc/init.d/elasticsearch') do
it { should_not exist }
end
if ['debian', 'ubuntu'].include?(os[:family])
describe file('/etc/default/elasticsearch') do
its(:content) { should match '' }
end
end
if ['centos', 'redhat'].include?(os[:family])
describe file('/etc/sysconfig/elasticsearch') do
its(:content) { should match '' }
end
end
describe file('/etc/elasticsearch/elasticsearch.yml') do
it { should_not exist }
end
describe file('/etc/elasticsearch/logging.yml') do
it { should_not exist }
end
end
end

View file

@ -0,0 +1,102 @@
require 'spec_helper'
require 'json'
vars = JSON.parse(File.read('/tmp/vars.json'))
shared_examples 'shared::init' do |vars|
describe user(vars['es_user']) do
it { should exist }
it { should belong_to_group vars['es_group'] }
it { should have_login_shell '/bin/false' }
it { should have_uid vars['es_user_id'] } if vars.key?('es_user_id')
its(:encrypted_password) { should eq('*') }
end
describe package(vars['es_package_name']) do
it { should be_installed }
end
describe service('node1_elasticsearch') do
it { should be_running }
end
describe port(vars['es_api_port']) do
it { should be_listening.with('tcp') }
end
# if vars['es_templates']
# describe file('/etc/elasticsearch/templates') do
# it { should be_directory }
# it { should be_owned_by vars['es_user'] }
# end
# describe file('/etc/elasticsearch/templates/basic.json') do
# it { should be_file }
# it { should be_owned_by vars['es_user'] }
# end
# describe 'Template Installed' do
# it 'should be reported as being installed', :retry => 3, :retry_wait => 10 do
# command = command('curl localhost:9200/_template/basic')
# expect(command.stdout).to match(/basic/)
# expect(command.exit_status).to eq(0)
# end
# end
# describe 'Template Installed' do
# it 'should be reported as being installed', :retry => 3, :retry_wait => 10 do
# command = command('curl localhost:9201/_template/basic')
# expect(command.stdout).to match(/basic/)
# expect(command.exit_status).to eq(0)
# end
# end
# end
if vars['es_scripts']
describe file('/etc/elasticsearch/node1/scripts') do
it { should be_directory }
it { should be_owned_by 'elasticsearch' }
end
describe file('/etc/elasticsearch/node1/scripts/calculate-score.groovy') do
it { should be_file }
it { should be_owned_by 'elasticsearch' }
end
end
describe file('/etc/init.d/elasticsearch') do
it { should_not exist }
end
if ['debian', 'ubuntu'].include?(os[:family])
describe file('/etc/default/elasticsearch') do
its(:content) { should match '' }
end
end
if ['centos', 'redhat'].include?(os[:family])
describe file('/etc/sysconfig/elasticsearch') do
its(:content) { should match '' }
end
end
describe file('/etc/elasticsearch/elasticsearch.yml') do
it { should_not exist }
end
describe file('/etc/elasticsearch/logging.yml') do
it { should_not exist }
end
vars['es_plugins'].each do |plugin|
name = plugin['plugin']
url = "http://localhost:#{vars['es_api_port']}"
describe file('/usr/share/elasticsearch/plugins/'+name) do
it { should be_directory }
it { should be_owned_by vars['es_user'] }
end
it 'should be installed and the right version' do
plugins = curl_json("#{url}/_nodes/plugins")
version = nil
_node, data = plugins['nodes'].first
data['plugins'].each do |p|
version = p['version'] if p['name'] == name
end
expect(version).to eql(vars['es_version'])
end
end
end

View file

@ -1,8 +1,8 @@
---
#Test ability to deploy multiple instances to a machine
# Test ability to deploy multiple instances to a machine
- name: Elasticsearch Multi test - master on 9200
hosts: localhost
tasks:
post_tasks:
- include: elasticsearch/test/integration/debug.yml
vars:
es_enable_xpack: false
@ -13,11 +13,20 @@
es_plugins:
- plugin: ingest-geoip
roles:
- { role: elasticsearch, es_instance_name: "master", es_data_dirs: ["/opt/elasticsearch/master"], es_config: { discovery.zen.ping.unicast.hosts: "localhost:9300", http.port: 9200, transport.tcp.port: 9300, node.data: false, node.master: true, bootstrap.memory_lock: true } }
- role: elasticsearch
es_instance_name: "master"
es_data_dirs: ["/opt/elasticsearch/master"]
es_config:
discovery.zen.ping.unicast.hosts: "localhost:9300"
http.port: 9200
transport.tcp.port: 9300
node.data: false
node.master: true
bootstrap.memory_lock: true
- name: Elasticsearch Multi test - data on 9201
hosts: localhost
tasks:
post_tasks:
- include: elasticsearch/test/integration/debug.yml
vars:
es_enable_xpack: false
@ -28,5 +37,12 @@
es_plugins:
- plugin: ingest-geoip
roles:
- { role: elasticsearch, es_instance_name: "node1", es_data_dirs: "/opt/elasticsearch/data-1,/opt/elasticsearch/data-2", es_config: { discovery.zen.ping.unicast.hosts: "localhost:9300", http.port: 9201, transport.tcp.port: 9301, node.data: true, node.master: false } }
#Plugins installed for this test are specified in .kitchen.yml under suite
- role: elasticsearch
es_instance_name: "node1"
es_data_dirs: "/opt/elasticsearch/data-1,/opt/elasticsearch/data-2"
es_config:
discovery.zen.ping.unicast.hosts: "localhost:9300"
http.port: 9201
transport.tcp.port: 9301
node.data: true
node.master: false

View file

@ -1,9 +1,12 @@
require 'multi_spec'
require 'shared_spec'
require 'json'
vars = JSON.parse(File.read('/tmp/vars.json'))
describe 'Multi Tests' do
include_examples 'multi::init', vars
describe 'Shared Tests' do
include_examples 'shared::init', vars
end
describe 'Multi Tests' do
include_examples 'multi::init', vars
end