Skip to content

Commit

Permalink
Merge pull request #87 from redBorder/bugfix/#17679_by_default_chef_s…
Browse files Browse the repository at this point in the history
…hould_be_up_and_running

Bugfix/#17679 by default chef should be up and running
  • Loading branch information
rgomezborder authored Dec 4, 2024
2 parents dfde3dd + 9727222 commit eedc20b
Showing 1 changed file with 22 additions and 44 deletions.
66 changes: 22 additions & 44 deletions spec/services/chef_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,54 +28,32 @@
end
end

service_status = command("systemctl is-enabled #{service}").stdout
service_status = service_status.strip

if service_status == 'enabled'
describe "Checking #{service_status} service for #{service}..." do
describe service(service) do
it { should be_enabled }
it { should be_running }
end

describe file(config_file) do
it { should exist }
it { should be_file }
end

describe port(port) do
it { should be_listening }
end

describe 'Registered in consul' do
service_json_cluster = command("curl -s #{api_endpoint}/catalog/service/#{serv_consul} | jq -c 'group_by(.ID)[]'")
service_json_cluster = service_json_cluster.stdout.chomp.split("\n")
health_cluster = command("curl -s #{api_endpoint}/health/service/#{serv_consul} | jq -r '.[].Checks[0].Status'")
health_cluster = health_cluster.stdout.chomp.split("\n")
service_and_health = service_json_cluster.zip(health_cluster)
service_and_health.each do |service, health|
registered = JSON.parse(service)[0].key?('Address') && health == 'passing' # ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
end
end
end
describe "Checking service_status for #{service}..." do
describe service(service) do
it { should be_enabled }
it { should be_running }
end
end

if service_status == 'disabled'
describe "Checking #{service_status} service for #{service}..." do
describe service(service) do
it { should_not be_enabled }
it { should_not be_running }
end
describe file(config_file) do
it { should exist }
it { should be_file }
end

describe file(config_file) do
it { should_not exist }
end
describe port(port) do
it { should be_listening }
end

describe port(port) do
it { should_not be_listening }
describe 'Registered in consul' do
service_json_cluster = command("curl -s #{api_endpoint}/catalog/service/#{serv_consul} | jq -c 'group_by(.ID)[]'")
service_json_cluster = service_json_cluster.stdout.chomp.split("\n")
health_cluster = command("curl -s #{api_endpoint}/health/service/#{serv_consul} | jq -r '.[].Checks[0].Status'")
health_cluster = health_cluster.stdout.chomp.split("\n")
service_and_health = service_json_cluster.zip(health_cluster)
service_and_health.each do |sv, health|
registered = JSON.parse(sv)[0].key?('Address') && health == 'passing' # ? true : false
it 'Should be registered and enabled' do
expect(registered).to be true
end
end
end
end

0 comments on commit eedc20b

Please sign in to comment.