[Toaster] bitbake: toaster: add functional testing toaster error details

Alexander Lussier-Cullen <[email protected]> Tue, 12 Dec 2023 15:24:28 -0500
Newsgroups org.yoctoproject.lists.toaster
Message-ID <20231212202428.1374197-1-alexander.lussier-cullen@savoirfairelinux.com>
Functional tests can sometimes fail to initialize toaster.
Most often this is due to a conflict on port 8000.
Add command information about whichever other process is running on
that port to better describe the initialization failure.

Signed-off-by: Alexander Lussier-Cullen <alexander.lussier-cullen@savoirf=
airelinux.com>
---
 .../lib/toaster/tests/functional/functional_helpers.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/bitbake/lib/toaster/tests/functional/functional_helpers.py b=
/bitbake/lib/toaster/tests/functional/functional_helpers.py
index d3e037a6d0..09cf3ba8e0 100644
--- a/bitbake/lib/toaster/tests/functional/functional_helpers.py
+++ b/bitbake/lib/toaster/tests/functional/functional_helpers.py
@@ -28,7 +28,7 @@ class SeleniumFunctionalTestCase(SeleniumTestCaseBase):
         # So that the buildinfo helper uses the test database'
         if os.environ.get('DJANGO_SETTINGS_MODULE', '') !=3D \
             'toastermain.settings_test':
-            raise RuntimeError("Please initialise django with the tests =
settings:  " \
+            raise RuntimeError("Please initialise django with the tests =
settings:  "
                 "DJANGO_SETTINGS_MODULE=3D'toastermain.settings_test'")
=20
         # start toaster
@@ -38,7 +38,13 @@ class SeleniumFunctionalTestCase(SeleniumTestCaseBase)=
:
             cwd=3Dos.environ.get("BUILDDIR"),
             shell=3DTrue)
         if cls.p.wait() !=3D 0:
-            raise RuntimeError("Can't initialize toaster")
+            port_use =3D os.popen("lsof -i -P -n | grep '8000 (LISTEN)'"=
).read().strip()
+            message =3D ''
+            if port_use:
+                process_id =3D port_use.split()[1]
+                process =3D os.popen(f"ps -o cmd=3D -p {process_id}").re=
ad().strip()
+                message =3D f"Port 8000 occupied by {process}"
+            raise RuntimeError(f"Can't initialize toaster. {message}")
=20
         super(SeleniumFunctionalTestCase, cls).setUpClass()
         cls.live_server_url =3D 'http://localhost:8000/'
--=20
2.34.1