Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion resultsdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,30 @@
# Jenkins sets LIBTEST_DB once for the whole pipeline rather than passing --db
# to every script invocation.
DEFAULT_DB = os.environ.get("LIBTEST_DB") or "sqlite3.db"


def hostname():
"""The machine the testing is running on, as something a human recognises.

socket.gethostname() is that machine, right up until the run is inside a
container, where it is the container id instead: job_claim holds rows saying
the wasm-jit libraries were tested by "e9725d308091", which identifies nothing
and is gone with the container. Jenkins does know the machine - it names its
agents - and propagates NODE_NAME into a container it starts, so prefer that
when there is a container to see through. LIBTEST_HOST overrides both, for
the same reason LIBTEST_DB exists.

Only consulted inside a container: outside one the kernel's answer is the
right one, and a NODE_NAME left over in the environment should not override
it.
"""
explicit = os.environ.get("LIBTEST_HOST")
if explicit:
return explicit
# Docker leaves /.dockerenv behind, podman /run/.containerenv.
if os.path.exists("/.dockerenv") or os.path.exists("/run/.containerenv"):
return os.environ.get("NODE_NAME") or socket.gethostname()
return socket.gethostname()
DB_HELP = ("Result database: a local sqlite3 file, or a postgresql://user@host/database URL for "
"the shared one, taken from the LIBTEST_DB environment variable when not given. "
"Several machines can write to the shared database at the same time; a library "
Expand Down Expand Up @@ -304,7 +328,7 @@ def __init__(self, url):
self.lostConnection = (psycopg2.OperationalError, psycopg2.InterfaceError)
self.pending = []
self.conn = self._connect()
self.host = socket.gethostname()
self.host = hostname()
self.claims = []
self.heartbeatThread = None
self.execute(JOB_CLAIM)
Expand Down
3 changes: 1 addition & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from joblib import Parallel, delayed
import simplejson as json
import psutil, subprocess, threading, hashlib
import socket
from subprocess import call
from monotonic import monotonic
from omcommon import friendlyStr, multiple_replace
Expand Down Expand Up @@ -1011,7 +1010,7 @@ def cpu_name():
except:
lsb_release = ""

hostname = socket.gethostname()
hostname = resultsdb.hostname()
sysInfo = "%s: %s, %d GB RAM, %s%s" % (hostname, cpu_name(), int(math.ceil(psutil.virtual_memory().total / (1024.0**3))), ("Docker " + docker + " ") if docker else "", lsb_release)

for (resultBranch, simulator) in resultBranches:
Expand Down
Loading