ansible-role-elasticsearch/test/integration/helpers/serverspec/xpack_standard_spec.rb

152 lines
4.8 KiB
Ruby
Raw Normal View History

2017-08-18 19:38:10 +01:00
require 'spec_helper'
shared_examples 'xpack_standard::init' do |vars|
2017-08-18 19:38:10 +01:00
describe user('elasticsearch') do
it { should exist }
end
describe service('security_node_elasticsearch') do
it { should be_running }
end
2018-06-13 08:29:45 +02:00
describe package(vars['es_package_name']) do
2017-08-18 19:38:10 +01:00
it { should be_installed }
end
describe file('/etc/elasticsearch/security_node/elasticsearch.yml') do
it { should be_file }
it { should be_owned_by 'elasticsearch' }
end
describe file('/etc/elasticsearch/security_node/log4j2.properties') do
it { should be_file }
it { should be_owned_by 'elasticsearch' }
end
describe file('/etc/elasticsearch/security_node/elasticsearch.yml') do
it { should contain 'node.name: localhost-security_node' }
it { should contain 'cluster.name: elasticsearch' }
2018-01-31 08:17:44 +01:00
if vars['es_major_version'] == '6.x'
it { should_not contain 'path.conf: /etc/elasticsearch/security_node' }
2018-01-31 08:17:44 +01:00
else
it { should contain 'path.conf: /etc/elasticsearch/security_node' }
2018-01-31 08:17:44 +01:00
end
2017-08-18 19:38:10 +01:00
it { should contain 'path.data: /var/lib/elasticsearch/localhost-security_node' }
it { should contain 'path.logs: /var/log/elasticsearch/localhost-security_node' }
2017-08-18 23:19:01 +01:00
it { should contain 'xpack.security.enabled: false' }
it { should contain 'xpack.watcher.enabled: false' }
2017-08-18 19:38:10 +01:00
end
describe 'Node listening' do
it 'listening in port 9200' do
expect(port 9200).to be_listening
end
end
describe 'version check' do
it 'should be reported as version '+vars['es_version'] do
2017-08-18 20:21:24 +01:00
command = command('curl -s localhost:9200 | grep number')
expect(command.stdout).to match(vars['es_version'])
2017-08-18 19:38:10 +01:00
expect(command.exit_status).to eq(0)
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
2017-08-18 19:38:10 +01:00
end
if ['centos', 'redhat'].include?(os[:family])
describe file('/etc/sysconfig/elasticsearch') do
its(:content) { should match '' }
end
2017-08-18 19:38:10 +01:00
end
describe file('/usr/lib/systemd/system/elasticsearch.service') do
it { should_not exist }
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
#Xpack specific tests
describe file('/usr/share/elasticsearch/plugins') do
it { should be_directory }
it { should be_owned_by 'elasticsearch' }
end
#Test if x-pack is activated
describe 'x-pack activation' do
it 'should be activated and valid' do
2017-08-18 20:21:24 +01:00
command = command('curl -s localhost:9200/_license?pretty=true')
2017-08-18 19:38:10 +01:00
expect(command.stdout).to match('"status" : "active"')
expect(command.exit_status).to eq(0)
end
end
2018-06-13 08:29:45 +02:00
# X-Pack is no longer installed as a plugin in elasticsearch
if vars['es_major_version'] == '5.x'
describe file('/usr/share/elasticsearch/plugins/x-pack') do
it { should be_directory }
it { should be_owned_by 'elasticsearch' }
end
2018-06-13 08:29:45 +02:00
describe 'x-pack-core plugin' do
it 'should be installed with the correct version' do
plugins = curl_json('http://localhost:9200/_nodes/plugins')
node, data = plugins['nodes'].first
version = 'plugin not found'
name = 'x-pack'
2018-06-13 08:29:45 +02:00
data['plugins'].each do |plugin|
if plugin['name'] == name
version = plugin['version']
end
end
2018-06-13 08:29:45 +02:00
expect(version).to eql(vars['es_version'])
end
end
2017-08-18 19:38:10 +01:00
2018-06-13 08:29:45 +02:00
describe file('/etc/elasticsearch/security_node/x-pack') do
it { should be_directory }
it { should be_owned_by 'elasticsearch' }
end
end
2018-06-13 08:29:45 +02:00
#Test users file, users_roles and roles.yml
describe file('/etc/elasticsearch/security_node' + vars['es_xpack_conf_subdir'] + '/users_roles') do
it { should be_owned_by 'elasticsearch' }
end
describe file('/etc/elasticsearch/security_node' + vars['es_xpack_conf_subdir'] + '/users') do
it { should be_owned_by 'elasticsearch' }
2017-08-18 19:38:10 +01:00
end
2018-06-13 08:29:45 +02:00
describe command('curl -s localhost:9200/_nodes/plugins?pretty=true -u es_admin:changeMeAgain | grep x-pack') do
its(:exit_status) { should eq 0 }
2017-08-18 19:38:10 +01:00
end
2017-08-18 23:19:01 +01:00
describe command('curl -s localhost:9200/_xpack') do
its(:stdout_as_json) { should include('features' => include('security' => include('enabled' => false))) }
its(:stdout_as_json) { should include('features' => include('watcher' => include('enabled' => false))) }
its(:stdout_as_json) { should include('features' => include('graph' => include('enabled' => true))) }
its(:stdout_as_json) { should include('features' => include('monitoring' => include('enabled' => true))) }
its(:stdout_as_json) { should include('features' => include('ml' => include('enabled' => true))) }
2017-08-18 19:38:10 +01:00
end
end