mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Add parsing logic for zone_updates
This commit adds support for parsing `zone_updates` from the CLI for the live migration and restore paths. Signed-off-by: Pascal Scholz <pascal.scholz@cyberus-technology.de> On-behalf-of: SAP pascal.scholz@sap.
This commit is contained in:
committed by
Rob Bradford
parent
ad3790a0ea
commit
d419338a47
@@ -426,7 +426,7 @@ impl<T: TryFrom<u64>> Parseable for IntegerList<T> {
|
||||
|
||||
/// Types that can appear as the second element of a [`Tuple`] pair.
|
||||
///
|
||||
/// Implemented for `u64`, `Vec<u8>`, `Vec<u64>`, and `Vec<usize>`.
|
||||
/// Implemented for `u32`, `u64`, `Vec<u8>`, `Vec<u64>`, and `Vec<usize>`.
|
||||
pub trait TupleValue {
|
||||
/// Parses the value portion of a `key@value` tuple element.
|
||||
fn parse_value(input: &str) -> Result<Self, TupleError>
|
||||
@@ -440,6 +440,12 @@ impl TupleValue for u64 {
|
||||
}
|
||||
}
|
||||
|
||||
impl TupleValue for u32 {
|
||||
fn parse_value(input: &str) -> Result<Self, TupleError> {
|
||||
input.parse::<u32>().map_err(TupleError::InvalidInteger)
|
||||
}
|
||||
}
|
||||
|
||||
impl TupleValue for Vec<u8> {
|
||||
fn parse_value(input: &str) -> Result<Self, TupleError> {
|
||||
Ok(IntegerList::<u8>::from_str(input)
|
||||
@@ -1026,6 +1032,20 @@ mod unit_tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tuple_parse_u32_value() {
|
||||
use std::num::IntErrorKind;
|
||||
let t = Tuple::<String, u32>::from_str("foo@42").unwrap();
|
||||
assert_eq!(t, Tuple("foo".to_owned(), 42));
|
||||
let t = Tuple::<String, u32>::from_str("foo@0").unwrap();
|
||||
assert_eq!(t, Tuple("foo".to_owned(), 0));
|
||||
let e = Tuple::<String, u32>::from_str("foo@-1").unwrap_err();
|
||||
assert!(
|
||||
matches!(e, TupleError::InvalidInteger(ref e) if *e.kind() == IntErrorKind::InvalidDigit),
|
||||
"Expected \"InvalidInteger(ParseIntError(kind: InvalidDigit))\"; got \"{e:?}\"",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_split_commas_unbalanced_bracket() {
|
||||
split_commas("[a,b").unwrap_err();
|
||||
|
||||
Reference in New Issue
Block a user