From c046739461627c85d024d55cf5fa7704db0b3700 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 24 Mar 2021 09:44:30 +0100 Subject: [PATCH] tape: fix MediaPool regression tests --- src/tape/inventory.rs | 5 +++++ src/tape/test/alloc_writable_media.rs | 4 ++++ src/tape/test/compute_media_state.rs | 2 ++ src/tape/test/current_set_usable.rs | 7 +++++++ 4 files changed, 18 insertions(+) diff --git a/src/tape/inventory.rs b/src/tape/inventory.rs index 3894f1ef..f9654538 100644 --- a/src/tape/inventory.rs +++ b/src/tape/inventory.rs @@ -763,6 +763,11 @@ pub fn lock_media_pool(base_path: &Path, name: &str) -> Result { let timeout = std::time::Duration::new(10, 0); let lock = proxmox::tools::fs::open_file_locked(&path, timeout, true)?; + if cfg!(test) { + // We cannot use chown inside test environment (no permissions) + return Ok(lock); + } + let backup_user = crate::backup::backup_user()?; fchown(lock.as_raw_fd(), Some(backup_user.uid), Some(backup_user.gid))?; diff --git a/src/tape/test/alloc_writable_media.rs b/src/tape/test/alloc_writable_media.rs index e293ec49..8ed3de11 100644 --- a/src/tape/test/alloc_writable_media.rs +++ b/src/tape/test/alloc_writable_media.rs @@ -42,6 +42,7 @@ fn test_alloc_writable_media_1() -> Result<(), Error> { RetentionPolicy::KeepForever, None, None, + false, )?; ctime += 10; @@ -71,6 +72,7 @@ fn test_alloc_writable_media_2() -> Result<(), Error> { RetentionPolicy::KeepForever, None, None, + false, )?; let ctime = 10; @@ -110,6 +112,7 @@ fn test_alloc_writable_media_3() -> Result<(), Error> { RetentionPolicy::KeepForever, None, None, + false, )?; let mut ctime = 10; @@ -156,6 +159,7 @@ fn test_alloc_writable_media_4() -> Result<(), Error> { RetentionPolicy::ProtectFor(parse_time_span("12s")?), None, None, + false, )?; let start_time = 10; diff --git a/src/tape/test/compute_media_state.rs b/src/tape/test/compute_media_state.rs index 7c6a5f86..70f03251 100644 --- a/src/tape/test/compute_media_state.rs +++ b/src/tape/test/compute_media_state.rs @@ -69,6 +69,7 @@ fn test_compute_media_state() -> Result<(), Error> { RetentionPolicy::KeepForever, None, None, + false, )?; // tape1 is free @@ -116,6 +117,7 @@ fn test_media_expire_time() -> Result<(), Error> { RetentionPolicy::ProtectFor(span), None, None, + false, )?; assert_eq!(pool.lookup_media(&tape0_uuid)?.status(), &MediaStatus::Full); diff --git a/src/tape/test/current_set_usable.rs b/src/tape/test/current_set_usable.rs index f6dee073..924f257b 100644 --- a/src/tape/test/current_set_usable.rs +++ b/src/tape/test/current_set_usable.rs @@ -49,6 +49,7 @@ fn test_current_set_usable_1() -> Result<(), Error> { RetentionPolicy::KeepForever, None, None, + false, )?; assert_eq!(pool.current_set_usable()?, false); @@ -75,6 +76,7 @@ fn test_current_set_usable_2() -> Result<(), Error> { RetentionPolicy::KeepForever, None, None, + false, )?; assert_eq!(pool.current_set_usable()?, false); @@ -103,6 +105,7 @@ fn test_current_set_usable_3() -> Result<(), Error> { RetentionPolicy::KeepForever, Some(String::from("changer1")), None, + false, )?; assert_eq!(pool.current_set_usable()?, false); @@ -131,6 +134,7 @@ fn test_current_set_usable_4() -> Result<(), Error> { RetentionPolicy::KeepForever, None, None, + false, )?; assert_eq!(pool.current_set_usable()?, true); @@ -161,6 +165,7 @@ fn test_current_set_usable_5() -> Result<(), Error> { RetentionPolicy::KeepForever, None, None, + false, )?; assert_eq!(pool.current_set_usable()?, true); @@ -189,6 +194,7 @@ fn test_current_set_usable_6() -> Result<(), Error> { RetentionPolicy::KeepForever, None, None, + false, )?; assert!(pool.current_set_usable().is_err()); @@ -223,6 +229,7 @@ fn test_current_set_usable_7() -> Result<(), Error> { RetentionPolicy::KeepForever, None, None, + false, )?; assert!(pool.current_set_usable().is_err());