mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-29 04:04:45 +00:00
runtime-rs: modify the transfer to oci::Hooks
In this commit, we have done: * modify the tranfer process from grpc::Hooks to oci::Hooks, so the code can be more clean * add more tests for create_runtime, create_container, start_container hooks Signed-off-by: Yushuo <y-shuo@linux.alibaba.com>
This commit is contained in:
parent
2c4428ee02
commit
12cfad4858
@ -835,6 +835,45 @@ mod tests {
|
||||
Timeout: 10,
|
||||
..Default::default()
|
||||
}])),
|
||||
CreateRuntime: protobuf::RepeatedField::from(Vec::from([grpc::Hook {
|
||||
Path: String::from("createruntimepath"),
|
||||
Args: protobuf::RepeatedField::from(Vec::from([
|
||||
String::from("arg1"),
|
||||
String::from("arg2"),
|
||||
])),
|
||||
Env: protobuf::RepeatedField::from(Vec::from([
|
||||
String::from("env1"),
|
||||
String::from("env2"),
|
||||
])),
|
||||
Timeout: 10,
|
||||
..Default::default()
|
||||
}])),
|
||||
CreateContainer: protobuf::RepeatedField::from(Vec::from([grpc::Hook {
|
||||
Path: String::from("createcontainerpath"),
|
||||
Args: protobuf::RepeatedField::from(Vec::from([
|
||||
String::from("arg1"),
|
||||
String::from("arg2"),
|
||||
])),
|
||||
Env: protobuf::RepeatedField::from(Vec::from([
|
||||
String::from("env1"),
|
||||
String::from("env2"),
|
||||
])),
|
||||
Timeout: 10,
|
||||
..Default::default()
|
||||
}])),
|
||||
StartContainer: protobuf::RepeatedField::from(Vec::from([grpc::Hook {
|
||||
Path: String::from("startcontainerpath"),
|
||||
Args: protobuf::RepeatedField::from(Vec::from([
|
||||
String::from("arg1"),
|
||||
String::from("arg2"),
|
||||
])),
|
||||
Env: protobuf::RepeatedField::from(Vec::from([
|
||||
String::from("env1"),
|
||||
String::from("env2"),
|
||||
])),
|
||||
Timeout: 10,
|
||||
..Default::default()
|
||||
}])),
|
||||
..Default::default()
|
||||
},
|
||||
result: oci::Hooks {
|
||||
@ -864,7 +903,24 @@ mod tests {
|
||||
env: Vec::from([String::from("env1"), String::from("env2")]),
|
||||
timeout: Some(10),
|
||||
}]),
|
||||
..Default::default()
|
||||
create_runtime: Vec::from([oci::Hook {
|
||||
path: String::from("createruntimepath"),
|
||||
args: Vec::from([String::from("arg1"), String::from("arg2")]),
|
||||
env: Vec::from([String::from("env1"), String::from("env2")]),
|
||||
timeout: Some(10),
|
||||
}]),
|
||||
create_container: Vec::from([oci::Hook {
|
||||
path: String::from("createcontainerpath"),
|
||||
args: Vec::from([String::from("arg1"), String::from("arg2")]),
|
||||
env: Vec::from([String::from("env1"), String::from("env2")]),
|
||||
timeout: Some(10),
|
||||
}]),
|
||||
start_container: Vec::from([oci::Hook {
|
||||
path: String::from("startcontainerpath"),
|
||||
args: Vec::from([String::from("arg1"), String::from("arg2")]),
|
||||
env: Vec::from([String::from("env1"), String::from("env2")]),
|
||||
timeout: Some(10),
|
||||
}]),
|
||||
},
|
||||
},
|
||||
TestData {
|
||||
@ -897,6 +953,45 @@ mod tests {
|
||||
Timeout: 10,
|
||||
..Default::default()
|
||||
}])),
|
||||
CreateRuntime: protobuf::RepeatedField::from(Vec::from([grpc::Hook {
|
||||
Path: String::from("createruntimepath"),
|
||||
Args: protobuf::RepeatedField::from(Vec::from([
|
||||
String::from("arg1"),
|
||||
String::from("arg2"),
|
||||
])),
|
||||
Env: protobuf::RepeatedField::from(Vec::from([
|
||||
String::from("env1"),
|
||||
String::from("env2"),
|
||||
])),
|
||||
Timeout: 10,
|
||||
..Default::default()
|
||||
}])),
|
||||
CreateContainer: protobuf::RepeatedField::from(Vec::from([grpc::Hook {
|
||||
Path: String::from("createcontainerpath"),
|
||||
Args: protobuf::RepeatedField::from(Vec::from([
|
||||
String::from("arg1"),
|
||||
String::from("arg2"),
|
||||
])),
|
||||
Env: protobuf::RepeatedField::from(Vec::from([
|
||||
String::from("env1"),
|
||||
String::from("env2"),
|
||||
])),
|
||||
Timeout: 10,
|
||||
..Default::default()
|
||||
}])),
|
||||
StartContainer: protobuf::RepeatedField::from(Vec::from([grpc::Hook {
|
||||
Path: String::from("startcontainerpath"),
|
||||
Args: protobuf::RepeatedField::from(Vec::from([
|
||||
String::from("arg1"),
|
||||
String::from("arg2"),
|
||||
])),
|
||||
Env: protobuf::RepeatedField::from(Vec::from([
|
||||
String::from("env1"),
|
||||
String::from("env2"),
|
||||
])),
|
||||
Timeout: 10,
|
||||
..Default::default()
|
||||
}])),
|
||||
..Default::default()
|
||||
},
|
||||
result: oci::Hooks {
|
||||
@ -913,7 +1008,24 @@ mod tests {
|
||||
env: Vec::from([String::from("env1"), String::from("env2")]),
|
||||
timeout: Some(10),
|
||||
}]),
|
||||
..Default::default()
|
||||
create_runtime: Vec::from([oci::Hook {
|
||||
path: String::from("createruntimepath"),
|
||||
args: Vec::from([String::from("arg1"), String::from("arg2")]),
|
||||
env: Vec::from([String::from("env1"), String::from("env2")]),
|
||||
timeout: Some(10),
|
||||
}]),
|
||||
create_container: Vec::from([oci::Hook {
|
||||
path: String::from("createcontainerpath"),
|
||||
args: Vec::from([String::from("arg1"), String::from("arg2")]),
|
||||
env: Vec::from([String::from("env1"), String::from("env2")]),
|
||||
timeout: Some(10),
|
||||
}]),
|
||||
start_container: Vec::from([oci::Hook {
|
||||
path: String::from("startcontainerpath"),
|
||||
args: Vec::from([String::from("arg1"), String::from("arg2")]),
|
||||
env: Vec::from([String::from("env1"), String::from("env2")]),
|
||||
timeout: Some(10),
|
||||
}]),
|
||||
},
|
||||
},
|
||||
];
|
||||
|
@ -973,30 +973,29 @@ impl From<crate::oci::Hook> for oci::Hook {
|
||||
|
||||
impl From<crate::oci::Hooks> for oci::Hooks {
|
||||
fn from(mut from: crate::oci::Hooks) -> Self {
|
||||
let mut prestart = Vec::new();
|
||||
for hook in from.take_Prestart().to_vec() {
|
||||
prestart.push(hook.into())
|
||||
}
|
||||
let mut create_runtime = Vec::new();
|
||||
for hook in from.take_CreateRuntime().to_vec() {
|
||||
create_runtime.push(hook.into())
|
||||
}
|
||||
let mut create_container = Vec::new();
|
||||
for hook in from.take_CreateContainer().to_vec() {
|
||||
create_container.push(hook.into())
|
||||
}
|
||||
let mut start_container = Vec::new();
|
||||
for hook in from.take_StartContainer().to_vec() {
|
||||
start_container.push(hook.into())
|
||||
}
|
||||
let mut poststart = Vec::new();
|
||||
for hook in from.take_Poststart().to_vec() {
|
||||
poststart.push(hook.into());
|
||||
}
|
||||
let mut poststop = Vec::new();
|
||||
for hook in from.take_Poststop().to_vec() {
|
||||
poststop.push(hook.into());
|
||||
}
|
||||
let prestart = from.take_Prestart().into_iter().map(|i| i.into()).collect();
|
||||
let create_runtime = from
|
||||
.take_CreateRuntime()
|
||||
.into_iter()
|
||||
.map(|i| i.into())
|
||||
.collect();
|
||||
let create_container = from
|
||||
.take_CreateContainer()
|
||||
.into_iter()
|
||||
.map(|i| i.into())
|
||||
.collect();
|
||||
let start_container = from
|
||||
.take_StartContainer()
|
||||
.into_iter()
|
||||
.map(|i| i.into())
|
||||
.collect();
|
||||
let poststart = from
|
||||
.take_Poststart()
|
||||
.into_iter()
|
||||
.map(|i| i.into())
|
||||
.collect();
|
||||
let poststop = from.take_Poststop().into_iter().map(|i| i.into()).collect();
|
||||
|
||||
oci::Hooks {
|
||||
prestart,
|
||||
create_runtime,
|
||||
|
Loading…
Reference in New Issue
Block a user