diff --git a/armi/bookkeeping/report/reportingUtils.py b/armi/bookkeeping/report/reportingUtils.py index 4ad1dd23d..2ce2c6b24 100644 --- a/armi/bookkeeping/report/reportingUtils.py +++ b/armi/bookkeeping/report/reportingUtils.py @@ -78,7 +78,7 @@ def _writeCaseInformation(o, cs): (Operator_ArmiCodebase, context.ROOT), (Operator_WorkingDirectory, os.getcwd()), (Operator_PythonInterperter, sys.version), - (Operator_MasterMachine, os.environ.get("COMPUTERNAME", "?")), + (Operator_MasterMachine, getNodeName()), (Operator_NumProcessors, context.MPI_SIZE), (Operator_Date, context.START_TIME), ] @@ -235,6 +235,30 @@ def _writeReactorCycleInformation(o, cs): _writeReactorCycleInformation(o, cs) +def getNodeName(): + """Get the name of this comput node. + + First, look in context.py. Then try various Linux tools. Then try Windows commands. + + Returns + ------- + str + Compute node name. + """ + hostNames = [ + context.MPI_NODENAME, + context.MPI_NODENAMES[0], + subprocess.run("hostname", capture_output=True, text=True, shell=True).stdout, + subprocess.run("uname -n", capture_output=True, text=True, shell=True).stdout, + os.environ.get("COMPUTERNAME", context.LOCAL), + ] + for nodeName in hostNames: + if nodeName and nodeName != context.LOCAL: + return nodeName + + return context.LOCAL + + def _getSystemInfoWindows(): """Get system information, assuming the system is Windows. diff --git a/armi/bookkeeping/report/tests/test_report.py b/armi/bookkeeping/report/tests/test_report.py index f96eecaf1..87298060e 100644 --- a/armi/bookkeeping/report/tests/test_report.py +++ b/armi/bookkeeping/report/tests/test_report.py @@ -25,6 +25,7 @@ from armi.bookkeeping.report.reportingUtils import ( _getSystemInfoLinux, _getSystemInfoWindows, + getNodeName, getSystemInfo, makeBlockDesignReport, setNeutronBalancesReport, @@ -103,6 +104,15 @@ def test_getSystemInfo(self): self.assertGreater(len(out), sum(len(sstr) + 5 for sstr in substrings)) + def test_getNodeName(self): + """Test that the getNodeName() method returns a non-empty string. + + It is hard to know what string SHOULD be return here, and it would depend on how the OS is + set up on your machine or cluster. But this simple test needs to pass as-is on Windows + and Linux. + """ + self.assertGreater(len(getNodeName()), 0) + class TestReport(unittest.TestCase): def setUp(self): diff --git a/armi/context.py b/armi/context.py index 49b8c43aa..4927b0254 100644 --- a/armi/context.py +++ b/armi/context.py @@ -104,8 +104,9 @@ def setMode(cls, mode): # MPI_SIZE is the total number of CPUs MPI_RANK = 0 MPI_SIZE = 1 -MPI_NODENAME = "local" -MPI_NODENAMES = ["local"] +LOCAL = "local" +MPI_NODENAME = LOCAL +MPI_NODENAMES = [LOCAL] try: