Skip to content
Snippets Groups Projects
Commit 74b67df9 authored by Damian Alvarez's avatar Damian Alvarez
Browse files

Merge branch 'site_contacts_hook' into '2020'

Site contacts hook

See merge request hps-public/easybuild-repository!630
parents f8f7fe2c a58cb3a8
Branches
No related tags found
No related merge requests found
import grp
import os
import subprocess
from easybuild.tools.run import run_cmd
from easybuild.tools.config import build_option
......@@ -28,7 +28,7 @@ SUPPORTED_MPI_TOOLCHAIN_FAMILIES = [
"iompi",
"gpsmpi",
"gompi",
"npsmpi",
"npsmpic",
"nompi",
"gmvapich2c",
"pmvapich2c",
......@@ -80,6 +80,49 @@ def installation_vetoer(ec):
print_msg(f"- {package}", stderr=True)
exit(1)
def get_user_info():
# Query jutil to extract the contact information
if os.getenv('CI') is None:
jutil = subprocess.Popen([os.getenv('JUMO_USRCMD_EXEC'), 'person', 'show'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = jutil.communicate()
if not stderr:
return stdout.decode('utf-8').splitlines()[-1]
else:
print_warning(f'Could not query jutil: {stderr}')
exit(1)
else:
return 'CI user'
def inject_site_contact(ec, site_contacts):
key = "site_contacts"
value = site_contacts
ec_dict = ec.asdict()
if key in ec_dict:
if ec_dict[key] is not None:
# Check current values if it is a list
if isinstance(ec_dict[key], list):
for contact in ec_dict[key]:
# Already in contact
if site_contacts in contact:
break
# We looped to the end and did not find the contact in this list
else:
# Do not add the generic one if there are other specific contacts
if 'sc@fz-juelich.de' not in site_contacts or len(ec_dict[key]) == 0:
ec.log.info("[parse hook] Injecting contact %s", value)
ec[key].append(site_contacts)
# Check current values if it is a string
else:
# Do not add the generic one if there are other specific contacts
if site_contacts not in ec_dict[key] and 'sc@fz-juelich.de' not in site_contacts:
ec.log.info("[parse hook] Injecting contact %s", value)
ec[key] = [ec_dict[key], site_contacts]
else:
ec.log.info("[parse hook] Injecting contact %s", value)
ec[key] = value
return ec
def parse_hook(ec, *args, **kwargs):
"""Custom parse hook to manage installations intended for JSC systems."""
......@@ -166,13 +209,16 @@ family("mpi")
# Check where installations are going to go and add appropriate site contact
# not sure of a fool-proof way to do this, let's just try a heuristic
site_contacts = None
if "stages" in install_path().lower():
users_groups = [grp.getgrgid(g).gr_name for g in os.getgroups()]
if any(group in users_groups for group in ["swmanage", "software"]):
site_contacts = "sc@fz-juelich.de"
if site_contacts is None:
# Non-user installation
if '/p/software' in install_path().lower() or '/gpfs/software' in install_path().lower():
if 'swmanage' in os.getenv('USER'):
site_contacts = 'sc@fz-juelich.de'
else:
site_contacts = get_user_info()
# Inject the user
site_contacts = os.getenv("USER")
ec = inject_site_contact(ec, site_contacts)
# User installation
else:
# Tag the build as a user build
key = "modluafooter"
value = 'add_property("build","user")'
......@@ -182,14 +228,9 @@ family("mpi")
else:
ec[key] = value
ec.log.info("[parse hook] Injecting user as Lmod build property")
if site_contacts:
key = "site_contacts"
value = site_contacts
if key in ec_dict:
if ec_dict[key] is not None and value not in ec_dict[key]:
value = ",".join([ec_dict[key], value])
ec[key] = value
ec.log.info("[parse hook] Injecting contact %s", value)
# Inject the user
site_contacts = get_user_info()
ec = inject_site_contact(ec, site_contacts)
# If we are parsing we are not searching, in this case if the easyconfig is
# located in the search path, warn that it's dependencies will (most probably)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment