Skip to content

Commit

Permalink
Fix RabbitMQ upgrade issue with using long names (#1977)
Browse files Browse the repository at this point in the history
* Set rabbitmq_use_longname to AUTOCONFIGURED

* Disable long node names before starting service

* Adjust automated tests

* Improve get_zookeeper_admin_server_port
  • Loading branch information
to-bar committed Jan 18, 2021
1 parent abd793e commit 6330f87
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
RABBITMQ_USE_LONGNAME={{ specification.rabbitmq_use_longname }}
# {{ ansible_managed }}

{% if specification.rabbitmq_use_longname|lower == 'autoconfigured' %}
{% if ansible_nodename == ansible_hostname %}
RABBITMQ_USE_LONGNAME=false
{% else %}
RABBITMQ_USE_LONGNAME=true
{% endif %}
{% else %}
RABBITMQ_USE_LONGNAME={{ specification.rabbitmq_use_longname | lower }}
{% endif %}

# Specifies new style config file location
CONFIG_FILE=/etc/rabbitmq/rabbitmq.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
name: rabbitmq-server
state: stopped

# The following task was added to solve issue #1975.
# Till v0.9.0 the default for specification.rabbitmq_use_longname was 'true'.
# On Ubuntu initscript of rabbitmq-server package starts rabbitmq-server.service automatically
# so this task has to be run before upgrading packages.
- name: RabbitMQ | Disable long node names in /etc/rabbitmq/rabbitmq-env.conf
lineinfile:
path: /etc/rabbitmq/rabbitmq-env.conf
regexp: '^RABBITMQ_USE_LONGNAME='
line: RABBITMQ_USE_LONGNAME=false
backup: true
when: ansible_hostname == ansible_fqdn

- name: RabbitMQ | Upgrade packages
package:
name: "{{ _packages[ansible_os_family] }}"
Expand All @@ -41,7 +53,7 @@
- erlang-public-key={{ versions.debian.erlang }}
- erlang-ssl={{ versions.debian.erlang }}

# Additional dependencies required to fix https://github.com/epiphany-platform/epiphany/issues/1920
# Additional dependencies required to fix issue #1920
- erlang-asn1={{ versions.debian.erlang }}
- erlang-base-hipe={{ versions.debian.erlang }}
- erlang-crypto={{ versions.debian.erlang }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ specification:
ulimit_open_files: 65535

amqp_port: 5672
rabbitmq_use_longname: false
rabbitmq_use_longname: AUTOCONFIGURED # true/false/AUTOCONFIGURED
rabbitmq_policies: []
rabbitmq_plugins: []
custom_configurations: []
Expand Down
19 changes: 13 additions & 6 deletions core/src/epicli/data/common/tests/spec/rabbitmq/rabbitmq_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,32 @@
it { should be_listening }
end
end


def rabbitmq_use_longname?
cmd = "grep -Po '(?<=^RABBITMQ_USE_LONGNAME=)\\w+' /etc/rabbitmq/rabbitmq-env.conf"
result = Specinfra.backend.run_command(cmd)
return result.stdout.chomp.downcase == "true"
end

describe 'Checking nodes health using RabbitMQ API' do
let(:disable_sudo) { false }
if clustered
listInventoryHosts("rabbitmq").each do |val|
val = val.split(".")[0]
describe command("curl -o /dev/null -s -w '%{http_code}' -u #{user}:#{pass} #{rabbitmq_host}:#{rabbitmq_api_port}/api/healthchecks/node/rabbit@#{val}") do
listInventoryHosts("rabbitmq").each do |hostname|
hostname = hostname.split(".")[0] unless rabbitmq_use_longname?
describe command("curl -o /dev/null -s -w '%{http_code}' -u #{user}:#{pass} #{rabbitmq_host}:#{rabbitmq_api_port}/api/healthchecks/node/rabbit@#{hostname}") do
it "is expected to be equal" do
expect(subject.stdout.to_i).to eq 200
end
end
describe command("curl -u #{user}:#{pass} #{rabbitmq_host}:#{rabbitmq_api_port}/api/healthchecks/node/rabbit@#{val}") do
describe command("curl -u #{user}:#{pass} #{rabbitmq_host}:#{rabbitmq_api_port}/api/healthchecks/node/rabbit@#{hostname}") do
its(:stdout_as_json) { should include('status' => /ok/) }
its(:stdout_as_json) { should_not include('status' => /failed/) }
its(:exit_status) { should eq 0 }
end
end
else
describe command("curl -o /dev/null -s -w '%{http_code}' -u #{user}:#{pass} #{rabbitmq_host}:#{rabbitmq_api_port}/api/healthchecks/node/rabbit@#{host_inventory['hostname']}") do
hostname = rabbitmq_use_longname? ? host_inventory['fqdn'] : host_inventory['hostname']
describe command("curl -o /dev/null -s -w '%{http_code}' -u #{user}:#{pass} #{rabbitmq_host}:#{rabbitmq_api_port}/api/healthchecks/node/rabbit@#{hostname}") do
it "is expected to be equal" do
expect(subject.stdout.to_i).to eq 200
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
require 'net/ssh'

def get_zookeeper_admin_server_port
default_port = 8080
config_file = "/opt/zookeeper/conf/zoo.cfg"
grep_cmd = "sudo -u zookeeper grep -Po '(?<=^admin\\.serverPort=)\\d+' #{config_file}"
port = ""

Net::SSH.start(ENV['TARGET_HOST'], ENV['user'], keys: [ENV['keypath']], :keys_only => true) do |ssh|
ssh.exec!(grep_cmd) do |channel, stream, data|
port << data if stream == :stdout && /^[0-9]+$/.match(data)
end
result = Specinfra.backend.run_command(grep_cmd)
if /^[0-9]+$/.match?(result.stdout)
port = result.stdout.chomp.to_i
else
port = default_port
end

return port.empty? ? default_port : port.to_i
return port
end

0 comments on commit 6330f87

Please sign in to comment.