Skip to content

Commit 9c26e78

Browse files
Alexandra Iordachealxiord
Alexandra Iordache
authored andcommitted
tests: integration tests for drive rescan
Signed-off-by: Alexandra Iordache <[email protected]>
1 parent 7375265 commit 9c26e78

File tree

2 files changed

+117
-4
lines changed

2 files changed

+117
-4
lines changed

tests/functional/test_api.py

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,18 @@ def test_api_put_update_post_boot(test_microvm_with_api):
285285
""" Network interface update is not allowed after boot."""
286286
assert(not test_microvm.api_session.is_good_response(response.status_code))
287287

288-
"""
289-
TODO: Right now, PUT on block device triggers a rescan. After we properly
290-
implement the rescan, we have to also check that PUT on /drives fails.
291-
"""
288+
response = test_microvm.api_session.put(
289+
test_microvm.blk_cfg_url + '/rootfs',
290+
json={
291+
'drive_id': 'rootfs',
292+
'path_on_host': test_microvm.slot.rootfs_file,
293+
'is_root_device': True,
294+
'permissions': 'rw',
295+
'state': 'Attached'
296+
}
297+
)
298+
""" Block device update is not allowed after boot."""
299+
assert(not test_microvm.api_session.is_good_response(response.status_code))
292300

293301

294302
def test_rate_limiters_api_config(test_microvm_with_api):
@@ -689,3 +697,50 @@ def test_api_unknown_fields(test_microvm_with_api):
689697
}
690698
)
691699
assert response.status_code == 400
700+
701+
702+
def test_api_actions(test_microvm_with_api):
703+
"""
704+
Tests PUT requests to /actions, other than InstanceStart and InstanceHalt.
705+
"""
706+
707+
test_microvm = test_microvm_with_api
708+
test_microvm.basic_config()
709+
"""
710+
Sets up the microVM with 2 vCPUs, 256 MiB of RAM, 1 network iface and
711+
a root file system with the rw permission.
712+
"""
713+
714+
test_microvm.put_default_scratch_device()
715+
716+
response = test_microvm.api_session.put(
717+
test_microvm.actions_url,
718+
json={
719+
'action_type': 'BlockDeviceRescan',
720+
'payload': 'scratch',
721+
}
722+
)
723+
""" Rescan operations before the guest boots are not allowed. """
724+
assert(not test_microvm.api_session.is_good_response(response.status_code))
725+
726+
test_microvm.start()
727+
728+
response = test_microvm.api_session.put(
729+
test_microvm.actions_url,
730+
json={
731+
'action_type': 'BlockDeviceRescan',
732+
'payload': 'scratch',
733+
}
734+
)
735+
""" Rescan operations after the guest boots are allowed. """
736+
assert(test_microvm.api_session.is_good_response(response.status_code))
737+
738+
response = test_microvm.api_session.put(
739+
test_microvm.actions_url,
740+
json={
741+
'action_type': 'BlockDeviceRescan',
742+
'payload': 'foobar',
743+
}
744+
)
745+
""" Rescan operations on non-existent drives are not allowed. """
746+
assert(not test_microvm.api_session.is_good_response(response.status_code))

tests/functional/test_drives.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
Tests that ensure the correctness of operations on /drives resources from the
3+
guest side.
4+
"""
5+
6+
from host_tools.network import SSHConnection
7+
8+
9+
def test_rescan(test_microvm_with_ssh, network_config):
10+
"""
11+
Tests that triggering a block device rescan makes the guest pick up any
12+
changes to the block device's size.
13+
"""
14+
15+
test_microvm = test_microvm_with_ssh
16+
17+
test_microvm.basic_config(net_iface_count=0)
18+
"""
19+
Sets up the microVM with 1 vCPUs, 256 MiB of RAM, 0 network ifaces and
20+
a root file system with the rw permission. The network interface is
21+
added after we get an unique MAC and IP.
22+
"""
23+
test_microvm.basic_network_config(network_config)
24+
25+
""" Adds a scratch block device. """
26+
test_microvm.put_default_scratch_device()
27+
28+
test_microvm.start()
29+
30+
ssh_connection = SSHConnection(test_microvm.slot.ssh_config)
31+
32+
_check_scratch_size(ssh_connection, test_microvm.slot.sizeof_fsfile('scratch'))
33+
34+
test_microvm.slot.resize_fsfile('scratch', 512)
35+
""" Resizes the filesystem file from 256 MiB (default) to 512 MiB."""
36+
37+
response = test_microvm.api_session.put(
38+
test_microvm.actions_url,
39+
json={
40+
'action_type': 'BlockDeviceRescan',
41+
'payload': 'scratch',
42+
}
43+
)
44+
""" Rescan operations after the guest boots are allowed. """
45+
assert(test_microvm.api_session.is_good_response(response.status_code))
46+
47+
_check_scratch_size(ssh_connection, test_microvm.slot.sizeof_fsfile('scratch'))
48+
49+
ssh_connection.close()
50+
51+
52+
def _check_scratch_size(ssh_connection, size):
53+
_, stdout, stderr = ssh_connection.execute_command(
54+
"blockdev --getsize64 /dev/vdb"
55+
)
56+
""" The scratch block device is /dev/vdb in the guest. """
57+
assert(stderr.read().decode("utf-8") == '')
58+
assert(stdout.readline().strip() == str(size))

0 commit comments

Comments
 (0)