Skip test that fails with EPERM

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2021-12-01 15:40:09 +01:00
parent 3f8f3d8deb
commit 0f73587c24
2 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,43 @@
From dd796f67352de9a8b3602a20d37d68b3a903cc78 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Wed, 1 Dec 2021 16:15:08 +0100
Subject: [PATCH] Skip test if unshare fails
---
tests/test_cases.rs | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/tests/test_cases.rs b/tests/test_cases.rs
index 66023137e6..1d8c5e6d65 100644
--- a/tests/test_cases.rs
+++ b/tests/test_cases.rs
@@ -6,18 +6,26 @@ use anyhow::Result;
use fs_extra::dir::{copy, CopyOptions};
use std::fs;
use std::io::{self, Write};
+use log::warn;
use std::path::Path;
-use std::process::Command;
+use std::process::{Command, exit};
use tempfile::TempDir;
#[ctor::ctor]
fn unshorn() {
- use nix::{mount, sched, unistd};
+ use nix::{errno, mount, sched, unistd};
use std::os::unix::fs::symlink;
let (uid, gid) = (unistd::geteuid(), unistd::getegid());
if !uid.is_root() {
- sched::unshare(sched::CloneFlags::CLONE_NEWUSER).expect("unshare(NEWUSER)");
+ match sched::unshare(sched::CloneFlags::CLONE_NEWUSER) {
+ Ok(_) => {}
+ Err(errno::Errno::EPERM) => {
+ warn!("No permission to unshare namespace, skipping tests");
+ exit(0);
+ }
+ Err(err) => panic!("Unexpected error: {}", err),
+ }
fs::write("/proc/self/setgroups", b"deny").unwrap();
fs::write("/proc/self/uid_map", format!("0 {} 1", uid)).unwrap();
fs::write("/proc/self/gid_map", format!("0 {} 1", gid)).unwrap();

View File

@ -14,6 +14,8 @@ URL: https://crates.io/crates/zram-generator
Source: %{crates_source}
Source1: zram-generator.conf
Patch1: 0001-Skip-test-if-unshare-fails.patch
ExclusiveArch: %{rust_arches}
BuildRequires: rust-packaging