Skip to content

Commit

Permalink
Replaced error logs with error propagation
Browse files Browse the repository at this point in the history
Replaced pancis to error propagation in LDAP modules
Converted panics to error propagation in slurm modules
  • Loading branch information
BoolPurist committed Jun 17, 2023
1 parent fe7ca30 commit c33807f
Show file tree
Hide file tree
Showing 7 changed files with 498 additions and 398 deletions.
91 changes: 63 additions & 28 deletions src/dir.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::util::ResultAccumalator;
/// Module for directory management
use log::{debug, error, info, warn};
use log::{debug, info, warn};

use crate::config::MgmtConfig;
use crate::prelude::AppResult;
Expand Down Expand Up @@ -88,22 +89,35 @@ fn handle_compute_nodes(
}
}

if mkdir_exit_codes.iter().all(|&x| x == 0) {
if owner_exit_codes
.iter()
.all(|x| x.as_ref().is_ok_and(|code| *code == 0))
{
if quota_exit_codes.iter().all(|&x| x == 0) {
info!("Successfully created directories on compute nodes.");
} else if can_set_quota {
error!("Not all compute nodes returned exit code 0 during quota setup!");
}
} else {
error!("Not all compute nodes returned exit code 0 during ownership change!");
}
} else {
error!("Not all compute nodes returned exit code 0 during directory creation!");
}
let mut errors_from_codes =
ResultAccumalator::new("Failed at creating directories on compute nodes.".to_owned());

let all_exit_codes_are_zero = mkdir_exit_codes.iter().all(|&x| x == 0);

errors_from_codes.add_err_if_false(
all_exit_codes_are_zero,
"Not all compute nodes returned exit code 0 during directory creation!".to_owned(),
);

let all_owner_exit_codes_are_zero = owner_exit_codes
.iter()
.all(|x| x.as_ref().is_ok_and(|code| *code == 0));

errors_from_codes.add_err_if_false(
all_owner_exit_codes_are_zero,
"Not all compute nodes returned exit code 0 during ownership change!".to_owned(),
);

let all_quota_exit_codes_are_zero = quota_exit_codes.iter().all(|&x| x == 0);

errors_from_codes.add_err_if_false(
all_quota_exit_codes_are_zero,
"Not all compute nodes returned exit code 0 during quota setup!".to_owned(),
);

AppResult::from(errors_from_codes)?;

info!("Successfully created directories on compute nodes.");

Ok(())
}
Expand Down Expand Up @@ -142,7 +156,10 @@ fn handle_nfs(entity: &Entity, config: &MgmtConfig, credentials: &SshCredential)
let directory = format!("{}/{}/{}", config.nfs_root_dir, group_dir, entity.username);
let dir_exit_code = make_directory(&sess, &directory)?;

if dir_exit_code == 0 {
let mut detected_errors =
ResultAccumalator::new("Errors in creating directories for NFS occured".to_owned());
let no_error_make_dir = dir_exit_code == 0;
if no_error_make_dir {
// Give ownership to user
let owner_exit_code = change_ownership(
&sess,
Expand All @@ -151,12 +168,16 @@ fn handle_nfs(entity: &Entity, config: &MgmtConfig, credentials: &SshCredential)
&entity.group.to_string(),
)?;
if owner_exit_code != 0 {
error!("NFS host did not return with exit code 0 during ownership change!");
detected_errors.add_err(
"NFS host did not return with exit code 0 during ownership change!".to_owned(),
);
} else {
info!("Successfully created user directory on NFS host.");
}
} else {
error!("NFS host did not return with exit code 0 during directory creation!");
detected_errors.add_err(
"NFS host did not return with exit code 0 during directory creation!".to_owned(),
);
}

// Set user quota
Expand All @@ -168,11 +189,15 @@ fn handle_nfs(entity: &Entity, config: &MgmtConfig, credentials: &SshCredential)
&config.quota_nfs_hardlimit,
&config.nfs_filesystem,
)?;
if quota_exit_code != 0 {
error!("NFS host did not return with exit code 0 during quota setup!")
}

detected_errors.add_err_if_false(
quota_exit_code == 0,
"NFS host did not return with exit code 0 during quota setup!".to_owned(),
)
}

AppResult::from(detected_errors)?;

Ok(())
}

Expand Down Expand Up @@ -207,6 +232,9 @@ fn handle_home(entity: &Entity, config: &MgmtConfig, credentials: &SshCredential
make_directory(&sess, &directory)
}?;

let mut detected_errors =
ResultAccumalator::new("Errors in creating the home folder of user occured".to_owned());

if dir_exit_code == 0 {
// Give ownership to user
let owner_exit_code = change_ownership(
Expand All @@ -216,12 +244,16 @@ fn handle_home(entity: &Entity, config: &MgmtConfig, credentials: &SshCredential
&entity.group.to_string(),
)?;
if owner_exit_code != 0 {
error!("Home host did not return with exit code 0 during ownership change!");
detected_errors.add_err(
"Home host did not return with exit code 0 during ownership change!".to_owned(),
);
} else {
info!("Successfully created user home directory.");
}
} else {
error!("Home host did not return with exit code 0 during directory creation!");
detected_errors.add_err(
"Home host did not return with exit code 0 during directory creation!".to_owned(),
);
}

// Set user quota
Expand All @@ -233,11 +265,14 @@ fn handle_home(entity: &Entity, config: &MgmtConfig, credentials: &SshCredential
&config.quota_home_hardlimit,
&config.home_filesystem,
)?;
if quota_exit_code != 0 {
error!("Home host did not return with exit code 0 during quota setup!")
}
detected_errors.add_err_if_false(
quota_exit_code != 0,
"Home host did not return with exit code 0 during quota setup!".to_owned(),
);
}

AppResult::from(detected_errors)?;

Ok(())
}

Expand Down
Loading

0 comments on commit c33807f

Please sign in to comment.