Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[testlib] Add fs mount options check to hpctstlib #2958

Merged
merged 11 commits into from
Oct 26, 2023
65 changes: 37 additions & 28 deletions docs/hpctestlib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,34 @@ ReFrame Test Library (experimental)
This is a collection of generic tests that you can either run out-of-the-box by specializing them for your system using the :option:`-S` option or create your site-specific tests by building upon them.


Data Analytics
==============

.. automodule:: hpctestlib.data_analytics.spark.spark_checks
:members:
:show-inheritance:


Interactive Computing
=====================

.. automodule:: hpctestlib.interactive.jupyter.ipcmagic
:members:
:show-inheritance:


Machine Learning
================

.. automodule:: hpctestlib.ml.tensorflow.horovod
:members:
:show-inheritance:

.. automodule:: hpctestlib.ml.pytorch.horovod
:members:
:show-inheritance:


Microbenchmarks
===============

Expand Down Expand Up @@ -55,25 +83,6 @@ GPU benchmarks
:show-inheritance:


Scientific Applications
=======================

.. automodule:: hpctestlib.sciapps.amber.nve
:members:
:show-inheritance:

.. automodule:: hpctestlib.sciapps.gromacs.benchmarks
:members:
:show-inheritance:

Data Analytics
==============

.. automodule:: hpctestlib.data_analytics.spark.spark_checks
:members:
:show-inheritance:


Python
======

Expand All @@ -82,21 +91,21 @@ Python
:show-inheritance:


Interactive Computing
=====================
Scientific Applications
=======================

.. automodule:: hpctestlib.interactive.jupyter.ipcmagic
.. automodule:: hpctestlib.sciapps.amber.nve
:members:
:show-inheritance:


Machine Learning
================

.. automodule:: hpctestlib.ml.tensorflow.horovod
.. automodule:: hpctestlib.sciapps.gromacs.benchmarks
:members:
:show-inheritance:

.. automodule:: hpctestlib.ml.pytorch.horovod

System
=======================

.. automodule:: hpctestlib.system.fs.mnt_opts
:members:
:show-inheritance:
161 changes: 72 additions & 89 deletions hpctestlib/system/fs/mnt_opts.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
# Copyright 2016-2022 Swiss National Supercomputing Centre (CSCS/ETH Zurich)
# Copyright 2016-2023 Swiss National Supercomputing Centre (CSCS/ETH Zurich)
# ReFrame Project Developers. See the top-level LICENSE file for details.
#
# SPDX-License-Identifier: BSD-3-Clause

import os

from string import Template

import reframe as rfm
import reframe.utility.sanity as sn
import reframe.utility.typecheck as typ


def get_mounted_fs():
result = []
with open('/proc/mounts','r') as f:
for line in f.readlines():
mnt_fs = dict()
_, mnt_point, type, options, _, _ = line.split()
result.append((mnt_point, type, options))
return result


@rfm.simple_test
class filesystem_options_check(rfm.RunOnlyRegressionTest):
'''filesystem mount options check
Expand All @@ -26,102 +20,91 @@ class filesystem_options_check(rfm.RunOnlyRegressionTest):
based on their type
'''

#: Parameter pack with listing the mounted file systems, mount points
#: type and mount options
#:
#: :type: `Tupe[str, str, str]`. The tuple fields represent
#: 'mount_point' with the filesystem mount point as a str value
#: 'type' with the filesystem type as a str value
#: 'options' with the filesystem options as a str value
#: E.g., '/home', 'xfs', 'rw,nosuid,logbsize=32k'
#:
#: :values: Values are generated using the `/proc/mounts` file
filesystems = parameter(get_mounted_fs(),
fmt=lambda x: x[0],
loggable=True)

#: Reference mount options
#:
#: :type: `Dict[str, str]`. The key should be the file system type.
#: and the value should be a string with options.
#: and the value should be a string with mount options.
#: E.g., {'xfs: 'nosuid,logbsize=32k'}
#: :default: ``{}``
fs_ref_opts = variable(typ.Dict, value={}, loggable=True)
vkarak marked this conversation as resolved.
Show resolved Hide resolved
fs_ref_opts = required
vkarak marked this conversation as resolved.
Show resolved Hide resolved

executable = 'stat'
tags = {'system', 'fs'}

@loggable
@property
def fs_mnt_point(self):
'''The file system mount point

:type: :class:`str`
'''
return self.filesystems[0]
#: Fail if the test finds a filesystem type that is not in the
#: reference dictionary
#:
#: :type: `Bool`.
#: :value: ``False``
fail_unknown_fs = variable(typ.Bool, value=False, loggable=True)

@loggable
@property
def fs_type(self):
'''The file system type
executable = 'cat'
executable_opts = ['/proc/mounts']
tags = {'system', 'fs'}

:type: :class:`str`
@run_before('sanity')
def process_system_fs_opts(self):
self.filesystem = []
stdout = os.path.join(self.stagedir, sn.evaluate(self.stdout))
with open(stdout, 'r') as fp:
for line in fp:
_, mnt_point, type, options, _, _ = line.split()
self.filesystem.append((mnt_point, type, options))

@run_before('sanity')
def print_test_variables_to_output(self):
'''
return self.filesystems[1]

@loggable
@property
def fs_mnt_opts(self):
'''The file system mount options

:type: :class:`str`
Write the reference mount point options used by the test
at the time of execution.
'''
return self.filesystems[2]

@run_after('init')
def set_fs_opts(self):
# skip the test if the filesystem is not supported by the test
self.skip_if(self.fs_type not in self.fs_ref_opts,
msg=f'This test does not support filesystem '
f'type {self.fs_type}')

self.ref_opts=self.explode_opts_str(self.fs_ref_opts[self.fs_type])
self.curr_opts=self.explode_opts_str(self.fs_mnt_opts)

@run_after('init')
def set_executable_opts(self):
self.executable_opts = [self.fs_mnt_point]
stdout = os.path.join(self.stagedir, sn.evaluate(self.stdout))
with open(stdout, 'a') as fp:
fp.write('\n---- Reference mount options ----\n')
for mnt_type, options in self.fs_ref_opts.items():
fp.write(f'{mnt_type} {options}\n')

def explode_opts_str(self, opts_str):
result=dict()
victorusu marked this conversation as resolved.
Show resolved Hide resolved
for opt in opts_str.split(','):
if opt == '':
continue
opt_splitted = opt.split('=')
keystr = opt_splitted[0]
valstr = opt_splitted[1] if len(opt_splitted) > 1 else ''
opt_parts = opt.split('=', maxsplit=2)
keystr = opt_parts[0]
valstr = opt_parts[1] if len(opt_parts) > 1 else ''
result[keystr] = valstr
return result

@sanity_function
def assert_config(self):
skip_me = sn.extractall('No such file or directory', self.stderr)
self.skip_if(skip_me, msg=f'Skipping test because filesystem '
f'{self.fs_mnt_point} was not found')

return sn.all(sn.chain(
sn.map(lambda x: sn.assert_in(x, self.curr_opts,
msg=f'Option {x} not present for '
f'mount point '
f'{self.fs_mnt_point}, '
f'of type {self.fs_type}'),
self.ref_opts),
sn.map(lambda x: sn.assert_eq(x[1], self.curr_opts[x[0]],
msg=f'Value {x[1]} not equal to '
f'{self.curr_opts[x[0]]} in '
f'the variable {x[0]} for the '
f'mount point '
f'{self.fs_mnt_point}, '
f'of type {self.fs_type}'),
self.ref_opts.items()),
))
def assert_mnt_options(self):
msg = Template('Found filesystem type(s) - "$mnt_type" - that are not '
'compatible with this test')
msg1 = Template('The mount point "$mnt_point" of type "$mnt_type" does'
' not have the "$opt" option.')
msg2 = Template('The "$variable" variable value of "$value" does not '
'match the reference "$ref_value" for the "$mnt_point"'
' mount point ("$mnt_type" type)')

errors = []
unsupported_types = set()
for mnt_point, mnt_type, options in self.filesystem:
opts = self.explode_opts_str(options)
if mnt_type not in self.fs_ref_opts:
unsupported_types.add(mnt_type)
continue

ref_opts = self.explode_opts_str(self.fs_ref_opts[mnt_type])
for ref_opt, ref_value in ref_opts.items():
if ref_opt not in opts:
errors.append(msg1.substitute(opt=ref_opt,
mnt_point=mnt_point,
mnt_type=mnt_type))
elif ref_value != opts[ref_opt]:
errors.append(msg2.substitute(value=opts[ref_opt],
ref_value=ref_value,
variable=ref_opt,
mnt_point=mnt_point,
mnt_type=mnt_type))

if self.fail_unknown_fs:
errors.append(msg.substitute(
mnt_type=', '.join(unsupported_types)))

return sn.assert_true(errors == [], msg='\n'.join(errors))