Skip to content

Commit

Permalink
add deprecation case for vsock_id in integ tests
Browse files Browse the repository at this point in the history
Signed-off-by: George Pisaltu <gpl@amazon.com>
  • Loading branch information
georgepisaltu committed Oct 28, 2021
1 parent e8d2070 commit 2644c44
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 21 deletions.
7 changes: 4 additions & 3 deletions tests/framework/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,14 +752,15 @@ def patch(self, **args):

@staticmethod
def create_json(
vsock_id,
guest_cid,
uds_path):
uds_path,
vsock_id=None):
"""Create the json for the vsock specific API request."""
datax = {
'vsock_id': vsock_id,
'guest_cid': guest_cid,
'uds_path': uds_path
}
if vsock_id:
datax['vsock_id'] = vsock_id

return datax
83 changes: 65 additions & 18 deletions tests/integration_tests/functional/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
import host_tools.drive as drive_tools
import host_tools.network as net_tools

from conftest import _test_images_s3_bucket
from framework.artifacts import ArtifactCollection
from framework.builder import MicrovmBuilder
from framework.utils import get_firecracker_version_from_toml

MEM_LIMIT = 1000000000


Expand Down Expand Up @@ -940,52 +945,96 @@ def test_api_version(test_microvm_with_api):
assert out.strip()[1:] == preboot_response.json()['firecracker_version']


def test_api_vsock(test_microvm_with_api):
def test_api_vsock(bin_cloner_path):
"""
Test vsock related API commands.
@type: functional
"""
test_microvm = test_microvm_with_api
test_microvm.spawn()
test_microvm.basic_config()
builder = MicrovmBuilder(bin_cloner_path)
artifacts = ArtifactCollection(_test_images_s3_bucket())
# Fetch 0.25 and older firecracker binaries.
# Create a vsock device with each FC binary
# artifact.
firecracker_artifacts = artifacts.firecrackers(
# v1.0.0 deprecated `vsock_id`.
min_version="0.25.0",
max_version=get_firecracker_version_from_toml())

for firecracker in firecracker_artifacts:
firecracker.download()
jailer = firecracker.jailer()
jailer.download()

vm_instance = builder.build_vm_nano(
fc_binary=firecracker.local_path(),
jailer_binary=jailer.local_path())

new_version = firecracker.base_name()[1] != '0'
_test_vsock(vm_instance.vm, new_version)


def _test_vsock(vm, new_version):
# vsock_id was mandatory in older versions.
if not new_version:
response = vm.vsock.put(
guest_cid=15,
uds_path='vsock.sock'
)
assert vm.api_session.is_status_bad_request(response.status_code)

response = test_microvm.vsock.put(
# Check PUT request. Although vsock_id is deprecated, it must still work.
response = vm.vsock.put(
vsock_id='vsock1',
guest_cid=15,
uds_path='vsock.sock'
)
assert test_microvm.api_session.is_status_no_content(response.status_code)
assert vm.api_session.is_status_no_content(response.status_code)
if new_version:
assert response.headers['deprecation']

# Updating an existing vsock is currently fine.
response = test_microvm.vsock.put(
response = vm.vsock.put(
vsock_id='vsock1',
guest_cid=166,
uds_path='vsock.sock'
)
assert test_microvm.api_session.is_status_no_content(response.status_code)
assert vm.api_session.is_status_no_content(response.status_code)
if new_version:
assert response.headers['deprecation']

# Not using vsock_id in new versions should work.
if new_version:
response = vm.vsock.put(
guest_cid=166,
uds_path='vsock.sock'
)
assert vm.api_session.is_status_no_content(response.status_code)
assert 'deprecation' not in response.headers

# No other vsock action is allowed after booting the VM.
test_microvm.start()
vm.start()

# Updating an existing vsock should not be fine at this point.
response = test_microvm.vsock.put(
response = vm.vsock.put(
vsock_id='vsock1',
guest_cid=17,
uds_path='vsock.sock'
)
assert test_microvm.api_session.is_status_bad_request(response.status_code)
assert vm.api_session.is_status_bad_request(response.status_code)
if new_version:
assert response.headers['deprecation']

# Attaching a new vsock device should not be fine at this point.
response = test_microvm.vsock.put(
response = vm.vsock.put(
vsock_id='vsock3',
guest_cid=18,
uds_path='vsock.sock'
)
assert test_microvm.api_session.is_status_bad_request(response.status_code)

response = test_microvm.vm.patch(state='Paused')
assert test_microvm.api_session.is_status_no_content(response.status_code)
assert vm.api_session.is_status_bad_request(response.status_code)
if new_version:
assert response.headers['deprecation']
vm.kill()


def test_api_balloon(test_microvm_with_api):
Expand Down Expand Up @@ -1127,13 +1176,11 @@ def test_get_full_config(test_microvm_with_api):

# Add a vsock device.
response = test_microvm.vsock.put(
vsock_id='vsock',
guest_cid=15,
uds_path='vsock.sock'
)
assert test_microvm.api_session.is_status_no_content(response.status_code)
expected_cfg['vsock'] = {
'vsock_id': 'vsock',
'guest_cid': 15,
'uds_path': 'vsock.sock'
}
Expand Down

0 comments on commit 2644c44

Please sign in to comment.