Skip to content

Commit 755fcc6

Browse files
committed
test: use a random port for rsyslogd
1 parent 6b1066d commit 755fcc6

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

systest/test_rsyslog.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,14 @@
3636

3737

3838
class _TestRsyslogd:
39-
def __init__(self, *, workdir, logfile, port):
39+
def __init__(self, *, config_file, port):
4040
if not os.path.exists(RSYSLOGD):
4141
raise RuntimeError('"{}" not available'.format(RSYSLOGD))
4242

43+
self.conffile = config_file
4344
self.port = port
44-
self.conffile = "{}/rsyslogd.conf".format(workdir)
4545
self.process = None
4646

47-
with open(self.conffile, "w") as fp:
48-
print(RSYSLOGD_TCP_CONF.format(logfile=logfile, port=port), file=fp)
49-
5047
def _wait_until_running(self):
5148
# Wait until the rsyslogd port is available, but if it is not up in
5249
# five seconds assume that it has failed to start
@@ -63,7 +60,7 @@ def _wait_until_running(self):
6360
def start(self):
6461
# Start rsyslogd in the foreground
6562
# pylint: disable=consider-using-with
66-
self.process = Popen([RSYSLOGD, "-f", self.conffile, "-i", "NONE", "-n", "-C"])
63+
self.process = Popen([RSYSLOGD, "-d", "-f", self.conffile, "-i", "NONE", "-n", "-C"])
6764
self._wait_until_running()
6865

6966
def stop(self):
@@ -124,7 +121,8 @@ def _run_pump_test(*, config_path, logfile):
124121

125122

126123
def test_rsyslogd_tcp_sender(tmpdir):
127-
workdir = tmpdir.dirname
124+
port = random.randrange(49152, 65536)
125+
workdir = str(tmpdir.mkdir(f"{port}"))
128126
logfile = "{}/test.log".format(workdir)
129127
config_path = "{}/journalpump.json".format(workdir)
130128
with open(config_path, "w") as fp:
@@ -137,7 +135,7 @@ def test_rsyslogd_tcp_sender(tmpdir):
137135
"rsyslog": {
138136
"output_type": "rsyslog",
139137
"rsyslog_server": "127.0.0.1",
140-
"rsyslog_port": 5140,
138+
"rsyslog_port": port,
141139
"format": "custom",
142140
"logline": "<%pri%>%timestamp% %HOSTNAME% %app-name%[%procid%]: %msg% {%%} %not-valid-tag%",
143141
},
@@ -147,7 +145,11 @@ def test_rsyslogd_tcp_sender(tmpdir):
147145
},
148146
fp,
149147
)
150-
rsyslogd = _TestRsyslogd(workdir=workdir, logfile=logfile, port=5140)
148+
rsyslogd_config_path = "{}/rsyslogd.conf".format(workdir)
149+
with open(rsyslogd_config_path, "w") as fp:
150+
fp.write(RSYSLOGD_TCP_CONF.format(logfile=logfile, port=port))
151+
152+
rsyslogd = _TestRsyslogd(config_file=rsyslogd_config_path, port=port)
151153
try:
152154
rsyslogd.start()
153155
_run_pump_test(config_path=config_path, logfile=logfile)

0 commit comments

Comments
 (0)