From c1de4c4760367361c96081d96ae03293bc49bb18 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Wed, 7 Oct 2020 07:23:42 +0300 Subject: fix: use a random port for Qemu client --- subplot/qemumgr.py | 6 +++++- subplot/subplot.py | 6 ++++-- 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", ] -- cgit v1.2.1