From a48e3ae08f344e81c90095d2ccff6a63078e282f Mon Sep 17 00:00:00 2001 From: przemyslavic <43173646+przemyslavic@users.noreply.github.com> Date: Wed, 31 Mar 2021 15:25:46 +0200 Subject: [PATCH] Test adjustments after recent changes to OpenDistro for Elasticsearch, Filebeat and Kibana (#2172) --- .../tests/spec/filebeat/filebeat_spec.rb | 6 ++-- .../common/tests/spec/kibana/kibana_spec.rb | 30 +++++++++++-------- .../common/tests/spec/logging/logging_spec.rb | 21 +++++++------ .../tests/spec/postgresql/postgresql_spec.rb | 7 +++-- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/core/src/epicli/data/common/tests/spec/filebeat/filebeat_spec.rb b/core/src/epicli/data/common/tests/spec/filebeat/filebeat_spec.rb index ca603d2b38..86b13e24f9 100644 --- a/core/src/epicli/data/common/tests/spec/filebeat/filebeat_spec.rb +++ b/core/src/epicli/data/common/tests/spec/filebeat/filebeat_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/core/src/epicli/data/common/tests/spec/kibana/kibana_spec.rb b/core/src/epicli/data/common/tests/spec/kibana/kibana_spec.rb index 6ee3df446b..75a7f763e2 100644 --- a/core/src/epicli/data/common/tests/spec/kibana/kibana_spec.rb +++ b/core/src/epicli/data/common/tests/spec/kibana/kibana_spec.rb @@ -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 @@ -52,7 +54,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 @@ -60,19 +62,23 @@ 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 diff --git a/core/src/epicli/data/common/tests/spec/logging/logging_spec.rb b/core/src/epicli/data/common/tests/spec/logging/logging_spec.rb index 1b95c27684..f8ee648b82 100644 --- a/core/src/epicli/data/common/tests/spec/logging/logging_spec.rb +++ b/core/src/epicli/data/common/tests/spec/logging/logging_spec.rb @@ -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 @@ -40,12 +41,12 @@ 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 @@ -53,11 +54,13 @@ 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 diff --git a/core/src/epicli/data/common/tests/spec/postgresql/postgresql_spec.rb b/core/src/epicli/data/common/tests/spec/postgresql/postgresql_spec.rb index 49496af9c9..e9a6a7b0be 100644 --- a/core/src/epicli/data/common/tests/spec/postgresql/postgresql_spec.rb +++ b/core/src/epicli/data/common/tests/spec/postgresql/postgresql_spec.rb @@ -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"] @@ -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 @@ -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