Make sure shared tests work for RedHat and Debian

This commit is contained in:
Michael Russell 2018-06-19 19:30:40 +02:00
parent 433ed7f5e3
commit 9673fe4679
No known key found for this signature in database
GPG key ID: A90C1696496085FE
3 changed files with 43 additions and 18 deletions

View file

@ -2,14 +2,37 @@ require 'spec_helper'
require 'json'
vars = JSON.parse(File.read('/tmp/vars.json'))
families = {
'Debian' => {
'shell' => '/bin/false',
'password' => '*',
'defaults_path' => '/etc/default/elasticsearch'
},
'RedHat' => {
'shell' => '/sbin/nologin',
'password' => '!!',
'defaults_path' => '/etc/sysconfig/elasticsearch'
}
}
family = families[vars['ansible_os_family']]
es_api_url = "http://localhost:#{vars['es_api_port']}"
shared_examples 'shared::init' do |vars|
describe 'version check' do
it 'should be reported as version '+vars['es_version'] do
expect(curl_json(es_api_url)['version']['number']).to eq(vars['es_version'])
end
end
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('*') }
it { should have_login_shell family['shell'] }
its(:encrypted_password) { should eq(family['password']) }
end
describe package(vars['es_package_name']) do
@ -61,16 +84,9 @@ shared_examples 'shared::init' do |vars|
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
describe file(family['defaults_path']) do
its(:content) { should match '' }
end
describe file('/etc/elasticsearch/elasticsearch.yml') do
@ -83,14 +99,13 @@ shared_examples 'shared::init' do |vars|
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")
plugins = curl_json("#{es_api_url}/_nodes/plugins")
version = nil
_node, data = plugins['nodes'].first
data['plugins'].each do |p|
@ -99,4 +114,15 @@ shared_examples 'shared::init' do |vars|
expect(version).to eql(vars['es_version'])
end
end
describe file('/etc/elasticsearch/node1/elasticsearch.yml') do
it { should contain 'node.name: localhost-node1' }
it { should contain 'cluster.name: elasticsearch' }
if vars['es_major_version'] == '6.x'
it { should_not contain 'path.conf: /etc/elasticsearch/node1' }
else
it { should contain 'path.conf: /etc/elasticsearch/node1' }
end
# it { should contain 'path.data: /var/lib/elasticsearch/localhost-node1' }
it { should contain 'path.logs: /var/log/elasticsearch/localhost-node1' }
end
end

View file

@ -39,7 +39,9 @@
roles:
- role: elasticsearch
es_instance_name: "node1"
es_data_dirs: "/opt/elasticsearch/data-1,/opt/elasticsearch/data-2"
es_data_dirs:
- "/opt/elasticsearch/data-1"
- "/opt/elasticsearch/data-2"
es_config:
discovery.zen.ping.unicast.hosts: "localhost:9300"
http.port: 9201

View file

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