Fix CNL version detection (#12207)

This commit is contained in:
Adam J. Stewart 2019-08-03 14:00:30 -05:00 committed by Todd Gamblin
parent 36558dc262
commit 98605bba0d
2 changed files with 76 additions and 6 deletions

View file

@ -3,22 +3,27 @@
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import os
import re import re
import llnl.util.tty as tty import llnl.util.tty as tty
import spack.error
import spack.version import spack.version
from spack.architecture import OperatingSystem from spack.architecture import OperatingSystem
from spack.util.module_cmd import module from spack.util.module_cmd import module
#: Location of the Cray CLE release file, which we look at to get the CNL #: Possible locations of the Cray CLE release file,
#: OS version. #: which we look at to get the CNL OS version.
_cle_release_file = '/etc/opt/cray/release/cle-release' _cle_release_file = '/etc/opt/cray/release/cle-release'
_clerelease_file = '/etc/opt/cray/release/clerelease'
def read_cle_release_file(): def read_cle_release_file():
"""Read the CLE release file and return a dict with its attributes. """Read the CLE release file and return a dict with its attributes.
This file is present on newer versions of Cray.
The release file looks something like this:: The release file looks something like this::
RELEASE=6.0.UP07 RELEASE=6.0.UP07
@ -33,6 +38,8 @@ def read_cle_release_file():
... ...
} }
Returns:
dict: dictionary of release attributes
""" """
with open(_cle_release_file) as release_file: with open(_cle_release_file) as release_file:
result = {} result = {}
@ -44,6 +51,23 @@ def read_cle_release_file():
return result return result
def read_clerelease_file():
"""Read the CLE release file and return the Cray OS version.
This file is present on older versions of Cray.
The release file looks something like this::
5.2.UP04
Returns:
str: the Cray OS version
"""
with open(_clerelease_file) as release_file:
for line in release_file:
return line.strip()
class Cnl(OperatingSystem): class Cnl(OperatingSystem):
"""Compute Node Linux (CNL) is the operating system used for the Cray XC """Compute Node Linux (CNL) is the operating system used for the Cray XC
series super computers. It is a very stripped down version of GNU/Linux. series super computers. It is a very stripped down version of GNU/Linux.
@ -63,9 +87,16 @@ def __str__(self):
@classmethod @classmethod
def _detect_crayos_version(cls): def _detect_crayos_version(cls):
if os.path.isfile(_cle_release_file):
release_attrs = read_cle_release_file() release_attrs = read_cle_release_file()
v = spack.version.Version(release_attrs['RELEASE']) v = spack.version.Version(release_attrs['RELEASE'])
return v[0] return v[0]
elif os.path.isfile(_clerelease_file):
v = read_clerelease_file()
return spack.version.Version(v)[0]
else:
raise spack.error.UnsupportedPlatformError(
'Unable to detect Cray OS version')
def arguments_to_detect_version_fn(self, paths): def arguments_to_detect_version_fn(self, paths):
import spack.compilers import spack.compilers

View file

@ -32,3 +32,42 @@ def test_read_cle_release_file(tmpdir, monkeypatch):
assert attrs['DUMMY'] == 'foo=bar' assert attrs['DUMMY'] == 'foo=bar'
assert cnl.Cnl._detect_crayos_version() == 6 assert cnl.Cnl._detect_crayos_version() == 6
def test_read_clerelease_file(tmpdir, monkeypatch):
"""test reading the Cray clerelease file"""
clerelease_path = tmpdir.join('clerelease')
with clerelease_path.open('w') as f:
f.write('5.2.UP04\n')
monkeypatch.setattr(cnl, '_clerelease_file', str(clerelease_path))
v = cnl.read_clerelease_file()
assert v == '5.2.UP04'
assert cnl.Cnl._detect_crayos_version() == 5
def test_cle_release_precedence(tmpdir, monkeypatch):
"""test that cle-release file takes precedence over clerelease file."""
cle_release_path = tmpdir.join('cle-release')
clerelease_path = tmpdir.join('clerelease')
with cle_release_path.open('w') as f:
f.write("""\
RELEASE=6.0.UP07
BUILD=6.0.7424
DATE=20190611
ARCH=noarch
NETWORK=ari
PATCHSET=35-201906112304
DUMMY=foo=bar
""")
with clerelease_path.open('w') as f:
f.write('5.2.UP04\n')
monkeypatch.setattr(cnl, '_clerelease_file', str(clerelease_path))
monkeypatch.setattr(cnl, '_cle_release_file', str(cle_release_path))
assert cnl.Cnl._detect_crayos_version() == 6