summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorzsdc <taras@vyos.io>2021-08-26 23:18:29 +0300
committerzsdc <taras@vyos.io>2021-08-26 23:18:29 +0300
commiteb11d4b688d883d0c1d150b00eee40b54df42b32 (patch)
tree271446b3fbedca66da86afc42fc1d2d03d04dfb1 /python
parent4523e9c897b3fa8d12c1b16c830c01820fee5583 (diff)
downloadvyos-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')
-rw-r--r--python/vyos/util.py12
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