Commit b5bb8cce authored by Alexis Janon's avatar Alexis Janon
Browse files

Additional transaction integration tests

- Create slice with a restricted list of controllers
- Spawn command with verification of the result of the command itself
parent e64be069
......@@ -11,9 +11,12 @@ const CREATE_NAME: &str = "integration_test_create";
const DELETE_NAME: &str = "integration_test_delete";
const MODIFY_NAME: &str = "integration_test_modify";
const CREATE_WITH_PROPERTIES_NAME: &str = "integration_test_create_with_properties";
const CREATE_RESTRICTED_CONTROLLERS_NAME: &str = "integration_test_create_restricted_controllers";
const SPAWN_CPUSET_NAME: &str = "integration_test_spawn_cpuset";
const PROPERTY: &str = "cpuset.cpus";
const CONTROLLER: &str = "cpuset";
const VALUE: &str = "0";
const SPAWN_CPUSET_RESULT_FILE: &str = "/tmp/integration_test_spawn_cpuset_result";
#[test]
fn test_create() {
......@@ -156,3 +159,77 @@ fn test_create_with_properties() {
assert!(fs::remove_dir(&path).is_ok());
}
}
#[test]
// TODO: need cpuset cgroup: make it more generic (or robust)
fn test_create_restricted_controllers() {
let json = format!(
r#"
{{
"commands":[
{{
"command":"create",
"name":"{}",
"args":[
"{}"
]
}}
]
}}
"#,
CREATE_RESTRICTED_CONTROLLERS_NAME, CONTROLLER
);
let controllers = Rc::new(configuration::sysfscontroller::get_sys_fs_controllers().unwrap());
let path = controllers
.get(CONTROLLER)
.map(SysFsController::get_path)
.map(path::Path::to_path_buf)
.map(|path| path.join(CREATE_RESTRICTED_CONTROLLERS_NAME))
.unwrap();
let mut commands = parsing::parse_json(&json, controllers).unwrap();
assert!(commands.exec().is_ok());
assert!(path.exists());
assert!(fs::remove_dir(&path).is_ok());
}
#[test]
// TODO: need cpuset cgroup: make it more generic (or robust)
fn test_spawn_cpuset() {
let json = format!(
r#"
{{
"commands":[
{{
"command":"spawn",
"name":"{}",
"args":[
"cpuset"
],
"properties":{{
"cpuset.mems":"0",
"cpuset.cpus":"0"
}},
"cmd":"bash",
"cmd_args":[
"-c", "echo $(nproc) > {}"
]
}}
]
}}
"#,
SPAWN_CPUSET_NAME, SPAWN_CPUSET_RESULT_FILE
);
let controllers = Rc::new(configuration::sysfscontroller::get_sys_fs_controllers().unwrap());
let paths = controllers
.values()
.map(SysFsController::get_path)
.map(path::Path::to_path_buf)
.map(|path| path.join(MODIFY_NAME))
.collect::<Vec<_>>();
let mut commands = parsing::parse_json(&json, controllers).unwrap();
assert!(commands.exec().is_ok());
let result_path = path::Path::new(SPAWN_CPUSET_RESULT_FILE);
assert_eq!(fs::read_to_string(&result_path).unwrap().trim(), "1");
assert!(fs::remove_file(&result_path).is_ok());
assert!(paths.iter().all(|p| !p.exists()));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment