예제 #1
0
    def test_module_wrappers(self):
        """Make sure module wrapper loading is sane too."""

        # Get an empty pavilion config and set some config dirs on it.
        pav_cfg = config.PavilionConfigLoader().load_empty()

        # We're loading multiple directories of plugins - AT THE SAME TIME!
        pav_cfg.config_dirs = [
            os.path.join(self.TEST_DATA_ROOT, 'pav_config_dir'),
            os.path.join(self.TEST_DATA_ROOT, 'pav_config_dir2')
        ]

        plugins.initialize_plugins(pav_cfg)

        module_wrapper.get_module_wrapper('foo', '1.0')
        bar1 = module_wrapper.get_module_wrapper('bar', '1.3')
        bar2 = module_wrapper.get_module_wrapper('bar', '1.2.0')
        self.assertIsNot(bar1, bar2)

        self.assertEqual('1.3', bar1.get_version('1.3'))
        self.assertEqual('1.2.0', bar2.get_version('1.2.0'))
        self.assertRaises(module_wrapper.ModuleWrapperError,
                          lambda: bar2.get_version('1.3.0'))

        bar1.load({})

        plugins._reset_plugins()
예제 #2
0
    def module_change(self, module, sys_vars):
        """Function to take the module changes specified in the user config
        and add the appropriate lines to the script.
        :param str module: Name of a module or a list thereof in the format
         used in the user config.
        :param dict sys_vars: The pavilion system variable dictionary.
        """

        fullname = get_name(module)
        if '/' in fullname:
            name, version = fullname.split('/')
        else:
            name = fullname
            version = None
        action = get_action(module)

        module_obj = module_wrapper.get_module_wrapper(name, version)

        if action == 'load':
            mod_act, mod_env = module_obj.load(sys_vars, version)

        elif action == 'unload':
            mod_act, mod_env = module_obj.unload()

        elif action == 'swap':
            old = get_old_swap(module)
            if '/' in old:
                oldname, oldver = old.split('/')
            else:
                oldname = old
                oldver = None

            mod_act, mod_env = module_obj.swap(old_module_name=oldname,
                                               old_version=oldver)
        else:
            # This is not an expected error
            raise RuntimeError("Invalid Module action '{}'".format(action))

        for act in mod_act:
            if isinstance(act, ModuleAction):
                self._script_lines.extend(act.action())
                self._script_lines.extend(act.verify())
            else:
                self._script_lines.append(act)

        self.env_change(mod_env)
예제 #3
0
    def _module_wrappers_cmd(self, _, args):
        """List the various module wrapper plugins."""

        modules = []
        for mod_name in sorted(module_wrapper.list_module_wrappers()):
            mod_wrap = module_wrapper.get_module_wrapper(mod_name)
            modules.append({
                'name': mod_name,
                'version': mod_wrap._version,  # pylint: disable=W0212
                'description': mod_wrap.help_text,
                'path': mod_wrap.path,
            })

        fields = ['name', 'version', 'description']

        if args.verbose:
            fields.append('path')

        output.draw_table(self.outfile,
                          fields=fields,
                          rows=modules,
                          title="Available Module Wrapper Plugins")
예제 #4
0
    def module_change(self, module, sys_vars):
        """Take the module changes specified in the user config and add the
        appropriate lines to the script. This will parse the module name into
        various actions, find the appropriate module_wrapper plugin, and use
        that to get the lines to add to the script.

        :param str module: Name of a module or a list thereof in the format
            used in the user config.
        :param dict sys_vars: The pavilion system variable dictionary.
        """

        action, (name, version), (oldname, oldver) = self.parse_module(module)

        module_obj = module_wrapper.get_module_wrapper(name, version)

        if action == 'load':
            mod_act, mod_env = module_obj.load(sys_vars, version)

        elif action == 'unload':
            mod_act, mod_env = module_obj.unload(sys_vars, version)
        elif action == 'swap':
            mod_act, mod_env = module_obj.swap(sys_vars,
                                               oldname,
                                               oldver,
                                               requested_version=version)
        else:
            # This is not an expected error
            raise RuntimeError("Invalid Module action '{}'".format(action))

        for act in mod_act:
            if isinstance(act, ModuleAction):
                self._script_lines.extend(act.action())
                self._script_lines.extend(act.verify())
            else:
                self._script_lines.append(act)

        self.env_change(mod_env)
예제 #5
0
    def _module_cmd(_, args, outfile=sys.stdout):

        modules = []
        for mod_name in sorted(module_wrapper.list_module_wrappers()):
            mod_wrap = module_wrapper.get_module_wrapper(mod_name)
            modules.append({
                'name': mod_name,
                'version': mod_wrap._version,  # pylint: disable=W0212
                'description': mod_wrap.help_text,
                'path': mod_wrap.path,
            })

        fields = ['name', 'version', 'description']

        if args.verbose:
            fields.append('path')

        utils.draw_table(
            outfile,
            field_info={},
            fields=fields,
            rows=modules,
            title="Available Module Wrapper Plugins"
        )