]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephadm: better port stripping
authorYuxiang Zhu <vfreex@gmail.com>
Mon, 2 Aug 2021 17:03:11 +0000 (01:03 +0800)
committerYuxiang Zhu <vfreex@gmail.com>
Fri, 6 Aug 2021 08:09:28 +0000 (16:09 +0800)
in case the specified port number contains leading zeros

Signed-off-by: Yuxiang Zhu <vfreex@gmail.com>
src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py

index 36ac41618cea6a942086ed92e088ceecf2e679bf..af3588567608b403d891493002229551d08e22f7 100755 (executable)
@@ -3612,7 +3612,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:
@@ -3621,7 +3622,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
@@ -3639,10 +3640,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 4fa0d63d37423bd7ef2a538a5f90d556c51b9f73..77508d1b389842866bffe80eaab01b9abf772c58 100644 (file)
@@ -1300,6 +1300,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
             (
                 '::',
@@ -1321,6 +1326,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"]}},
@@ -1357,6 +1372,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']}},
@@ -1368,6 +1388,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']}},