Skip to content

api: Added GET method for machine-config #242

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

Conversation

andreeaflorescu
Copy link
Member

Testing Done

Build

cargo build
cargo build --release
cargo fmt --all
sudo env "PATH=$PATH" cargo test --all

Integration Tests

Test1a get machine-config; Should output vcpu_count: 1, mem_size: 128
HTTP/1.1 200 OK
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 27 Apr 2018 08:33:51 GMT

{ "vcpu_count": 1, "mem_size_mib": 128 }

=======================================================
Test1 setting the vCPU to 2; Should output Updated
HTTP/1.1 204 No Content
Date: Fri, 27 Apr 2018 08:33:51 GMT

=======================================================
Test1a get machine-config; Should output vcpu_count: 2, mem_size: 128
HTTP/1.1 200 OK
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 27 Apr 2018 08:33:51 GMT

{ "vcpu_count": 2, "mem_size_mib": 128 }

=======================================================
Test1 setting the vCPU to 3; Should output Error (The cpuid is not an even number) - EXPECTED TO FAIL NOW
HTTP/1.1 204 No Content
Date: Fri, 27 Apr 2018 08:33:51 GMT

=======================================================
Test2 setting the vCPU to -1; Should output Bad Request
HTTP/1.1 400 Bad Request
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 27 Apr 2018 08:33:51 GMT

{
"fault_message": "invalid value: integer -1, expected u8 at line 1 column 18"
}

=======================================================
Test3 setting the vCPU to string; Should output Bad Request
HTTP/1.1 400 Bad Request
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 27 Apr 2018 08:33:51 GMT

{
"fault_message": "invalid type: string "str", expected u8 at line 1 column 21"
}

=======================================================
Test3a get machine-config; Should output vcpu_count: 2 (this should be 2 in the future), mem_size: 128
HTTP/1.1 200 OK
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 27 Apr 2018 08:33:51 GMT

{ "vcpu_count": 3, "mem_size_mib": 128 }

=======================================================
Test4 setting the memory size to 256; Should output Updated
HTTP/1.1 204 No Content
Date: Fri, 27 Apr 2018 08:33:51 GMT

=======================================================
Test5 setting the memory size to -1; Should output Bad Request
HTTP/1.1 400 Bad Request
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 27 Apr 2018 08:33:51 GMT

{
"fault_message": "invalid value: integer -1, expected usize at line 1 column 20"
}

=======================================================
Test6 setting the memory size to string; Should output Bad Request
HTTP/1.1 400 Bad Request
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 27 Apr 2018 08:33:51 GMT

{
"fault_message": "invalid type: string "str", expected usize at line 1 column 23"
}

=======================================================
Test7 send request with empty body; Should output Bad Request
HTTP/1.1 204 No Content
Date: Fri, 27 Apr 2018 08:33:51 GMT

=======================================================
Test8 send request with both memory and vcpu configuration; Should output Updated
HTTP/1.1 204 No Content
Date: Fri, 27 Apr 2018 08:33:51 GMT

=======================================================
Test9 send request with vCPU set to 0; Should output BadRequest
HTTP/1.1 400 Bad Request
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 27 Apr 2018 08:33:51 GMT

{
"fault_message": "The vCPU number is invalid!"
}

=======================================================
Test9 send request with memory set to 0; Should output BadRequest
HTTP/1.1 400 Bad Request
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 27 Apr 2018 08:33:51 GMT

{
"fault_message": "The memory size (MiB) is invalid!"
}

@acatangiu
Copy link
Contributor

Please update the swagger files as well to define this API.

"machine-config" => {
match v[1..].len() {
0 if is_get => Ok(serde_json::from_slice::<request::MachineConfigurationBody>(
body,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a body on the GET request?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted it, check the new PR: #248

@@ -299,6 +300,18 @@ impl Default for VirtualMachineConfig {
}
}

impl GenerateResponse for VirtualMachineConfig {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote for having this block of code in "api_server/" rather than "vmm/". It's common to implement a trait for an object in a different place/crate than the object definition.
I believe vmm is already linked in api_server.
This also helps us avoid hyper dependencies in vmm while also keeping HTTP/API-related code contained to api_server crate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a shared crate so this code is not in the VMM any more: #248

@andreeaflorescu andreeaflorescu deleted the get_machine_config branch May 8, 2018 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants