summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-10-07 07:23:42 +0300
committerLars Wirzenius <liw@liw.fi>2020-10-07 07:23:42 +0300
commitc1de4c4760367361c96081d96ae03293bc49bb18 (patch)
tree6d8615c175427e426aea8b279d00d0c891d6c87c
parent746ddbc6e17d9ab8238cc4a8e3a348ccb44878b5 (diff)
downloaddebian-ansible-c1de4c4760367361c96081d96ae03293bc49bb18.tar.gz
fix: use a random port for Qemu client
-rwxr-xr-xsubplot/qemumgr.py6
-rw-r--r--subplot/subplot.py6
2 files changed, 9 insertions, 3 deletions
diff --git a/subplot/qemumgr.py b/subplot/qemumgr.py
index 8951122..0550bdb 100755
--- a/subplot/qemumgr.py
+++ b/subplot/qemumgr.py
@@ -3,6 +3,7 @@
import logging
import os
+import random
import shlex
import shutil
import signal
@@ -51,6 +52,9 @@ class QemuSystem:
def set_username(self, username):
self._username = username
+ def get_port(self):
+ return self._port
+
def _copy_image(self, base_image, size):
image = self._join("qemu.img")
logging.debug(f"QemuSystem: actual disk image: {image}")
@@ -92,7 +96,7 @@ class QemuSystem:
def start(self):
iso = self._cloud_init_iso()
- self._port = 2222 # FIXME
+ self._port = random.randint(2000, 30000)
pid_file = self._join("qemu.pid")
out_file = self._join("qemu.out")
err_file = self._join("qemu.err")
diff --git a/subplot/subplot.py b/subplot/subplot.py
index 4434f24..c9c3cdc 100644
--- a/subplot/subplot.py
+++ b/subplot/subplot.py
@@ -81,6 +81,8 @@ def run_playbook(ctx):
assert_ne = globals()["assert_ne"]
srcdir = globals()["srcdir"]
+ qemu = ctx["qemu"]
+
with open("hosts", "w") as f:
f.write("test-host\n")
@@ -98,7 +100,7 @@ def run_playbook(ctx):
"-ostricthostkeychecking=accept-new",
"-i",
os.path.join(srcdir, "ssh", "id"),
- "-p2222",
+ f"-p{qemu.get_port()}",
]
env = dict(os.environ)
@@ -112,7 +114,7 @@ def run_playbook(ctx):
"hosts",
f"-e@vars.yml",
"-eansible_ssh_host=localhost",
- "-eansible_ssh_port=2222",
+ f"-eansible_ssh_port={qemu.get_port()}",
"playbook.yml",
]