Skip to content
Snippets Groups Projects
Commit 03b4de04 authored by Adrian Ciu's avatar Adrian Ciu
Browse files

esd-spack-installation: spack install method and additional tests

parent 60faa456
No related branches found
No related tags found
1 merge request!4feat(spack_operation): implement setup_spack_env functionality
Pipeline #58929 passed with stages
in 16 minutes and 10 seconds
import os
import re
import subprocess
from abc import ABC, abstractmethod
from pathlib import Path
from tabnanny import check
......@@ -49,10 +50,6 @@ class SpackManager(ABC):
def concretize_spack_env(self, force=True):
pass
@abstractmethod
def install_spack_packages(self, jobs: 3, verbose=False, debug=False):
pass
def create_fetch_spack_environment(self):
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)
......@@ -168,18 +165,24 @@ class SpackManager(ABC):
return None
@check_spack_env
def install_packages(self, jobs: int, signed=True, fresh=False):
def install_packages(self, jobs: int, signed=True, fresh=False, debug=False):
signed = '' if signed else '--no-check-signature'
fresh = '--fresh' if fresh else ''
debug = '--debug' if debug else ''
install_result = run_command("bash", "-c",
f'source {self.spack_setup_script} && spack env activate -p {self.env_path} && spack {debug} install -v {signed} --j {jobs} {fresh}',
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
logger=self.logger,
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:
run_command("bash", "-c",
f'source {self.spack_setup_script} && spack install --env {self.env.env_name} -v {signed} --j {jobs} {fresh}',
stdout=log_file,
capture_output=True, text=True, check=True,
logger=self.logger,
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)
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:
......
......@@ -14,6 +14,3 @@ class SpackManagerBuildCache(SpackManager):
def concretize_spack_env(self, force=True):
pass
def install_spack_packages(self, jobs: 3, verbose=False, debug=False):
pass
......@@ -23,6 +23,3 @@ class SpackManagerScratch(SpackManager):
else:
self.logger.debug('No spack environment defined')
raise NoSpackEnvironmentException('No spack environment defined')
def install_spack_packages(self, jobs: 3, verbose=False, debug=False):
pass
......@@ -12,7 +12,6 @@ test_spack_env_git = f'https://oauth2:{SPACK_ENV_ACCESS_TOKEN}@gitlab.ebrains.eu
ebrains_spack_builds_git = 'https://gitlab.ebrains.eu/ri/tech-hub/platform/esd/ebrains-spack-builds.git'
def test_spack_repo_exists_1():
spack_manager = SpackManagerCreator.get_spack_manger(SpackManagerEnum.FROM_SCRATCH)
assert spack_manager.spack_repo_exists('ebrains-spack-builds') == False
......@@ -159,3 +158,16 @@ def test_spack_from_scratch_concretize_7(tmp_path):
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.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
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