Ejemplo n.º 1
0
    def test_quiet(self):
        """Test enabling quiet logging (errors only)."""

        for quiet_arg in ["--quiet"]:
            args = ["--software-name=somethingrandom", quiet_arg]
            try:
                main((args, self.logfile, False))
            except (SystemExit, Exception), err:
                pass
            outtxt = read_file(self.logfile)

            for log_msg_type in ["ERROR"]:
                res = re.search(" %s " % log_msg_type, outtxt)
                self.assertTrue(
                    res, "%s log messages are included when using %s (outtxt: %s)" % (log_msg_type, quiet_arg, outtxt)
                )

            for log_msg_type in ["DEBUG", "INFO"]:
                res = re.search(" %s " % log_msg_type, outtxt)
                self.assertTrue(
                    not res,
                    "%s log messages are *not* included when using %s (outtxt: %s)" % (log_msg_type, quiet_arg, outtxt),
                )

            modify_env(os.environ, self.orig_environ)
            tempfile.tempdir = None
Ejemplo n.º 2
0
    def test_skip(self):
        """Test skipping installation of module (--skip, -k)."""

        # keep track of original environment to restore after purging *all* loaded modules
        orig_environ = copy.deepcopy(os.environ)

        # use temporary paths for build/install paths, make sure sources can be found
        buildpath = tempfile.mkdtemp()
        installpath = tempfile.mkdtemp()
        sourcepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'sandbox', 'sources')

        # set MODULEPATH to included modules
        orig_modulepath = os.getenv('MODULEPATH', None)
        os.environ['MODULEPATH'] = os.path.abspath(os.path.join(os.path.dirname(__file__), 'modules'))

        # use toy-0.0.eb easyconfig file that comes with the tests
        eb_file = os.path.join(os.path.dirname(__file__), 'easyconfigs', 'toy-0.0.eb')

        # check log message with --skip for existing module
        args = [
                eb_file,
                '--sourcepath=%s' % sourcepath,
                '--buildpath=%s' % buildpath,
                '--installpath=%s' % installpath,
                '--force',
                '--skip',
                '--debug',
               ]

        try:
            main((args, self.logfile, True))
        except (SystemExit, Exception), err:
            pass
Ejemplo n.º 3
0
    def test_zzz_logtostdout(self):
        """Testing redirecting log to stdout."""

        for stdout_arg in ['--logtostdout', '-l']:

            _stdout = sys.stdout

            myerr = None
            fd, fn = tempfile.mkstemp()
            fh = os.fdopen(fd, 'w')
            sys.stdout = fh

            args = [
                    '--software-name=somethingrandom',
                    '--robot=.',
                    '--debug',
                    stdout_arg,
                   ]
            try:
                main((args, None))
            except Exception, err:
                myerr = err

            # make sure we restore
            sys.stdout.flush()
            sys.stdout = _stdout
            fancylogger.logToScreen(enable=False, stdout=True)

            outtxt = open(fn, 'r').read()

            self.assertTrue(len(outtxt) > 100, "Log messages are printed to stdout when %s is used (outtxt: %s)" % (stdout_arg, outtxt))

            # cleanup
            os.remove(fn)
Ejemplo n.º 4
0
    def test_info(self):
        """Test enabling info logging."""

        for info_arg in ["--info"]:
            args = ["--software-name=somethingrandom", info_arg]
            myerr = None
            try:
                main((args, self.logfile, False))
            except (SystemExit, Exception), err:
                myerr = err
            outtxt = read_file(self.logfile)

            for log_msg_type in ["INFO", "ERROR"]:
                res = re.search(" %s " % log_msg_type, outtxt)
                self.assertTrue(
                    res,
                    "%s log messages are included when using %s (err: %s, out: %s)"
                    % (log_msg_type, info_arg, myerr, outtxt),
                )

            for log_msg_type in ["DEBUG"]:
                res = re.search(" %s " % log_msg_type, outtxt)
                self.assertTrue(not res, "%s log messages are *not* included when using %s" % (log_msg_type, info_arg))

            modify_env(os.environ, self.orig_environ)
            tempfile.tempdir = None
Ejemplo n.º 5
0
    def test_toy_build(self):
        """Perform a toy build."""
        fd, dummylogfn = tempfile.mkstemp(prefix='easybuild-dummy', suffix='.log')
        os.close(fd)

        # adjust PYTHONPATH such that test easyblocks are found
        orig_sys_path = sys.path[:]

        sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'sandbox')))
        import easybuild.easyblocks
        reload(easybuild.easyblocks)
        reload(easybuild.tools.module_naming_scheme)

        # clear log
        write_file(self.logfile, '')

        buildpath = tempfile.mkdtemp()
        installpath = tempfile.mkdtemp()
        sourcepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'sandbox', 'sources')

        args = [
                os.path.join(os.path.dirname(__file__), 'easyconfigs', 'toy-0.0.eb'),
                '--sourcepath=%s' % sourcepath,
                '--buildpath=%s' % buildpath,
                '--installpath=%s' % installpath,
                '--debug',
                '--unittest-file=%s' % self.logfile,
                '--force',
               ]
        try:
            main((args, dummylogfn, True))
        except (SystemExit, Exception), err:
            print err
Ejemplo n.º 6
0
    def eb_main(self, args, do_build=False, return_error=False, logfile=None, verbose=False, raise_error=False,
                reset_env=True, raise_systemexit=False, testing=True):
        """Helper method to call EasyBuild main function."""
        cleanup()

        myerr = False
        if logfile is None:
            logfile = self.logfile
        # clear log file
        if logfile:
            f = open(logfile, 'w')
            f.write('')
            f.close()

        env_before = copy.deepcopy(os.environ)

        try:
            main(args=args, logfile=logfile, do_build=do_build, testing=testing)
        except SystemExit:
            if raise_systemexit:
                raise err
        except Exception, err:
            myerr = err
            if verbose:
                print "err: %s" % err
Ejemplo n.º 7
0
    def test_job(self):
        """Test submitting build as a job."""

        # set MODULEPATH to included modules
        orig_modulepath = os.getenv('MODULEPATH', None)
        os.environ['MODULEPATH'] = os.path.join(os.path.dirname(__file__), 'modules')

        # use gzip-1.4.eb easyconfig file that comes with the tests
        eb_file = os.path.join(os.path.dirname(__file__), 'easyconfigs', 'gzip-1.4.eb')

        # check log message with --job
        for job_args in [  # options passed are reordered, so order here matters to make tests pass
                         ['--debug'],
                         ['--debug', '--stop=configure', '--try-software-name=foo'],
                        ]:

            # clear log file
            outtxt = write_file(self.logfile, '')

            args = [
                    eb_file,
                    '--job',
                   ] + job_args
            try:
                main((args, self.logfile))
            except (SystemExit, Exception), err:
                pass
            outtxt = read_file(self.logfile)

            job_msg = "INFO.* Command template for jobs: .* && eb %%\(spec\)s %s.*\n" % ' .*'.join(job_args)
            assertmsg = "Info log message with job command template when using --job (job_msg: %s, outtxt: %s)" % (job_msg, outtxt)
            self.assertTrue(re.search(job_msg, outtxt), assertmsg)
Ejemplo n.º 8
0
    def test_tmpdir(self):
        """Test setting temporary directory to use by EasyBuild."""

        # use temporary paths for build/install paths, make sure sources can be found
        buildpath = tempfile.mkdtemp()
        installpath = tempfile.mkdtemp()
        tmpdir = tempfile.mkdtemp()
        sourcepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'sandbox', 'sources')

        # set MODULEPATH to included modules
        os.environ['MODULEPATH'] = os.path.abspath(os.path.join(os.path.dirname(__file__), 'modules'))

        # use toy-0.0.eb easyconfig file that comes with the tests
        eb_file = os.path.join(os.path.dirname(__file__), 'easyconfigs', 'toy-0.0.eb')

        # check log message with --skip for existing module
        args = [
            eb_file,
            '--sourcepath=%s' % sourcepath,
            '--buildpath=%s' % buildpath,
            '--installpath=%s' % installpath,
            '--debug',
            '--tmpdir=%s' % tmpdir,
        ]

        try:
            main((args, self.logfile, True))
        except (SystemExit, Exception), err:
            pass
Ejemplo n.º 9
0
    def test_no_args(self):
        """Test using no arguments."""

        try:
            main(([], self.logfile))
        except (SystemExit, Exception), err:
            pass
Ejemplo n.º 10
0
    def test_job(self):
        """Test submitting build as a job."""

        # use gzip-1.4.eb easyconfig file that comes with the tests
        eb_file = os.path.join(os.path.dirname(__file__), "easyconfigs", "gzip-1.4.eb")

        # check log message with --job
        for job_args in [  # options passed are reordered, so order here matters to make tests pass
            ["--debug"],
            ["--debug", "--stop=configure", "--try-software-name=foo"],
        ]:

            # clear log file
            outtxt = write_file(self.logfile, "")

            args = [eb_file, "--job"] + job_args
            try:
                main((args, self.logfile, False))
            except (SystemExit, Exception), err:
                pass
            outtxt = read_file(self.logfile)

            job_msg = "INFO.* Command template for jobs: .* && eb %%\(spec\)s %s.*\n" % " .*".join(job_args)
            assertmsg = "Info log message with job command template when using --job (job_msg: %s, outtxt: %s)" % (
                job_msg,
                outtxt,
            )
            self.assertTrue(re.search(job_msg, outtxt), assertmsg)

            modify_env(os.environ, self.orig_environ)
            tempfile.tempdir = None
    def test_list_easyblocks(self):
        """Test listing easyblock hierarchy."""

        # adjust PYTHONPATH such that test easyblocks are found
        orig_sys_path = sys.path

        import easybuild
        sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'easyblocks_sandbox')))
        easybuild = reload(easybuild)
        import easybuild.easyblocks
        easybuild.easyblocks = reload(easybuild.easyblocks)

        # simple view
        for list_arg in ['--list-easyblocks', '--list-easyblocks=simple']:

            # clear log
            open(self.logfile, 'w').write('')

            args = [
                    list_arg,
                    '--unittest-file=%s' % self.logfile,
                   ]
            try:
                main((args, None))
            except (SystemExit, Exception), err:
                pass
            outtxt = open(self.logfile, 'r').read()

            for pat in [
                        r"EasyBlock\n",
                        r"|--\s+EB_foo\n|\s+|--\s+EB_foofoo\n",
                        r"|--\s+bar\n",
                       ]:

                self.assertTrue(re.search(pat, outtxt), "Pattern '%s' is found in output of --list-easyblocks: %s" % (pat, outtxt))
Ejemplo n.º 12
0
    def test_avail_lists(self):
        """Test listing available values of certain types."""

        fd, dummylogfn = tempfile.mkstemp(prefix='easybuild-dummy', suffix='.log')
        os.close(fd)

        name_items = {
            'modules-tools': ['EnvironmentModulesC', 'Lmod'],
            'module-naming-schemes': ['EasyBuildModuleNamingScheme'],
        }
        for (name, items) in name_items.items():
            args = [
                    '--avail-%s' % name,
                    '--unittest-file=%s' % self.logfile,
                   ]
            try:
                main((args, dummylogfn, False))
            except (SystemExit, Exception), err:
                pass
            outtxt = read_file(self.logfile)

            words = name.replace('-', ' ')
            info_msg = r"INFO List of supported %s:" % words
            self.assertTrue(re.search(info_msg, outtxt), "Info message with list of available %s" % words)
            for item in items:
                res = re.findall("^\s*%s" % item, outtxt, re.M)
                self.assertTrue(res, "%s is included in list of available %s" % (item, words))
                # every item should only be mentioned once
                n = len(res)
                self.assertEqual(n, 1, "%s is only mentioned once (count: %d)" % (item, n))
Ejemplo n.º 13
0
    def test_toy_build_formatv2(self):
        """Perform a toy build (format v2)."""
        # set $MODULEPATH such that modules for specified dependencies are found
        modulepath = os.environ.get('MODULEPATH')
        os.environ['MODULEPATH'] = os.path.abspath(os.path.join(os.path.dirname(__file__), 'modules'))

        args = [
            os.path.join(os.path.dirname(__file__), 'easyconfigs', 'v2.0', 'toy.eb'),
            '--sourcepath=%s' % self.sourcepath,
            '--buildpath=%s' % self.buildpath,
            '--installpath=%s' % self.installpath,
            '--debug',
            '--unittest-file=%s' % self.logfile,
            '--force',
            '--robot=%s' % os.pathsep.join([self.buildpath, os.path.dirname(__file__)]),
            '--software-version=0.0',
            '--toolchain=dummy,dummy',
            '--experimental',
        ]
        try:
            main((args, self.dummylogfn, True))
        except SystemExit:
            pass
        outtxt = read_file(self.logfile)

        self.check_toy(self.installpath, outtxt)

        # restore
        if modulepath is not None:
            os.environ['MODULEPATH'] = modulepath
        else:
            del os.environ['MODULEPATH']
Ejemplo n.º 14
0
    def test_recursive_module_unload(self):
        """Test generating recursively unloading modules."""

        # use temporary paths for build/install paths, make sure sources can be found
        buildpath = tempfile.mkdtemp()
        installpath = tempfile.mkdtemp()
        tmpdir = tempfile.mkdtemp()
        sourcepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "sandbox", "sources")

        # use toy-0.0.eb easyconfig file that comes with the tests
        eb_file = os.path.join(os.path.dirname(__file__), "easyconfigs", "toy-0.0-deps.eb")

        # check log message with --skip for existing module
        args = [
            eb_file,
            "--sourcepath=%s" % sourcepath,
            "--buildpath=%s" % buildpath,
            "--installpath=%s" % installpath,
            "--debug",
            "--force",
            "--recursive-module-unload",
        ]

        try:
            main((args, self.logfile, True))
        except (SystemExit, Exception), err:
            pass
Ejemplo n.º 15
0
    def test_tmpdir(self):
        """Test setting temporary directory to use by EasyBuild."""

        # use temporary paths for build/install paths, make sure sources can be found
        buildpath = tempfile.mkdtemp()
        installpath = tempfile.mkdtemp()
        tmpdir = tempfile.mkdtemp()
        sourcepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "sandbox", "sources")

        # use toy-0.0.eb easyconfig file that comes with the tests
        eb_file = os.path.join(os.path.dirname(__file__), "easyconfigs", "toy-0.0.eb")

        # check log message with --skip for existing module
        args = [
            eb_file,
            "--sourcepath=%s" % sourcepath,
            "--buildpath=%s" % buildpath,
            "--installpath=%s" % installpath,
            "--debug",
            "--tmpdir=%s" % tmpdir,
        ]

        try:
            main((args, self.logfile, True))
        except (SystemExit, Exception), err:
            pass
Ejemplo n.º 16
0
    def test_footer(self):
        """Test specifying a module footer."""
        # use temporary paths for build/install paths, make sure sources can be found
        buildpath = tempfile.mkdtemp()
        installpath = tempfile.mkdtemp()
        tmpdir = tempfile.mkdtemp()
        sourcepath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "sandbox", "sources")

        # create file containing modules footer
        module_footer_txt = "\n".join(["# test footer", "setenv SITE_SPECIFIC_ENV_VAR foobar"])
        fd, modules_footer = tempfile.mkstemp(prefix="modules-footer-")
        os.close(fd)
        f = open(modules_footer, "w")
        f.write(module_footer_txt)
        f.close()

        # use toy-0.0.eb easyconfig file that comes with the tests
        eb_file = os.path.join(os.path.dirname(__file__), "easyconfigs", "toy-0.0.eb")

        # check log message with --skip for existing module
        args = [
            eb_file,
            "--sourcepath=%s" % sourcepath,
            "--buildpath=%s" % buildpath,
            "--installpath=%s" % installpath,
            "--debug",
            "--force",
            "--modules-footer=%s" % modules_footer,
        ]

        try:
            main((args, self.logfile, True))
        except (SystemExit, Exception), err:
            pass
Ejemplo n.º 17
0
    def test_toy_build_with_blocks(self):
        """Test a toy build with multiple blocks."""
        orig_sys_path = sys.path[:]
        # add directory in which easyconfig file can be found to Python search path, since we're not specifying it full path below
        tmpdir = tempfile.mkdtemp()
        # note get_paths_for expects easybuild/easyconfigs subdir
        ecs_path = os.path.join(tmpdir, "easybuild", "easyconfigs")
        os.makedirs(ecs_path)
        shutil.copy2(os.path.join(os.path.dirname(__file__), 'easyconfigs', 'toy-0.0-multiple.eb'), ecs_path)
        sys.path.append(tmpdir)

        args = [
                'toy-0.0-multiple.eb',
                '--sourcepath=%s' % self.sourcepath,
                '--buildpath=%s' % self.buildpath,
                '--installpath=%s' % self.installpath,
                '--debug',
                '--unittest-file=%s' % self.logfile,
                '--force',
               ]
        try:
            main((args, self.dummylogfn, True))
        except SystemExit:
            pass
        except Exception, err:
            print "err: %s" % err
Ejemplo n.º 18
0
    def test_avail_lists(self):
        """Test listing available values of certain types."""

        fd, dummylogfn = tempfile.mkstemp(prefix="easybuild-dummy", suffix=".log")
        os.close(fd)

        name_items = {
            "modules-tools": ["EnvironmentModulesC", "Lmod"],
            "module-naming-schemes": ["EasyBuildModuleNamingScheme"],
        }
        for (name, items) in name_items.items():
            args = ["--avail-%s" % name, "--unittest-file=%s" % self.logfile]
            try:
                main((args, dummylogfn, False))
            except (SystemExit, Exception), err:
                pass
            outtxt = read_file(self.logfile)

            words = name.replace("-", " ")
            info_msg = r"INFO List of supported %s:" % words
            self.assertTrue(re.search(info_msg, outtxt), "Info message with list of available %s" % words)
            for item in items:
                res = re.findall("^\s*%s" % item, outtxt, re.M)
                self.assertTrue(res, "%s is included in list of available %s" % (item, words))
                # every item should only be mentioned once
                n = len(res)
                self.assertEqual(n, 1, "%s is only mentioned once (count: %d)" % (item, n))

            modify_env(os.environ, self.orig_environ)
            tempfile.tempdir = None
Ejemplo n.º 19
0
    def test_no_such_software(self):
        """Test using no arguments."""

        args = ["--software-name=nosuchsoftware", "--robot=.", "--debug"]
        myerr = None
        try:
            main((args, self.logfile, False))
        except (SystemExit, Exception), err:
            myerr = err
Ejemplo n.º 20
0
    def test__list_toolchains(self):
        """Test listing known compiler toolchains."""

        fd, dummylogfn = tempfile.mkstemp(prefix="easybuild-dummy", suffix=".log")
        os.close(fd)

        args = ["--list-toolchains", "--unittest-file=%s" % self.logfile]
        try:
            main((args, dummylogfn, False))
        except (SystemExit, Exception), err:
            pass
    def test_list_toolchains(self):
        """Test listing known compiler toolchains."""

        args = [
                '--list-toolchains',
                '--unittest-file=%s' % self.logfile,
               ]
        try:
            main((args, None))
        except (SystemExit, Exception), err:
            pass
Ejemplo n.º 22
0
 def test_search(self):
     """Test searching for easyconfigs."""
     args = [
             '--search=gzip',
             '--robot=%s' % os.path.join(os.path.dirname(__file__), 'easyconfigs'),
             '--unittest-file=%s' % self.logfile,
            ]
     try:
         main((args, None))
     except (SystemExit, Exception), err:
         pass
Ejemplo n.º 23
0
    def test_no_args(self):
        """Test using no arguments."""

        try:
            main(([], self.logfile))
        except:
            pass
        outtxt = open(self.logfile, 'r').read()

        error_msg = "ERROR .* Please provide one or multiple easyconfig files,"
        error_msg += " or use software build options to make EasyBuild search for easyconfigs"
        self.assertTrue(re.search(error_msg, outtxt), "Error message when eb is run without arguments")
Ejemplo n.º 24
0
    def test_no_such_software(self):
        """Test using no arguments."""

        args = [
                '--software-name=nosuchsoftware',
                '--robot=.',
                '--debug',
               ]
        myerr = None
        try:
            main((args, self.logfile))
        except Exception, err:
            myerr = err
Ejemplo n.º 25
0
    def test_list_toolchains(self):
        """Test listing known compiler toolchains."""

        fd, dummylogfn = tempfile.mkstemp(prefix='easybuild-dummy', suffix='.log')
        os.close(fd)

        args = [
                '--list-toolchains',
                '--unittest-file=%s' % self.logfile,
               ]
        try:
            main((args, dummylogfn))
        except (SystemExit, Exception), err:
            pass
Ejemplo n.º 26
0
    def test_force(self):
        """Test forcing installation even if the module is already available."""

        # use GCC-4.6.3.eb easyconfig file that comes with the tests
        eb_file = os.path.join(os.path.dirname(__file__), "easyconfigs", "GCC-4.6.3.eb")

        # check log message without --force
        args = [eb_file, "--debug"]

        error_thrown = False
        try:
            main((args, self.logfile, False))
        except (SystemExit, Exception), err:
            error_thrown = err
Ejemplo n.º 27
0
    def eb_main(self, args, do_build=False, return_error=False, logfile=None, verbose=False, raise_error=False,
                reset_env=True, raise_systemexit=False, testing=True):
        """Helper method to call EasyBuild main function."""
        cleanup()

        myerr = False
        if logfile is None:
            logfile = self.logfile
        # clear log file
        if logfile:
            f = open(logfile, 'w')
            f.write('')
            f.close()

        env_before = copy.deepcopy(os.environ)

        try:
            main(args=args, logfile=logfile, do_build=do_build, testing=testing, modtool=self.modtool)
        except SystemExit as err:
            if raise_systemexit:
                raise err
        except Exception as err:
            myerr = err
            if verbose:
                print "err: %s" % err

        if logfile and os.path.exists(logfile):
            logtxt = read_file(logfile)
        else:
            logtxt = None

        os.chdir(self.cwd)

        # make sure config is reinitialized
        init_config(with_include=False)

        # restore environment to what it was before running main,
        # changes may have been made by eb_main (e.g. $TMPDIR & co)
        if reset_env:
            modify_env(os.environ, env_before, verbose=False)
            tempfile.tempdir = None

        if myerr and raise_error:
            raise myerr

        if return_error:
            return logtxt, myerr
        else:
            return logtxt
Ejemplo n.º 28
0
    def test_search(self):
        """Test searching for easyconfigs."""

        fd, dummylogfn = tempfile.mkstemp(prefix='easybuild-dummy', suffix='.log')
        os.close(fd)

        args = [
                '--search=gzip',
                '--robot=%s' % os.path.join(os.path.dirname(__file__), 'easyconfigs'),
                '--unittest-file=%s' % self.logfile,
               ]
        try:
            main((args, dummylogfn))
        except (SystemExit, Exception), err:
            pass
Ejemplo n.º 29
0
    def test_search(self):
        """Test searching for easyconfigs."""

        fd, dummylogfn = tempfile.mkstemp(prefix="easybuild-dummy", suffix=".log")
        os.close(fd)

        args = [
            "--search=gzip",
            "--robot=%s" % os.path.join(os.path.dirname(__file__), "easyconfigs"),
            "--unittest-file=%s" % self.logfile,
        ]
        try:
            main((args, dummylogfn, False))
        except (SystemExit, Exception), err:
            pass
Ejemplo n.º 30
0
 def test_toy_build(self):
     """Perform a toy build."""
     args = [
             os.path.join(os.path.dirname(__file__), 'easyconfigs', 'toy-0.0.eb'),
             '--sourcepath=%s' % self.sourcepath,
             '--buildpath=%s' % self.buildpath,
             '--installpath=%s' % self.installpath,
             '--debug',
             '--unittest-file=%s' % self.logfile,
             '--force',
            ]
     try:
         main((args, self.dummylogfn, True))
     except (SystemExit, Exception), err:
         print err
Ejemplo n.º 31
0
 def eb_main(self, args, do_build=False, return_error=False, logfile=None, verbose=False, raise_error=False):
     """Helper method to call EasyBuild main function."""
     # clear instance of BuildOptions and ConfigurationVariables to ensure configuration is reinitialized
     config.ConfigurationVariables.__metaclass__._instances.pop(config.ConfigurationVariables, None)
     config.BuildOptions.__metaclass__._instances.pop(config.BuildOptions, None)
     myerr = False
     if logfile is None:
         logfile = self.logfile
     try:
         main((args, logfile, do_build))
     except SystemExit:
         pass
     except Exception, err:
         myerr = err
         if verbose:
             print "err: %s" % err
Ejemplo n.º 32
0
 def test_toy_build(self):
     """Perform a toy build."""
     args = [
         os.path.join(os.path.dirname(__file__), 'easyconfigs',
                      'toy-0.0.eb'),
         '--sourcepath=%s' % self.sourcepath,
         '--buildpath=%s' % self.buildpath,
         '--installpath=%s' % self.installpath,
         '--debug',
         '--unittest-file=%s' % self.logfile,
         '--force',
     ]
     try:
         main((args, self.dummylogfn, True))
     except (SystemExit, Exception), err:
         print err
Ejemplo n.º 33
0
    def test_search(self):
        """Test searching for easyconfigs."""

        fd, dummylogfn = tempfile.mkstemp(prefix='easybuild-dummy',
                                          suffix='.log')
        os.close(fd)

        args = [
            '--search=gzip',
            '--robot=%s' %
            os.path.join(os.path.dirname(__file__), 'easyconfigs'),
            '--unittest-file=%s' % self.logfile,
        ]
        try:
            main((args, dummylogfn, False))
        except (SystemExit, Exception), err:
            pass
Ejemplo n.º 34
0
    def test_debug(self):
        """Test enabling debug logging."""

        for debug_arg in ['-d', '--debug']:
            args = [
                    '--software-name=somethingrandom',
                    debug_arg,
                   ]
            try:
                main((args, self.logfile))
            except (SystemExit, Exception), err:
                myerr = err
            outtxt = read_file(self.logfile)

            for log_msg_type in ['DEBUG', 'INFO', 'ERROR']:
                res = re.search(' %s ' % log_msg_type, outtxt)
                self.assertTrue(res, "%s log messages are included when using %s: %s" % (log_msg_type, debug_arg, outtxt))
Ejemplo n.º 35
0
    def test_list_easyblocks(self):
        """Test listing easyblock hierarchy."""

        fd, dummylogfn = tempfile.mkstemp(prefix='easybuild-dummy',
                                          suffix='.log')
        os.close(fd)

        # adjust PYTHONPATH such that test easyblocks are found
        orig_sys_path = sys.path[:]

        import easybuild
        sys.path.append(
            os.path.abspath(os.path.join(os.path.dirname(__file__),
                                         'sandbox')))
        easybuild = reload(easybuild)
        import easybuild.easyblocks
        reload(easybuild.easyblocks)
        reload(easybuild.tools.module_naming_scheme
               )  # required to run options unit tests stand-alone

        # simple view
        for list_arg in ['--list-easyblocks', '--list-easyblocks=simple']:

            # clear log
            write_file(self.logfile, '')

            args = [
                list_arg,
                '--unittest-file=%s' % self.logfile,
            ]
            try:
                main((args, dummylogfn, False))
            except (SystemExit, Exception), err:
                pass
            outtxt = read_file(self.logfile)

            for pat in [
                    r"EasyBlock\n",
                    r"|--\s+EB_foo\n|\s+|--\s+EB_foofoo\n",
                    r"|--\s+bar\n",
            ]:

                self.assertTrue(
                    re.search(pat, outtxt),
                    "Pattern '%s' is found in output of --list-easyblocks: %s"
                    % (pat, outtxt))
Ejemplo n.º 36
0
        def run_test(custom=None, extra_params=[]):
            """Inner function to run actual test in current setting."""

            fd, dummylogfn = tempfile.mkstemp(prefix='easybuild-dummy', suffix='.log')
            os.close(fd)

            for avail_arg in [
                              '-a',
                              '--avail-easyconfig-params',
                             ]:

                # clear log
                write_file(self.logfile, '')

                args = [
                        avail_arg,
                        '--unittest-file=%s' % self.logfile,
                       ]
                if custom is not None:
                    args.extend(['-e', custom])

                try:
                    main((args, dummylogfn))
                except (SystemExit, Exception), err:
                    pass
                outtxt = read_file(self.logfile)

                # check whether all parameter types are listed
                par_types = [BUILD, DEPENDENCIES, EXTENSIONS, FILEMANAGEMENT,
                             LICENSE, MANDATORY, MODULES, OTHER, TOOLCHAIN]
                if custom is not None:
                    par_types.append(CUSTOM)

                for param_type in [x[1] for x in par_types]:
                    self.assertTrue(re.search("%s\n%s" % (param_type.upper(), '-' * len(param_type)), outtxt),
                                    "Parameter type %s is featured in output of eb %s (args: %s): %s" %
                                    (param_type, avail_arg, args, outtxt))

                # check a couple of easyconfig parameters
                for param in ["name", "version", "toolchain", "versionsuffix", "makeopts", "sources", "start_dir",
                              "dependencies", "group", "exts_list", "moduleclass", "buildstats"] + extra_params:
                    self.assertTrue(re.search("%s(?:\(\*\))?:\s*\w.*" % param, outtxt),
                                    "Parameter %s is listed with help in output of eb %s (args: %s): %s" %
                                    (param, avail_arg, args, outtxt)
                                    )
Ejemplo n.º 37
0
    def test_zzz_logtostdout(self):
        """Testing redirecting log to stdout."""

        fd, dummylogfn = tempfile.mkstemp(prefix='easybuild-dummy',
                                          suffix='.log')
        os.close(fd)

        for stdout_arg in ['--logtostdout', '-l']:

            _stdout = sys.stdout

            myerr = None
            fd, fn = tempfile.mkstemp()
            fh = os.fdopen(fd, 'w')
            sys.stdout = fh

            args = [
                '--software-name=somethingrandom',
                '--robot',
                '.',
                '--debug',
                stdout_arg,
            ]
            try:
                main((args, dummylogfn, False))
            except (SystemExit, Exception), err:
                myerr = err

            # make sure we restore
            sys.stdout.flush()
            sys.stdout = _stdout
            fancylogger.logToScreen(enable=False, stdout=True)

            outtxt = read_file(fn)

            self.assertTrue(
                len(outtxt) > 100,
                "Log messages are printed to stdout when %s is used (outtxt: %s)"
                % (stdout_arg, outtxt))

            # cleanup
            os.remove(fn)
Ejemplo n.º 38
0
    def test_force(self):
        """Test forcing installation even if the module is already available."""

        # set MODULEPATH to included modules
        orig_modulepath = os.getenv('MODULEPATH', None)
        os.environ['MODULEPATH'] = os.path.abspath(os.path.join(os.path.dirname(__file__), 'modules'))

        # use GCC-4.6.3.eb easyconfig file that comes with the tests
        eb_file = os.path.join(os.path.dirname(__file__), 'easyconfigs', 'GCC-4.6.3.eb')

        # check log message without --force
        args = [
                eb_file,
               ]

        error_thrown = False
        try:
            main((args, self.logfile))
        except (SystemExit, Exception), err:
            error_thrown = err
Ejemplo n.º 39
0
    def eb_main(self,
                args,
                do_build=False,
                return_error=False,
                logfile=None,
                verbose=False,
                raise_error=False):
        """Helper method to call EasyBuild main function."""
        cleanup()

        myerr = False
        if logfile is None:
            logfile = self.logfile
        try:
            main((args, logfile, do_build))
        except SystemExit:
            pass
        except Exception, err:
            myerr = err
            if verbose:
                print "err: %s" % err
Ejemplo n.º 40
0
    def test_quiet(self):
        """Test enabling quiet logging (errors only)."""

        for quiet_arg in ['--quiet']:
            args = [
                    '--software-name=somethingrandom',
                    quiet_arg,
                   ]
            try:
                main((args, self.logfile))
            except (SystemExit, Exception), err:
                pass
            outtxt = read_file(self.logfile)

            for log_msg_type in ['ERROR']:
                res = re.search(' %s ' % log_msg_type, outtxt)
                self.assertTrue(res, "%s log messages are included when using %s (outtxt: %s)" % (log_msg_type, quiet_arg, outtxt))

            for log_msg_type in ['DEBUG', 'INFO']:
                res = re.search(' %s ' % log_msg_type, outtxt)
                self.assertTrue(not res, "%s log messages are *not* included when using %s (outtxt: %s)" % (log_msg_type, quiet_arg, outtxt))
Ejemplo n.º 41
0
    def test_info(self):
        """Test enabling info logging."""

        for info_arg in ['--info']:
            args = [
                    '--software-name=somethingrandom',
                    info_arg,
                   ]
            myerr = None
            try:
                main((args, self.logfile))
            except (SystemExit, Exception), err:
                myerr = err
            outtxt = read_file(self.logfile)

            for log_msg_type in ['INFO', 'ERROR']:
                res = re.search(' %s ' % log_msg_type, outtxt)
                self.assertTrue(res, "%s log messages are included when using %s (err: %s, out: %s)" % (log_msg_type, info_arg, myerr, outtxt))

            for log_msg_type in ['DEBUG']:
                res = re.search(' %s ' % log_msg_type, outtxt)
                self.assertTrue(not res, "%s log messages are *not* included when using %s" % (log_msg_type, info_arg))
Ejemplo n.º 42
0
    def test_toy_build(self):
        """Perform a toy build."""
        fd, dummylogfn = tempfile.mkstemp(prefix='easybuild-dummy',
                                          suffix='.log')
        os.close(fd)

        # adjust PYTHONPATH such that test easyblocks are found
        orig_sys_path = sys.path[:]

        sys.path.append(
            os.path.abspath(os.path.join(os.path.dirname(__file__),
                                         'sandbox')))
        import easybuild.easyblocks
        reload(easybuild.easyblocks)
        reload(easybuild.tools.module_naming_scheme)

        # clear log
        write_file(self.logfile, '')

        buildpath = tempfile.mkdtemp()
        installpath = tempfile.mkdtemp()
        sourcepath = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                  'sandbox', 'sources')

        args = [
            os.path.join(os.path.dirname(__file__), 'easyconfigs',
                         'toy-0.0.eb'),
            '--sourcepath=%s' % sourcepath,
            '--buildpath=%s' % buildpath,
            '--installpath=%s' % installpath,
            '--debug',
            '--unittest-file=%s' % self.logfile,
            '--force',
        ]
        try:
            main((args, dummylogfn, True))
        except (SystemExit, Exception), err:
            print err
Ejemplo n.º 43
0
    def eb_main(self,
                args,
                do_build=False,
                return_error=False,
                logfile=None,
                verbose=False,
                raise_error=False,
                reset_env=True,
                raise_systemexit=False,
                testing=True):
        """Helper method to call EasyBuild main function."""
        cleanup()

        myerr = False
        if logfile is None:
            logfile = self.logfile
        # clear log file
        if logfile:
            f = open(logfile, 'w')
            f.write('')
            f.close()

        env_before = copy.deepcopy(os.environ)

        try:
            main(args=args,
                 logfile=logfile,
                 do_build=do_build,
                 testing=testing,
                 modtool=self.modtool)
        except SystemExit:
            if raise_systemexit:
                raise err
        except Exception, err:
            myerr = err
            if verbose:
                print "err: %s" % err
Ejemplo n.º 44
0
    def test_job(self):
        """Test submitting build as a job."""

        # set MODULEPATH to included modules
        orig_modulepath = os.getenv('MODULEPATH', None)
        os.environ['MODULEPATH'] = os.path.join(os.path.dirname(__file__),
                                                'modules')

        # use gzip-1.4.eb easyconfig file that comes with the tests
        eb_file = os.path.join(os.path.dirname(__file__), 'easyconfigs',
                               'gzip-1.4.eb')

        # check log message with --job
        for job_args in [  # options passed are reordered, so order here matters to make tests pass
            ['--debug'],
            ['--debug', '--stop=configure', '--try-software-name=foo'],
        ]:

            # clear log file
            outtxt = write_file(self.logfile, '')

            args = [
                eb_file,
                '--job',
            ] + job_args
            try:
                main((args, self.logfile, False))
            except (SystemExit, Exception), err:
                pass
            outtxt = read_file(self.logfile)

            job_msg = "INFO.* Command template for jobs: .* && eb %%\(spec\)s %s.*\n" % ' .*'.join(
                job_args)
            assertmsg = "Info log message with job command template when using --job (job_msg: %s, outtxt: %s)" % (
                job_msg, outtxt)
            self.assertTrue(re.search(job_msg, outtxt), assertmsg)
Ejemplo n.º 45
0
    def test_skip(self):
        """Test skipping installation of module (--skip, -k)."""

        # keep track of original environment to restore after purging *all* loaded modules
        orig_environ = copy.deepcopy(os.environ)

        # use temporary paths for build/install paths, make sure sources can be found
        buildpath = tempfile.mkdtemp()
        installpath = tempfile.mkdtemp()
        sourcepath = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                  'sandbox', 'sources')

        # set MODULEPATH to included modules
        orig_modulepath = os.getenv('MODULEPATH', None)
        os.environ['MODULEPATH'] = os.path.abspath(
            os.path.join(os.path.dirname(__file__), 'modules'))

        # use toy-0.0.eb easyconfig file that comes with the tests
        eb_file = os.path.join(os.path.dirname(__file__), 'easyconfigs',
                               'toy-0.0.eb')

        # check log message with --skip for existing module
        args = [
            eb_file,
            '--sourcepath=%s' % sourcepath,
            '--buildpath=%s' % buildpath,
            '--installpath=%s' % installpath,
            '--force',
            '--skip',
            '--debug',
        ]

        try:
            main((args, self.logfile, True))
        except (SystemExit, Exception), err:
            pass
Ejemplo n.º 46
0
        already_msg = "GCC/4.6.3 is already installed"
        self.assertTrue(
            re.search(already_msg, outtxt),
            "Already installed message without --force, outtxt: %s" % outtxt)

        # clear log file
        write_file(self.logfile, '')

        # check that --force works
        args = [
            eb_file,
            '--force',
            '--debug',
        ]
        try:
            main((args, self.logfile, False))
        except (SystemExit, Exception), err:
            pass
        outtxt = read_file(self.logfile)

        self.assertTrue(not re.search(already_msg, outtxt),
                        "Already installed message not there with --force")

        # restore original MODULEPATH
        if orig_modulepath is not None:
            os.environ['MODULEPATH'] = orig_modulepath
        else:
            os.environ.pop('MODULEPATH')

    def test_skip(self):
        """Test skipping installation of module (--skip, -k)."""
Ejemplo n.º 47
0
    def eb_main(self,
                args,
                do_build=False,
                return_error=False,
                logfile=None,
                verbose=False,
                raise_error=False,
                reset_env=True,
                raise_systemexit=False,
                testing=True,
                redo_init_config=True):
        """Helper method to call EasyBuild main function."""
        cleanup()

        # always run main in unit testing mode (which for example allows for using deprecated toolchains);
        # note: don't change 'args' value, which is passed by reference!
        main_args = args + ['--unit-testing-mode']

        myerr = False
        if logfile is None:
            logfile = self.logfile
        # clear log file
        if logfile:
            with open(logfile, 'w') as fh:
                fh.write('')

        env_before = copy.deepcopy(os.environ)

        try:
            if '--fetch' in args:
                # The config sets modules_tool to None if --fetch is specified,
                # so do the same here to keep the behavior consistent
                modtool = None
            else:
                modtool = self.modtool
            main(args=main_args,
                 logfile=logfile,
                 do_build=do_build,
                 testing=testing,
                 modtool=modtool)
        except SystemExit as err:
            if raise_systemexit:
                raise err
        except Exception as err:
            myerr = err
            if verbose:
                print("err: %s" % err)

        if logfile and os.path.exists(logfile):
            logtxt = read_file(logfile)
        else:
            logtxt = None

        os.chdir(self.cwd)

        if redo_init_config:
            # make sure config is reinitialized
            init_config(with_include=False)

        # restore environment to what it was before running main,
        # changes may have been made by eb_main (e.g. $TMPDIR & co)
        if reset_env:
            modify_env(os.environ, env_before, verbose=False)
            tempfile.tempdir = None

        if myerr and raise_error:
            raise myerr

        if return_error:
            return logtxt, myerr
        else:
            return logtxt
Ejemplo n.º 48
0
        self.assertTrue(not error_thrown, "No error is thrown if software is already installed (error_thrown: %s)" % error_thrown)

        already_msg = "GCC \(version 4.6.3\) is already installed"
        self.assertTrue(re.search(already_msg, outtxt), "Already installed message without --force, outtxt: %s" % outtxt)

        # clear log file
        write_file(self.logfile, '')

        # check that --force works
        args = [
                eb_file,
                '--force',
               ]
        try:
            main((args, self.logfile))
        except (SystemExit, Exception), err:
            pass
        outtxt = read_file(self.logfile)

        self.assertTrue(not re.search(already_msg, outtxt), "Already installed message not there with --force")

        # restore original MODULEPATH
        if orig_modulepath is not None:
            os.environ['MODULEPATH'] = orig_modulepath
        else:
            os.environ.pop('MODULEPATH')

    def test_job(self):
        """Test submitting build as a job."""
Ejemplo n.º 49
0
    def eb_main(self,
                args,
                do_build=False,
                return_error=False,
                logfile=None,
                verbose=False,
                raise_error=False,
                reset_env=True,
                raise_systemexit=False,
                testing=True,
                redo_init_config=True):
        """Helper method to call EasyBuild main function."""
        cleanup()

        myerr = False
        if logfile is None:
            logfile = self.logfile
        # clear log file
        if logfile:
            f = open(logfile, 'w')
            f.write('')
            f.close()

        env_before = copy.deepcopy(os.environ)

        try:
            main(args=args,
                 logfile=logfile,
                 do_build=do_build,
                 testing=testing,
                 modtool=self.modtool)
        except SystemExit as err:
            if raise_systemexit:
                raise err
        except Exception as err:
            myerr = err
            if verbose:
                print("err: %s" % err)

        if logfile and os.path.exists(logfile):
            logtxt = read_file(logfile)
        else:
            logtxt = None

        os.chdir(self.cwd)

        if redo_init_config:
            # make sure config is reinitialized
            init_config(with_include=False)

        # restore environment to what it was before running main,
        # changes may have been made by eb_main (e.g. $TMPDIR & co)
        if reset_env:
            modify_env(os.environ, env_before, verbose=False)
            tempfile.tempdir = None

        if myerr and raise_error:
            raise myerr

        if return_error:
            return logtxt, myerr
        else:
            return logtxt