From ae7271d47da01dfeb90ed643da2cba91fc8fa2ce Mon Sep 17 00:00:00 2001 From: Michael Fritch Date: Thu, 10 Jun 2021 21:22:56 -0600 Subject: [PATCH] cephadm: add log warn when unable to infer mon ip addr fixup for `--mon-ip` bootstrap test (introduced b3e2c43): ValueError: 'eth0' does not appear to be an IPv4 or IPv6 address Signed-off-by: Michael Fritch --- src/cephadm/cephadm | 18 ++++++++++-------- src/cephadm/tests/test_cephadm.py | 6 +++--- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 26fd130dce254..597483bc94bf4 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -3501,19 +3501,21 @@ def prepare_mon_addresses( if not ctx.skip_mon_network: # make sure IP is configured locally, and then figure out the # CIDR network + errmsg = f'Cannot infer CIDR network for mon IP `{base_ip}`' for net, ifaces in list_networks(ctx).items(): ips: List[str] = [] for iface, ls in ifaces.items(): ips.extend(ls) - if ipaddress.ip_address(unwrap_ipv6(base_ip)) in \ - [ipaddress.ip_address(ip) for ip in ips]: - mon_network = net - logger.info('Mon IP %s is in CIDR network %s' % (base_ip, - mon_network)) - break + try: + if ipaddress.ip_address(unwrap_ipv6(base_ip)) in \ + [ipaddress.ip_address(ip) for ip in ips]: + mon_network = net + logger.info(f'Mon IP `{base_ip}` is in CIDR network `{mon_network}`') + break + except ValueError as e: + logger.warning(f'{errmsg}: {e}') if not mon_network: - raise Error('Failed to infer CIDR network for mon ip %s; pass ' - '--skip-mon-network to configure it later' % base_ip) + raise Error(f'{errmsg}: pass --skip-mon-network to configure it later') return (addr_arg, ipv6, mon_network) diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index 0dc33aa7b992f..7fcde238fd382 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -1065,7 +1065,7 @@ class TestBootstrap(object): cmd = self._get_cmd('--mon-ip', '192.168.1.1') with with_cephadm_ctx(cmd, list_networks={}) as ctx: - msg = r'Failed to infer CIDR network' + msg = r'--skip-mon-network' with pytest.raises(cd.Error, match=msg): cd.command_bootstrap(ctx) @@ -1132,8 +1132,8 @@ class TestBootstrap(object): def test_mon_ip(self, mon_ip, list_networks, result, cephadm_fs): cmd = self._get_cmd('--mon-ip', mon_ip) if not result: - with with_cephadm_ctx(cmd, list_networks={}) as ctx: - msg = r'Failed to infer CIDR network' + with with_cephadm_ctx(cmd, list_networks=list_networks) as ctx: + msg = r'--skip-mon-network' with pytest.raises(cd.Error, match=msg): cd.command_bootstrap(ctx) else: -- 2.39.5