[Asterisk-code-review] utils socket: range of random ports searched only once (testsuite[13])
Jenkins2
asteriskteam at digium.com
Fri Apr 27 07:42:10 CDT 2018
Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/8863 )
Change subject: utils_socket: range of random ports searched only once
......................................................................
utils_socket: range of random ports searched only once
If a range (greater than 1) of random ports was asked for, and if a port in
range was not available an exception was thrown stating the port in range
was not free.
This patch makes it so the exception is caught and a new random port range is
tried again (up to "attempts" tries) before quitting.
Change-Id: I96affa9df38acf569f5d3c0965ac7b78d865455d
---
M lib/python/asterisk/utils_socket.py
1 file changed, 16 insertions(+), 5 deletions(-)
Approvals:
Corey Farrell: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Jenkins2: Approved for Submit
diff --git a/lib/python/asterisk/utils_socket.py b/lib/python/asterisk/utils_socket.py
index 2a11c97..1f62f13 100644
--- a/lib/python/asterisk/utils_socket.py
+++ b/lib/python/asterisk/utils_socket.py
@@ -195,6 +195,9 @@
if not isinstance(ports, list):
ports = list(ports)
+ LOGGER.debug("Checking the following {0}/{1} ports for availability: "
+ "{2}".format(socket_type(socktype), socket_family(family), ports))
+
res = []
for port in ports:
for attempt in range(attempts):
@@ -238,11 +241,19 @@
# Need a random port first
port = self.get_avail(host, 0, socktype, family)
- ports = self.get_avail(
- host, range(port[0] + step, port[0] + num, step),
- socktype, family, attempts)
- if ports:
- return port + ports
+
+ if abs(num) <= 1:
+ return port
+
+ try:
+ ports = self.get_avail(
+ host, range(port[0] + step, port[0] + num, step),
+ socktype, family, attempts)
+ except PortError:
+ # At least one port not free, try again
+ continue
+
+ return port + ports
raise PortError(socktype, family, attempts=attempts)
--
To view, visit https://gerrit.asterisk.org/8863
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: testsuite
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I96affa9df38acf569f5d3c0965ac7b78d865455d
Gerrit-Change-Number: 8863
Gerrit-PatchSet: 3
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180427/1af88be3/attachment.html>
More information about the asterisk-code-review
mailing list