Path: blob/main/tests/integration_tests/functional/test_max_devices.py
1958 views
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.1# SPDX-License-Identifier: Apache-2.02"""Tests scenario for adding the maximum number of devices to a microVM."""34import platform5import pytest6import host_tools.network as net_tools78# IRQs are available from 5 to 23, so the maximum number of devices9# supported at the same time is 19.10MAX_DEVICES_ATTACHED = 19111213@pytest.mark.skipif(14platform.machine() != "x86_64",15reason="Firecracker supports 24 IRQs on x86_64."16)17def test_attach_maximum_devices(test_microvm_with_ssh, network_config):18"""Test attaching maximum number of devices to the microVM."""19test_microvm = test_microvm_with_ssh20test_microvm.spawn()2122# Set up a basic microVM.23test_microvm.basic_config()2425# Add (`MAX_DEVICES_ATTACHED` - 1) devices because the rootfs26# has already been configured in the `basic_config()`function.27guest_ips = []28for i in range(MAX_DEVICES_ATTACHED - 1):29# Create tap before configuring interface.30_tap, _host_ip, guest_ip = test_microvm.ssh_network_config(31network_config,32str(i)33)34guest_ips.append(guest_ip)3536test_microvm.start()3738# Test that network devices attached are operational.39for i in range(MAX_DEVICES_ATTACHED - 1):40test_microvm.ssh_config['hostname'] = guest_ips[i]41ssh_connection = net_tools.SSHConnection(test_microvm.ssh_config)42# Verify if guest can run commands.43exit_code, _, _ = ssh_connection.execute_command("sync")44assert exit_code == 0454647@pytest.mark.skipif(48platform.machine() != "x86_64",49reason="Firecracker supports 24 IRQs on x86_64."50)51def test_attach_too_many_devices(test_microvm_with_ssh, network_config):52"""Test attaching to a microVM more devices than available IRQs."""53test_microvm = test_microvm_with_ssh54test_microvm.spawn()5556# Set up a basic microVM.57test_microvm.basic_config()5859# Add `MAX_DEVICES_ATTACHED` network devices on top of the60# already configured rootfs.61for i in range(MAX_DEVICES_ATTACHED):62# Create tap before configuring interface.63_tap, _host_ip, _guest_ip = test_microvm.ssh_network_config(64network_config,65str(i)66)6768# Attempting to start a microVM with more than69# `MAX_DEVICES_ATTACHED` devices should fail.70response = test_microvm.actions.put(action_type='InstanceStart')71assert test_microvm.api_session.is_status_bad_request(response.status_code)72assert "no more IRQs are available" in response.text737475