]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: fixing ipv6/128 and ipv4/32 subnets handling 46309/head
authorRedouane Kachach <rkachach@redhat.com>
Thu, 5 May 2022 14:08:12 +0000 (16:08 +0200)
committerAdam King <adking@redhat.com>
Tue, 17 May 2022 22:25:25 +0000 (18:25 -0400)
Fixes: https://tracker.ceph.com/issues/51257
Fixes: https://tracker.ceph.com/issues/53496
Signed-off-by: Redouane Kachach <rkachach@redhat.com>
(cherry picked from commit 75945ad74cf614b3516abd3a50de56cbaab58346)

src/cephadm/cephadm
src/cephadm/tests/test_networks.py

index b5d342c596ebfb63ee3b5d95135c2ed0060efaa2..0abe9c91c6912927288caa5876b53bfe6970fea6 100755 (executable)
@@ -5356,12 +5356,14 @@ def _list_ipv4_networks(ctx: CephadmContext) -> Dict[str, Dict[str, Set[str]]]:
 
 def _parse_ipv4_route(out: str) -> Dict[str, Dict[str, Set[str]]]:
     r = {}  # type: Dict[str, Dict[str, Set[str]]]
-    p = re.compile(r'^(\S+) dev (\S+) (.*)scope link (.*)src (\S+)')
+    p = re.compile(r'^(\S+) (?:via \S+)? ?dev (\S+) (.*)scope link (.*)src (\S+)')
     for line in out.splitlines():
         m = p.findall(line)
         if not m:
             continue
         net = m[0][0]
+        if '/' not in net:  # aggregate /32 mask for single host sub-networks
+            net += '/32'
         iface = m[0][1]
         ip = m[0][4]
         if net not in r:
@@ -5391,9 +5393,11 @@ def _parse_ipv6_route(routes: str, ips: str) -> Dict[str, Dict[str, Set[str]]]:
         if not m or m[0][0].lower() == 'default':
             continue
         net = m[0][0]
-        if '/' not in net:  # only consider networks with a mask
-            continue
+        if '/' not in net:  # aggregate /128 mask for single host sub-networks
+            net += '/128'
         iface = m[0][1]
+        if iface == 'lo':  # skip loopback devices
+            continue
         if net not in r:
             r[net] = {}
         if iface not in r[net]:
index ef0f6778a77dc19a4ff3fb44094d67c62da9e531..6fa47ea2704f6efda5932b47a4d71085d572543f 100644 (file)
@@ -24,6 +24,8 @@ class TestCommandListNetworks:
             139.1.0.0/16 via 10.4.0.1 dev tun0 proto static metric 50
             140.1.0.0/17 via 10.4.0.1 dev tun0 proto static metric 50
             141.1.0.0/16 via 10.4.0.1 dev tun0 proto static metric 50
+            172.16.100.34 via 172.16.100.34 dev eth1 proto kernel scope link src 172.16.100.34
+            192.168.122.1 dev ens3 proto dhcp scope link src 192.168.122.236 metric 100
             169.254.0.0/16 dev docker0 scope link metric 1000
             172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1
             192.168.39.0/24 dev virbr1 proto kernel scope link src 192.168.39.1 linkdown
@@ -33,7 +35,9 @@ class TestCommandListNetworks:
             195.135.221.12 via 192.168.178.1 dev enxd89ef3f34260 proto static metric 100
             """),
             {
-                '10.4.0.1': {'tun0': {'10.4.0.2'}},
+                '172.16.100.34/32': {'eth1': {'172.16.100.34'}},
+                '192.168.122.1/32': {'ens3': {'192.168.122.236'}},
+                '10.4.0.1/32': {'tun0': {'10.4.0.2'}},
                 '172.17.0.0/16': {'docker0': {'172.17.0.1'}},
                 '192.168.39.0/24': {'virbr1': {'192.168.39.1'}},
                 '192.168.122.0/24': {'virbr0': {'192.168.122.1'}},
@@ -61,7 +65,7 @@ class TestCommandListNetworks:
             {
                 '10.3.64.0/24': {'eno1': {'10.3.64.23', '10.3.64.27'}},
                 '10.88.0.0/16': {'cni-podman0': {'10.88.0.1'}},
-                '172.21.3.1': {'tun0': {'172.21.3.2'}},
+                '172.21.3.1/32': {'tun0': {'172.21.3.2'}},
                 '192.168.122.0/24': {'virbr0': {'192.168.122.1'}}
             }
         ),
@@ -175,11 +179,14 @@ class TestCommandListNetworks:
                    valid_lft forever preferred_lft forever
             """),
             {
-                '2001:1458:301:eb::/64': {
+                '2001:1458:301:eb::100:1a/128': {
                     'ens20f0': {
                         '2001:1458:301:eb::100:1a'
                     },
                 },
+                '2001:1458:301:eb::/64': {
+                    'ens20f0': set(),
+                },
                 'fe80::/64': {
                     'ens20f0': {'fe80::2e60:cff:fef8:da41'},
                 },
@@ -224,5 +231,5 @@ class TestCommandListNetworks:
         with with_cephadm_ctx([]) as ctx:
             cd.command_list_networks(ctx)
             assert json.loads(capsys.readouterr().out) == {
-                '10.4.0.1': {'tun0': ['10.4.0.2']}
+                '10.4.0.1/32': {'tun0': ['10.4.0.2']}
             }
\ No newline at end of file