Skip to content

api_server: convert the VmmActionError to a JSON object #1547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/api_server/src/parsed_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ impl ParsedRequest {
vmm_action_error
);
let mut response = Response::new(Version::Http11, StatusCode::BadRequest);
response.set_body(Body::new(vmm_action_error.to_string()));
response.set_body(Body::new(ApiServer::json_fault_message(
vmm_action_error.to_string(),
)));
response
}
}
Expand Down Expand Up @@ -465,18 +467,20 @@ mod tests {
assert_eq!(&buf[..], expected_response.as_bytes());

// Error.
let mut buf: [u8; 160] = [0; 160];
let response = ParsedRequest::convert_to_response(Err(VmmActionError::from(
StartMicrovmError::EventFd,
)));
let error = VmmActionError::from(StartMicrovmError::EventFd);
let mut buf: [u8; 185] = [0; 185];
let json = ApiServer::json_fault_message(error.to_string());
let response = ParsedRequest::convert_to_response(Err(error));
assert!(response.write_all(&mut buf.as_mut()).is_ok());

let expected_response = format!(
"HTTP/1.1 400 \r\n\
Server: Firecracker API\r\n\
Connection: keep-alive\r\n\
Content-Type: application/json\r\n\
Content-Length: 42\r\n\r\n{}",
VmmActionError::from(StartMicrovmError::EventFd).to_string()
Content-Length: {}\r\n\r\n{}",
json.len(),
json,
);
assert_eq!(&buf[..], expected_response.as_bytes());
}
Expand Down
17 changes: 17 additions & 0 deletions tests/integration_tests/functional/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,23 @@ def test_error_logs(test_microvm_with_ssh):
)


def test_log_config_failure(test_microvm_with_api):
"""Check passing invalid FIFOs is detected and reported as an error."""
microvm = test_microvm_with_api
microvm.spawn()
microvm.basic_config()

response = microvm.logger.put(
log_fifo='invalid log fifo',
metrics_fifo='invalid metrics fifo',
level='Info',
show_level=True,
show_log_origin=True,
)
assert microvm.api_session.is_status_bad_request(response.status_code)
assert response.json()['fault_message']


def log_file_contains_strings(log_fifo, string_list):
"""Check if the log file contains all strings in string_list.

Expand Down