mirror of
				https://github.com/kata-containers/kata-containers.git
				synced 2025-11-04 03:29:55 +00:00 
			
		
		
		
	agent: Remove shadowed function, add slog-term
Remove shadowed get_mounts(), added slog-term as a new crate, slog can directly log to stdout and we can capture output in the test-cases that are created in the function to be tested. Signed-off-by: Zvonko Kaiser <zkaiser@nvidia.com>
This commit is contained in:
		
							
								
								
									
										1
									
								
								src/agent/Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1
									
								
								src/agent/Cargo.lock
									
									
									
										generated
									
									
									
								
							@@ -842,6 +842,7 @@ dependencies = [
 | 
			
		||||
 "slog",
 | 
			
		||||
 "slog-scope",
 | 
			
		||||
 "slog-stdlog",
 | 
			
		||||
 "slog-term",
 | 
			
		||||
 "tempfile",
 | 
			
		||||
 "test-utils",
 | 
			
		||||
 "thiserror",
 | 
			
		||||
 
 | 
			
		||||
@@ -43,6 +43,7 @@ ipnetwork = "0.17.0"
 | 
			
		||||
logging = { path = "../libs/logging" }
 | 
			
		||||
slog = "2.5.2"
 | 
			
		||||
slog-scope = "4.1.2"
 | 
			
		||||
slog-term = "2.9.0"
 | 
			
		||||
 | 
			
		||||
# Redirect ttrpc log calls
 | 
			
		||||
slog-stdlog = "4.0.0"
 | 
			
		||||
 
 | 
			
		||||
@@ -36,6 +36,7 @@ use crate::Sandbox;
 | 
			
		||||
use crate::{ccw, device::get_virtio_blk_ccw_device_name};
 | 
			
		||||
use anyhow::{anyhow, Context, Result};
 | 
			
		||||
use slog::Logger;
 | 
			
		||||
 | 
			
		||||
use tracing::instrument;
 | 
			
		||||
 | 
			
		||||
pub const TYPE_ROOTFS: &str = "rootfs";
 | 
			
		||||
@@ -1132,6 +1133,7 @@ fn parse_options(option_list: Vec<String>) -> HashMap<String, String> {
 | 
			
		||||
mod tests {
 | 
			
		||||
    use super::*;
 | 
			
		||||
    use protocols::agent::FSGroup;
 | 
			
		||||
    use slog::Drain;
 | 
			
		||||
    use std::fs::File;
 | 
			
		||||
    use std::fs::OpenOptions;
 | 
			
		||||
    use std::io::Write;
 | 
			
		||||
@@ -1142,25 +1144,11 @@ mod tests {
 | 
			
		||||
        skip_if_not_root, skip_loop_by_user, skip_loop_if_not_root, skip_loop_if_root,
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    // Shadow get_mounts during tests since this is only used in the test
 | 
			
		||||
    // context, compiler will warn about dead-code.
 | 
			
		||||
    #[allow(dead_code)]
 | 
			
		||||
    fn get_mounts() -> Result<String, std::io::Error> {
 | 
			
		||||
        Ok(String::from(
 | 
			
		||||
            "
 | 
			
		||||
            rootfs / rootfs rw,size=1694984k,nr_inodes=423746 0 0
 | 
			
		||||
            proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0
 | 
			
		||||
            sys /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0
 | 
			
		||||
            dev /dev devtmpfs rw,nosuid,relatime,size=1695000k,nr_inodes=423750,mode=755 0 0
 | 
			
		||||
            run /run tmpfs rw,nosuid,nodev,relatime,mode=755 0 0
 | 
			
		||||
        ",
 | 
			
		||||
        ))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[test]
 | 
			
		||||
    fn test_already_baremounted() {
 | 
			
		||||
        let drain = slog::Discard;
 | 
			
		||||
        let logger = slog::Logger::root(drain, o!());
 | 
			
		||||
        let plain = slog_term::PlainSyncDecorator::new(std::io::stdout());
 | 
			
		||||
        let logger = Logger::root(slog_term::FullFormat::new(plain).build().fuse(), o!());
 | 
			
		||||
 | 
			
		||||
        let test_cases = [
 | 
			
		||||
            ("dev", "/dev", "devtmpfs"),
 | 
			
		||||
            ("udev", "/dev", "devtmpfs"),
 | 
			
		||||
@@ -1173,7 +1161,10 @@ mod tests {
 | 
			
		||||
            let destination = Path::new(destination);
 | 
			
		||||
            let flags = MsFlags::MS_RDONLY;
 | 
			
		||||
            let options = "mode=755";
 | 
			
		||||
            println!("baremount({:?} {:?} {:?}", source, destination, fs_type);
 | 
			
		||||
            println!(
 | 
			
		||||
                "testing if already mounted baremount({:?} {:?} {:?})",
 | 
			
		||||
                source, destination, fs_type
 | 
			
		||||
            );
 | 
			
		||||
            assert!(baremount(source, destination, fs_type, flags, options, &logger).is_ok());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user