Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/firecracker
Path: blob/main/tests/integration_tests/functional/test_max_devices.py
1958 views
1
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
# SPDX-License-Identifier: Apache-2.0
3
"""Tests scenario for adding the maximum number of devices to a microVM."""
4
5
import platform
6
import pytest
7
import host_tools.network as net_tools
8
9
# IRQs are available from 5 to 23, so the maximum number of devices
10
# supported at the same time is 19.
11
MAX_DEVICES_ATTACHED = 19
12
13
14
@pytest.mark.skipif(
15
platform.machine() != "x86_64",
16
reason="Firecracker supports 24 IRQs on x86_64."
17
)
18
def test_attach_maximum_devices(test_microvm_with_ssh, network_config):
19
"""Test attaching maximum number of devices to the microVM."""
20
test_microvm = test_microvm_with_ssh
21
test_microvm.spawn()
22
23
# Set up a basic microVM.
24
test_microvm.basic_config()
25
26
# Add (`MAX_DEVICES_ATTACHED` - 1) devices because the rootfs
27
# has already been configured in the `basic_config()`function.
28
guest_ips = []
29
for i in range(MAX_DEVICES_ATTACHED - 1):
30
# Create tap before configuring interface.
31
_tap, _host_ip, guest_ip = test_microvm.ssh_network_config(
32
network_config,
33
str(i)
34
)
35
guest_ips.append(guest_ip)
36
37
test_microvm.start()
38
39
# Test that network devices attached are operational.
40
for i in range(MAX_DEVICES_ATTACHED - 1):
41
test_microvm.ssh_config['hostname'] = guest_ips[i]
42
ssh_connection = net_tools.SSHConnection(test_microvm.ssh_config)
43
# Verify if guest can run commands.
44
exit_code, _, _ = ssh_connection.execute_command("sync")
45
assert exit_code == 0
46
47
48
@pytest.mark.skipif(
49
platform.machine() != "x86_64",
50
reason="Firecracker supports 24 IRQs on x86_64."
51
)
52
def test_attach_too_many_devices(test_microvm_with_ssh, network_config):
53
"""Test attaching to a microVM more devices than available IRQs."""
54
test_microvm = test_microvm_with_ssh
55
test_microvm.spawn()
56
57
# Set up a basic microVM.
58
test_microvm.basic_config()
59
60
# Add `MAX_DEVICES_ATTACHED` network devices on top of the
61
# already configured rootfs.
62
for i in range(MAX_DEVICES_ATTACHED):
63
# Create tap before configuring interface.
64
_tap, _host_ip, _guest_ip = test_microvm.ssh_network_config(
65
network_config,
66
str(i)
67
)
68
69
# Attempting to start a microVM with more than
70
# `MAX_DEVICES_ATTACHED` devices should fail.
71
response = test_microvm.actions.put(action_type='InstanceStart')
72
assert test_microvm.api_session.is_status_bad_request(response.status_code)
73
assert "no more IRQs are available" in response.text
74
75