-
Notifications
You must be signed in to change notification settings - Fork 403
Added recursive mount attr test #1428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
YJDoc2
merged 6 commits into
youki-dev:main
from
higuruchi:Add/Recursive_mount_attrs_test
Jan 30, 2023
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
88452c5
Added recursive mount attr test.
higuruchi d68af0a
Added rnosuid mount option test.
higuruchi 40e113a
Fixed rnosuid mount option test method
higuruchi 3cc9061
Added rnoexec mount option test.
higuruchi 3749a46
Remove clap from runtimetest
higuruchi ccbd26b
Fix error messages
higuruchi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
tests/rust-integration-tests/integration_test/src/tests/mounts_recursive/mod.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| use crate::utils::test_inside_container; | ||
| use nix::mount::{mount, umount, MsFlags}; | ||
| use oci_spec::runtime::{get_default_mounts, Mount, ProcessBuilder, Spec, SpecBuilder}; | ||
| use std::fs; | ||
| use std::path::{Path, PathBuf}; | ||
| use std::str::FromStr; | ||
| use test_framework::{Test, TestGroup, TestResult}; | ||
|
|
||
| fn get_spec(added_mounts: Vec<Mount>) -> Spec { | ||
| let mut mounts = get_default_mounts(); | ||
| for mount in added_mounts { | ||
| mounts.push(mount); | ||
| } | ||
|
|
||
| SpecBuilder::default() | ||
| .mounts(mounts) | ||
| .process( | ||
| ProcessBuilder::default() | ||
| .args(vec![ | ||
| "runtimetest".to_string(), | ||
| "mounts_recursive".to_string(), | ||
| ]) | ||
| .build() | ||
| .unwrap(), | ||
| ) | ||
| .build() | ||
| .unwrap() | ||
| } | ||
|
|
||
| fn setup_mount(mount_dir: &Path, sub_mount_dir: &Path) { | ||
| fs::create_dir(mount_dir).unwrap(); | ||
| mount::<Path, Path, str, str>(None, mount_dir, Some("tmpfs"), MsFlags::empty(), None).unwrap(); | ||
| fs::create_dir(sub_mount_dir).unwrap(); | ||
| mount::<Path, Path, str, str>(None, sub_mount_dir, Some("tmpfs"), MsFlags::empty(), None) | ||
| .unwrap(); | ||
| } | ||
|
|
||
| fn clean_mount(mount_dir: &Path, sub_mount_dir: &Path) { | ||
| umount(sub_mount_dir).unwrap(); | ||
| umount(mount_dir).unwrap(); | ||
| fs::remove_dir_all(mount_dir).unwrap(); | ||
| } | ||
|
|
||
| fn check_recursive_readonly() -> TestResult { | ||
| let rro_test_base_dir = PathBuf::from_str("/tmp").unwrap(); | ||
| let rro_dir_path = rro_test_base_dir.join("rro_dir"); | ||
| let rro_subdir_path = rro_dir_path.join("rro_subdir"); | ||
| let mount_dest_path = PathBuf::from_str("/mnt").unwrap(); | ||
|
|
||
| let mount_options = vec!["rbind".to_string(), "rro".to_string()]; | ||
| let mut mount_spec = Mount::default(); | ||
| mount_spec | ||
| .set_destination(mount_dest_path.clone()) | ||
| .set_typ(None) | ||
| .set_source(Some(rro_dir_path.clone())) | ||
| .set_options(Some(mount_options.clone())); | ||
| let spec = get_spec(vec![mount_spec]); | ||
|
|
||
| let result = test_inside_container(spec, &|_| { | ||
| setup_mount(&rro_dir_path, &rro_subdir_path); | ||
| Ok(()) | ||
| }); | ||
|
|
||
| clean_mount(&rro_dir_path, &rro_subdir_path); | ||
|
|
||
| result | ||
| } | ||
|
|
||
| pub fn get_mounts_recursive_test() -> TestGroup { | ||
| let rro_test = Test::new("rro_test", Box::new(check_recursive_readonly)); | ||
| let mut tg = TestGroup::new("mounts_recursive"); | ||
| tg.add(vec![Box::new(rro_test)]); | ||
| tg | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| use crate::utils::{test_read_access, test_write_access}; | ||
| use crate::utils::{self, test_read_access, test_write_access}; | ||
| use anyhow::{bail, Result}; | ||
| use nix::errno::Errno; | ||
| use oci_spec::runtime::Spec; | ||
| use std::fs::read_dir; | ||
| use std::path::Path; | ||
|
|
||
| pub fn validate_readonly_paths(spec: &Spec) { | ||
| let linux = spec.linux().as_ref().unwrap(); | ||
|
|
@@ -76,3 +79,51 @@ pub fn validate_hostname(spec: &Spec) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| /// Run argument test recursively for files after base_dir | ||
| fn do_test_mounts_recursive(base_dir: &Path, test_fn: &dyn Fn(&Path) -> Result<()>) -> Result<()> { | ||
| let rd = read_dir(base_dir).unwrap(); | ||
| for d in rd { | ||
| let d = d.unwrap(); | ||
| let f_type = d.file_type().unwrap(); | ||
| if f_type.is_dir() { | ||
| do_test_mounts_recursive(d.path().as_path(), test_fn)?; | ||
| } | ||
|
|
||
| if f_type.is_file() { | ||
| test_fn(d.path().as_path())?; | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
YJDoc2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| pub fn validate_mounts_recursive(spec: &Spec) { | ||
| if let Some(mounts) = spec.mounts() { | ||
| for m in mounts { | ||
| if let Some(options) = m.options() { | ||
| for o in options { | ||
| match o.as_str() { | ||
YJDoc2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "rro" => { | ||
| if let Err(e) = | ||
| do_test_mounts_recursive(m.destination(), &|test_file_path| { | ||
| if utils::test_write_access(test_file_path.to_str().unwrap()) | ||
| .is_ok() | ||
| { | ||
| // Return Err if writeable | ||
| bail!("Unexpectedl writeable"); | ||
YJDoc2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| Ok(()) | ||
| }) | ||
| { | ||
| eprintln!("mounts_recursive rro error: {}", e); | ||
YJDoc2 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| "rrw" => { /* TODO... */ } | ||
|
||
| _ => {} | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.