Use hostname for report-host with ipv6

The router does not support ipv6 addresses as hostname for the
report-host option.
We now use get_hostname() for a PTR lookup and provide a hostname
instead in ipv6 enviroments.
Closes-Bug: #2061984

Change-Id: If2079e3a8ec7ac025aad7c3b1c7d5282fd3a436d
This commit is contained in:
Federico Bosi 2024-04-17 16:10:11 +02:00
parent 17595788ed
commit cfec8eeaa7
No known key found for this signature in database
GPG Key ID: F7B881CCF7085A75
2 changed files with 55 additions and 2 deletions

View File

@ -503,17 +503,30 @@ class MySQLRouterCharm(charms_openstack.charm.OpenStackCharm):
"WARNING")
return
address_or_hostname = self.db_router_address
if ch_net_ip.is_ipv6(address_or_hostname):
address_or_hostname = \
ch_net_ip.get_hostname(self.db_router_address)
if address_or_hostname is None:
ch_core.hookenv.log("Could not resolve a hostname for {}."
"Bootstrapping WILL fail."
"See LP: #2061984"
.format(self.db_router_address),
level=ch_core.hookenv.ERROR)
cmd = [self.mysqlrouter_bin,
"--user", self.mysqlrouter_user,
"--name", self.name,
"--bootstrap",
"{}:{}@{}".format(self.db_router_user,
self.db_router_password,
self.cluster_address),
ch_net_ip.format_ipv6_addr(
self.cluster_address)
or self.cluster_address),
"--directory", self.mysqlrouter_working_dir,
"--conf-use-sockets",
"--conf-bind-address", self.shared_db_address,
"--report-host", self.db_router_address,
"--report-host", address_or_hostname,
"--conf-base-port", str(self.mysqlrouter_port)]
# Avoid multiple routers trying to bind to the same api port
# Bug #1911907

View File

@ -395,6 +395,10 @@ class TestMySQLRouterCharm(test_utils.PatchHelper):
self.db_router.password.return_value = _json_pass
self.db_router.db_host.return_value = _json_addr
self.is_flag_set.return_value = False
self.patch_object(mysql_router.ch_net_ip, "format_ipv6_addr")
self.format_ipv6_addr.return_value = None
self.patch_object(mysql_router.ch_net_ip, "is_ipv6")
self.is_ipv6.return_value = False
mrc = mysql_router.MySQLRouterCharm()
mrc.options.system_user = _user
@ -484,6 +488,42 @@ class TestMySQLRouterCharm(test_utils.PatchHelper):
self.clear_flag.assert_called_once_with(
mysql_router.MYSQL_ROUTER_BOOTSTRAP_ATTEMPTED)
# Test ipv6 report-host
self.subprocess.reset_mock()
self.set_flag.reset_mock()
self.clear_flag.reset_mock()
self.cmp_pkgrevno.return_value = 1
self.is_flag_set.side_effect = None
self.is_flag_set.return_value = False
self.subprocess.check_output.side_effect = None
_ipv6_addr = "2a01:348:2f4:0:685e:5748:ae62:209f"
_ipv6_json_addr = json.dumps(_ipv6_addr)
self.format_ipv6_addr.return_value = "[{}]".format(_ipv6_addr)
self.is_ipv6.return_value = True
self.patch_object(mysql_router.ch_net_ip, "get_hostname")
db_router_fake_hostname = "FakeHostname.test.tld"
self.get_hostname.return_value = db_router_fake_hostname
self.db_router.db_host.return_value = _ipv6_json_addr
mrc.bootstrap_mysqlrouter()
self.subprocess.check_output.assert_called_once_with(
[mrc.mysqlrouter_bin, "--user", _user, "--name", mrc.name,
"--bootstrap", "{}:{}@[{}]"
.format(mrc.db_router_user, _pass, _ipv6_addr),
"--directory", mrc.mysqlrouter_working_dir,
"--conf-use-sockets",
"--conf-bind-address", mrc.shared_db_address,
"--report-host", db_router_fake_hostname,
"--conf-base-port", _port,
"--disable-rest"],
stderr=self.stdout)
self.set_flag.assert_has_calls([
mock.call(mysql_router.MYSQL_ROUTER_BOOTSTRAP_ATTEMPTED),
mock.call(mysql_router.MYSQL_ROUTER_BOOTSTRAPPED)])
self.clear_flag.assert_called_once_with(
mysql_router.MYSQL_ROUTER_BOOTSTRAP_ATTEMPTED)
def test_start_mysqlrouter(self):
self.patch_object(mysql_router.ch_core.host, "service_start")
_name = "keystone-mysql-router"