diff --git a/lib/spack/spack/operating_systems/cnl.py b/lib/spack/spack/operating_systems/cnl.py index 2e3b566ede..a64cf5b55f 100644 --- a/lib/spack/spack/operating_systems/cnl.py +++ b/lib/spack/spack/operating_systems/cnl.py @@ -7,9 +7,42 @@ import llnl.util.tty as tty +import spack.version from spack.architecture import OperatingSystem from spack.util.module_cmd import module +#: Location of the Cray CLE release file, which we look at to get the CNL +#: OS version. +_cle_release_file = '/etc/opt/cray/release/cle-release' + + +def read_cle_release_file(): + """Read the CLE release file and return a dict with its attributes. + + The release file looks something like this:: + + RELEASE=6.0.UP07 + BUILD=6.0.7424 + ... + + The dictionary we produce looks like this:: + + { + "RELEASE": "6.0.UP07", + "BUILD": "6.0.7424", + ... + } + + """ + with open(_cle_release_file) as release_file: + result = {} + for line in release_file: + # use partition instead of split() to ensure we only split on + # the first '=' in the line. + key, _, value = line.partition('=') + result[key] = value.strip() + return result + class Cnl(OperatingSystem): """ Compute Node Linux (CNL) is the operating system used for the Cray XC @@ -28,12 +61,11 @@ def __init__(self): def __str__(self): return self.name + str(self.version) - def _detect_crayos_version(self): - output = module("avail", "PrgEnv-cray") - matches = re.findall(r'PrgEnv-cray/(\d+).\d+.\d+', output) - major_versions = set(matches) - latest_version = max(major_versions) - return latest_version + @classmethod + def _detect_crayos_version(cls): + release_attrs = read_cle_release_file() + v = spack.version.Version(release_attrs['RELEASE']) + return v[0] def arguments_to_detect_version_fn(self, paths): import spack.compilers diff --git a/lib/spack/spack/test/operating_system.py b/lib/spack/spack/test/operating_system.py new file mode 100644 index 0000000000..1f34354409 --- /dev/null +++ b/lib/spack/spack/test/operating_system.py @@ -0,0 +1,34 @@ +# Copyright 2013-2019 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + +import spack.operating_systems.cnl as cnl + + +def test_read_cle_release_file(tmpdir, monkeypatch): + """test reading the Cray cle-release file""" + cle_release_path = tmpdir.join('cle-release') + 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 +""") + + monkeypatch.setattr(cnl, '_cle_release_file', str(cle_release_path)) + attrs = cnl.read_cle_release_file() + + assert attrs['RELEASE'] == '6.0.UP07' + assert attrs['BUILD'] == '6.0.7424' + assert attrs['DATE'] == '20190611' + assert attrs['ARCH'] == 'noarch' + assert attrs['NETWORK'] == 'ari' + assert attrs['PATCHSET'] == '35-201906112304' + assert attrs['DUMMY'] == 'foo=bar' + + assert cnl.Cnl._detect_crayos_version() == 6