From 6330f87c059193f5876f5fac7a11cb4b12415ddb Mon Sep 17 00:00:00 2001 From: to-bar <46519524+to-bar@users.noreply.github.com> Date: Mon, 18 Jan 2021 18:17:29 +0100 Subject: [PATCH] Fix RabbitMQ upgrade issue with using long names (#1977) * Set rabbitmq_use_longname to AUTOCONFIGURED * Disable long node names before starting service * Adjust automated tests * Improve get_zookeeper_admin_server_port --- .../rabbitmq/templates/rabbitmq-env.conf.j2 | 12 +++++++++++- .../roles/upgrade/tasks/rabbitmq.yml | 14 +++++++++++++- .../defaults/configuration/rabbitmq.yml | 2 +- .../tests/spec/rabbitmq/rabbitmq_spec.rb | 19 +++++++++++++------ .../tests/spec/zookeeper/zookeeper_helpers.rb | 14 ++++++-------- 5 files changed, 44 insertions(+), 17 deletions(-) diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/rabbitmq/templates/rabbitmq-env.conf.j2 b/core/src/epicli/data/common/ansible/playbooks/roles/rabbitmq/templates/rabbitmq-env.conf.j2 index c2df4e0316..46f4e7fc4f 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/rabbitmq/templates/rabbitmq-env.conf.j2 +++ b/core/src/epicli/data/common/ansible/playbooks/roles/rabbitmq/templates/rabbitmq-env.conf.j2 @@ -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 diff --git a/core/src/epicli/data/common/ansible/playbooks/roles/upgrade/tasks/rabbitmq.yml b/core/src/epicli/data/common/ansible/playbooks/roles/upgrade/tasks/rabbitmq.yml index f69b34f1c0..2af13cd6a0 100644 --- a/core/src/epicli/data/common/ansible/playbooks/roles/upgrade/tasks/rabbitmq.yml +++ b/core/src/epicli/data/common/ansible/playbooks/roles/upgrade/tasks/rabbitmq.yml @@ -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] }}" @@ -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 }} diff --git a/core/src/epicli/data/common/defaults/configuration/rabbitmq.yml b/core/src/epicli/data/common/defaults/configuration/rabbitmq.yml index ddacc0ac4e..da923cb9f3 100644 --- a/core/src/epicli/data/common/defaults/configuration/rabbitmq.yml +++ b/core/src/epicli/data/common/defaults/configuration/rabbitmq.yml @@ -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: [] diff --git a/core/src/epicli/data/common/tests/spec/rabbitmq/rabbitmq_spec.rb b/core/src/epicli/data/common/tests/spec/rabbitmq/rabbitmq_spec.rb index b4e286c2a8..7d563b1701 100644 --- a/core/src/epicli/data/common/tests/spec/rabbitmq/rabbitmq_spec.rb +++ b/core/src/epicli/data/common/tests/spec/rabbitmq/rabbitmq_spec.rb @@ -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 diff --git a/core/src/epicli/data/common/tests/spec/zookeeper/zookeeper_helpers.rb b/core/src/epicli/data/common/tests/spec/zookeeper/zookeeper_helpers.rb index b14fb411ee..8290d9fda4 100644 --- a/core/src/epicli/data/common/tests/spec/zookeeper/zookeeper_helpers.rb +++ b/core/src/epicli/data/common/tests/spec/zookeeper/zookeeper_helpers.rb @@ -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