diff options
author | zsdc <taras@vyos.io> | 2021-08-26 23:18:29 +0300 |
---|---|---|
committer | zsdc <taras@vyos.io> | 2021-08-26 23:18:29 +0300 |
commit | eb11d4b688d883d0c1d150b00eee40b54df42b32 (patch) | |
tree | 271446b3fbedca66da86afc42fc1d2d03d04dfb1 /python/vyos/util.py | |
parent | 4523e9c897b3fa8d12c1b16c830c01820fee5583 (diff) | |
download | vyos-1x-eb11d4b688d883d0c1d150b00eee40b54df42b32.tar.gz vyos-1x-eb11d4b688d883d0c1d150b00eee40b54df42b32.zip |
vyos.util: T3763: Optimized the check_port_availability function
`print` was removed or replaced to `ValueError`, where possible.
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r-- | python/vyos/util.py | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index fc2834a97..93a2f6640 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -834,16 +834,13 @@ def check_port_availability(ipaddress, port, protocol): try: ipaddress = ip_address(ipaddress).compressed except: - print(f'The {ipaddress} is not a valid IPv4 or IPv6 address') - return + raise ValueError(f'The {ipaddress} is not a valid IPv4 or IPv6 address') if port not in range(1, 65536): - print(f'The port number {port} is not in the 1-65535 range') - return + raise ValueError(f'The port number {port} is not in the 1-65535 range') if protocol not in ['tcp', 'udp']: - print( + raise ValueError( f'The protocol {protocol} is not supported. Only tcp and udp are allowed' ) - return # check port availability try: @@ -854,7 +851,4 @@ def check_port_availability(ipaddress, port, protocol): server.server_close() return True except: - print( - f'The {protocol} port {port} on the {ipaddress} is busy or unavailable' - ) return False |