Skip to content

Commit

Permalink
Test adjustments after recent changes to OpenDistro for Elasticsearch…
Browse files Browse the repository at this point in the history
…, Filebeat and Kibana (#2172)
  • Loading branch information
przemyslavic authored Mar 31, 2021
1 parent 87b3c9e commit a48e3ae
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'

elasticsearch_admin_password = readDataYaml("configuration/logging")["specification"]["admin_password"]
elasticsearch_api_port = 9200
kibana_api_port = 5601
kibanaserver_password = readDataYaml("configuration/logging")["specification"]["kibanaserver_password"]

describe 'Checking if Filebeat package is installed' do
describe package('filebeat') do
Expand Down Expand Up @@ -41,7 +43,7 @@
listInventoryHosts("logging").each do |val|
describe 'Checking the connection to the Elasticsearch hosts' do
let(:disable_sudo) { false }
describe command("curl -k -u admin:admin -o /dev/null -s -w '%{http_code}' https://#{val}:#{elasticsearch_api_port}") do
describe command("curl -k -u admin:#{elasticsearch_admin_password} -o /dev/null -s -w '%{http_code}' https://#{val}:#{elasticsearch_api_port}") do
it "is expected to be equal" do
expect(subject.stdout.to_i).to eq 200
end
Expand All @@ -52,7 +54,7 @@
listInventoryHosts("kibana").each do |val|
describe 'Checking the connection to the Kibana endpoint' do
let(:disable_sudo) { false }
describe command("curl -u admin:admin -o /dev/null -s -w '%{http_code}' http://#{val}:#{kibana_api_port}/app/kibana") do
describe command("curl -u admin:#{kibanaserver_password} -o /dev/null -s -w '%{http_code}' http://#{val}:#{kibana_api_port}/app/kibana") do
it "is expected to be equal" do
expect(subject.stdout.to_i).to eq 200
end
Expand Down
30 changes: 18 additions & 12 deletions core/src/epicli/data/common/tests/spec/kibana/kibana_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
require 'spec_helper'

kibana_default_port = 5601
elasticsearch_admin_password = readDataYaml("configuration/logging")["specification"]["admin_password"]
elasticsearch_api_port = 9200
kibana_default_port = 5601
kibanaserver_password = readDataYaml("configuration/logging")["specification"]["kibanaserver_password"]

describe 'Checking if Kibana package is installed' do
describe package('opendistroforelasticsearch-kibana') do
Expand Down Expand Up @@ -52,27 +54,31 @@
listInventoryHosts("logging").each do |val|
describe 'Checking the connection to the Elasticsearch hosts' do
let(:disable_sudo) { false }
describe command("curl -k -u admin:admin -o /dev/null -s -w '%{http_code}' https://#{val}:#{elasticsearch_api_port}") do
describe command("curl -k -u admin:#{elasticsearch_admin_password} -o /dev/null -s -w '%{http_code}' https://#{val}:#{elasticsearch_api_port}") do
it "is expected to be equal" do
expect(subject.stdout.to_i).to eq 200
end
end
end
end

describe 'Checking Kibana app HTTP status code' do
let(:disable_sudo) { false }
describe command("curl -u admin:admin -o /dev/null -s -w '%{http_code}' http://$(hostname):#{kibana_default_port}/app/kibana") do
it "is expected to be equal" do
expect(subject.stdout.to_i).to eq 200
listInventoryHosts("kibana").each do |val|
describe 'Checking Kibana app HTTP status code' do
let(:disable_sudo) { false }
describe command("curl -u admin:#{kibanaserver_password} -o /dev/null -s -w '%{http_code}' http://#{val}:#{kibana_default_port}/app/kibana") do
it "is expected to be equal" do
expect(subject.stdout.to_i).to eq 200
end
end
end
end

describe 'Checking Kibana health' do
let(:disable_sudo) { false }
describe command("curl http://$(hostname):#{kibana_default_port}/api/status") do
its(:stdout_as_json) { should include('status' => include('overall' => include('state' => 'green'))) }
its(:exit_status) { should eq 0 }
listInventoryHosts("kibana").each do |val|
describe 'Checking Kibana health' do
let(:disable_sudo) { false }
describe command("curl http://#{val}:#{kibana_default_port}/api/status") do
its(:stdout_as_json) { should include('status' => include('overall' => include('state' => 'green'))) }
its(:exit_status) { should eq 0 }
end
end
end
21 changes: 12 additions & 9 deletions core/src/epicli/data/common/tests/spec/logging/logging_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
require 'spec_helper'

elasticsearch_rest_api_port = 9200
elasticsearch_admin_password = readDataYaml("configuration/logging")["specification"]["admin_password"]
elasticsearch_communication_port = 9300
elasticsearch_rest_api_port = 9200

describe 'Checking if Elasticsearch service is running' do
describe service('elasticsearch') do
Expand Down Expand Up @@ -40,24 +41,26 @@
describe port(elasticsearch_communication_port) do
it { should be_listening }
end
end
end

listInventoryHosts("logging").each do |val|
describe 'Checking Elasticsearch nodes status codes' do
let(:disable_sudo) { false }
describe command("curl -k -u admin:admin -o /dev/null -s -w '%{http_code}' https://#{val}:#{elasticsearch_rest_api_port}") do
describe command("curl -k -u admin:#{elasticsearch_admin_password} -o /dev/null -s -w '%{http_code}' https://#{val}:#{elasticsearch_rest_api_port}") do
it "is expected to be equal" do
expect(subject.stdout.to_i).to eq 200
end
end
end
end

describe 'Checking Elasticsearch health' do
let(:disable_sudo) { false }
describe command("curl -k -u admin:admin https://$(hostname):#{elasticsearch_rest_api_port}/_cluster/health?pretty=true") do
its(:stdout_as_json) { should include('status' => /green|yellow/) }
its(:stdout_as_json) { should include('number_of_nodes' => countInventoryHosts("logging")) }
its(:exit_status) { should eq 0 }
listInventoryHosts("logging").each do |val|
describe 'Checking Elasticsearch health' do
let(:disable_sudo) { false }
describe command("curl -k -u admin:#{elasticsearch_admin_password} https://#{val}:#{elasticsearch_rest_api_port}/_cluster/health?pretty=true") do
its(:stdout_as_json) { should include('status' => /green|yellow/) }
its(:stdout_as_json) { should include('number_of_nodes' => countInventoryHosts("logging")) }
its(:exit_status) { should eq 0 }
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
pgbouncer_default_port = 6432
ELASTICSEARCH = { # must be global until we introduce modules
host: listInventoryHosts("logging")[0],
api_port: 9200
api_port: 9200,
admin_password: readDataYaml("configuration/logging")["specification"]["admin_password"]
}
replicated = readDataYaml("configuration/postgresql")["specification"]["extensions"]["replication"]["enabled"]
replication_user = readDataYaml("configuration/postgresql")["specification"]["extensions"]["replication"]["replication_user_name"]
Expand Down Expand Up @@ -536,7 +537,7 @@ def get_elasticsearch_query(message_pattern:, size: 20, with_sort: true)
def get_query_command_with_retries(json_query:, min_doc_hits:, retries: 600, elasticsearch: ELASTICSEARCH)
command = <<~COMMAND
for i in {1..#{retries}}; do
if curl -k -s -u admin:admin 'https://#{elasticsearch[:host]}:#{elasticsearch[:api_port]}/_search?pretty=true' -H 'Content-Type: application/json' -d '#{json_query}'
if curl -k -s -u admin:#{elasticsearch[:admin_password]} 'https://#{elasticsearch[:host]}:#{elasticsearch[:api_port]}/_search?pretty=true' -H 'Content-Type: application/json' -d '#{json_query}'
| jq --exit-status '. | select(.hits.total.value >= #{min_doc_hits})'; then
echo 'READY'; break;
else
Expand Down Expand Up @@ -577,7 +578,7 @@ def get_query_command_with_retries(json_query:, min_doc_hits:, retries: 600, ela

describe 'Check support for multiline messages' do
query = get_elasticsearch_query(message_pattern: "\"ADD COLUMN city text\"")
describe command("curl -k -u admin:admin 'https://#{ELASTICSEARCH[:host]}:#{ELASTICSEARCH[:api_port]}/_search?pretty=true' -H 'Content-Type: application/json' -d '#{query.squish}'") do
describe command("curl -k -u admin:#{ELASTICSEARCH[:admin_password]} 'https://#{ELASTICSEARCH[:host]}:#{ELASTICSEARCH[:api_port]}/_search?pretty=true' -H 'Content-Type: application/json' -d '#{query.squish}'") do
its(:stdout) { should match /ALTER TABLE serverspec_test\.test.*\\n\\t.*ADD COLUMN id.*\\n\\t.*ADD COLUMN name.*\\n\\t.*ADD COLUMN city.*\\n\\t.*ADD COLUMN description/ }
its(:exit_status) { should eq 0 }
end
Expand Down

0 comments on commit a48e3ae

Please sign in to comment.