Exemplo n.º 1
0
    def test_make_json(self):
        """More or less the code from convert_lmod_cache_to_json"""
        cachefile = os.path.join(get_lmod_conf()['dir'], CACHEFILENAME)
        self.assertEqual(cachefile, './test/data/spiderT.lua')

        mpathMapT, spiderT = get_lmod_cache(cachefile)

        mpath = '/apps/gent/CO7/cascadelake-volta-ib-PILOT/modules/all'
        name = 'Autoconf'
        module = 'Autoconf/2.69-GCCcore-8.2.0'
        version = '2.69-GCCcore-8.2.0'

        # only test one value
        self.assertEqual(mpathMapT[mpath], {'cluster/.joltik': '/etc/modulefiles/vsc'})
        # only test one value
        self.assertEqual(spiderT[mpath][name]['fileT'][module]['Version'], version)

        clustermap, mpmap = cluster_map(mpathMapT)
        # test 2 values, one hidden cluster
        self.assertEqual(clustermap['banette'], 'cluster/.banette')
        self.assertEqual(clustermap['delcatty'], 'cluster/delcatty')

        # test one, multivalue
        self.assertEqual(mpmap['/apps/gent/CO7/haswell-ib/modules/all'], ['golett', 'swalot', 'phanpy'])

        # only two mpaths in the mocked spiderT
        mpath2 = '/apps/gent/CO7/skylake-ib/modules/all'
        newmpmap = {mpath: mpmap[mpath], mpath2: mpmap[mpath2]}
        softmap = software_map(spiderT, newmpmap)
        self.assertEqual(softmap['Autotools'],
                         {'.default': {'joltik': '20180311-GCCcore-8.3.0'},
                          '20180311-GCCcore-8.2.0': ['joltik'],
                          '20180311-GCCcore-8.3.0': ['joltik']})
        self.assertEqual(softmap['Bazel'],
                         {'.default': {'skitty': '0.20.0-GCCcore-8.2.0',
                                       'victini': '0.20.0-GCCcore-8.2.0'},
                          '0.20.0-GCCcore-8.2.0': ['skitty', 'victini'],
                          '0.24.1-GCCcore-8.2.0': ['skitty', 'victini'],
                          '0.25.2-GCCcore-8.2.0': ['skitty', 'victini'],
                          '0.26.1-GCCcore-8.2.0': ['skitty', 'victini']})


        clview = software_cluster_view(softmap=softmap)
        # regular ordered
        self.assertEqual(clview['joltik']['Autoconf'], ['2.69-GCCcore-8.3.0', u'2.69-GCCcore-8.2.0'])
        # non-trivial (first) default, rest ordered
        #   this default was manually set in the spiderT.lua test data
        self.assertEqual(clview['skitty']['Bazel'],
                         ['0.20.0-GCCcore-8.2.0', '0.26.1-GCCcore-8.2.0',
                          '0.25.2-GCCcore-8.2.0', '0.24.1-GCCcore-8.2.0'])
Exemplo n.º 2
0
def main():
    """
    Set the options and initiates the main run.
    Returns the errors if any in a nagios/icinga friendly way.
    """
    options = {
        'nagios-check-interval-threshold': NAGIOS_CHECK_INTERVAL_THRESHOLD,
        'create-cache': ('Create the Lmod cache', None, 'store_true', False),
        'freshness-threshold': ('The interval in minutes for how long we consider the cache to be fresh',
                                'int', 'store', 120),
    }
    opts = ExtendedSimpleOption(options)

    try:
        if opts.options.create_cache:
            opts.log.info("Updating the Lmod cache")
            exitcode, msg = run_cache_create()
            if exitcode != 0:
                opts.log.error("Lmod cache update failed: %s", msg)
                opts.critical("Lmod cache update failed")

            try:
                convert_lmod_cache_to_json()
            except Exception as err:
                opts.log.exception("Lmod to JSON failed: %s", err)
                opts.critical("Lmod to JSON failed.")

        opts.log.info("Checking the Lmod cache freshness")
        timestamp = os.stat(get_lmod_conf()['timestamp'])

        # give a warning when the cache is older then --freshness-threshold
        if (time.time() - timestamp.st_mtime) > opts.options.freshness_threshold * 60:
            errmsg = "Lmod cache is not fresh"
            opts.log.warn(errmsg)
            opts.warning(errmsg)

    except RuntimeError as err:
        opts.log.exception("Failed to update Lmod cache: %s", err)
        opts.critical("Failed to update Lmod cache. See logs.")
    except Exception as err:  # pylint: disable=W0703
        opts.log.exception("critical exception caught: %s", err)
        opts.critical("Script failed because of uncaught exception. See logs.")

    if opts.options.create_cache:
        opts.epilogue("Lmod cache updated.")
    else:
        opts.epilogue("Lmod cache is still fresh.")
Exemplo n.º 3
0
 def test_lmod_conf(self):
     self.assertEqual(
         get_lmod_conf(), {
             'timestamp': '/apps/gent/lmodcache/timestamp',
             'dir': '/apps/gent/lmodcache'
         })