Skip to content
Snippets Groups Projects
Commit 2e79473f authored by Jithu Murugan's avatar Jithu Murugan
Browse files

Merge remote-tracking branch 'origin/esd-spack-installation' into...

Merge remote-tracking branch 'origin/esd-spack-installation' into VT-70-function-Migrate-Spack-env-setup-into-ESD-repo-with-buildcache

# Conflicts:
#	esd/spack_manager/SpackManager.py
#	esd/tests/spack_from_scratch_test.py
parents 654656c7 03b4de04
No related branches found
No related tags found
1 merge request!4feat(spack_operation): implement setup_spack_env functionality
Pipeline #58937 passed with stages
in 16 minutes and 12 seconds
...@@ -40,5 +40,6 @@ testing-pytest: ...@@ -40,5 +40,6 @@ testing-pytest:
paths: paths:
- test-results.xml - test-results.xml
- .esd.log - .esd.log
- .generate_cache.log
expire_in: 1 week expire_in: 1 week
import os import os
import re import re
import subprocess
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from pathlib import Path from pathlib import Path
from tabnanny import check
from esd.error_handling.exceptions import BashCommandException, NoSpackEnvironmentException, \ from esd.error_handling.exceptions import BashCommandException, NoSpackEnvironmentException, \
SpackInstallPackagesException SpackInstallPackagesException
from esd.logger.logger_builder import get_logger from esd.logger.logger_builder import get_logger
from esd.model.SpackModel import SpackModel from esd.model.SpackModel import SpackModel
from esd.spack_manager.wrapper.spack_wrapper import no_spack_env from esd.spack_manager.wrapper.spack_wrapper import check_spack_env
from esd.utils.utils import run_command, git_clone_repo from esd.utils.utils import run_command, git_clone_repo
...@@ -48,12 +50,7 @@ class SpackManager(ABC): ...@@ -48,12 +50,7 @@ class SpackManager(ABC):
def concretize_spack_env(self, force=True): def concretize_spack_env(self, force=True):
pass pass
@abstractmethod
def install_spack_packages(self, jobs: 3, verbose=False, debug=False):
pass
def create_fetch_spack_environment(self): def create_fetch_spack_environment(self):
if self.env.git_path: if self.env.git_path:
git_clone_repo(self.env.env_name, self.env.path / self.env.env_name, self.env.git_path, logger=self.logger) git_clone_repo(self.env.env_name, self.env.path / self.env.env_name, self.env.git_path, logger=self.logger)
else: else:
...@@ -127,7 +124,7 @@ class SpackManager(ABC): ...@@ -127,7 +124,7 @@ class SpackManager(ABC):
return False return False
return True return True
@no_spack_env @check_spack_env
def add_spack_repo(self, repo_path: Path, repo_name: str): def add_spack_repo(self, repo_path: Path, repo_name: str):
"""Add the Spack repository if it does not exist.""" """Add the Spack repository if it does not exist."""
run_command("bash", "-c", run_command("bash", "-c",
...@@ -137,7 +134,7 @@ class SpackManager(ABC): ...@@ -137,7 +134,7 @@ class SpackManager(ABC):
exception_msg=f"Failed to add {repo_name} to spack environment {self.env.env_name}", exception_msg=f"Failed to add {repo_name} to spack environment {self.env.env_name}",
exception=BashCommandException) exception=BashCommandException)
@no_spack_env @check_spack_env
def get_compiler_version(self): def get_compiler_version(self):
result = run_command("bash", "-c", result = run_command("bash", "-c",
f'source {self.spack_setup_script} && spack env activate -p {self.env_path} && spack compiler list', f'source {self.spack_setup_script} && spack env activate -p {self.env_path} && spack compiler list',
...@@ -167,18 +164,27 @@ class SpackManager(ABC): ...@@ -167,18 +164,27 @@ class SpackManager(ABC):
return spack_version.stdout.strip().split()[0] return spack_version.stdout.strip().split()[0]
return None return None
@no_spack_env @check_spack_env
def install_packages(self, jobs: int): def install_packages(self, jobs: int, signed=True, fresh=False, debug=False):
# spack install -v --j "$cpu_count" --fresh signed = '' if signed else '--no-check-signature'
run_command("bash", "-c", fresh = '--fresh' if fresh else ''
f'source {self.spack_setup_script} && spack install --env {self.env.env_name} -v --j {jobs} --fresh', debug = '--debug' if debug else ''
capture_output=True, text=True, check=True, install_result = run_command("bash", "-c",
logger=self.logger, f'source {self.spack_setup_script} && spack env activate -p {self.env_path} && spack {debug} install -v {signed} --j {jobs} {fresh}',
debug_msg=f"Installing spack packages for {self.env.env_name}", stdout=subprocess.PIPE,
exception_msg=f"Error installing spack packages for {self.env.env_name}", stderr=subprocess.PIPE,
exception=SpackInstallPackagesException) text=True,
logger=self.logger,
def install_spack(self, spack_version="v0.21.1", spack_repo='https://github.com/spack/spack'): debug_msg=f"Installing spack packages for {self.env.env_name}",
exception_msg=f"Error installing spack packages for {self.env.env_name}",
exception=SpackInstallPackagesException)
with open(str(Path(os.getcwd()).resolve() / ".generate_cache.log"), "w") as log_file:
log_file.write(install_result.stdout)
log_file.write("\n--- STDERR ---\n")
log_file.write(install_result.stderr)
return install_result
def install_spack(self, spack_version="v0.22.0", spack_repo='https://github.com/spack/spack'):
try: try:
user = os.getlogin() user = os.getlogin()
except OSError: except OSError:
......
...@@ -14,6 +14,3 @@ class SpackManagerBuildCache(SpackManager): ...@@ -14,6 +14,3 @@ class SpackManagerBuildCache(SpackManager):
def concretize_spack_env(self, force=True): def concretize_spack_env(self, force=True):
pass pass
def install_spack_packages(self, jobs: 3, verbose=False, debug=False):
pass
...@@ -23,6 +23,3 @@ class SpackManagerScratch(SpackManager): ...@@ -23,6 +23,3 @@ class SpackManagerScratch(SpackManager):
else: else:
self.logger.debug('No spack environment defined') self.logger.debug('No spack environment defined')
raise NoSpackEnvironmentException('No spack environment defined') raise NoSpackEnvironmentException('No spack environment defined')
def install_spack_packages(self, jobs: 3, verbose=False, debug=False):
pass
...@@ -3,7 +3,7 @@ import functools ...@@ -3,7 +3,7 @@ import functools
from esd.error_handling.exceptions import NoSpackEnvironmentException from esd.error_handling.exceptions import NoSpackEnvironmentException
def no_spack_env(method): def check_spack_env(method):
@functools.wraps(method) @functools.wraps(method)
def wrapper(self, *args, **kwargs): def wrapper(self, *args, **kwargs):
if self.spack_env_exists(): if self.spack_env_exists():
......
...@@ -8,6 +8,9 @@ from esd.spack_manager.factory.SpackManagerCreator import SpackManagerCreator ...@@ -8,6 +8,9 @@ from esd.spack_manager.factory.SpackManagerCreator import SpackManagerCreator
from esd.utils.utils import file_exists_and_not_empty from esd.utils.utils import file_exists_and_not_empty
SPACK_ENV_ACCESS_TOKEN = os.getenv("SPACK_ENV_ACCESS_TOKEN") SPACK_ENV_ACCESS_TOKEN = os.getenv("SPACK_ENV_ACCESS_TOKEN")
test_spack_env_git = f'https://oauth2:{SPACK_ENV_ACCESS_TOKEN}@gitlab.ebrains.eu/ri/projects-and-initiatives/virtualbraintwin/tools/test-spack-env.git'
ebrains_spack_builds_git = 'https://gitlab.ebrains.eu/ri/tech-hub/platform/esd/ebrains-spack-builds.git'
def test_spack_repo_exists_1(): def test_spack_repo_exists_1():
spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH) spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH)
...@@ -32,8 +35,7 @@ def test_spack_repo_exists_3(tmp_path): ...@@ -32,8 +35,7 @@ def test_spack_repo_exists_3(tmp_path):
def test_spack_from_scratch_setup_1(tmp_path): def test_spack_from_scratch_setup_1(tmp_path):
install_dir = tmp_path install_dir = tmp_path
env = SpackModel('ebrains-spack-builds', install_dir, env = SpackModel('ebrains-spack-builds', install_dir, ebrains_spack_builds_git)
'https://gitlab.ebrains.eu/ri/tech-hub/platform/esd/ebrains-spack-builds.git')
spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env, spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env,
system_name='ebrainslab') system_name='ebrainslab')
spack_manager.setup_spack_env() spack_manager.setup_spack_env()
...@@ -42,8 +44,7 @@ def test_spack_from_scratch_setup_1(tmp_path): ...@@ -42,8 +44,7 @@ def test_spack_from_scratch_setup_1(tmp_path):
def test_spack_from_scratch_setup_2(tmp_path): def test_spack_from_scratch_setup_2(tmp_path):
install_dir = tmp_path install_dir = tmp_path
env = SpackModel('ebrains-spack-builds', install_dir, env = SpackModel('ebrains-spack-builds', install_dir, ebrains_spack_builds_git)
'https://gitlab.ebrains.eu/ri/tech-hub/platform/esd/ebrains-spack-builds.git')
repo = env repo = env
spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env, spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env,
repos=[repo, repo], repos=[repo, repo],
...@@ -83,8 +84,7 @@ def test_spack_not_a_valid_repo(): ...@@ -83,8 +84,7 @@ def test_spack_not_a_valid_repo():
def test_spack_from_scratch_concretize_1(tmp_path): def test_spack_from_scratch_concretize_1(tmp_path):
install_dir = tmp_path install_dir = tmp_path
env = SpackModel('ebrains-spack-builds', install_dir, env = SpackModel('ebrains-spack-builds', install_dir, ebrains_spack_builds_git)
'https://gitlab.ebrains.eu/ri/tech-hub/platform/esd/ebrains-spack-builds.git')
repo = env repo = env
spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env, repos=[repo, repo], spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env, repos=[repo, repo],
system_name='ebrainslab') system_name='ebrainslab')
...@@ -96,8 +96,7 @@ def test_spack_from_scratch_concretize_1(tmp_path): ...@@ -96,8 +96,7 @@ def test_spack_from_scratch_concretize_1(tmp_path):
def test_spack_from_scratch_concretize_2(tmp_path): def test_spack_from_scratch_concretize_2(tmp_path):
install_dir = tmp_path install_dir = tmp_path
env = SpackModel('ebrains-spack-builds', install_dir, env = SpackModel('ebrains-spack-builds', install_dir, ebrains_spack_builds_git)
'https://gitlab.ebrains.eu/ri/tech-hub/platform/esd/ebrains-spack-builds.git')
repo = env repo = env
spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env, repos=[repo, repo], spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env, repos=[repo, repo],
system_name='ebrainslab') system_name='ebrainslab')
...@@ -109,8 +108,7 @@ def test_spack_from_scratch_concretize_2(tmp_path): ...@@ -109,8 +108,7 @@ def test_spack_from_scratch_concretize_2(tmp_path):
def test_spack_from_scratch_concretize_3(tmp_path): def test_spack_from_scratch_concretize_3(tmp_path):
install_dir = tmp_path install_dir = tmp_path
env = SpackModel('ebrains-spack-builds', install_dir, env = SpackModel('ebrains-spack-builds', install_dir, ebrains_spack_builds_git)
'https://gitlab.ebrains.eu/ri/tech-hub/platform/esd/ebrains-spack-builds.git')
repo = env repo = env
spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env, spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env,
repos=[repo, repo], repos=[repo, repo],
...@@ -122,8 +120,7 @@ def test_spack_from_scratch_concretize_3(tmp_path): ...@@ -122,8 +120,7 @@ def test_spack_from_scratch_concretize_3(tmp_path):
def test_spack_from_scratch_concretize_4(tmp_path): def test_spack_from_scratch_concretize_4(tmp_path):
install_dir = tmp_path install_dir = tmp_path
env = SpackModel('test-spack-env', install_dir, env = SpackModel('test-spack-env', install_dir, test_spack_env_git)
f'https://oauth2:{SPACK_ENV_ACCESS_TOKEN}@gitlab.ebrains.eu/ri/projects-and-initiatives/virtualbraintwin/test-spack-env.git')
spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env) spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env)
spack_manager.setup_spack_env() spack_manager.setup_spack_env()
spack_manager.concretize_spack_env(force=False) spack_manager.concretize_spack_env(force=False)
...@@ -133,8 +130,7 @@ def test_spack_from_scratch_concretize_4(tmp_path): ...@@ -133,8 +130,7 @@ def test_spack_from_scratch_concretize_4(tmp_path):
def test_spack_from_scratch_concretize_5(tmp_path): def test_spack_from_scratch_concretize_5(tmp_path):
install_dir = tmp_path install_dir = tmp_path
env = SpackModel('test-spack-env', install_dir, env = SpackModel('test-spack-env', install_dir, test_spack_env_git)
f'https://oauth2:{SPACK_ENV_ACCESS_TOKEN}@gitlab.ebrains.eu/ri/projects-and-initiatives/virtualbraintwin/test-spack-env.git')
spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env) spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env)
spack_manager.setup_spack_env() spack_manager.setup_spack_env()
spack_manager.concretize_spack_env(force=True) spack_manager.concretize_spack_env(force=True)
...@@ -144,10 +140,8 @@ def test_spack_from_scratch_concretize_5(tmp_path): ...@@ -144,10 +140,8 @@ def test_spack_from_scratch_concretize_5(tmp_path):
def test_spack_from_scratch_concretize_6(tmp_path): def test_spack_from_scratch_concretize_6(tmp_path):
install_dir = tmp_path install_dir = tmp_path
env = SpackModel('test-spack-env', install_dir, env = SpackModel('test-spack-env', install_dir, test_spack_env_git)
f'https://oauth2:"$SPACK_ENV_ACCESS_TOKEN"@gitlab.ebrains.eu/ri/projects-and-initiatives/virtualbraintwin/test-spack-env.git') repo = SpackModel('ebrains-spack-builds', install_dir, ebrains_spack_builds_git)
repo = SpackModel('ebrains-spack-builds', install_dir,
'https://gitlab.ebrains.eu/ri/tech-hub/platform/esd/ebrains-spack-builds.git')
spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env, repos=[repo]) spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env, repos=[repo])
spack_manager.setup_spack_env() spack_manager.setup_spack_env()
spack_manager.concretize_spack_env(force=False) spack_manager.concretize_spack_env(force=False)
...@@ -157,12 +151,23 @@ def test_spack_from_scratch_concretize_6(tmp_path): ...@@ -157,12 +151,23 @@ def test_spack_from_scratch_concretize_6(tmp_path):
def test_spack_from_scratch_concretize_7(tmp_path): def test_spack_from_scratch_concretize_7(tmp_path):
install_dir = tmp_path install_dir = tmp_path
env = SpackModel('test-spack-env', install_dir, env = SpackModel('test-spack-env', install_dir, test_spack_env_git)
f'https://oauth2:"$SPACK_ENV_ACCESS_TOKEN"gitlab.ebrains.eu/ri/projects-and-initiatives/virtualbraintwin/test-spack-env.git') repo = SpackModel('ebrains-spack-builds', install_dir, ebrains_spack_builds_git)
repo = SpackModel('ebrains-spack-builds', install_dir, spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env, repos=[repo])
'https://gitlab.ebrains.eu/ri/tech-hub/platform/esd/ebrains-spack-builds.git') spack_manager.setup_spack_env()
spack_manager.concretize_spack_env(force=True)
concretization_file_path = spack_manager.env_path / 'spack.lock'
assert file_exists_and_not_empty(concretization_file_path) == True
def test_spack_from_scratch_install(tmp_path):
install_dir = tmp_path
env = SpackModel('test-spack-env', install_dir, test_spack_env_git)
repo = SpackModel('ebrains-spack-builds', install_dir, ebrains_spack_builds_git)
spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env, repos=[repo]) spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH, env=env, repos=[repo])
spack_manager.setup_spack_env() spack_manager.setup_spack_env()
spack_manager.concretize_spack_env(force=True) spack_manager.concretize_spack_env(force=True)
concretization_file_path = spack_manager.env_path / 'spack.lock' concretization_file_path = spack_manager.env_path / 'spack.lock'
assert file_exists_and_not_empty(concretization_file_path) == True assert file_exists_and_not_empty(concretization_file_path) == True
install_result = spack_manager.install_packages(jobs=2, signed=False, fresh=True, debug=False)
assert install_result.returncode == 0
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment