From 7a8c177929dda432daec9f384ede8eeaa7e8d74b Mon Sep 17 00:00:00 2001 From: Redouane Kachach Date: Wed, 31 Aug 2022 13:49:37 +0200 Subject: [PATCH] mgr/cephadm: Fix how we check if a host belongs to public network Fixes: https://tracker.ceph.com/issues/57060 Signed-off-by: Redouane Kachach (cherry picked from commit 1c8833feaf42fd518e19c9a347c6c5781943862a) (cherry picked from commit 511996b755d333fba60c843634a02a11c9b3ba38) Resolves: rhbz#2104947 --- src/pybind/mgr/cephadm/serve.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/pybind/mgr/cephadm/serve.py b/src/pybind/mgr/cephadm/serve.py index c43abca16e320..cea88bb18e41f 100644 --- a/src/pybind/mgr/cephadm/serve.py +++ b/src/pybind/mgr/cephadm/serve.py @@ -1,3 +1,4 @@ +import ipaddress import hashlib import json import logging @@ -608,14 +609,19 @@ class CephadmServe: def matches_network(host): # type: (str) -> bool - # make sure we have 1 or more IPs for any of those networks on that - # host - for network in public_networks: - if len(self.mgr.cache.networks[host].get(network, [])) > 0: - return True + # make sure the host has at least one network that belongs to some configured public network(s) + for pn in public_networks: + public_network = ipaddress.ip_network(pn) + for hn in self.mgr.cache.networks[host]: + host_network = ipaddress.ip_network(hn) + if host_network.overlaps(public_network): + return True + + host_networks = ','.join(self.mgr.cache.networks[host]) + pub_networks = ','.join(public_networks) self.log.info( - f"Filtered out host {host}: does not belong to mon public_network" - f" ({','.join(public_networks)})" + f"Filtered out host {host}: does not belong to mon public_network(s): " + f" {pub_networks}, host network(s): {host_networks}" ) return False -- 2.39.5