From 2cf7e77813f04f6e8bfc4c99333332685f9627a2 Mon Sep 17 00:00:00 2001 From: Matthias Kraushaar Date: Fri, 14 Dec 2018 18:09:58 +0100 Subject: [PATCH 1/3] first steps to add show-config option --- reframe/core/runtime.py | 33 +++++++++++++++++++++++++++++++++ reframe/core/systems.py | 11 +++++++++-- reframe/frontend/cli.py | 10 ++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/reframe/core/runtime.py b/reframe/core/runtime.py index 13406bbd70..667b39fa44 100644 --- a/reframe/core/runtime.py +++ b/reframe/core/runtime.py @@ -251,6 +251,39 @@ def modules_system(self): """ return self._modules_system + def show_config(self): + """Prepare configuration of the current system for printing""" + +# config_listing[l1][l2[2]] = {} +# for p in self.system.partitions: +# config_listing[l1][l2[2]][str(p)] = {} +# config_listing[l1][l2[2]][str(p)] \ +# ['Scheduler: '] = str(p.scheduler.registered_name) +# config_listing[l1][l2[2]][str(p)] \ +# ['Launcher: '] = str(p.launcher.registered_name) +# if p.access: +# config_listing[l1][l2[2]][str(p)] \ +# ['Access: '] = str(p.access) +# config_listing[l1][l2[2]][str(p)] \ +# ['Max number of jobs: '] = p.max_jobs +# config_listing[l1][l2[2]][str(p)] \ +# ['Environs: '] = [] +# for e in p.environs: +# config_listing[l1][l2[2]][str(p)] \ +# ['Environs: '].append(e.name) +# if p.resources: +# for r in p.resources: +# config_listing[l1][l2[2]][str(p)] \ +# ['Resources: '] = {} +# config_listing[l1][l2[2]][str(p)] \ +# ['Resources: '][str(r)] = p.get_resource(r) + + + return '\nCurrent system configuration\n' + \ + '============================\n\n' + \ + '%s\n' % str(self.system) + + # Global resources for the current host _runtime_context = None diff --git a/reframe/core/systems.py b/reframe/core/systems.py index ea663f0f7c..c57adff19b 100644 --- a/reframe/core/systems.py +++ b/reframe/core/systems.py @@ -249,5 +249,12 @@ def __repr__(self): return debug.repr(self) def __str__(self): - return '%s (partitions: %s)' % (self._name, - [str(p) for p in self._partitions]) + return '- %s:\n' \ + '\t- System description:\t%s\n' \ + '\t- Modules system:\t%s\n' \ + '\t- Resouces directory:\t%s\n' % (self._name, + self._descr, + self._modules_system, + self._resourcesdir) + #return '%s (partitions: %s)' % (self._name, + # [str(p) for p in self._partitions]) diff --git a/reframe/frontend/cli.py b/reframe/frontend/cli.py index 3dfe1081d7..d02482bbbb 100644 --- a/reframe/frontend/cli.py +++ b/reframe/frontend/cli.py @@ -1,5 +1,6 @@ import os import inspect +import json import socket import sys @@ -217,6 +218,9 @@ def main(): help='Specify a custom config-file for the machine. ' '(default: %s' % os.path.join(reframe.INSTALL_PREFIX, 'reframe/settings.py')) + misc_options.add_argument( + '-S', '--show-config', action='store_true', dest='show_config', + help='Print configuration of the current system') misc_options.add_argument('-V', '--version', action='version', version=reframe.VERSION) @@ -320,6 +324,12 @@ def main(): logging.LOG_CONFIG_OPTS['handlers.filelog.prefix'] = (rt.resources. perflog_prefix) + if options.show_config: + #print("Hello, World!") + system_info = rt.show_config() + print(system_info) + sys.exit(0) + if hasattr(settings, 'perf_logging_config'): try: logging.configure_perflogging(settings.perf_logging_config) From b109895925b6b3f39b50fa98955ef80616af6fbb Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Wed, 19 Dec 2018 23:01:03 +0100 Subject: [PATCH 2/3] Finalize impl. for printing env/sys configuration - New options added: `--show-config` and `--show-config-env ENV`. - Unit tests added as well --- reframe/core/environments.py | 14 +++++++++++ reframe/core/runtime.py | 48 +++++++++++------------------------- reframe/core/systems.py | 25 ++++++++++--------- reframe/frontend/cli.py | 26 +++++++++++++++---- unittests/test_cli.py | 27 ++++++++++++++++++++ 5 files changed, 89 insertions(+), 51 deletions(-) diff --git a/reframe/core/environments.py b/reframe/core/environments.py index 64b524b1fc..467a1ef6f0 100644 --- a/reframe/core/environments.py +++ b/reframe/core/environments.py @@ -159,7 +159,21 @@ def __eq__(self, other): set(self._modules) == set(other._modules) and self._variables == other._variables) + def details(self): + """Return a detailed description of this environment.""" + variables = '\n'.join(' '*8 + '- %s=%s' % (k, v) + for k, v in self.variables.items()) + lines = [ + self._name + ':', + ' modules: ' + ', '.join(self.modules), + ' variables:' + ('\n' if variables else '') + variables + ] + return '\n'.join(lines) + def __str__(self): + return self.name + + def __repr__(self): ret = "{0}(name='{1}', modules={2}, variables={3})" return ret.format(type(self).__name__, self.name, self.modules, self.variables) diff --git a/reframe/core/runtime.py b/reframe/core/runtime.py index 667b39fa44..27c700e64a 100644 --- a/reframe/core/runtime.py +++ b/reframe/core/runtime.py @@ -70,7 +70,16 @@ def partition(self, name): return None def __str__(self): - return str(self._system) + partitions = '\n'.join(re.sub('(?m)^', 6*' ', '- ' + str(p)) + for p in self.partitions) + lines = [ + '%s [%s]:' % (self._name, self._descr), + ' hostnames: ' + ', '.join(self._hostnames), + ' modules_system: ' + str(self._modules_system), + ' resourcesdir: ' + self._resourcesdir, + ' partitions:\n' + partitions, + ] + return '\n'.join(lines) def __repr__(self): return 'HostSystem(%r, %r)' % (self._system, self._partname) @@ -93,13 +102,13 @@ class HostResources: #: prefix = fields.AbsolutePathField('prefix') outputdir = fields.AbsolutePathField('outputdir', type(None)) - stagedir = fields.AbsolutePathField('stagedir', type(None)) + stagedir = fields.AbsolutePathField('stagedir', type(None)) perflogdir = fields.AbsolutePathField('perflogdir', type(None)) def __init__(self, prefix=None, stagedir=None, outputdir=None, perflogdir=None, timefmt=None): self.prefix = prefix or '.' - self.stagedir = stagedir + self.stagedir = stagedir self.outputdir = outputdir self.perflogdir = perflogdir self.timefmt = timefmt @@ -252,37 +261,8 @@ def modules_system(self): return self._modules_system def show_config(self): - """Prepare configuration of the current system for printing""" - -# config_listing[l1][l2[2]] = {} -# for p in self.system.partitions: -# config_listing[l1][l2[2]][str(p)] = {} -# config_listing[l1][l2[2]][str(p)] \ -# ['Scheduler: '] = str(p.scheduler.registered_name) -# config_listing[l1][l2[2]][str(p)] \ -# ['Launcher: '] = str(p.launcher.registered_name) -# if p.access: -# config_listing[l1][l2[2]][str(p)] \ -# ['Access: '] = str(p.access) -# config_listing[l1][l2[2]][str(p)] \ -# ['Max number of jobs: '] = p.max_jobs -# config_listing[l1][l2[2]][str(p)] \ -# ['Environs: '] = [] -# for e in p.environs: -# config_listing[l1][l2[2]][str(p)] \ -# ['Environs: '].append(e.name) -# if p.resources: -# for r in p.resources: -# config_listing[l1][l2[2]][str(p)] \ -# ['Resources: '] = {} -# config_listing[l1][l2[2]][str(p)] \ -# ['Resources: '][str(r)] = p.get_resource(r) - - - return '\nCurrent system configuration\n' + \ - '============================\n\n' + \ - '%s\n' % str(self.system) - + """Return a textual representation of the current runtime.""" + return str(self._system) # Global resources for the current host diff --git a/reframe/core/systems.py b/reframe/core/systems.py index c57adff19b..969c9d1319 100644 --- a/reframe/core/systems.py +++ b/reframe/core/systems.py @@ -1,3 +1,5 @@ +import re + import reframe.core.debug as debug import reframe.core.fields as fields import reframe.utility.typecheck as typ @@ -136,7 +138,17 @@ def __eq__(self, other): self._local_env == other._local_env) def __str__(self): - return self._name + local_env = re.sub('(?m)^', 6*' ', ' - ' + self._local_env.details()) + lines = [ + '%s [%s]:' % (self._name, self._descr), + ' fullname: ' + self.fullname, + ' scheduler: ' + self._scheduler.registered_name, + ' launcher: ' + self._launcher.registered_name, + ' access: ' + ' '.join(self._access), + ' local_env:\n' + local_env, + ' environs: ' + ', '.join(str(e) for e in self._environs) + ] + return '\n'.join(lines) def __repr__(self): return debug.repr(self) @@ -247,14 +259,3 @@ def __eq__(self, other): def __repr__(self): return debug.repr(self) - - def __str__(self): - return '- %s:\n' \ - '\t- System description:\t%s\n' \ - '\t- Modules system:\t%s\n' \ - '\t- Resouces directory:\t%s\n' % (self._name, - self._descr, - self._modules_system, - self._resourcesdir) - #return '%s (partitions: %s)' % (self._name, - # [str(p) for p in self._partitions]) diff --git a/reframe/frontend/cli.py b/reframe/frontend/cli.py index d02482bbbb..b6234ad697 100644 --- a/reframe/frontend/cli.py +++ b/reframe/frontend/cli.py @@ -219,8 +219,11 @@ def main(): '(default: %s' % os.path.join(reframe.INSTALL_PREFIX, 'reframe/settings.py')) misc_options.add_argument( - '-S', '--show-config', action='store_true', dest='show_config', - help='Print configuration of the current system') + '--show-config', action='store_true', + help='Print configuration of the current system and exit') + misc_options.add_argument( + '--show-config-env', action='store', metavar='ENV', + help='Print configuration of environment ENV and exit') misc_options.add_argument('-V', '--version', action='version', version=reframe.VERSION) @@ -324,10 +327,23 @@ def main(): logging.LOG_CONFIG_OPTS['handlers.filelog.prefix'] = (rt.resources. perflog_prefix) + # Show configuration after everything is set up if options.show_config: - #print("Hello, World!") - system_info = rt.show_config() - print(system_info) + printer.info(rt.show_config()) + sys.exit(0) + + if options.show_config_env: + envname = options.show_config_env + for p in rt.system.partitions: + env = p.environment(envname) + if env: + break + + if env is None: + printer.error('no such environment: ' + envname) + sys.exit(1) + + printer.info(env.details()) sys.exit(0) if hasattr(settings, 'perf_logging_config'): diff --git a/unittests/test_cli.py b/unittests/test_cli.py index 41691fea5b..21f9bb8537 100644 --- a/unittests/test_cli.py +++ b/unittests/test_cli.py @@ -360,3 +360,30 @@ def test_list_with_details(self): self.assertNotIn('Traceback', stdout) self.assertNotIn('Traceback', stderr) self.assertEqual(0, returncode) + + def test_show_config(self): + # Just make sure that this option does not make the frontend crash + self.more_options = ['--show-config'] + self.system = 'testsys' + returncode, stdout, stderr = self._run_reframe() + self.assertNotIn('Traceback', stdout) + self.assertNotIn('Traceback', stderr) + self.assertEqual(0, returncode) + + def test_show_env_config(self): + # Just make sure that this option does not make the frontend crash + self.more_options = ['--show-config-env', 'PrgEnv-gnu'] + self.system = 'testsys' + returncode, stdout, stderr = self._run_reframe() + self.assertNotIn('Traceback', stdout) + self.assertNotIn('Traceback', stderr) + self.assertEqual(0, returncode) + + def test_show_env_config_unknown_env(self): + # Just make sure that this option does not make the frontend crash + self.more_options = ['--show-config-env', 'foobar'] + self.system = 'testsys' + returncode, stdout, stderr = self._run_reframe() + self.assertNotIn('Traceback', stdout) + self.assertNotIn('Traceback', stderr) + self.assertEqual(1, returncode) From a025fd34883f410801a768a0ad5d8f253a59a8e6 Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Fri, 21 Dec 2018 23:17:07 +0100 Subject: [PATCH 3/3] Add documentation of the `--show-config*` options --- docs/configure.rst | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/configure.rst b/docs/configure.rst index 304b711958..72d5af85e9 100644 --- a/docs/configure.rst +++ b/docs/configure.rst @@ -315,3 +315,18 @@ If this cannot be found the hostname will be obtained from the standard ``hostna The detection process stops at the first match found, and the system it belongs to is considered as the current system. If the system cannot be auto-detected, ReFrame will fail with an error message. You can override completely the auto-detection process by specifying a system or a system partition with the ``--system`` option (e.g., ``--system daint`` or ``--system daint:gpu``). + + +Showing configuration +--------------------- + +.. versionadded:: 2.16 + +It is possible to ask ReFrame to print the configuration of the current system or the configuration of any programming environment defined for the current system. +There are two command-line options for performing these operations: + +* ``--show-config``: This option shows the current system's configuration and exits. + It can be combined with the ``--system`` option in order to show the configuration of another system. +* ``--show-config-env ENV``: This option shows the configuration of the programming environment ``ENV`` and exits. + The environment ``ENV`` must be defined for any of the partitions of the current system. + This option can also be combined with ``--system`` in order to show the configuration of a programming environment defined for another system.