tape/drive: improve error and email handling for requesting a tape load

Try once first to load the correct tape before sending an email to
insert the correct one. This way, the admin does not get a mail
if the correct tape is already inserted.

Also include the error we got that prompted the email to insert the
tape. This means that if the admin gets prompted to insert e.g.
"FOO" but inserts "BAR", he'll get an email that the wrong
tape is inserted.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2021-03-03 15:00:52 +01:00 committed by Dietmar Maurer
parent 7d6f03a7fe
commit 78593b5b5c
2 changed files with 32 additions and 16 deletions

View File

@ -7,12 +7,17 @@ pub fn send_load_media_email(
drive: &str, drive: &str,
label_text: &str, label_text: &str,
to: &str, to: &str,
reason: Option<String>,
) -> Result<(), Error> { ) -> Result<(), Error> {
let subject = format!("Load Media '{}' request for drive '{}'", label_text, drive); let subject = format!("Load Media '{}' request for drive '{}'", label_text, drive);
let mut text = String::new(); let mut text = String::new();
if let Some(reason) = reason {
text.push_str(&format!("The drive has the wrong or no tape inserted. Error:\n{}\n\n", reason));
}
text.push_str("Please insert the requested media into the backup drive.\n\n"); text.push_str("Please insert the requested media into the backup drive.\n\n");
text.push_str(&format!("Drive: {}\n", drive)); text.push_str(&format!("Drive: {}\n", drive));

View File

@ -375,18 +375,34 @@ pub fn request_and_load_media(
return Ok((handle, media_id)); return Ok((handle, media_id));
} }
task_log!(worker, "Please insert media '{}' into drive '{}'", label_text, drive);
let to = "root@localhost"; // fixme let to = "root@localhost"; // fixme
send_load_media_email(drive, &label_text, to)?;
let mut last_media_uuid = None; let mut last_media_uuid = None;
let mut last_error = None; let mut last_error = None;
let mut tried = false;
let mut failure_reason = None;
loop { loop {
worker.check_abort()?; worker.check_abort()?;
if tried {
if let Some(reason) = failure_reason {
task_log!(worker, "Please insert media '{}' into drive '{}'", label_text, drive);
send_load_media_email(drive, &label_text, to, Some(reason))?;
}
failure_reason = None;
for _ in 0..50 { // delay 5 seconds
worker.check_abort()?;
std::thread::sleep(std::time::Duration::from_millis(100));
}
}
tried = true;
let mut handle = match drive_config.open() { let mut handle = match drive_config.open() {
Ok(handle) => handle, Ok(handle) => handle,
Err(err) => { Err(err) => {
@ -394,10 +410,7 @@ pub fn request_and_load_media(
if Some(err.clone()) != last_error { if Some(err.clone()) != last_error {
task_log!(worker, "tape open failed - {}", err); task_log!(worker, "tape open failed - {}", err);
last_error = Some(err); last_error = Some(err);
} failure_reason = last_error.clone();
for _ in 0..50 { // delay 5 seconds
worker.check_abort()?;
std::thread::sleep(std::time::Duration::from_millis(100));
} }
continue; continue;
} }
@ -414,19 +427,22 @@ pub fn request_and_load_media(
); );
return Ok((Box::new(handle), media_id)); return Ok((Box::new(handle), media_id));
} else if Some(media_id.label.uuid.clone()) != last_media_uuid { } else if Some(media_id.label.uuid.clone()) != last_media_uuid {
task_log!( let err = format!(
worker,
"wrong media label {} ({})", "wrong media label {} ({})",
media_id.label.label_text, media_id.label.label_text,
media_id.label.uuid.to_string(), media_id.label.uuid.to_string(),
); );
task_log!(worker, "{}", err);
last_media_uuid = Some(media_id.label.uuid); last_media_uuid = Some(media_id.label.uuid);
failure_reason = Some(err);
} }
} }
Ok((None, _)) => { Ok((None, _)) => {
if last_media_uuid.is_some() { if last_media_uuid.is_some() {
task_log!(worker, "found empty media without label (please label all tapes first)"); let err = "found empty media without label (please label all tapes first)";
task_log!(worker, "{}", err);
last_media_uuid = None; last_media_uuid = None;
failure_reason = Some(err.to_string());
} }
} }
Err(err) => { Err(err) => {
@ -434,15 +450,10 @@ pub fn request_and_load_media(
if Some(err.clone()) != last_error { if Some(err.clone()) != last_error {
task_log!(worker, "tape open failed - {}", err); task_log!(worker, "tape open failed - {}", err);
last_error = Some(err); last_error = Some(err);
failure_reason = last_error.clone();
} }
} }
} }
// eprintln!("read label failed - test again in 5 secs");
for _ in 0..50 { // delay 5 seconds
worker.check_abort()?;
std::thread::sleep(std::time::Duration::from_millis(100));
}
} }
} }
_ => bail!("drive type '{}' not implemented!"), _ => bail!("drive type '{}' not implemented!"),