tests/{ctrl,vty}_test_runner.py: dump stdout/stderr

From time to time, we're seeing the following error in Jenkins:

----------------------------------------------------------------------
Traceback (most recent call last):
  File ".../tests/vty_test_runner.py", line 70, in tearDown
    raise Exception("Process returned %d" % rc)
Exception: Process returned -9
----------------------------------------------------------------------

Let's dump stdout/stderr of the process to get more information.

Change-Id: Ie6a2f5b1bc56d35513643b52923403798e5a0a5a
Related: OS#5665
This commit is contained in:
Vadim Yanitskiy
2025-09-17 19:37:55 +07:00
parent ebbee0e250
commit d59562d1b4
2 changed files with 37 additions and 2 deletions

View File

@@ -26,6 +26,8 @@ import unittest
import socket
import sys
import struct
import subprocess
import tempfile
import osmopy.obscvty as obscvty
import osmopy.osmoutil as osmoutil
@@ -50,8 +52,12 @@ class TestCtrlBase(unittest.TestCase):
cfi = config_index + 1
osmo_ctrl_cmd[cfi] = os.path.join(confpath, osmo_ctrl_cmd[cfi])
self.stdout = tempfile.TemporaryFile()
self.stderr = tempfile.TemporaryFile()
try:
self.proc = osmoutil.popen_devnull(osmo_ctrl_cmd)
# self.proc = osmoutil.popen_devnull(osmo_ctrl_cmd)
print("Launching: PWD=%s %s" % (os.getcwd(), ' '.join([repr(c) for c in osmo_ctrl_cmd])))
self.proc = subprocess.Popen(osmo_ctrl_cmd, stdout=self.stdout, stderr=self.stderr)
except OSError:
print("Current directory: %s" % os.getcwd(), file=sys.stderr)
print("Consider setting -b", file=sys.stderr)
@@ -62,11 +68,23 @@ class TestCtrlBase(unittest.TestCase):
self.connect("127.0.0.1", appport)
self.next_id = 1000
def dump_file(self, file, name):
file.seek(0)
data = file.read()
print('=' * 80)
print(name)
print('=' * 80)
print(data.decode())
def tearDown(self):
self.disconnect()
rc = osmoutil.end_proc(self.proc)
if rc is not None and rc != 0:
self.dump_file(self.stdout, 'stdout')
self.dump_file(self.stderr, 'stderr')
raise Exception("Process returned %d" % rc)
self.stdout.close()
self.stderr.close()
def disconnect(self):
if not (self.sock is None):

View File

@@ -20,6 +20,7 @@ import time
import unittest
import socket
import subprocess
import tempfile
import osmopy.obscvty as obscvty
import osmopy.osmoutil as osmoutil
@@ -51,8 +52,12 @@ class TestVTYBase(unittest.TestCase):
cfi = config_index + 1
osmo_vty_cmd[cfi] = os.path.join(confpath, osmo_vty_cmd[cfi])
self.stdout = tempfile.TemporaryFile()
self.stderr = tempfile.TemporaryFile()
try:
self.proc = osmoutil.popen_devnull(osmo_vty_cmd)
# self.proc = osmoutil.popen_devnull(osmo_vty_cmd)
print("Launching: PWD=%s %s" % (os.getcwd(), ' '.join([repr(c) for c in osmo_vty_cmd])))
self.proc = subprocess.Popen(osmo_vty_cmd, stdout=self.stdout, stderr=self.stderr)
except OSError:
print("Current directory: %s" % os.getcwd(), file=sys.stderr)
print("Consider setting -b", file=sys.stderr)
@@ -61,13 +66,25 @@ class TestVTYBase(unittest.TestCase):
appport = self.vty_app()[0]
self.vty = obscvty.VTYInteract(appstring, "127.0.0.1", appport)
def dump_file(self, file, name):
file.seek(0)
data = file.read()
print('=' * 80)
print(name)
print('=' * 80)
print(data.decode())
def tearDown(self):
if self.vty:
self.vty._close_socket()
self.vty = None
rc = osmoutil.end_proc(self.proc)
if rc is not None and rc != 0:
self.dump_file(self.stdout, 'stdout')
self.dump_file(self.stderr, 'stderr')
raise Exception("Process returned %d" % rc)
self.stdout.close()
self.stderr.close()
class TestVTYMSC(TestVTYBase):