Skip to content

Commit

Permalink
Merge pull request #58 from HPCNow/main
Browse files Browse the repository at this point in the history
froster v0.12.14 - Tests improvements
  • Loading branch information
victormachadoperez authored Jun 6, 2024
2 parents 63d486f + 8aa6019 commit ba47f19
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 98 deletions.
File renamed without changes.
55 changes: 25 additions & 30 deletions froster/froster.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,15 +471,14 @@ def set_aws(self, aws: 'AWSBoto'):

# Ask user to enter the path to a aws credentials directory

if os.path.exists(os.path.join(self.home_dir, '.aws')):
default_aws_dir = os.path.join(self.home_dir, '.aws')
else:
default_aws_dir = None
default_aws_dir = os.path.join(self.home_dir, '.aws')
if not os.path.exists(os.path.join(self.home_dir, '.aws')):
os.makedirs(self.aws_dir, exist_ok=True, mode=0o775)

aws_dir_question = [
inquirer.Path(
'aws_dir',
message=f'Enter the path to aws credentials directory (default: {default_aws_dir})',
message=f'Enter the path to aws credentials directory (default: ~/.aws)',
default=default_aws_dir,
validate=self.__inquirer_check_path_exists)
]
Expand Down Expand Up @@ -660,9 +659,6 @@ def __set_aws_config(self, aws_profile_name, region):
if not region:
raise ValueError('No region provided')

# If it does not exist, create aws directory
os.makedirs(self.aws_dir, exist_ok=True, mode=0o775)

# Create a aws config ConfigParser object
aws_config = configparser.ConfigParser()

Expand Down Expand Up @@ -706,9 +702,6 @@ def __set_aws_credentials(self,
if not aws_secret_access_key:
raise ValueError('No AWS secret access key provided')

# If it does not exist, create aws directory
os.makedirs(self.aws_dir, exist_ok=True, mode=0o775)

# Create a aws credentials ConfigParser object
aws_credentials = configparser.ConfigParser()

Expand Down Expand Up @@ -1118,19 +1111,22 @@ def set_slurm(self, args):
'''Set the Slurm configuration'''

try:
# Run the sacctmgr command
result = subprocess.run(
['sacctmgr', 'show', 'config'], capture_output=False)

if result.returncode != 0:
print(
"sacctmgr command failed. Please ensure it's installed and in your PATH and you are in a head node.")
return False

if shutil.which('scontrol'):

print(f'\n*** SLURM CONFIGURATION ***\n')

# Run the sacctmgr command
result = subprocess.run(
['sacctmgr', 'show', 'config'], capture_output=True)

if result.returncode != 0:
print(
"\nError: sacctmgr command failed. Please ensure it's installed and in your PATH and you are in a head node.")
print(f'\n stdout: {result.stdout.decode("utf-8")}\n')
print(f'\n stderr: {result.stderr.decode("utf-8")}\n')
return False

slurm_walltime_days = inquirer.text(
message="Set the Slurm --time (days) for froster jobs (default = 7)",
default=7,
Expand All @@ -1141,12 +1137,11 @@ def set_slurm(self, args):
default=0,
validate=self.__inquirer_check_is_number)

# TODO: This class __init__ should not be here, it should be in the main
se = Slurm(args, self)

# Get the allowed partitions and QOS
parts = se.get_allowed_partitions_and_qos()

print (parts)
if parts is not None:
# Ask the user to select the Slurm partition and QOS
slurm_partition = inquirer.list_input(
Expand Down Expand Up @@ -6057,10 +6052,10 @@ def subcmd_config(self, cfg: ConfigManager, aws: AWSBoto):
if self.args.print:
return cfg.print_config()

if self.args.monitor:
froster_binary = os.path.join(cfg.bin_dir, 'froster')
return cfg.add_systemd_cron_job(
f'{froster_binary} restore --monitor', '30')
# if self.args.monitor:
# froster_binary = os.path.join(cfg.bin_dir, 'froster')
# return cfg.add_systemd_cron_job(
# f'{froster_binary} restore --monitor', '30')

print(f'\n*****************************')
print(f'*** FROSTER CONFIGURATION ***')
Expand All @@ -6086,7 +6081,7 @@ def subcmd_config(self, cfg: ConfigManager, aws: AWSBoto):

if not cfg.set_shared():
return False

# If shared configuration and shared_config.ini file exists, then use it
if cfg.is_shared:
if hasattr(cfg, 'shared_config_file') and os.path.exists(cfg.shared_config_file):
Expand Down Expand Up @@ -6215,10 +6210,10 @@ def subcmd_restore(self, arch: Archiver, aws: AWSBoto):
'Invalid credentials. Set new AWS credentials by running "froster config --aws"')
sys.exit(1)

if self.args.monitor:
# aws inactivity and cost monitoring
aws.monitor_ec2()
return
# if self.args.monitor:
# # aws inactivity and cost monitoring
# aws.monitor_ec2()
# return

if not self.args.folders:

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "froster"
version = "0.12.12"
version = "0.12.14"
description = "Froster is a tool for easy data transfer between local file systems and AWS S3 storage."
authors = ["Victor Machado <[email protected]>"]
readme = "README.md"
Expand Down
Loading

0 comments on commit ba47f19

Please sign in to comment.