forked from firecracker-microvm/firecracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cmd_line_parameters.py
More file actions
111 lines (87 loc) · 3.29 KB
/
test_cmd_line_parameters.py
File metadata and controls
111 lines (87 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
"""Tests that ensure the correctness of the command line parameters."""
import subprocess
from pathlib import Path
import pytest
from framework.utils import check_output
from host_tools.fcmetrics import validate_fc_metrics
def test_describe_snapshot(uvm_plain):
"""
Test `--describe-snapshot` correctness for all snapshot versions.
For each release create a snapshot and verify the data version of the
snapshot state file.
"""
vm = uvm_plain
fc_binary = vm.fc_binary_path
cmd = [fc_binary, "--snapshot-version"]
snap_version_tuple = check_output(cmd).stdout.strip().split("\n")[0].split(".")
snap_version = ".".join(str(x) for x in snap_version_tuple)
vm.spawn()
vm.basic_config(track_dirty_pages=True)
vm.start()
snapshot = vm.snapshot_diff()
vm.kill()
cmd = [fc_binary, "--describe-snapshot", snapshot.vmstate]
_, stdout, stderr = check_output(cmd)
assert stderr == ""
assert snap_version in stdout
def test_cli_metrics_path(uvm_plain):
"""
Test --metrics-path parameter
"""
microvm = uvm_plain
metrics_path = Path(microvm.path) / "my_metrics.ndjson"
microvm.spawn(metrics_path=metrics_path)
microvm.basic_config()
microvm.start()
metrics = microvm.flush_metrics()
validate_fc_metrics(metrics)
def test_cli_metrics_path_if_metrics_initialized_twice_fail(uvm_plain):
"""
Given: a running firecracker with metrics configured with the CLI option
When: Configure metrics via API
Then: API returns an error
"""
microvm = uvm_plain
# First configure the µvm metrics with --metrics-path
metrics_path = Path(microvm.path) / "metrics.ndjson"
metrics_path.touch()
microvm.spawn(metrics_path=metrics_path)
# Then try to configure it with PUT /metrics
metrics2_path = Path(microvm.path) / "metrics2.ndjson"
metrics2_path.touch()
# It should fail with because it's already configured
with pytest.raises(RuntimeError, match="Reinitialization of metrics not allowed."):
microvm.api.metrics.put(
metrics_path=microvm.create_jailed_resource(metrics2_path)
)
def test_cli_metrics_if_resume_no_metrics(uvm_plain, microvm_factory):
"""
Check that metrics configuration is not part of the snapshot
"""
# Given: a snapshot of a FC with metrics configured with the CLI option
uvm1 = uvm_plain
metrics_path = Path(uvm1.path) / "metrics.ndjson"
metrics_path.touch()
uvm1.spawn(metrics_path=metrics_path)
uvm1.basic_config()
uvm1.start()
snapshot = uvm1.snapshot_full()
# When: restoring from the snapshot
uvm2 = microvm_factory.build_from_snapshot(snapshot)
# Then: the old metrics configuration does not exist
metrics2 = Path(uvm2.jailer.chroot_path()) / metrics_path.name
assert not metrics2.exists()
def test_cli_no_params(microvm_factory):
"""
Test running firecracker with no parameters should work
"""
fc_binary = microvm_factory.fc_binary_path
process = subprocess.Popen(fc_binary)
try:
process.communicate(timeout=3)
assert process.returncode is None
except subprocess.TimeoutExpired:
# The good case
process.kill()