From c708d57a58db5333e07542ee773bae48f2e6431e Mon Sep 17 00:00:00 2001
From: adrianciu <adrian.ciu@codemart.ro>
Date: Thu, 6 Feb 2025 18:14:49 +0200
Subject: [PATCH] esd-spack-installation: fixed passing access token to tests;
 added log file for spack install step

---
 .gitlab-ci.yml                             |  1 +
 esd/spack_manager/SpackManager.py          | 25 ++++++++++++++++------
 esd/spack_manager/wrapper/spack_wrapper.py |  2 +-
 3 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 7af0dd30..d1b09e6a 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -39,5 +39,6 @@ testing-pytest:
     paths:
       - test-results.xml
       - .esd.log
+      - .generate_cache.log
     expire_in: 1 week
 
diff --git a/esd/spack_manager/SpackManager.py b/esd/spack_manager/SpackManager.py
index a7f46c27..d534b30a 100644
--- a/esd/spack_manager/SpackManager.py
+++ b/esd/spack_manager/SpackManager.py
@@ -2,12 +2,13 @@ import os
 import re
 from abc import ABC, abstractmethod
 from pathlib import Path
+from tabnanny import check
 
 from esd.error_handling.exceptions import BashCommandException, NoSpackEnvironmentException, \
     SpackInstallPackagesException
 from esd.logger.logger_builder import get_logger
 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
 
 
@@ -53,7 +54,6 @@ class SpackManager(ABC):
         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)
         else:
@@ -127,7 +127,7 @@ class SpackManager(ABC):
             return False
         return True
 
-    @no_spack_env
+    @check_spack_env
     def add_spack_repo(self, repo_path: Path, repo_name: str):
         """Add the Spack repository if it does not exist."""
         run_command("bash", "-c",
@@ -137,7 +137,7 @@ class SpackManager(ABC):
                     exception_msg=f"Failed to add {repo_name} to spack environment {self.env.env_name}",
                     exception=BashCommandException)
 
-    @no_spack_env
+    @check_spack_env
     def get_compiler_version(self):
         result = run_command("bash", "-c",
                              f'source {self.spack_setup_script} && spack env activate -p {self.env_path} && spack compiler list',
@@ -167,8 +167,21 @@ class SpackManager(ABC):
             return spack_version.stdout.strip().split()[0]
         return None
 
-
-    def install_spack(self, spack_version="v0.21.1", spack_repo='https://github.com/spack/spack'):
+    @check_spack_env
+    def install_packages(self, jobs: int, signed=True, fresh=False):
+        signed = '' if signed else '--no-check-signature'
+        fresh = '--fresh' if fresh else ''
+        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)
+
+    def install_spack(self, spack_version="v0.22.0", spack_repo='https://github.com/spack/spack'):
         try:
             user = os.getlogin()
         except OSError:
diff --git a/esd/spack_manager/wrapper/spack_wrapper.py b/esd/spack_manager/wrapper/spack_wrapper.py
index d075a317..c2f9c116 100644
--- a/esd/spack_manager/wrapper/spack_wrapper.py
+++ b/esd/spack_manager/wrapper/spack_wrapper.py
@@ -3,7 +3,7 @@ import functools
 from esd.error_handling.exceptions import NoSpackEnvironmentException
 
 
-def no_spack_env(method):
+def check_spack_env(method):
     @functools.wraps(method)
     def wrapper(self, *args, **kwargs):
         if self.spack_env_exists():
-- 
GitLab