<p>Kevin Harwell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/8863">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">utils_socket: range of random ports searched only once<br><br>If a range (greater than 1) of random ports was asked for, and if a port in<br>range was not available an exception was thrown stating the a port in range<br>was not free.<br><br>This patch makes it so the exception is caught and a new random port range is<br>tried again (up to "attempts" tries) before quitting.<br><br>Change-Id: I96affa9df38acf569f5d3c0965ac7b78d865455d<br>---<br>M lib/python/asterisk/utils_socket.py<br>1 file changed, 15 insertions(+), 3 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/testsuite refs/changes/63/8863/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/lib/python/asterisk/utils_socket.py b/lib/python/asterisk/utils_socket.py<br>index 2a11c97..8e4b32e 100644<br>--- a/lib/python/asterisk/utils_socket.py<br>+++ b/lib/python/asterisk/utils_socket.py<br>@@ -195,6 +195,9 @@<br>         if not isinstance(ports, list):<br>             ports = list(ports)<br> <br>+        LOGGER.debug("Checking the following {0}/{1} ports for availability: "<br>+            "{2}".format(socket_type(socktype), socket_family(family), ports))<br>+<br>         res = []<br>         for port in ports:<br>             for attempt in range(attempts):<br>@@ -238,9 +241,18 @@<br> <br>             # Need a random port first<br>             port = self.get_avail(host, 0, socktype, family)<br>-            ports = self.get_avail(<br>-                host, range(port[0] + step, port[0] + num, step),<br>-                socktype, family, attempts)<br>+<br>+            if abs(num) <= 1:<br>+                return port<br>+<br>+            try:<br>+                ports = self.get_avail(<br>+                    host, range(port[0] + step, port[0] + num, step),<br>+                    socktype, family, attempts)<br>+            except PortError:<br>+                # At least one port not free, try again<br>+                continue<br>+<br>             if ports:<br>                 return port + ports<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8863">change 8863</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/8863"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: testsuite </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I96affa9df38acf569f5d3c0965ac7b78d865455d </div>
<div style="display:none"> Gerrit-Change-Number: 8863 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Kevin Harwell <kharwell@digium.com> </div>