Skip to content

Commit

Permalink
Fix tests and reformat code
Browse files Browse the repository at this point in the history
Fix broken tests and reformat code, additionally removing TODOs.
Tests still fail, however this is expected as the API remains
unimplemented.

Signed-off-by: James Curtis <jxcurtis@amazon.co.uk>
  • Loading branch information
JamesC1305 committed Jun 11, 2024
1 parent d2d6d41 commit bf738f5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/firecracker/src/api_server/parsed_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ pub mod tests {
.unwrap();
connection.try_read().unwrap();
let req = connection.pop_parsed_request().unwrap();
ParsedRequest::try_from(&req).unwrap()
ParsedRequest::try_from(&req).unwrap();
}

#[test]
Expand Down
30 changes: 17 additions & 13 deletions src/firecracker/src/api_server/request/hotplug.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
use vmm::logger::{IncMetric, METRICS};

use vmm::vmm_config::hotplug::VcpuHotPlugConfig;

use super::{Body, StatusCode, Method};
use super::super::parsed_request::{ParsedRequest, RequestError};
use super::{Body, Method, StatusCode};

pub(crate) fn parse_put_hotplug(body: &Body, resource_type_from_path: Option<&str>) -> Result<ParsedRequest, RequestError> {
pub(crate) fn parse_put_hotplug(
body: &Body,
resource_type_from_path: Option<&str>,
) -> Result<ParsedRequest, RequestError> {
METRICS.put_api_requests.hotplug.inc();
match resource_type_from_path {
// TODO: Implement memory hotplug
// Memory hotplugging not implemented yet.
Some(resource) => match resource {
"vcpu" => parse_put_vcpu_hotplug(body),
_ => Err(RequestError::InvalidPathMethod(
Expand All @@ -22,9 +24,8 @@ pub(crate) fn parse_put_hotplug(body: &Body, resource_type_from_path: Option<&st
StatusCode::BadRequest,
"Missing hotplug resource type.".to_string(),
)),
}
}

}

fn parse_put_vcpu_hotplug(body: &Body) -> Result<ParsedRequest, RequestError> {
METRICS.hotplug.vcpu_hotplug_request_count.inc();
Expand All @@ -33,23 +34,23 @@ fn parse_put_vcpu_hotplug(body: &Body) -> Result<ParsedRequest, RequestError> {
err
})?;

Err(RequestError::Generic(StatusCode::BadRequest, "Placeholder".to_string()))
// API functionality not implemented yet.
}

#[cfg(test)]
mod tests {

use hotplug::{parse_put_hotplug, parse_put_vcpu_hotplug};
use vmm::logger::{IncMetric, METRICS};

use super::super::*;


#[test]
#[test]
fn test_parse_put_hotplug() {
// Case 1. Invalid resource type
parse_put_hotplug(&Body::new("invalid body"), Some("invalid")).unwrap_err();
// Case 2. No resource type

// Case 2. No resource type
parse_put_hotplug(&Body::new("invalid body"), None).unwrap_err();

// Case 3. vCPU Resource
Expand All @@ -61,7 +62,6 @@ mod tests {

#[test]
fn test_parse_put_vcpu_hotplug() {

// Case 1. invalid payload
parse_put_vcpu_hotplug(&Body::new("invalid")).unwrap_err();

Expand All @@ -81,6 +81,10 @@ mod tests {
let body = r#"{
"vcpu_count" : 8,
}"#;
assert!(METRICS.hotplug.vcpu_hotplug_request_count > 0 && METRICS.hotplug.vcpu_hotplug_request_fails == 0);
// 4 total requests, 3 of which are erroneous
assert!(
METRICS.hotplug.vcpu_hotplug_request_count.count() == 4
&& METRICS.hotplug.vcpu_hotplug_request_fails.count() == 3
);
}
}
1 change: 0 additions & 1 deletion src/vmm/src/logger/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,6 @@ impl VmmMetrics {
}
}


/// Metrics specific to hotplugging
#[derive(Debug, Default, Serialize)]
pub struct HotplugMetrics {
Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/vmm_config/hotplug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ pub const MAX_SUPPORTED_VCPUS: u8 = 32;
/// Errors associated with hot-plugging vCPUs
#[derive(Debug)]
pub enum VcpuHotPlugConfigError {
/// The number of vCPUs must be greater than 0, less than {MAX_SUPPORTED_VCPUS:} and must be 1 or an even number if SMT is enabled.
/// The number of vCPUs must be greater than 0, less than {MAX_SUPPORTED_VCPUS:} and must be 1
/// or an even number if SMT is enabled.
InvalidVcpuCount,
}

Expand All @@ -21,4 +22,3 @@ pub struct VcpuHotPlugConfig {
/// Number of vcpus to start.
pub vcpu_count: u8,
}

0 comments on commit bf738f5

Please sign in to comment.