agent/device: Remove unnecessary check for empty container_path

update_spec_devices() explicitly checks for being called with an empty
container path and fails.  We have a unit test to verify this behaviour.

But while an empty container_path probably does mean something has gone
wrong elsewhere, that's also true of any number of other bad paths.  Having
an empty string here doesn't prevent what we're doing in this function
making sense - we can compare it to the strings in the OCI spec perfectly
well (though more likely we simply won't find it there).

So, there's no real reason to check this one particular odd case.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2021-11-05 16:37:22 +11:00
parent c855a312f0
commit 89ff700038

View File

@ -522,12 +522,6 @@ fn update_spec_devices(spec: &mut Spec, updates: HashMap<&str, DevUpdate>) -> Re
}
for (container_path, update) in updates {
// If no container_path is provided, we won't be able to match and
// update the device in the OCI spec device list. This is an error.
if container_path.is_empty() {
return Err(anyhow!("Container path cannot be empty for device"));
}
info!(
sl!(),
"update_spec_devices() considering device";
@ -837,20 +831,9 @@ mod tests {
let update = DevNumUpdate::from_vm_path("");
assert!(update.is_err());
// container_path empty
let container_path = "";
let vm_path = "/dev/null";
let res = update_spec_devices(
&mut spec,
HashMap::from_iter(vec![(
container_path,
DevNumUpdate::from_vm_path(vm_path).unwrap().into(),
)]),
);
assert!(res.is_err());
// linux is empty
let container_path = "/dev/null";
let vm_path = "/dev/null";
let res = update_spec_devices(
&mut spec,
HashMap::from_iter(vec![(