Skip to content

Commit 11c8b26

Browse files
committed
api: make ht_enabled optional
Signed-off-by: alindima <[email protected]>
1 parent 4f71574 commit 11c8b26

File tree

12 files changed

+66
-31
lines changed

12 files changed

+66
-31
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
by adding the network interface's ID to the `network_interfaces` field of PUT
5959
`/mmds/config` request's body.
6060
- Configuring `ht_enabled: true` on aarch64 via the API is forbidden.
61+
- `ht_enabled` field is now optional on PUT `/machine-config`, defaulting to
62+
`false`.
6163

6264
### Fixed
6365

docs/getting-started.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,7 @@ curl --unix-socket /tmp/firecracker.socket -i \
216216
-H 'Content-Type: application/json' \
217217
-d '{
218218
"vcpu_count": 2,
219-
"mem_size_mib": 1024,
220-
"ht_enabled": false
219+
"mem_size_mib": 1024
221220
}'
222221
```
223222

src/api_server/src/parsed_request.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,7 @@ pub(crate) mod tests {
788788
let mut connection = HttpConnection::new(receiver);
789789
let body = "{ \
790790
\"vcpu_count\": 0, \
791-
\"mem_size_mib\": 0, \
792-
\"ht_enabled\": false \
791+
\"mem_size_mib\": 0 \
793792
}";
794793
sender
795794
.write_all(http_request("PUT", "/machine-config", Some(&body)).as_bytes())
@@ -1009,8 +1008,7 @@ pub(crate) mod tests {
10091008
let mut connection = HttpConnection::new(receiver);
10101009
let body = "{ \
10111010
\"vcpu_count\": 0, \
1012-
\"mem_size_mib\": 0, \
1013-
\"ht_enabled\": false \
1011+
\"mem_size_mib\": 0 \
10141012
}";
10151013
sender
10161014
.write_all(http_request("PATCH", "/machine-config", Some(&body)).as_bytes())

src/api_server/src/request/machine_configuration.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,17 @@ pub(crate) fn parse_put_machine_config(body: &Body) -> Result<ParsedRequest, Err
2222
#[cfg(target_arch = "aarch64")]
2323
check_unsupported_fields(&vm_config)?;
2424

25-
if vm_config.vcpu_count.is_none()
26-
|| vm_config.mem_size_mib.is_none()
27-
|| vm_config.ht_enabled.is_none()
28-
{
25+
if vm_config.vcpu_count.is_none() {
26+
return Err(Error::Generic(
27+
StatusCode::BadRequest,
28+
"Missing mandatory field: `vcpu_count`.".to_string(),
29+
));
30+
}
31+
32+
if vm_config.mem_size_mib.is_none() {
2933
return Err(Error::Generic(
3034
StatusCode::BadRequest,
31-
"Missing mandatory fields.".to_string(),
35+
"Missing mandatory field: `mem_size_mib`.".to_string(),
3236
));
3337
}
3438

@@ -99,30 +103,39 @@ mod tests {
99103

100104
// 2. Test case for mandatory fields.
101105
let body = r#"{
102-
"mem_size_mib": 1024,
103-
"ht_enabled": false
106+
"mem_size_mib": 1024
104107
}"#;
105108
assert!(parse_put_machine_config(&Body::new(body)).is_err());
106109

107110
let body = r#"{
108-
"vcpu_count": 8,
109-
"ht_enabled": false
111+
"vcpu_count": 8
110112
}"#;
111113
assert!(parse_put_machine_config(&Body::new(body)).is_err());
112114

115+
// 3. Test case for success scenarios for both architectures.
113116
let body = r#"{
114117
"vcpu_count": 8,
115118
"mem_size_mib": 1024
116119
}"#;
117-
assert!(parse_put_machine_config(&Body::new(body)).is_err());
120+
let expected_config = VmConfig {
121+
vcpu_count: Some(8),
122+
mem_size_mib: Some(1024),
123+
ht_enabled: None,
124+
cpu_template: None,
125+
track_dirty_pages: false,
126+
};
127+
128+
match vmm_action_from_request(parse_put_machine_config(&Body::new(body)).unwrap()) {
129+
VmmAction::SetVmConfiguration(config) => assert_eq!(config, expected_config),
130+
_ => panic!("Test failed."),
131+
}
118132

119-
// 3. Test case a success scenario for both architectures.
120133
let body = r#"{
121134
"vcpu_count": 8,
122135
"mem_size_mib": 1024,
123136
"ht_enabled": false,
124137
"track_dirty_pages": true
125-
}"#;
138+
}"#;
126139
let expected_config = VmConfig {
127140
vcpu_count: Some(8),
128141
mem_size_mib: Some(1024),

src/api_server/swagger/firecracker.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,6 @@ definitions:
928928
Describes the number of vCPUs, memory size, Hyperthreading capabilities and
929929
the CPU template.
930930
required:
931-
- ht_enabled
932931
- mem_size_mib
933932
- vcpu_count
934933
properties:

src/vmm/src/resources.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,7 @@ mod tests {
609609
],
610610
"machine-config": {{
611611
"vcpu_count": 0,
612-
"mem_size_mib": 1024,
613-
"ht_enabled": false
612+
"mem_size_mib": 1024
614613
}}
615614
}}"#,
616615
kernel_file.as_path().to_str().unwrap(),
@@ -639,8 +638,7 @@ mod tests {
639638
],
640639
"machine-config": {{
641640
"vcpu_count": 2,
642-
"mem_size_mib": 0,
643-
"ht_enabled": false
641+
"mem_size_mib": 0
644642
}}
645643
}}"#,
646644
kernel_file.as_path().to_str().unwrap(),

tests/framework/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def build(self,
152152
response = vm.machine_cfg.put(
153153
vcpu_count=int(microvm_config['vcpu_count']),
154154
mem_size_mib=int(microvm_config['mem_size_mib']),
155-
ht_enabled=bool(microvm_config['ht_enabled']),
155+
ht_enabled=microvm_config['ht_enabled'],
156156
track_dirty_pages=diff_snapshots,
157157
cpu_template=cpu_template,
158158
)

tests/framework/microvm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ def serial_input(self, input_string):
634634
def basic_config(
635635
self,
636636
vcpu_count: int = 2,
637-
ht_enabled: bool = False,
637+
ht_enabled: bool = None,
638638
mem_size_mib: int = 256,
639639
add_root_device: bool = True,
640640
boot_args: str = None,

tests/integration_tests/functional/test_api.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,33 @@ def test_api_machine_config(test_microvm_with_api):
426426
)
427427
assert test_microvm.api_session.is_status_bad_request(response.status_code)
428428

429+
# Test missing vcpu_count.
430+
response = test_microvm.machine_cfg.put(
431+
mem_size_mib=128
432+
)
433+
assert test_microvm.api_session.is_status_bad_request(response.status_code)
434+
assert "Missing mandatory field: `vcpu_count`." in response.text
435+
436+
# Test missing mem_size_mib.
437+
response = test_microvm.machine_cfg.put(
438+
vcpu_count=2
439+
)
440+
assert test_microvm.api_session.is_status_bad_request(response.status_code)
441+
assert "Missing mandatory field: `mem_size_mib`." in response.text
442+
443+
# Test default ht_enabled value.
444+
response = test_microvm.machine_cfg.put(
445+
mem_size_mib=128,
446+
vcpu_count=1
447+
)
448+
assert test_microvm.api_session.is_status_no_content(
449+
response.status_code
450+
)
451+
452+
response = test_microvm.machine_cfg.get()
453+
assert test_microvm.api_session.is_status_ok(response.status_code)
454+
assert response.json()["ht_enabled"] is False
455+
429456
# Test that ht_enabled=True errors on ARM.
430457
response = test_microvm.machine_cfg.patch(
431458
ht_enabled=True
@@ -520,8 +547,11 @@ def test_api_machine_config(test_microvm_with_api):
520547
# Validate full vm configuration after patching machine config.
521548
response = test_microvm.full_cfg.get()
522549
assert test_microvm.api_session.is_status_ok(response.status_code)
523-
assert response.json()['machine-config']['vcpu_count'] == 2
524-
assert response.json()['machine-config']['mem_size_mib'] == 256
550+
json = response.json()
551+
assert json['machine-config']['vcpu_count'] == 2
552+
assert json['machine-config']['mem_size_mib'] == 256
553+
assert json['machine-config']['ht_enabled'] == (
554+
platform.machine() == "x86_64")
525555

526556

527557
def test_api_put_update_post_boot(test_microvm_with_api):
@@ -570,7 +600,6 @@ def test_api_put_update_post_boot(test_microvm_with_api):
570600

571601
response = test_microvm.machine_cfg.put(
572602
vcpu_count=4,
573-
ht_enabled=False,
574603
mem_size_mib=128
575604
)
576605
assert test_microvm.api_session.is_status_bad_request(response.status_code)

tests/integration_tests/functional/test_cpu_features.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ def test_cpu_template(test_microvm_with_api, network_config, cpu_template):
165165
response = test_microvm.machine_cfg.put(
166166
vcpu_count=1,
167167
mem_size_mib=256,
168-
ht_enabled=False,
169168
cpu_template=cpu_template,
170169
)
171170
assert test_microvm.api_session.is_status_no_content(response.status_code)

0 commit comments

Comments
 (0)