Skip to content
Snippets Groups Projects
Commit 6a159917 authored by Ashwin Kumar Karnad's avatar Ashwin Kumar Karnad
Browse files

update and test logging

parent 062bb997
No related branches found
No related tags found
2 merge requests!19Move linux-debian11 into main,!1Resolve "First draft for user interface for top level install command"
......@@ -15,7 +15,7 @@ for given system architecture and MPSD software stack version.\n
The toolchains are built using the bash script spack_setup.sh, and the results are logged.
"""
config_vars = {
"cmd_log_file": "logs/install-software-environment.log",
"cmd_log_file": "install.log",
"build_log_file": f"build_toolchains_mpsd_spack_ver_{time.strftime('%Y%m%d-%H%M%S')}.log", # TODO: modify toolchains,mpsd_spack_ver when the variable is available
"spack_environments_repo": "https://gitlab.gwdg.de/mpsd-cs/spack-environments.git",
}
......@@ -34,44 +34,44 @@ class os_chdir:
os.chdir(self.saved_dir)
def setup_log_cmd(msg=None, *args, **kwargs):
# Create log directory if it doesn't exist
if not os.path.exists("logs"):
os.makedirs("logs")
# Write to the log file with the following format
# --------------------------------------------------
# 2023-02-29T23:32:01, install-software-environment.py --release dev-23a --install ALL
# Software environment installer branch: script_branch (commit hash: script_commit_hash)
# Spack environments branch: dev-23a (commit hash: spe_commit_hash)
# MSGs
with open(config_vars["cmd_log_file"], "a") as f:
if msg:
# Write the message to the log file
f.write(msg + "\n")
else:
# Write the header
f.write("-" * 50 + "\n")
# Gather data to log
# call statement:
cmd_line = " ".join(sys.argv)
# script branch and commit hash
script_branch = (
subprocess.run(["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=subprocess.PIPE)
.stdout.decode()
.strip()
)
script_commit_hash = (
subprocess.run(["git", "rev-parse", "--short", "HEAD"], stdout=subprocess.PIPE).stdout.decode().strip()
)
# spack-environments branch and commit hash from kwargs
spe_branch = kwargs.get("spe_branch", None)
spe_commit_hash = kwargs.get("spe_commit_hash", None)
def setup_log_cmd(mpsd_release, script_dir, msg=None, *args, **kwargs):
release_base_dir = script_dir / mpsd_release
with os_chdir(release_base_dir):
# Write to the log file with the following format
# --------------------------------------------------
# 2023-02-29T23:32:01, install-software-environment.py --release dev-23a --install ALL
# Software environment installer branch: script_branch (commit hash: script_commit_hash)
# Spack environments branch: dev-23a (commit hash: spe_commit_hash)
# MSGs
with open(config_vars["cmd_log_file"], "a") as f:
if msg:
# Write the message to the log file
f.write(msg + "\n")
else:
# Write the header
f.write("-" * 50 + "\n")
# Gather data to log
# call statement:
cmd_line = " ".join(sys.argv)
# script branch and commit hash
script_branch = (
subprocess.run(["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=subprocess.PIPE)
.stdout.decode()
.strip()
)
script_commit_hash = (
subprocess.run(["git", "rev-parse", "--short", "HEAD"], stdout=subprocess.PIPE).stdout.decode().strip()
)
# spack-environments branch and commit hash from kwargs
spe_branch = kwargs.get("spe_branch", None)
spe_commit_hash = kwargs.get("spe_commit_hash", None)
# Write to log file
f.write(f"{datetime.datetime.now().isoformat()}, {cmd_line}\n")
f.write(f"Software environment installer branch: {script_branch} (commit hash: {script_commit_hash})\n")
f.write(f"Spack environments branch: {spe_branch} (commit hash: {spe_commit_hash})\n")
# Write to log file
f.write(f"{datetime.datetime.now().isoformat()}, {cmd_line}\n")
f.write(f"Software environment installer branch: {script_branch} (commit hash: {script_commit_hash})\n")
f.write(f"Spack environments branch: {spe_branch} (commit hash: {spe_commit_hash})\n")
def create_dir_structure(mpsd_release, script_dir):
......@@ -125,7 +125,7 @@ def prepare_environment(mpsd_release, script_dir):
create_dir_structure(mpsd_release, script_dir)
spe_branch, spe_commit_hash, available_toolchains = get_release_info(mpsd_release, script_dir)
setup_log_cmd(spe_branch=spe_branch, spe_commit_hash=spe_commit_hash)
setup_log_cmd(mpsd_release, script_dir, spe_branch=spe_branch, spe_commit_hash=spe_commit_hash)
return available_toolchains
......
......@@ -69,23 +69,30 @@ def test_prepare_environment(tmp_path):
def test_setup_log_cmd(tmp_path):
# check that logs/install-software-environment.log is updated when the module is run
log_file = "logs/install-software-environment.log"
if os.path.exists(log_file):
log_file = "install.log"
script_dir = tmp_path / "test_prepare_env"
spack_environments = "spack-environments"
mpsd_release_to_test = "dev-23a"
release_base_dir = script_dir / mpsd_release_to_test
if os.path.exists(release_base_dir/log_file):
initial_bytes = os.path.getsize(log_file)
else:
initial_bytes = 0
# run the prepare_env functionality
mod.prepare_env(
toolchain_base_dir=(tmp_path),
mpsd_spack_ver="dev-23a",
skip_dir_check=False,
shared_var=shared_var,
result = mod.prepare_environment(
mpsd_release=mpsd_release_to_test, script_dir=(script_dir)
)
# check that logs/install-software-environment.log is updated
assert os.path.exists("logs/install-software-environment.log")
assert os.path.getsize("logs/install-software-environment.log") > initial_bytes
assert os.path.exists(release_base_dir/log_file)
assert os.path.getsize(release_base_dir/log_file) > initial_bytes
# Check that the log file has "Spack environments branch: dev-23a " in the last line
with open(release_base_dir/log_file, "r") as f:
last_line = f.readlines()[-1]
assert "Spack environments branch: dev-23a " in last_line
def test_install_environment(tmp_path):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment