From 6e806faef8879bad179c852aa9ec8dc76eca4a1a Mon Sep 17 00:00:00 2001 From: Caspar van Leeuwen Date: Fri, 29 Mar 2024 15:12:06 +0100 Subject: [PATCH 1/9] Make sure EESSI's SitePackage.lua loads host's SitePackage.lua's if they exist --- create_lmodsitepackage.py | 68 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/create_lmodsitepackage.py b/create_lmodsitepackage.py index 5a7a915494..4f99f1a614 100755 --- a/create_lmodsitepackage.py +++ b/create_lmodsitepackage.py @@ -19,6 +19,71 @@ return content end +local function load_sitespecific_hooks() + -- This function will be run after the EESSI hooks are registered + -- It will load a local SitePackage.lua that is architecture independent (if it exists) from e.g. + -- /cvmfs/software.eessi.io/host_injections/2023.06/.lmod/SitePackage.lua + -- That can define a new hook + -- + -- function site_specific_load_hook(t) + -- + -- end + -- + -- And the either append to the existing hook: + -- + -- local function final_load_hook(t) + -- eessi_load_hook(t) + -- site_specific_load_hook(t) + -- end + -- + -- Over overwrite the EESSI hook entirely: + -- + -- hook.register("load", final_load_hook) + -- + -- Note that the appending procedure can be simplified once we have an lmod >= 8.7.36 + -- See https://github.com/TACC/Lmod/pull/696#issuecomment-1998765722 + -- + -- Subsequently, this function will look for an architecture-specific SitePackage.lua, e.g. from + -- /cvmfs/software.eessi.io/host_injections/2023.06/software/linux/x86_64/amd/zen2/.lmod/SitePackage.lua + -- This can then register an additional hook, e.g. + -- + -- function arch_specific_load_hook(t) + -- + -- end + -- + -- local function final_load_hook(t) + -- eessi_load_hook(t) + -- site_specific_load_hook(t) + -- arch_specific_load_hook(t) + -- end + -- + -- hook.register("load", final_load_hook) + -- + -- Again, the host site could also decide to overwrite by simply doing + -- + -- hook.register("load", arch_specific_load_hook) + + -- get path to to architecture independent SitePackage.lua + local prefixHostInjections = string.gsub(os.getenv('EESSI_PREFIX'), 'versions', 'host_injections') + local hostSitePackage = prefixHostInjections .. "/.lmod/SitePackage.lua" + + -- If the file exists, run it + if isDir(hostSitePackage) then + dofile(hostSitePackage) + end + + -- build the full architecture specific path in host_injections + local archHostInjections = string.gsub(os.getenv('EESSI_SOFTWARE_PATH') or "", 'versions', 'host_injections') + local archSitePackage = archHostInjections .. "/.lmod/SitePackage.lua" + + -- If the file exists, run it + if isDir(archSitePackage) + dofile(archSitePackage) + end + +end + + local function eessi_cuda_enabled_load_hook(t) local frameStk = require("FrameStk"):singleton() local mt = frameStk:mt() @@ -92,6 +157,9 @@ hook.register("load", eessi_load_hook) + +-- Note that this needs to happen at the end, so that any EESSI specific hooks can be overwritten by the site +load_site_specific_hooks() """ def error(msg): From 4bc0369d3505347441167436fb2f8de1a005b6b1 Mon Sep 17 00:00:00 2001 From: Caspar van Leeuwen Date: Fri, 29 Mar 2024 15:14:17 +0100 Subject: [PATCH 2/9] Forgot 'then' --- create_lmodsitepackage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/create_lmodsitepackage.py b/create_lmodsitepackage.py index 4f99f1a614..6b67b4beca 100755 --- a/create_lmodsitepackage.py +++ b/create_lmodsitepackage.py @@ -77,7 +77,7 @@ local archSitePackage = archHostInjections .. "/.lmod/SitePackage.lua" -- If the file exists, run it - if isDir(archSitePackage) + if isDir(archSitePackage) then dofile(archSitePackage) end From b59d327ecce05ad1e5904fe2581c45c3e0b68d10 Mon Sep 17 00:00:00 2001 From: Caspar van Leeuwen Date: Tue, 2 Apr 2024 17:19:14 +0200 Subject: [PATCH 3/9] Changed isDir to isFile --- create_lmodsitepackage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/create_lmodsitepackage.py b/create_lmodsitepackage.py index 6b67b4beca..cddb40da5c 100755 --- a/create_lmodsitepackage.py +++ b/create_lmodsitepackage.py @@ -68,7 +68,7 @@ local hostSitePackage = prefixHostInjections .. "/.lmod/SitePackage.lua" -- If the file exists, run it - if isDir(hostSitePackage) then + if isFile(hostSitePackage) then dofile(hostSitePackage) end @@ -77,7 +77,7 @@ local archSitePackage = archHostInjections .. "/.lmod/SitePackage.lua" -- If the file exists, run it - if isDir(archSitePackage) then + if isFile(archSitePackage) then dofile(archSitePackage) end From 9ff3cfab728cf66177b903aaa0e9d63099da2c2d Mon Sep 17 00:00:00 2001 From: Caspar van Leeuwen Date: Tue, 2 Apr 2024 17:20:23 +0200 Subject: [PATCH 4/9] Account for the possibility that EESSI_PREFIX isn't set --- create_lmodsitepackage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/create_lmodsitepackage.py b/create_lmodsitepackage.py index cddb40da5c..30f11c9c6f 100755 --- a/create_lmodsitepackage.py +++ b/create_lmodsitepackage.py @@ -64,7 +64,7 @@ -- hook.register("load", arch_specific_load_hook) -- get path to to architecture independent SitePackage.lua - local prefixHostInjections = string.gsub(os.getenv('EESSI_PREFIX'), 'versions', 'host_injections') + local prefixHostInjections = string.gsub(os.getenv('EESSI_PREFIX') or "", 'versions', 'host_injections') local hostSitePackage = prefixHostInjections .. "/.lmod/SitePackage.lua" -- If the file exists, run it From f25bfe09cf46f15d1869c32019640005aab2006b Mon Sep 17 00:00:00 2001 From: Caspar van Leeuwen Date: Tue, 2 Apr 2024 17:31:17 +0200 Subject: [PATCH 5/9] Corrected function name --- create_lmodsitepackage.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/create_lmodsitepackage.py b/create_lmodsitepackage.py index 30f11c9c6f..29b2d39bd7 100755 --- a/create_lmodsitepackage.py +++ b/create_lmodsitepackage.py @@ -19,7 +19,7 @@ return content end -local function load_sitespecific_hooks() +local function load_site_specific_hooks() -- This function will be run after the EESSI hooks are registered -- It will load a local SitePackage.lua that is architecture independent (if it exists) from e.g. -- /cvmfs/software.eessi.io/host_injections/2023.06/.lmod/SitePackage.lua From 12d17a4777b2e2aa4f9ddaa1433d75d9c0012c59 Mon Sep 17 00:00:00 2001 From: Kenneth Hoste Date: Tue, 2 Apr 2024 17:43:01 +0200 Subject: [PATCH 6/9] also test create_lmodsitepackage.py in CI --- .github/workflows/tests_scripts.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/.github/workflows/tests_scripts.yml b/.github/workflows/tests_scripts.yml index df1884dd8c..476be3dc4d 100644 --- a/.github/workflows/tests_scripts.yml +++ b/.github/workflows/tests_scripts.yml @@ -5,6 +5,7 @@ on: paths: - build_container.sh - create_directory_tarballs.sh + - create_lmodsitepackage.py - EESSI-install-software.sh - install_software_layer.sh - load_easybuild_module.sh @@ -16,6 +17,7 @@ on: paths: - build_container.sh - create_directory_tarballs.sh + - create_lmodsitepackage.py - EESSI-install-software.sh - install_software_layer.sh - load_easybuild_module.sh @@ -94,3 +96,22 @@ jobs: ./eessi_container.sh --mode run --verbose /software-layer/create_directory_tarballs.sh 2023.06 # check if tarballs have been produced ls -l *.tar.gz + + - name: test create_lmodsitepackage.py script + run: | + # bind current directory into container as /software-layer + export SINGULARITY_BIND="${PWD}:/software-layer" + + python3 create_lmodsitepackage.py . + export LMOD_PACKAGE_PATH="$PWD/.lmod" + # run some commands to make sure that generated Lmod SitePackage file works + test_script="${PWD}/test_lmod_sitepackage.sh" + echo '#!/bin/bash' > ${test_script} + echo 'ml --config' >> ${test_script} + + chmod u+x ${test_script} + + ./eessi_container.sh --mode run --verbose /software-layer/run_in_compat_layer_env.sh /software-layer/test_lmod_sitepackage.sh 2>&1 | tee ${out} + for pattern in "^Site Pkg location.*$PWD/.lmod/SitePackage.lua" "LMOD_SITEPACKAGE_LOCATION.*${PWD}/.lmod/SitePackage.lua"; do + grep "${pattern}" ${out} || (echo "Pattern '${pattern}' not found in output!" && exit 1) + done From 60c46ce702948e3c97e1dc432f5651f837efb39c Mon Sep 17 00:00:00 2001 From: Caspar van Leeuwen Date: Tue, 2 Apr 2024 18:38:23 +0200 Subject: [PATCH 7/9] Make sure export is done inside test script, as environment is lost when running in compat layer env --- .github/workflows/tests_scripts.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests_scripts.yml b/.github/workflows/tests_scripts.yml index 476be3dc4d..95baedac08 100644 --- a/.github/workflows/tests_scripts.yml +++ b/.github/workflows/tests_scripts.yml @@ -102,11 +102,12 @@ jobs: # bind current directory into container as /software-layer export SINGULARITY_BIND="${PWD}:/software-layer" + # Creates .lmod/SitePackage.lua in current dir, which then gets bind-mounted into /software-layer python3 create_lmodsitepackage.py . - export LMOD_PACKAGE_PATH="$PWD/.lmod" # run some commands to make sure that generated Lmod SitePackage file works test_script="${PWD}/test_lmod_sitepackage.sh" echo '#!/bin/bash' > ${test_script} + echo 'export LMOD_PACKAGE_PATH="/software-layer/.lmod"' > ${test_script} echo 'ml --config' >> ${test_script} chmod u+x ${test_script} From d59238b9643de5d34a301122afef133c231747fa Mon Sep 17 00:00:00 2001 From: Caspar van Leeuwen Date: Tue, 2 Apr 2024 18:46:58 +0200 Subject: [PATCH 8/9] Change expected output - we need to account for the fact that this is a bind-mounted location --- .github/workflows/tests_scripts.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests_scripts.yml b/.github/workflows/tests_scripts.yml index 95baedac08..96838b99df 100644 --- a/.github/workflows/tests_scripts.yml +++ b/.github/workflows/tests_scripts.yml @@ -113,6 +113,6 @@ jobs: chmod u+x ${test_script} ./eessi_container.sh --mode run --verbose /software-layer/run_in_compat_layer_env.sh /software-layer/test_lmod_sitepackage.sh 2>&1 | tee ${out} - for pattern in "^Site Pkg location.*$PWD/.lmod/SitePackage.lua" "LMOD_SITEPACKAGE_LOCATION.*${PWD}/.lmod/SitePackage.lua"; do + for pattern in "^Site Pkg location.*/software-layer/.lmod/SitePackage.lua" "LMOD_SITEPACKAGE_LOCATION.*/software-layer/.lmod/SitePackage.lua"; do grep "${pattern}" ${out} || (echo "Pattern '${pattern}' not found in output!" && exit 1) done From 1e8eb6eac7a040cf16d2f97d4126b93300da05c7 Mon Sep 17 00:00:00 2001 From: Caspar van Leeuwen Date: Tue, 2 Apr 2024 19:12:20 +0200 Subject: [PATCH 9/9] Output variable was undefined --- .github/workflows/tests_scripts.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests_scripts.yml b/.github/workflows/tests_scripts.yml index 96838b99df..ac55231bf0 100644 --- a/.github/workflows/tests_scripts.yml +++ b/.github/workflows/tests_scripts.yml @@ -112,6 +112,7 @@ jobs: chmod u+x ${test_script} + out="${PWD}/test_create_lmodsitepackage.out" ./eessi_container.sh --mode run --verbose /software-layer/run_in_compat_layer_env.sh /software-layer/test_lmod_sitepackage.sh 2>&1 | tee ${out} for pattern in "^Site Pkg location.*/software-layer/.lmod/SitePackage.lua" "LMOD_SITEPACKAGE_LOCATION.*/software-layer/.lmod/SitePackage.lua"; do grep "${pattern}" ${out} || (echo "Pattern '${pattern}' not found in output!" && exit 1)