X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=test%2Fintegration%2Ftestlib%2Fproc.py;fp=test%2Fintegration%2Ftestlib%2Fproc.py;h=660b95549c9191421618730f9b0c543f7bb008c4;hp=ffa0a5f50c536d41478e7f537082a42af4dedc94;hb=49265a9689d08a5d9d4663ee61f3c613d6896f14;hpb=99259f215aca7929a17e7f7429c14e8324a2c9f4 diff --git a/test/integration/testlib/proc.py b/test/integration/testlib/proc.py index ffa0a5f5..660b9554 100755 --- a/test/integration/testlib/proc.py +++ b/test/integration/testlib/proc.py @@ -2,6 +2,7 @@ import os import random +import tempfile import typing as T import subprocess as subp from enum import Enum @@ -16,6 +17,9 @@ from .util import random_string, random_port # Does the OS support all addresses in 127.0.0.0/8 without additional configuration? _FULL_LOCALHOST_SUBNET = system() in ("Linux", "Windows") +# Path to the system temporary directory. +_TEMPDIR = tempfile.gettempdir() + def _make_wd(name: str) -> str: work_dir = os.path.join(path.TEST_WD, "data", name) @@ -63,6 +67,7 @@ class Tinc: name: str address: str _work_dir: str + _pid_file: str _port: T.Optional[int] _scripts: T.Dict[str, TincScript] _procs: T.List[subp.Popen] @@ -71,6 +76,8 @@ class Tinc: self.name = name if name else random_string(10) self.address = addr if addr else _rand_localhost() self._work_dir = _make_wd(self.name) + os.makedirs(self._work_dir, exist_ok=True) + self._pid_file = os.path.join(_TEMPDIR, f"tinc_{self.name}") self._port = None self._scripts = {} self._procs = [] @@ -80,12 +87,16 @@ class Tinc: self._port = random_port() return self._port + @property + def pid_file(self) -> str: + """Get the path to the pid file.""" + return self._pid_file + def read_port(self) -> int: """Read port used by tincd from its pidfile and update the _port field.""" - pidfile = self.sub("pid") - log.debug("reading pidfile at %s", pidfile) + log.debug("reading pidfile at %s", self.pid_file) - with open(pidfile, "r", encoding="utf-8") as f: + with open(self.pid_file, "r", encoding="utf-8") as f: content = f.read() log.debug("found data %s", content) @@ -140,9 +151,9 @@ class Tinc: "--net", self.name, "--config", - self._work_dir, + self.work_dir, "--pidfile", - self.sub("pid"), + self.pid_file, ] def sub(self, *paths: str) -> str: