From c25cf054312b85482e73c5886370d7db0cf08df7 Mon Sep 17 00:00:00 2001
From: Takashi Kajinami <tkajinam@redhat.com>
Date: Sun, 19 Mar 2023 16:42:36 +0900
Subject: [PATCH] RabbitMQ: Override hostname to ensure correct IP version

Change fe83b5488d33b75be6a9bba97faa8ddd69210973 enforced usage of IPv6
in case the scenario requires IPv6, but this causes the following
failure during rabbitmq startup, because hostname is sometimes resolved
to IPv4 address in CI.

```
ERROR: epmd error for host np0033504771: badarg (unknown POSIX error)
```

This makes sure that hostname env is set according to IP address
version.

Change-Id: I4d876200f0fd8b2b84d893f243fe5615352ef11d
---
 manifests/config.pp   | 2 ++
 manifests/rabbitmq.pp | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/manifests/config.pp b/manifests/config.pp
index 4713a9348..a642acee5 100644
--- a/manifests/config.pp
+++ b/manifests/config.pp
@@ -49,6 +49,7 @@ class openstack_integration::config (
 
   if $ipv6 {
     $host = '::1'
+    $hostname = 'localhost6'
     $ip_version = '6'
     # Note (dmsimard): ipv6 parsing in Swift and keystone_authtoken are
     # different: https://bugs.launchpad.net/swift/+bug/1610064
@@ -57,6 +58,7 @@ class openstack_integration::config (
     $tooz_url = "redis://[${host}]:6379"
   } else {
     $host = '127.0.0.1'
+    $hostname = 'localhost'
     $ip_version = '4'
     $memcached_servers = ["${host}:11211"]
     $swift_memcached_servers = $memcached_servers
diff --git a/manifests/rabbitmq.pp b/manifests/rabbitmq.pp
index 809106742..c191a7d2e 100644
--- a/manifests/rabbitmq.pp
+++ b/manifests/rabbitmq.pp
@@ -28,7 +28,9 @@ class openstack_integration::rabbitmq {
     ssl_cert              => $::openstack_integration::params::cert_path,
     ssl_key               => "/etc/rabbitmq/ssl/private/${facts['networking']['fqdn']}.pem",
     environment_variables => {
-      'LC_ALL' => 'en_US.UTF-8',
+      'LC_ALL'            => 'en_US.UTF-8',
+      'HOSTNAME'          => $::openstack_integration::config::hostname,
+      'RABBITMQ_NODENAME' => "rabbit@${::openstack_integration::config::hostname}"
     },
     repos_ensure          => false,
     manage_python         => false,