Skip to content

Commit 85d4276

Browse files
authored
Merge pull request #211 from TaekyungHeo/rm-config
Remove Config File Handling and TOML Dependency from SlurmInstaller
2 parents d808b7d + 201a123 commit 85d4276

File tree

1 file changed

+2
-96
lines changed

1 file changed

+2
-96
lines changed

src/cloudai/installer/slurm_installer.py

Lines changed: 2 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
import contextlib
1817
import os
1918
import subprocess
20-
from pathlib import Path
21-
from typing import Dict, Iterable, cast
22-
23-
import toml
19+
from typing import Iterable, cast
2420

2521
from cloudai import BaseInstaller, InstallStatusResult, System, TestTemplate
2622
from cloudai.systems import SlurmSystem
@@ -33,15 +29,12 @@ class SlurmInstaller(BaseInstaller):
3329
Handles the installation of benchmarks or test templates for Slurm-managed systems.
3430
3531
Attributes
36-
CONFIG_FILE_NAME (str): The name of the configuration file.
3732
PREREQUISITES (List[str]): A list of required binaries for the installer.
3833
REQUIRED_SRUN_OPTIONS (List[str]): A list of required srun options to check.
3934
install_path (Path): Path where the benchmarks are to be installed. This is optional since uninstallation does
4035
not require it.
41-
config_path (Path): Path to the installation configuration file.
4236
"""
4337

44-
CONFIG_FILE_NAME = ".cloudai.toml"
4538
PREREQUISITES = ["git", "sbatch", "sinfo", "squeue", "srun", "scancel"]
4639
REQUIRED_SRUN_OPTIONS = [
4740
"--mpi",
@@ -61,7 +54,6 @@ def __init__(self, system: System):
6154
super().__init__(system)
6255
slurm_system = cast(SlurmSystem, self.system)
6356
self.install_path = slurm_system.install_path
64-
self.config_path = Path.home() / self.CONFIG_FILE_NAME
6557

6658
def _check_prerequisites(self) -> InstallStatusResult:
6759
"""
@@ -107,67 +99,6 @@ def _check_srun_options(self) -> None:
10799
missing_options_str = ", ".join(missing_options)
108100
raise EnvironmentError(f"Required srun options missing: {missing_options_str}")
109101

110-
def _write_config(self) -> InstallStatusResult:
111-
"""Write the installation configuration to a TOML file atomically."""
112-
absolute_install_path = self.install_path.resolve()
113-
config_data: Dict[str, str] = {"install_path": str(absolute_install_path)}
114-
115-
try:
116-
with self.config_path.open("w") as file:
117-
toml.dump(config_data, file)
118-
return InstallStatusResult(True)
119-
except Exception as e:
120-
with contextlib.suppress(OSError):
121-
self.config_path.unlink()
122-
return InstallStatusResult(False, str(e))
123-
124-
def _read_config(self) -> Dict[str, str]:
125-
"""
126-
Read the installation configuration from a TOML file.
127-
128-
Returns
129-
Dict[str, str]: Configuration, including installation path.
130-
"""
131-
try:
132-
with self.config_path.open("r") as file:
133-
return toml.load(file)
134-
except FileNotFoundError as e:
135-
raise FileNotFoundError(
136-
f"Configuration file not found at {self.config_path}. "
137-
"The configuration file is automatically created during installation to store any settings."
138-
) from e
139-
140-
def _remove_config(self) -> None:
141-
"""Remove the installation configuration file."""
142-
if self.config_path.exists():
143-
self.config_path.unlink()
144-
145-
def is_installed(self, test_templates: Iterable[TestTemplate]) -> InstallStatusResult:
146-
"""
147-
Check if the necessary components for the provided test templates are already installed.
148-
149-
Verify the existence of the configuration file and the installation status of each test template.
150-
151-
Args:
152-
test_templates (Iterable[TestTemplate]): The test templates to check for installation.
153-
154-
Returns:
155-
InstallStatusResult: Result containing the installation status and error message if not installed.
156-
"""
157-
if not self.config_path.exists():
158-
return InstallStatusResult(
159-
False,
160-
f"Configuration file does not exist at {self.config_path}. "
161-
"The configuration file is automatically created during installation to store any settings.",
162-
)
163-
164-
try:
165-
self._read_config()
166-
except FileNotFoundError as e:
167-
return InstallStatusResult(False, str(e))
168-
169-
return super().is_installed(test_templates)
170-
171102
def install(self, test_templates: Iterable[TestTemplate]) -> InstallStatusResult:
172103
"""
173104
Check if the necessary components are installed and install them if not.
@@ -197,29 +128,4 @@ def install(self, test_templates: Iterable[TestTemplate]) -> InstallStatusResult
197128
if not self.install_path.is_dir() or not os.access(self.install_path, os.W_OK):
198129
return InstallStatusResult(False, f"The installation path {self.install_path} is not writable.")
199130

200-
install_result = super().install(test_templates)
201-
202-
if install_result.success:
203-
config_result = self._write_config()
204-
if not config_result.success:
205-
return config_result
206-
return install_result
207-
208-
def uninstall(self, test_templates: Iterable[TestTemplate]) -> InstallStatusResult:
209-
"""
210-
Uninstall the benchmarks or test from the installation path and remove the configuration file.
211-
212-
This method does not require the installation path to be set in advance.
213-
214-
Args:
215-
test_templates (Iterable[TestTemplate]): The test templates to uninstall.
216-
217-
Returns:
218-
InstallStatusResult: Result containing the uninstallation status and error message if any.
219-
"""
220-
uninstall_result = super().uninstall(test_templates)
221-
222-
if uninstall_result.success:
223-
self._remove_config()
224-
225-
return uninstall_result
131+
return super().install(test_templates)

0 commit comments

Comments
 (0)