[lxc-devel] [lxd/master] tests: Add alternative TCP port finder
stgraber on Github
lxc-bot at linuxcontainers.org
Wed Jul 4 15:52:59 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180704/ac7e55e2/attachment.bin>
-------------- next part --------------
From 3024992f0bcfd7337f811efd4489954cafe769d5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 4 Jul 2018 11:50:08 -0400
Subject: [PATCH] tests: Add alternative TCP port finder
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
test/includes/net.sh | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/test/includes/net.sh b/test/includes/net.sh
index e6e3c2757..1b5512523 100644
--- a/test/includes/net.sh
+++ b/test/includes/net.sh
@@ -2,6 +2,19 @@
# Return an available random local port
local_tcp_port() {
+ if which python3 >/dev/null 2>&1; then
+ (
+ cat << EOF
+import socket
+s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+s.bind(('127.0.0.1', 0))
+print(s.getsockname()[1])
+s.close()
+EOF
+ ) | python3
+ return
+ fi
+
# shellcheck disable=SC2039
local port pid
More information about the lxc-devel
mailing list