Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • hmenke/mpsd-software-manager
  • mpsd-cs/mpsd-software-manager
2 results
Show changes
Commits on Source (15)
......@@ -193,6 +193,7 @@ def setup_log_cmd(
run(
["git", "rev-parse", "--abbrev-ref", "HEAD"],
stdout=subprocess.PIPE,
check=True,
)
.stdout.decode()
.strip()
......@@ -201,6 +202,7 @@ def setup_log_cmd(
run(
["git", "rev-parse", "--short", "HEAD"],
stdout=subprocess.PIPE,
check=True,
)
.stdout.decode()
.strip()
......@@ -250,7 +252,8 @@ def create_dir_structure(mpsd_release: str, script_dir: Path) -> None:
"git",
"clone",
config_vars["spack_environments_repo"],
]
],
check=True,
)
with os_chdir("spack-environments"):
# Git fetch and checkout the release branch and git pull
......@@ -460,6 +463,7 @@ def install_environment(
f"bash {spack_setup_script} {' '.join(install_flags)} {toolchain} 2>&1 "
f"| tee -a {install_log_file} ",
shell=True,
check=True,
)
......
......@@ -11,6 +11,41 @@ import pytest
mod = importlib.import_module("mpsd-software-environment")
def create_mock_git_repository(target_directory, create_directory=True):
"""
Create a git repository in the directory `target_directory`.
Arguments
---------
target_directory : pathlib.Path
- path at which the root of the repository should be located (i.e. `.git` folder)
create_directory : bool
- create `target_directory` and parent directories if True
"""
# create directory first
if create_directory:
target_directory.mkdir(parents=True)
# then create git repository:
with mod.os_chdir(str(target_directory)):
subprocess.run("git init .", shell=True, check=True)
subprocess.run("echo 'fake content' > readme.txt", shell=True, check=True)
subprocess.run("git add readme.txt", shell=True, check=True)
subprocess.run("pwd", shell=True)
# if email and username are not available (such as on naked test container),
# git may complain. We set a temporary user for this one commit to work around
# that.
user_details = "-c user.name='Tes Ta' -c user.email='tester@some-ci.org'"
subprocess.run(
f'git {user_details} commit -m "first commit" readme.txt',
shell=True,
check=True,
)
def test_os_chdir(tmp_path):
"""Test the os_chdir context manager."""
# create a temporary directory for testing
......@@ -43,26 +78,34 @@ def test_prepare_environment(tmp_path):
# check that the test directory does not exist
assert not script_dir.exists()
# prepare_environment expects to be executed in git repository
# (mpsd-software-environments). It queries the commit on which we are to
# log that information. For this to work, we need to execute the command
# within a directory tree that has a git repository at the same or high
# level. Let's create one:
create_mock_git_repository(script_dir)
# now call the function we want to test
result = mod.prepare_environment(
mpsd_release=mpsd_release_to_test, script_dir=(script_dir)
mpsd_release=mpsd_release_to_test, script_dir=script_dir
)
# wait for 20 seconds for the git clone to finish
# time.sleep(20)
# check if the directory now is created
assert release_base_dir.exists()
# check for spack-environments directory
assert spack_environments in os.listdir(release_base_dir)
# check if the git branch is correctly checked out
assert (
subprocess.run(
f"cd {str(release_base_dir/spack_environments)} && git branch",
shell=True,
capture_output=True,
)
.stdout.decode("utf-8")
.split("\n")[0]
== f"* {mpsd_release_to_test}"
# check if the git branch is correctly checked out. We expect output such as
# git_branch_stdout = '* dev-23a\n develop\n'
# The entry with the '* ' prefix is the active branch.
git_branch_output_raw = subprocess.run(
f"cd {str(release_base_dir/spack_environments)} && git branch",
shell=True,
capture_output=True,
)
git_branch_stdout = git_branch_output_raw.stdout.decode("utf-8")
assert f"* {mpsd_release_to_test}" in git_branch_stdout
# check that result is a list and contains atleast ['global','foss2021a-mpi']
assert isinstance(result, list)
assert "global" in result
......@@ -91,6 +134,7 @@ def test_setup_log_cmd(tmp_path):
initial_bytes = 0
# run the prepare_env functionality
create_mock_git_repository(target_directory=script_dir, create_directory=True)
mod.prepare_environment(mpsd_release=mpsd_release_to_test, script_dir=(script_dir))
# check that logs/install-software-environment.log is updated
......@@ -103,20 +147,22 @@ def test_setup_log_cmd(tmp_path):
assert "Spack environments branch: dev-23a " in last_line
def test_install_environment(tmp_path):
"""Test the installation of a toolchain.
This is a long test, its handy to test this with print statements printed to
stdout, use:
pytest -s
Expect an Exception when wrong toolchains are provided
"""
def test_install_environment_wrong_toolchain(tmp_path):
"""Test exception is raised for non-existing toolchain."""
# This is a long test, its handy to test this with print statements printed to
# stdout, use:
# pytest -s
# Expect an Exception when wrong toolchains are provided
with pytest.raises(Exception):
mod.install_environment(
mpsd_release="dev-23a",
toolchains=["wrong-toolchain"],
script_dir=(tmp_path),
)
def test_install_environment_wrong_mpsd_release(tmp_path):
"""Test exception is raised for non-existing mpsd release."""
# Expect an Exception when wrong mpsd_release is provided (part of
# prepare_environment)
with pytest.raises(Exception):
......@@ -125,6 +171,10 @@ def test_install_environment(tmp_path):
toolchains=["foss2021a-mpi"],
script_dir=(tmp_path),
)
def test_install_environment_zlib(tmp_path):
"""Test installation of toolchain."""
# prepare a test of global generic with only zlib to test the installation
# prepare dev-23a release
# script_dir = tmp_path / "test_global_generic"
......@@ -138,6 +188,7 @@ def test_install_environment(tmp_path):
toolchain_to_test = "global_generic"
mpsd_microarch = os.getenv("MPSD_MICROARCH", "UNKNOWN_MICROARCH")
release_base_dir = script_dir / mpsd_release_to_test
create_mock_git_repository(target_directory=script_dir, create_directory=False)
mod.prepare_environment(mpsd_release=mpsd_release_to_test, script_dir=(script_dir))
# Patch the spack environments to create a fake global_generic
# create a test toolchain
......