def test_details(self):
        """Testing the ScriptDetails class."""

        testPath = self.pav_cfg.working_dir / 'testScript.sh'

        testGroup = 'anonymous'

        testPerms = 0o531

        # Testing valid uses.

        # Testing initialization and defaults.
        test_details = scriptcomposer.ScriptDetails()

        self.assertEqual(test_details.group, utils.get_login())
        self.assertEqual(test_details.perms, oct(0o770))

        # Testing individual assignment.
        test_details.path = testPath
        test_details.group = testGroup
        test_details.perms = testPerms

        self.assertEqual(test_details.path, Path(testPath))
        self.assertEqual(test_details.group, testGroup)
        self.assertEqual(test_details.perms, oct(testPerms))

        # Testing initialization assignment.
        test_details = scriptcomposer.ScriptDetails(path=testPath,
                                                    group=testGroup,
                                                    perms=testPerms)

        self.assertEqual(test_details.path, Path(testPath))
        self.assertEqual(test_details.group, testGroup)
        self.assertEqual(test_details.perms, oct(testPerms))

        test_details = scriptcomposer.ScriptDetails()

        # Testing invalid uses.
        with self.assertRaises(TypeError):
            test_details.path = True

        with self.assertRaises(TypeError):
            test_details.perms = 'string'

        with self.assertRaises(TypeError):
            test_details.perms = u'fail'

        with self.assertRaises(TypeError):
            test_details.perms = 7.5

        # Testing invalid initialization.
        with self.assertRaises(TypeError):
            scriptcomposer.ScriptDetails(path=testPath,
                                         group=testGroup,
                                         perms='fail')
Example #2
0
    def _write_script(self, path, config, sys_vars):
        """Write a build or run script or template. The formats for each are
            identical.
        :param str path: Path to the template file to write.
        :param dict config: Configuration dictionary for the script file.
        :return:
        """

        if sys_vars is None:
            raise RuntimeError("Trying to write script without sys_vars "
                               "in test '{}'.".format(self.id))

        script = scriptcomposer.ScriptComposer(
            details=scriptcomposer.ScriptDetails(
                path=path,
                group=self._pav_cfg.shared_group,
            ))

        pav_lib_bash = self._pav_cfg.pav_root / 'bin' / 'pav-lib.bash'

        # If we include this directly, it breaks build hashing.
        script.comment('The first (and only) argument of the build script is '
                       'the test id.')
        script.env_change({'TEST_ID': '$1'})
        script.command('source {}'.format(pav_lib_bash))

        modules = config.get('modules', [])
        if modules:
            script.newline()
            script.comment(
                'Perform module related changes to the environment.')

            for module in config.get('modules', []):
                script.module_change(module, sys_vars)

        env = config.get('env', {})
        if env:
            script.newline()
            script.comment("Making any environment changes needed.")
            script.env_change(config.get('env', {}))

        script.newline()
        cmds = config.get('cmds', [])
        if cmds:
            script.comment("Perform the sequence of test commands.")
            for line in config.get('cmds', []):
                for split_line in line.split('\n'):
                    script.command(split_line)
        else:
            script.comment('No commands given for this script.')

        script.write()
Example #3
0
    def _write_script(self, path, config):
        """Write a build or run script or template. The formats for each are
            identical.
        :param str path: Path to the template file to write.
        :param dict config: Configuration dictionary for the script file.
        :return:
        """

        script = scriptcomposer.ScriptComposer(
            details=scriptcomposer.ScriptDetails(
                path=path,
                group=self._pav_cfg.shared_group,
            ))

        pav_lib_bash = os.path.join(self._pav_cfg.pav_root,
                                    'bin', 'pav-lib.bash')

        script.comment('The following is added to every test build and '
                       'run script.')
        script.env_change({'TEST_ID': '{}'.format(self.id)})
        script.command('source {}'.format(pav_lib_bash))

        modules = config.get('modules', [])
        if modules:
            script.newline()
            script.comment('Perform module related changes to the environment.')

            for module in config.get('modules', []):
                script.module_change(module, self._pav_cfg.sys_vars)

        env = config.get('env', {})
        if env:
            script.newline()
            script.comment("Making any environment changes needed.")
            script.env_change(config.get('env', {}))

        script.newline()
        cmds = config.get('cmds', [])
        if cmds:
            script.comment("Perform the sequence of test commands.")
            for line in config.get('cmds', []):
                for split_line in line.split('\n'):
                    script.command(split_line)
        else:
            script.comment('No commands given for this script.')

        script.write()
Example #4
0
    def _create_kickoff_script(self, pav_cfg, test_obj):
        """Function to accept a list of lines and generate a script that is
        then submitted to the scheduler.

        :param pavilion.test_config.TestRun test_obj:
        """

        header = self._get_kickoff_script_header(test_obj)

        script = scriptcomposer.ScriptComposer(
            header=header,
            details=scriptcomposer.ScriptDetails(
                path=self._kickoff_script_path(test_obj)),
        )

        script.comment("Redirect all output to kickoff.log")
        script.command("exec >{} 2>&1".format(test_obj.path / 'kickoff.log'))

        # Make sure the pavilion spawned
        env_changes = {
            'PATH': '{}:${{PATH}}'.format(pav_cfg.pav_root / 'bin'),
            'PAV_CONFIG_FILE': str(pav_cfg.pav_cfg_file),
        }
        if 'PAV_CONFIG_DIR' in os.environ:
            env_changes['PAV_CONFIG_DIR'] = os.environ['PAV_CONFIG_DIR']

        script.env_change(env_changes)

        # Run Kickoff Env setup commands
        for command in pav_cfg.env_setup:
            script.command(command)

        # Run the test via pavilion
        script.command('pav _run {t.id}'.format(t=test_obj))

        script.write()

        return script.details.path
Example #5
0
    def _write_kick_off_script(self, test):
        """Function to accept a list of lines and generate a script that is
           then submitted to the scheduler.
        """

        header = self._get_kick_off_header(test)

        script = scriptcomposer.ScriptComposer(
            header=header,
            details=scriptcomposer.ScriptDetails(
                path=os.path.join(test.path,
                                  'kickoff.{}'.format(self.KICKOFF_SCRIPT_EXT))

            ),
        )

        script.newline()

        script.comment("Within the allocation, run the command.")
        script.command(test.run_cmd())

        script.write()

        return script.details.path
Example #6
0
    def _write_script(self, path, config):
        """Write a build or run script or template. The formats for each are
            identical.
        :param Path path: Path to the template file to write.
        :param dict config: Configuration dictionary for the script file.
        :return:
        """

        script = scriptcomposer.ScriptComposer(
            details=scriptcomposer.ScriptDetails(
                path=path,
                group=self._pav_cfg.shared_group,
            ))

        verbose = config.get('verbose', 'false').lower() == 'true'

        if verbose:
            script.comment('# Echoing all commands to log.')
            script.command('set -v')
            script.newline()

        pav_lib_bash = self._pav_cfg.pav_root / 'bin' / 'pav-lib.bash'

        # If we include this directly, it breaks build hashing.
        script.comment('The first (and only) argument of the build script is '
                       'the test id.')
        script.env_change({
            'TEST_ID': '${1:-0}',  # Default to test id 0 if one isn't given.
            'PAV_CONFIG_FILE': self._pav_cfg['pav_cfg_file']
        })
        script.command('source {}'.format(pav_lib_bash))

        if config.get('preamble', []):
            script.newline()
            script.comment('Preamble commands')
            for cmd in config['preamble']:
                script.command(cmd)

        modules = config.get('modules', [])
        if modules:
            script.newline()
            script.comment(
                'Perform module related changes to the environment.')

            for module in config.get('modules', []):
                script.module_change(module, self.var_man)

        env = config.get('env', {})
        if env:
            script.newline()
            script.comment("Making any environment changes needed.")
            script.env_change(config.get('env', {}))

        if verbose:
            script.newline()
            script.comment('List all the module modules for posterity')
            script.command("module -t list")
            script.newline()
            script.comment('Output the environment for posterity')
            script.command("declare -p")

        script.newline()
        cmds = config.get('cmds', [])
        if cmds:
            script.comment("Perform the sequence of test commands.")
            for line in config.get('cmds', []):
                for split_line in line.split('\n'):
                    script.command(split_line)
        else:
            script.comment('No commands given for this script.')

        script.write()
    def test_scriptComposer(self):
        """Testing ScriptComposer class variable setting."""

        # Testing valid uses.

        # Testing initialization defaults.
        composer = scriptcomposer.ScriptComposer()

        self.assertIsInstance(composer.header, scriptcomposer.ScriptHeader)
        self.assertIsInstance(composer.details, scriptcomposer.ScriptDetails)

        self.assertEqual(composer.header.shell_path, '#!/bin/bash')
        self.assertEqual(composer.header.scheduler_headers, [])

        self.assertEqual(composer.details.group, utils.get_login())
        self.assertEqual(composer.details.perms, oct(0o770))

        # Testing individual assignment
        test_header_shell = "/usr/env/python"
        test_header_scheduler = OrderedDict()
        test_header_scheduler['-G'] = 'pam'
        test_header_scheduler['-N'] = 'fam'

        composer.newline()

        composer.command(['taco', 'burrito', 'nachos'])

        test_details_path = 'testPath'
        test_details_group = 'groupies'
        test_details_perms = 0o543

        composer.header.shell_path = test_header_shell
        composer.header.scheduler_headers = test_header_scheduler

        composer.details.path = test_details_path
        composer.details.group = test_details_group
        composer.details.perms = test_details_perms

        self.assertEqual(composer.header.shell_path, test_header_shell)
        self.assertEqual(composer.header.scheduler_headers,
                         test_header_scheduler)

        self.assertEqual(composer.details.path, Path(test_details_path))
        self.assertEqual(composer.details.group, test_details_group)
        self.assertEqual(composer.details.perms, oct(test_details_perms))

        composer = scriptcomposer.ScriptComposer()

        self.assertEqual(composer.header.shell_path, '#!/bin/bash')
        self.assertEqual(composer.header.scheduler_headers, [])

        self.assertEqual(composer.details.group, utils.get_login())
        self.assertEqual(composer.details.perms, oct(0o770))

        # Testing object assignment.
        header = scriptcomposer.ScriptHeader(
            shell_path=test_header_shell,
            scheduler_headers=test_header_scheduler)

        testDetailsObj = scriptcomposer.ScriptDetails(path=test_details_path,
                                                      group=test_details_group,
                                                      perms=test_details_perms)

        composer.header = header
        composer.details = testDetailsObj

        self.assertEqual(composer.header.shell_path, test_header_shell)
        self.assertEqual(composer.header.scheduler_headers,
                         test_header_scheduler)

        self.assertEqual(composer.details.path, Path(test_details_path))
        self.assertEqual(composer.details.group, test_details_group)
        self.assertEqual(composer.details.perms, oct(test_details_perms))