Skip to content

Commit

Permalink
config: Consistently using net_config
Browse files Browse the repository at this point in the history
We were using the network config param as `net_config` inside the
`VMMConfig`, but the actual CLI parameter was called `net`. There were a
few places where this inconsistency was there. Now consistently using
`net_config` everywhere so that the CLI parem `--net` makes sense

Signed-off-by: Abhijit Gadgil <[email protected]>
  • Loading branch information
gabhijit committed Jan 22, 2021
1 parent 4fa75ac commit 97421ee
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
6 changes: 3 additions & 3 deletions src/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl CLI {
.memory_config(matches.value_of("memory"))
.kernel_config(matches.value_of("kernel"))
.vcpu_config(matches.value_of("vcpu"))
.network_config(matches.value_of("net"))
.net_config(matches.value_of("net"))
.block_config(matches.value_of("block"))
.build()
.map_err(|e| format!("{:?}", e))?)
Expand Down Expand Up @@ -233,7 +233,7 @@ mod tests {
memory_config: MemoryConfig { size_mib: 128 },
vcpu_config: VcpuConfig { num: 1 },
block_config: None,
network_config: None,
net_config: None,
}
);

Expand All @@ -249,7 +249,7 @@ mod tests {
memory_config: MemoryConfig { size_mib: 256 },
vcpu_config: VcpuConfig { num: 1 },
block_config: None,
network_config: None,
net_config: None,
}
);
}
Expand Down
18 changes: 9 additions & 9 deletions src/vmm/src/config/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,23 @@ impl Builder {
///
/// let vmmconfig = VMMConfig::builder()
/// .kernel_config(Some("path=/pat/to/bzImage") // Required for 'build' to succeed.
/// .network_config(Some("tap=tap0"))
/// .net_config(Some("tap=tap0"))
/// .build()
///
/// assert!(vmmconfig.is_ok())
///
/// assert_eq!(vmmconfig.unwrap().network_config, NetConfig { tap_name: "tap0"})
/// assert_eq!(vmmconfig.unwrap().net_config, NetConfig { tap_name: "tap0"})
///
/// ```
///
pub fn network_config<T>(self, network: Option<T>) -> Self
pub fn net_config<T>(self, net: Option<T>) -> Self
where
NetConfig: TryFrom<T>,
<NetConfig as TryFrom<T>>::Error: Into<ConversionError>,
{
match network {
match net {
Some(n) => self.and_then(|mut config| {
config.network_config = Some(TryFrom::try_from(n).map_err(Into::into)?);
config.net_config = Some(TryFrom::try_from(n).map_err(Into::into)?);
Ok(config)
}),
None => self,
Expand Down Expand Up @@ -326,22 +326,22 @@ mod tests {
#[test]
fn test_builder_net_config_none_default() {
let vmm_config = Builder::default()
.network_config(None as Option<&str>)
.net_config(None as Option<&str>)
.kernel_config(Some("path=bzImage"))
.build();
assert!(vmm_config.is_ok());
assert!(vmm_config.unwrap().network_config.is_none());
assert!(vmm_config.unwrap().net_config.is_none());
}

#[test]
fn test_builder_net_config_success() {
let vmm_config = Builder::default()
.network_config(Some("tap=tap0"))
.net_config(Some("tap=tap0"))
.kernel_config(Some("path=bzImage"))
.build();
assert!(vmm_config.is_ok(), "{:?}", vmm_config.err());
assert_eq!(
vmm_config.unwrap().network_config,
vmm_config.unwrap().net_config,
Some(NetConfig {
tap_name: "tap0".to_string()
})
Expand Down
38 changes: 19 additions & 19 deletions src/vmm/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub enum ConversionError {
/// Failed to parse the string representation for the vCPUs.
ParseVcpus(String),
/// Failed to parse the string representation for the network.
ParseNetwork(String),
ParseNet(String),
/// Failed to parse the string representation for the block.
ParseBlock(String),
}
Expand All @@ -45,8 +45,8 @@ impl ConversionError {
fn new_block<T: fmt::Display>(err: T) -> Self {
Self::ParseBlock(err.to_string())
}
fn new_network<T: fmt::Display>(err: T) -> Self {
Self::ParseNetwork(err.to_string())
fn new_net<T: fmt::Display>(err: T) -> Self {
Self::ParseNet(err.to_string())
}
}

Expand All @@ -64,8 +64,8 @@ impl fmt::Display for ConversionError {
ParseKernel(ref s) => write!(f, "Invalid input for kernel: {}", s),
ParseMemory(ref s) => write!(f, "Invalid input for memory: {}", s),
ParseVcpus(ref s) => write!(f, "Invalid input for vCPUs: {}", s),
ParseNetwork(ref s) => write!(f, "Invalid input for network: {}", s),
ParseBlock(ref s) => write!(f, "Invalid input for network: {}", s),
ParseNet(ref s) => write!(f, "Invalid input for network: {}", s),
ParseBlock(ref s) => write!(f, "Invalid input for block: {}", s),
}
}
}
Expand Down Expand Up @@ -201,12 +201,12 @@ impl TryFrom<&str> for NetConfig {

let tap_name = arg_parser
.value_of("tap")
.map_err(ConversionError::new_network)?
.ok_or_else(|| ConversionError::new_network("Missing required argument: tap"))?;
.map_err(ConversionError::new_net)?
.ok_or_else(|| ConversionError::new_net("Missing required argument: tap"))?;

arg_parser
.all_consumed()
.map_err(ConversionError::new_network)?;
.map_err(ConversionError::new_net)?;
Ok(NetConfig { tap_name })
}
}
Expand Down Expand Up @@ -247,7 +247,7 @@ pub struct VMMConfig {
/// Guest kernel configuration.
pub kernel_config: KernelConfig,
/// Network device configuration.
pub network_config: Option<NetConfig>,
pub net_config: Option<NetConfig>,
/// Block device configuration.
pub block_config: Option<BlockConfig>,
}
Expand Down Expand Up @@ -313,28 +313,28 @@ mod tests {
}

#[test]
fn test_network_config() {
let network_str = "tap=vmtap";
let network_cfg = NetConfig::try_from(network_str).unwrap();
fn test_net_config() {
let netcfg_str = "tap=vmtap";
let net_cfg = NetConfig::try_from(netcfg_str).unwrap();
let expected_cfg = NetConfig {
tap_name: "vmtap".to_string(),
};
assert_eq!(network_cfg, expected_cfg);
assert_eq!(net_cfg, expected_cfg);

// Test case: empty string error.
assert!(NetConfig::try_from("").is_err());

// Test case: empty tap name error.
let network_str = "tap=";
assert!(NetConfig::try_from(network_str).is_err());
let netcfg_str = "tap=";
assert!(NetConfig::try_from(netcfg_str).is_err());

// Test case: invalid string.
let network_str = "blah=blah";
assert!(NetConfig::try_from(network_str).is_err());
let netcfg_str = "blah=blah";
assert!(NetConfig::try_from(netcfg_str).is_err());

// Test case: unused parameters
let network_str = "tap=something,blah=blah";
assert!(NetConfig::try_from(network_str).is_err());
let netcfg_str = "tap=something,blah=blah";
assert!(NetConfig::try_from(netcfg_str).is_err());
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ mod tests {
},
vcpu_config: VcpuConfig { num: NUM_VCPUS },
block_config: None,
network_config: None,
net_config: None,
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/vmm/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn test_dummy_vmm_elf() {
memory_config: default_memory_config(),
vcpu_config: default_vcpu_config(),
block_config: None,
network_config: None,
net_config: None,
};
// Sanity check. Because the VMM runs in a separate process, if the file doesn't exist,
// all we see is a different exit code than 0.
Expand All @@ -59,7 +59,7 @@ fn test_dummy_vmm_bzimage() {
memory_config: default_memory_config(),
vcpu_config: default_vcpu_config(),
block_config: None,
network_config: None,
net_config: None,
};
assert!(vmm_config.kernel_config.path.as_path().exists());
run_vmm(pid, vmm_config);
Expand Down

0 comments on commit 97421ee

Please sign in to comment.