]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: better port stripping
authorYuxiang Zhu <vfreex@gmail.com>
Mon, 2 Aug 2021 17:03:11 +0000 (01:03 +0800)
committerSebastian Wagner <sewagner@redhat.com>
Thu, 2 Sep 2021 14:24:39 +0000 (16:24 +0200)
in case the specified port number contains leading zeros

Signed-off-by: Yuxiang Zhu <vfreex@gmail.com>
(cherry picked from commit 496a2c40c87858c188467b7dbacf5e2385ad521c)

src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py

index 4be920db8e0c5eb1ec56f49185e75313000e774f..3bb98dbf6c7056d4bea1c9870f98827a46a5add1 100755 (executable)
@@ -3587,7 +3587,8 @@ def prepare_mon_addresses(
             ctx.mon_ip = wrap_ipv6(ctx.mon_ip)
         hasport = r.findall(ctx.mon_ip)
         if hasport:
-            port = int(hasport[0])
+            port_str = hasport[0]
+            port = int(port_str)
             if port == 6789:
                 addr_arg = '[v1:%s]' % ctx.mon_ip
             elif port == 3300:
@@ -3596,7 +3597,7 @@ def prepare_mon_addresses(
                 logger.warning('Using msgr2 protocol for unrecognized port %d' %
                                port)
                 addr_arg = '[v2:%s]' % ctx.mon_ip
-            base_ip = ctx.mon_ip[0:-(len(str(port))) - 1]
+            base_ip = ctx.mon_ip[0:-(len(port_str)) - 1]
             check_ip_port(ctx, base_ip, port)
         else:
             base_ip = ctx.mon_ip
@@ -3614,10 +3615,11 @@ def prepare_mon_addresses(
             if not hasport:
                 raise Error('--mon-addrv value %s must include port number' %
                             addr_arg)
-            port = int(hasport[0])
+            port_str = hasport[0]
+            port = int(port_str)
             # strip off v1: or v2: prefix
             addr = re.sub(r'^v\d+:', '', addr)
-            base_ip = addr[0:-(len(str(port))) - 1]
+            base_ip = addr[0:-(len(port_str)) - 1]
             check_ip_port(ctx, base_ip, port)
     else:
         raise Error('must specify --mon-ip or --mon-addrv')
index 7a91f4b4b85cfb302d389bfff77b22fa2b7b7315..cd5ed98933ab697689a936f83d92ef02a431829e 100644 (file)
@@ -1280,6 +1280,11 @@ class TestBootstrap(object):
                 {'192.168.1.0/24': {'eth0': ['192.168.1.1']}},
                 True,
             ),
+            (
+                '192.168.1.1:0123',
+                {'192.168.1.0/24': {'eth0': ['192.168.1.1']}},
+                True,
+            ),
             # IPv6
             (
                 '::',
@@ -1301,6 +1306,16 @@ class TestBootstrap(object):
                 {"ffff::/64": {"eth0": ["::ffff:c0a8:101"]}},
                 True,
             ),
+            (
+                '[::ffff:c0a8:101]:1234',
+                {"ffff::/64": {"eth0": ["::ffff:c0a8:101"]}},
+                True,
+            ),
+            (
+                '[::ffff:c0a8:101]:0123',
+                {"ffff::/64": {"eth0": ["::ffff:c0a8:101"]}},
+                True,
+            ),
             (
                 '0000:0000:0000:0000:0000:FFFF:C0A8:0101',
                 {"ffff::/64": {"eth0": ["::ffff:c0a8:101"]}},
@@ -1337,6 +1352,11 @@ class TestBootstrap(object):
                 {'192.168.1.0/24': {'eth0': ['192.168.1.1']}},
                 None,
             ),
+            (
+                '[192.168.1.1:0123]',
+                {'192.168.1.0/24': {'eth0': ['192.168.1.1']}},
+                None,
+            ),
             (
                 '[v2:192.168.1.1:3300,v1:192.168.1.1:6789]',
                 {'192.168.1.0/24': {'eth0': ['192.168.1.1']}},
@@ -1348,6 +1368,11 @@ class TestBootstrap(object):
                 {'ffff::/64': {'eth0': ['::ffff:c0a8:101']}},
                 None,
             ),
+            (
+                '[::ffff:192.168.1.1:0123]',
+                {'ffff::/64': {'eth0': ['::ffff:c0a8:101']}},
+                None,
+            ),
             (
                 '[0000:0000:0000:0000:0000:FFFF:C0A8:0101:1234]',
                 {'ffff::/64': {'eth0': ['::ffff:c0a8:101']}},