tape: fix media_expire_time

This commit is contained in:
Dietmar Maurer 2021-03-04 13:11:04 +01:00
parent 207f763d1a
commit cd5d6103ea
2 changed files with 72 additions and 13 deletions

View File

@ -505,13 +505,18 @@ impl Inventory {
Some(time) => time,
};
let max_use_time = match media_set_policy {
MediaSetPolicy::ContinueCurrent => {
match self.media_set_next_start_time(&set.uuid) {
Some(next_start_time) => next_start_time,
None => return i64::MAX,
let max_use_time = match self.media_set_next_start_time(&set.uuid) {
Some(next_start_time) => {
match media_set_policy {
MediaSetPolicy::AlwaysCreate => set_start_time,
_ => next_start_time,
}
}
None => {
match media_set_policy {
MediaSetPolicy::ContinueCurrent => {
return i64::MAX;
}
MediaSetPolicy::AlwaysCreate => {
set_start_time
}
@ -521,6 +526,8 @@ impl Inventory {
Ok(None) | Err(_) => return i64::MAX,
}
}
}
}
};
match retention_policy {

View File

@ -84,3 +84,55 @@ fn test_compute_media_state() -> Result<(), Error> {
Ok(())
}
#[test]
fn test_media_expire_time() -> Result<(), Error> {
let testdir = create_testdir("test_media_expire_time")?;
let ctime = 0;
let mut inventory = Inventory::load(&testdir)?;
// tape0: single tape media set
let sl0 = MediaSetLabel::with_data("p1", Uuid::generate(), 0, ctime, None);
let tape0_uuid = inventory.generate_used_tape("tape0", sl0, 0);
// tape1: single tape media set
let sl1 = MediaSetLabel::with_data("p1", Uuid::generate(), 0, ctime + 60, None);
let tape1_uuid = inventory.generate_used_tape("tape1", sl1, 0);
// tape2: single tape media set
let sl2= MediaSetLabel::with_data("p1", Uuid::generate(), 0, ctime + 120, None);
let tape2_uuid = inventory.generate_used_tape("tape2", sl2, 0);
let event = crate::tools::systemd::time::parse_calendar_event("*:0/2")?;
let span = crate::tools::systemd::time::parse_time_span("120 seconds")?;
let pool = MediaPool::new(
"p1",
&testdir ,
MediaSetPolicy::CreateAt(event),
RetentionPolicy::ProtectFor(span),
None,
None,
)?;
assert_eq!(pool.lookup_media(&tape0_uuid)?.status(), &MediaStatus::Full);
assert_eq!(pool.lookup_media(&tape1_uuid)?.status(), &MediaStatus::Full);
assert_eq!(pool.lookup_media(&tape2_uuid)?.status(), &MediaStatus::Writable);
assert_eq!(pool.media_is_expired(&pool.lookup_media(&tape0_uuid)?, 0), false);
assert_eq!(pool.media_is_expired(&pool.lookup_media(&tape0_uuid)?, 60), false);
assert_eq!(pool.media_is_expired(&pool.lookup_media(&tape0_uuid)?, 120), false);
assert_eq!(pool.media_is_expired(&pool.lookup_media(&tape0_uuid)?, 180), true);
assert_eq!(pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 0), false);
assert_eq!(pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 60), false);
assert_eq!(pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 120), false);
assert_eq!(pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 180), false);
assert_eq!(pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 190), false);
assert_eq!(pool.media_is_expired(&pool.lookup_media(&tape1_uuid)?, 240), true);
Ok(())
}