]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commit
python-common: fix valid_addr on python 3.11
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 27 Jul 2023 18:17:36 +0000 (14:17 -0400)
committerAdam King <adking@redhat.com>
Thu, 20 Feb 2025 20:47:12 +0000 (15:47 -0500)
commitd46c898fc5deacc7007e2a9e2fc5286b9e84707b
treee2e2521e5ea154d83d669a639e62988278c36c58
parenta33d4403d61d1920174396cfeed5d4a47b73657c
python-common: fix valid_addr on python 3.11

The behavior on python 3.11 regarding IPv4 addresses in bracket has
changed:
```
$ python3.8 -c 'from urllib.parse import urlparse; urlparse("http://[192.168.0.1]")'

[john@edfu ~]$ python3.11 -c 'from urllib.parse import urlparse; urlparse("http://[192.168.0.1]")'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib64/python3.11/urllib/parse.py", line 395, in urlparse
    splitresult = urlsplit(url, scheme, allow_fragments)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.11/urllib/parse.py", line 500, in urlsplit
    _check_bracketed_host(bracketed_host)
  File "/usr/lib64/python3.11/urllib/parse.py", line 448, in
_check_bracketed_host
    raise ValueError(f"An IPv4 address cannot be in brackets")
ValueError: An IPv4 address cannot be in brackets
```

This breaks the test in test_valid_addr that asserts that function
valid_addr returns the string "IPv4 address wrapped in brackets is
invalid".
Move the step that checks for brackets and dots above the urllib
check so that the function continues returning the expected string.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
(cherry picked from commit ef72af7d720f8811368f25cb6f613ccaf5dcd55d)
src/python-common/ceph/deployment/utils.py