@@ -285,10 +285,18 @@ def test_api_put_update_post_boot(test_microvm_with_api):
285
285
""" Network interface update is not allowed after boot."""
286
286
assert (not test_microvm .api_session .is_good_response (response .status_code ))
287
287
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 ))
292
300
293
301
294
302
def test_rate_limiters_api_config (test_microvm_with_api ):
@@ -689,3 +697,50 @@ def test_api_unknown_fields(test_microvm_with_api):
689
697
}
690
698
)
691
699
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 ))
0 commit comments