Module Wrapper Plugins

pavilion.module_wrapper module

Plugin system for altering module behavior.

class pavilion.module_wrapper.ModuleWrapper(name, description, version=None, priority=10)

Bases: IPlugin

The base class for all module wrapper plugins.

EMOD = 'emod'
LMOD = 'lmod'
NAME_VERS_RE = re.compile('^[a-zA-Z0-9_.*-]+$')
NONE = 'none'
PRIO_COMMON = 10
PRIO_CORE = 0
PRIO_USER = 20
activate()

Add this module to the wrapped module list.

deactivate()

Remove this module from the wrapped module list.

get_version(requested_version)

Get the version of the module to load, given the requested version and the version set in the instance. This should always be used to figure out what version to load.

Parameters

requested_version (Union(str, None)) – The version requested by the user.

Return type

str

Returns

The version that should be loaded.

load(var_man: ~pavilion.variables.VariableSetManager, req_name: str, requested_version: ~typing.Optional[str] = None) -> (typing.List[typing.Union[pavilion.module_actions.ModuleAction, str]], <class 'dict'>)

Generate the list of module actions and environment changes to load this module.

Parameters
  • var_man (VariableSetManager) – The test’s variable manager. al

  • req_name – The module name as requested.

  • requested_version – The version requested to load.

Returns

A list of actions (or bash command strings), and a dict of environment changes.

Return type

(Union(str, ModuleAction), dict)

Raises

ModuleWrapperError – If the requested version does not work with this instance.

property path

The location of this module wrapper plugin.

swap(var_man: ~pavilion.variables.VariableSetManager, out_name: str, out_version: str, req_name: str, requested_version=None) -> (typing.List[typing.Union[pavilion.module_actions.ModuleAction, str]], <class 'dict'>)

Swap out the ‘out’ module and swap in the new module.

Parameters
  • var_man – The test’s variable manager. Module wrappers can use this to lookup any non-deferred test variable.

  • out_name (str) – The name of the module to swap out.

  • out_version (str) – The version of the module to swap out.

  • req_name – The module name as requested.

  • requested_version (str) – The version requested to load.

Returns

A list of actions (or bash command strings), and a dict of environment changes.

Return type

(Union(str, ModuleAction), dict)

Raises

ModuleWrapperError – If the requested version does not work with this instance.

unload(var_man, req_name, requested_version=None)

Remove this module from the environment.

Parameters
  • var_man – The test’s variable manager. Module wrappers can use this to lookup any non-deferred test variable.

  • req_name – The module name as requested by the user.

  • requested_version (str) – The version requested to remove.

Returns

A list of actions (or bash command strings), and a dict of environment changes.

Return type

(Union(str, ModuleAction), dict)

Raises

ModuleWrapperError – If the requested version does not work with this instance.

exception pavilion.module_wrapper.ModuleWrapperError

Bases: RuntimeError

Raised when any module wrapping related errors occur.

class pavilion.module_wrapper.ModuleWrapperViaConfig(name: str, version: Union[None, str], config: Dict[str, dict])

Bases: ModuleWrapper

A dynamic module wrapper based on one defined in the test config.

pavilion.module_wrapper.add_wrapped_module(module_wrapper, version)

Add the module wrapper to the set of wrapped modules.

Parameters
  • module_wrapper (ModuleWrapper) – The module_wrapper class for the module.

  • version (Union(str, None)) – The version to add it under.

Returns

None

Raises

KeyError – On module version conflict.

pavilion.module_wrapper.get_module_wrapper(name, version: Optional[str] = None, config_wrappers: Optional[Dict[str, dict]] = None) ModuleWrapper

Finds and returns a module wrapper to match the specified module name and version. The default module wrapper is returned if a match isn’t found.

Parameters
  • name – The name of the module.

  • version – The version requested. If None is specified this will look for the version-generic module wrapper for this module.

  • config_wrappers – The module wrappers defined via test config.

pavilion.module_wrapper.list_module_wrappers()

Returns a list of all loaded module wrapper plugins.

Return type

list

pavilion.module_wrapper.parse_module(mod_line)

Parse a module specification into it’s components. These can come in one of three formats:

  1. ‘mod-name[/version]’ - Load the given module name and version

  2. ‘-mod-name[/version]’ - Unload the given module/version.

  3. ‘old_name[/old_vers]->mod-name[/version]’ - Swap the given old module for the new one.

Parameters

mod_line (str) – String provided by the user in the config.

Return type

(str, (str, str), (str, str))

Returns

action, (name, vers), (old_name, old_vers)

pavilion.module_wrapper.remove_wrapped_module(module_wrapper, version)

Remove the indicated module_wrapper from the set of wrapped module.

Parameters
  • module_wrapper (ModuleWrapper) – The module_wrapper to remove, if it exists.

  • version (Union(str, None)) – The specific version to remove.

Returns

None

pavilion.module_actions module

Defines the how to perform module loads, swaps and unloads.

class pavilion.module_actions.ModuleAction(module_name, version=None)

Bases: object

The base module action class.

action()

Returns a list of bash commands that should perform the action for the given module.

Return type

list(str)

property module

A properly formatted module name for the given module and version.

verify()

Returns a list of bash commands that should verify that the module action has been performed successfully. These should set the test status to ENV_FAILED, and exit the bash script with a non-zero return code.

class pavilion.module_actions.ModuleLoad(module_name, version=None)

Bases: ModuleAction

Provides module loading commands and verification.

action()

Returns a list of bash commands that should perform the action for the given module.

Return type

list(str)

verify()

Returns a list of bash commands that should verify that the module action has been performed successfully. These should set the test status to ENV_FAILED, and exit the bash script with a non-zero return code.

class pavilion.module_actions.ModuleRestore(module_name, version=None)

Bases: ModuleAction

Provides module restore commands and verification for collections. This should only be used with Cray PrgEnv-… collections for now. The check for this working is the presence of a ‘cpe-’ module matching the environment of the collection.

action()

Returns a list of bash commands that should perform the action for the given module.

Return type

list(str)

verify()

Returns a list of bash commands that should verify that the module action has been performed successfully. These should set the test status to ENV_FAILED, and exit the bash script with a non-zero return code.

class pavilion.module_actions.ModuleSwap(module_name, version, old_module_name, old_version)

Bases: ModuleAction

Provides module swapping commands and verification. The ‘old_module’ can be a glob, like PrgEnv-*.

action()

Returns a list of bash commands that should perform the action for the given module.

Return type

list(str)

property old_module
verify()

Returns a list of bash commands that should verify that the module action has been performed successfully. These should set the test status to ENV_FAILED, and exit the bash script with a non-zero return code.

class pavilion.module_actions.ModuleUnload(module_name, version=None)

Bases: ModuleAction

Provides module unloading commands and verification.

action()

Returns a list of bash commands that should perform the action for the given module.

Return type

list(str)

verify()

Returns a list of bash commands that should verify that the module action has been performed successfully. These should set the test status to ENV_FAILED, and exit the bash script with a non-zero return code.