tests: fix race for invalid metadata files
The microvm.spawn would not always throw a FileNotFoundError,
as the `self._wait_create()` function may succeed before the
mmds data is deserialized (since wait_create polls only for the
API socket).
@@ -390,11 +390,11 @@ def test_start_with_missing_metadata(test_microvm_with_api):
)
test_microvm.metadata_file = vm_metadata_path
- # This will be a FileNotFound on the firecracker socket
- # and not the metadata file
- with pytest.raises(FileNotFoundError):
+ try:
test_microvm.spawn()
-
+ except FileNotFoundError:
+ pass
+ finally:
test_microvm.check_log_message(
"Unable to open or read from the mmds content file"
)
@@ -417,9 +417,11 @@ def test_start_with_invalid_metadata(test_microvm_with_api):
shutil.copy(metadata_file, vm_metadata_path)
test_microvm.metadata_file = vm_metadata_path
- with pytest.raises(FileNotFoundError):
+ try:
test_microvm.spawn()
-
+ except FileNotFoundError:
+ pass
+ finally:
test_microvm.check_log_message(
"MMDS error: metadata provided not valid json"
)
